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
38class Casarc {
39 friend class CasarcCleanup;
40
41 public:
42 typedef std::map<std::string, std::string>::const_iterator iterator;
43
44 // return default casarc file, e.g. ~/.casarc
45 static Casarc &instance();
46
47 // set and clear the default casarc path (to something other than ~/.casarc)
48 static void setDefaultPath(const std::string &path);
49 static void clearDefaultPath();
50
51 // return a casarc object attached to a particular file
52 static Casarc &instance(const std::string &path);
53
54 // return the list of rcfiles that have been loaded
55 static const std::list<Casarc *> &list();
56
57 // adds the keyword->value mapping
58 void put(const std::string &keyword, const std::string &value);
59
60 // retrieves the mapping for keyword (or "" if the mapping is not defined)
61 std::string get(const std::string &keyword);
62
63 // retrieves the mapping for keyword in value (and returns true if the
64 // mapping is defined or false otherwise)
65 bool get(const std::string &keyword, std::string &value);
66
67 size_t size() const;
68
69 // path to the file that this Casarc mirrors...
70 const std::string &path() const { return filename; }
71
74
75 private:
77 public:
78 meta_entry_(off_t keys_, int keyl_, off_t vals_, int vall_, off_t times_, int timel_)
79 : key_offset_(keys_),
80 key_len_(keyl_),
81 val_offset_(vals_),
82 val_len_(vall_),
83 time_offset_(times_),
84 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();
143};
144
145static class CasarcCleanup {
146 public:
149 if (--creation_count == 0) {
151 }
152 }
153
154 private:
155 static unsigned int creation_count;
157
158} // namespace casacore
159
160#endif
static unsigned int creation_count
Definition Casarc.h:155
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:78
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)
std::map< std::string, std::string > rcmap
Definition Casarc.h:123
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 std::map< std::string, Casarc * > * filenames
Definition Casarc.h:134
static Casarc & instance()
return default casarc file, e.g.
off_t mapped_file_size
Definition Casarc.h:105
iterator begin()
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
static std::list< Casarc * > * rclist
Definition Casarc.h:135
size_t size() const
std::map< std::string, std::string >::const_iterator iterator
Definition Casarc.h:42
static std::string * default_path
Definition Casarc.h:136
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()
iterator end()
void unlock(int fd)
friend class CasarcCleanup
Definition Casarc.h:39
static std::map< ino_t, Casarc * > * rcfiles
singleton Casarcs, (inode->casarc)
Definition Casarc.h:133
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
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
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:70
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
static class casacore::CasarcCleanup local_cleanup_object
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:360