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