casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Options.h
Go to the documentation of this file.
00001 //# Options.h: base class for storing and parsing parameters 
00002 //# Copyright (C) 2011
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id$
00027 
00028 #ifndef DISPLAY_OPTIONS_H__
00029 #define DISPLAY_OPTIONS_H__
00030 #include <map>
00031 #include <set>
00032 #include <string>
00033 #include <sys/stat.h>
00034 
00035 namespace casa {
00036     namespace viewer {
00037 
00038         class Options {
00039             public:
00040                 class Kernel {
00041                     public:
00042                         virtual std::string tmp( ) const = 0;
00043                         virtual ~Kernel( ) { }
00044                 };
00045 
00046                 std::string tmp( ) const { return kernel->tmp( ); }
00047 
00048                 // this returns a path to be used as a temporary file or directory, and
00049                 // by default, deletes the file when the viewer exits... the "base_name"
00050                 // is just the name to be used as a starting point for finding a unique
00051                 // file name, an example would be "my_tmp_file"... but it could be
00052                 // anything (not including directories, i.e. "/")... this function
00053                 // guarantees that no two returned strings will be identical... and that
00054                 // all will be valid path names...
00055                 std::string temporaryPath( const std::string &base_name, bool remove=true )
00056                         { return _temporary_path_( base_name, remove ); }
00057 
00058                 Options( ) { }  /*** initialized by options_init_  ***/
00059                 ~Options( ) { } /*** finalized by options_init_    ***/
00060                 
00061 
00062             private:
00063                 friend class options_init_;
00064                 Options( const Options & ) { }
00065                 const Options &operator=(const Options&) { return *this; }
00066                 void init( Kernel *k ) { kernel = k; returned_paths = new std::map<std::string,std::pair<std::string,bool> >( ); }
00067                 void finalize( );
00068                 typedef std::map<std::string,std::pair<std::string,bool> > path_map;
00069                 path_map *returned_paths;
00070                 Kernel *kernel;
00071 
00072                 std::string _temporary_path_( const std::string &/*base_dir_name*/, bool /*remove*/ );
00073         };
00074 
00075         extern Options options;
00076 
00077         static class options_init_ {
00078             public:
00079                 options_init_( ) { if ( count++ == 0 ) do_init( ); }
00080                 ~options_init_( ) { if ( --count == 0 ) { options.finalize( ); } }
00081             private:
00082                 static unsigned int count;
00083                 // to be defined in qt (or other windowing library) land....
00084                 void do_init( );
00085         } _options_init_object_;
00086     }
00087 }
00088 
00089 #endif