casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Options.h
Go to the documentation of this file.
1 //# Options.h: base class for storing and parsing parameters
2 //# Copyright (C) 2011
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef DISPLAY_OPTIONS_H__
29 #define DISPLAY_OPTIONS_H__
30 #include <map>
31 #include <set>
32 #include <string>
33 #include <sys/stat.h>
34 
35 namespace casa {
36  namespace viewer {
37 
38  class Options {
39  public:
40  class Kernel {
41  public:
42  virtual std::string tmp( ) const = 0;
43  virtual ~Kernel( ) { }
44  };
45 
46  std::string tmp( ) const {
47  return kernel->tmp( );
48  }
49 
50  // this returns a path to be used as a temporary file or directory, and
51  // by default, deletes the file when the viewer exits... the "base_name"
52  // is just the name to be used as a starting point for finding a unique
53  // file name, an example would be "my_tmp_file"... but it could be
54  // anything (not including directories, i.e. "/")... this function
55  // guarantees that no two returned strings will be identical... and that
56  // all will be valid path names...
57  std::string temporaryPath( const std::string &base_name, bool remove=true ) {
58  return _temporary_path_( base_name, remove );
59  }
60 
61  Options( ) { } /*** initialized by options_init_ ***/
62  ~Options( ) { } /*** finalized by options_init_ ***/
63 
64 
65  private:
66  friend class options_init_;
67  Options( const Options & ) { }
68  const Options &operator=(const Options&) {
69  return *this;
70  }
71  void init( Kernel *k ) {
72  kernel = k;
73  returned_paths = new std::map<std::string,std::pair<std::string,bool> >( );
74  }
75  void finalize( );
76  typedef std::map<std::string,std::pair<std::string,bool> > path_map;
79 
80  std::string _temporary_path_( const std::string &/*base_dir_name*/, bool /*remove*/ );
81  };
82 
83  extern Options options;
84 
85  static class options_init_ {
86  public:
88  if ( count++ == 0 ) do_init( );
89  }
91  if ( --count == 0 ) {
92  options.finalize( );
93  }
94  }
95  private:
96  static unsigned int count;
97  // to be defined in qt (or other windowing library) land....
98  void do_init( );
100  }
101 }
102 
103 #endif
static class casa::viewer::options_init_ _options_init_object_
void do_init()
to be defined in qt (or other windowing library) land....
std::string temporaryPath(const std::string &base_name, bool remove=true)
this returns a path to be used as a temporary file or directory, and by default, deletes the file whe...
Definition: Options.h:57
const Options & operator=(const Options &)
Definition: Options.h:68
path_map * returned_paths
Definition: Options.h:77
Options options
std::map< std::string, std::pair< std::string, bool > > path_map
Definition: Options.h:76
std::string _temporary_path_(const std::string &, bool)
Options(const Options &)
Definition: Options.h:67
static unsigned int count
Definition: Options.h:96
virtual std::string tmp() const =0
std::string tmp() const
Definition: Options.h:46
void init(Kernel *k)
Definition: Options.h:71