casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Casarc.h
Go to the documentation of this file.
1 //# Casarc.h: Class to read the casa general resource files
2 //# Copyright (C) 2009
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 CASA_CASARC_H
29 #define CASA_CASARC_H
30 
31 #include <casacore/casa/aips.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <string>
35 #include <list>
36 #include <map>
37 
38 namespace casacore { //# NAMESPACE CASACORE - BEGIN
39 
40  class Casarc {
41 
42  friend class CasarcCleanup;
43 
44  public:
45 
47 
48  // return default casarc file, e.g. ~/.casarc
49  static Casarc &instance( );
50 
51  // set and clear the default casarc path (to something other than ~/.casarc)
52  static void setDefaultPath( const std::string &path );
53  static void clearDefaultPath( );
54 
55  // return a casarc object attached to a particular file
56  static Casarc &instance( const std::string &path );
57 
58  // return the list of rcfiles that have been loaded
59  static const std::list<Casarc*> & list( );
60 
61  // adds the keyword->value mapping
62  void put( const std::string &keyword, const std::string &value );
63 
64  // retrieves the mapping for keyword (or "" if the mapping is not defined)
65  std::string get( const std::string &keyword );
66 
67  // retrieves the mapping for keyword in value (and returns true if the
68  // mapping is defined or false otherwise)
69  bool get( const std::string &keyword, std::string &value );
70 
71  size_t size( ) const;
72 
73  // path to the file that this Casarc mirrors...
74  const std::string &path( ) const { return filename; }
75 
76  iterator begin( );
77  iterator end( );
78 
79  private:
80 
81  class meta_entry_ {
82  public:
83  meta_entry_( off_t keys_, int keyl_, off_t vals_, int vall_, off_t times_, int timel_ ) :
84  key_offset_(keys_), key_len_(keyl_),
85  val_offset_(vals_), val_len_(vall_),
86  time_offset_(times_), time_len_(timel_) { }
87 
88  off_t key_offset( ) const { return key_offset_; }
89  int key_length( ) const { return key_len_; }
90 
91  off_t value_offset( ) const { return val_offset_; }
92  int value_length( ) const { return val_len_; }
93 
94  off_t time_offset( ) const { return time_offset_; }
95  int time_length( ) const { return time_len_; }
96 
97  private:
98  off_t key_offset_;
99  int key_len_;
100  off_t val_offset_;
101  int val_len_;
104  };
105 
106  char *mapped_file;
108 
109  std::list<int> stale_fds;
110  void close( int );
111 
112  std::list<pid_t> have_lock;
113 
115  // returns a file descriptor or -1 on error...
116  int lock( lock_mode mode );
117  void unlock( int fd );
118 
119  void sync( );
120  double current_modification_time( struct stat &buf );
121 
122  std::string filename;
123  double timestamp;
124 
125  std::map<std::string,std::string> rcmap;
126  // this is broken off separate from the rcmap to allow the
127  // rcmap to be used for iteration by users of this class...
128  std::map<std::string,meta_entry_> rcmetamap;
129 
130  void read_file( );
131 
132  ino_t inode;
133 
134  // singleton Casarcs, (inode->casarc)
135  static std::map<ino_t,Casarc*> *rcfiles;
136  static std::map<std::string,Casarc*> *filenames;
137  static std::list<Casarc*> *rclist;
138  static std::string *default_path;
139  // path is the path to the .casarc (or .aipsrc file)
140  Casarc( const std::string &path );
141  static bool initialized;
142  static void startup( );
143  static void shutdown( );
144  ~Casarc( ) { }
145  };
146 
147  static class CasarcCleanup {
148  public:
150  ~CasarcCleanup( ) { if ( --creation_count == 0 ) { Casarc::shutdown( ); } }
151  private:
152  static unsigned int creation_count;
154 
155 } //# NAMESPACE CASACORE - END
156 
157 #endif
static void shutdown()
off_t key_offset_
Definition: Casarc.h:98
static void startup()
off_t mapped_file_size
Definition: Casarc.h:107
Elements::const_iterator const_iterator
iterator end()
off_t time_offset() const
Definition: Casarc.h:94
meta_entry_(off_t keys_, int keyl_, off_t vals_, int vall_, off_t times_, int timel_)
Definition: Casarc.h:83
off_t value_offset() const
Definition: Casarc.h:91
double current_modification_time(struct stat &buf)
int time_len_
Definition: Casarc.h:103
static unsigned int creation_count
Definition: Casarc.h:152
void put(const std::string &keyword, const std::string &value)
adds the keyword-&gt;value mapping
Casarc(const std::string &path)
path is the path to the.casarc (or.aipsrc file)
int time_length() const
Definition: Casarc.h:95
std::string filename
Definition: Casarc.h:122
static void setDefaultPath(const std::string &path)
set and clear the default casarc path (to something other than ~/.casarc)
std::map< std::string, meta_entry_ > rcmetamap
this is broken off separate from the rcmap to allow the rcmap to be used for iteration by users of th...
Definition: Casarc.h:128
static const std::list< Casarc * > & list()
return the list of rcfiles that have been loaded
char * mapped_file
Definition: Casarc.h:106
int val_len_
Definition: Casarc.h:101
double timestamp
Definition: Casarc.h:123
static bool initialized
Definition: Casarc.h:141
int key_len_
Definition: Casarc.h:99
static std::list< Casarc * > * rclist
Definition: Casarc.h:137
off_t val_offset_
Definition: Casarc.h:100
std::map< std::string, std::string >::const_iterator iterator
Definition: Casarc.h:46
int value_length() const
Definition: Casarc.h:92
std::map< std::string, std::string > rcmap
Definition: Casarc.h:125
std::list< int > stale_fds
Definition: Casarc.h:109
int key_length() const
Definition: Casarc.h:89
static std::map< std::string, Casarc * > * filenames
Definition: Casarc.h:136
std::list< pid_t > have_lock
Definition: Casarc.h:112
static class casacore::CasarcCleanup local_cleanup_object
const std::string & path() const
path to the file that this Casarc mirrors...
Definition: Casarc.h:74
static std::string * default_path
Definition: Casarc.h:138
off_t time_offset_
Definition: Casarc.h:102
void unlock(int fd)
iterator begin()
static void clearDefaultPath()
off_t key_offset() const
Definition: Casarc.h:88
static Casarc & instance()
return default casarc file, e.g.
static std::map< ino_t, Casarc * > * rcfiles
singleton Casarcs, (inode-&gt;casarc)
Definition: Casarc.h:135
Definition: Casarc.h:81
size_t size() const
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
int lock(lock_mode mode)
returns a file descriptor or -1 on error...
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42