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 {
00047                                 return kernel->tmp( );
00048                         }
00049 
00050                         // this returns a path to be used as a temporary file or directory, and
00051                         // by default, deletes the file when the viewer exits... the "base_name"
00052                         // is just the name to be used as a starting point for finding a unique
00053                         // file name, an example would be "my_tmp_file"... but it could be
00054                         // anything (not including directories, i.e. "/")... this function
00055                         // guarantees that no two returned strings will be identical... and that
00056                         // all will be valid path names...
00057                         std::string temporaryPath( const std::string &base_name, bool remove=true ) {
00058                                 return _temporary_path_( base_name, remove );
00059                         }
00060 
00061                         Options( ) { }  /*** initialized by options_init_  ***/
00062                         ~Options( ) { } /*** finalized by options_init_    ***/
00063 
00064 
00065                 private:
00066                         friend class options_init_;
00067                         Options( const Options & ) { }
00068                         const Options &operator=(const Options&) {
00069                                 return *this;
00070                         }
00071                         void init( Kernel *k ) {
00072                                 kernel = k;
00073                                 returned_paths = new std::map<std::string,std::pair<std::string,bool> >( );
00074                         }
00075                         void finalize( );
00076                         typedef std::map<std::string,std::pair<std::string,bool> > path_map;
00077                         path_map *returned_paths;
00078                         Kernel *kernel;
00079 
00080                         std::string _temporary_path_( const std::string &/*base_dir_name*/, bool /*remove*/ );
00081                 };
00082 
00083                 extern Options options;
00084 
00085                 static class options_init_ {
00086                 public:
00087                         options_init_( ) {
00088                                 if ( count++ == 0 ) do_init( );
00089                         }
00090                         ~options_init_( ) {
00091                                 if ( --count == 0 ) {
00092                                         options.finalize( );
00093                                 }
00094                         }
00095                 private:
00096                         static unsigned int count;
00097                         // to be defined in qt (or other windowing library) land....
00098                         void do_init( );
00099                 } _options_init_object_;
00100         }
00101 }
00102 
00103 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1