GWOLLUM 4.2.0
Tools for gravitational-wave analyses
Loading...
Searching...
No Matches
IO.h
Go to the documentation of this file.
1
6#ifndef __IO__
7#define __IO__
8
9#include "Monitor.h"
10
11using namespace std;
12
29class IO {
30
31public:
32
43 IO(const char* filepattern);
44
48 virtual ~IO(void);
49
60 void Dump(ostream& out = cout) const;
61
66 inline bool IsZombie(void) const {return !fAllLines.size();}
67
73 friend ostream& operator<<(ostream& out, IO& io);
74
83 template <class T>
84 bool GetOpt(const char* tag, const char* key, vector< T >& values) const;
85
94 template <class T>
95 bool GetOpt(const char* tag, const char* key, T& value) const;
96
105 bool GetOpt(const char* tag, const char* key, string& value) const;
106
117 template <class T>
118 bool GetAllOpt(const char* tag, const char* key, vector< T >& values);
119
130 template <class T>
131 bool GetAllOpt(const char* tag, const char* key, T& value);
132
139 string GetLineData(const char* tag, const char* key) const;
140
147 string GetNextLineData(const char* tag, const char* key);
148
149private:
150
152 vector< pair<string,string> > fAllLines;
153 bool ParseFile(const char* filename);
154 unsigned int fCurline;
155 string fCurkey;
156 string fCurtag;
157 static const unsigned int sLinesize = 2048;
158
159
160};
161
163template <class T>
164bool IO::GetOpt(const char* tag, const char* key, vector< T >& values) const {
166 string data = GetLineData(tag,key);
167
168 istringstream in(data.c_str());
169 while(1) {
170 T tmp;
171 in>>tmp;
172 if(!in) break;
173 values.push_back(tmp);
174 }
175
176 return (bool)values.size();
177}
178
180template <class T>
181bool IO::GetOpt(const char* tag, const char* key, T& value) const{
183 string data = GetLineData(tag,key);
184
185 istringstream in(data.c_str());
186 in>>value;
187 return (!!in)&&data.size();
188}
189
191template <class T>
192bool IO::GetAllOpt(const char* tag, const char* key, vector< T >& values){
194
195 string data;
196 T tmp;
197 while(1) {// loop over lines
198 data=GetNextLineData(tag, key);
199 if(!data.compare("")) break;
200 istringstream inval(data.c_str());
201 while(1) {// loop over values
202 inval>>tmp;
203 if(!inval) break;
204 values.push_back(tmp);
205 }
206 inval.clear();
207 }
208
209 return (bool)values.size();
210}
211
213template <class T>
214bool IO::GetAllOpt(const char* tag, const char* key, T& value){
216 string data = GetNextLineData(tag, key);
217 if(data.empty()) return false;
218
219 istringstream in(data.c_str());
220 in>>value;
221 if(in) {
222 return true;
223 }
224 else {
225 return false;
226 }
227}
228
229
230#endif
Process monitoring.
Parse option files.
Definition IO.h:29
string fCurtag
Current tag.
Definition IO.h:156
bool ParseFile(const char *filename)
File parser.
Definition IO.cc:22
bool GetOpt(const char *tag, const char *key, vector< T > &values) const
Gets an option vector.
Definition IO.h:164
static const unsigned int sLinesize
Maximum number of characters in a line.
Definition IO.h:157
bool IsZombie(void) const
Flags the parsing sequence.
Definition IO.h:66
Monitor * mon
Class monitor.
Definition IO.h:151
bool GetAllOpt(const char *tag, const char *key, vector< T > &values)
Gets a vector of all options.
Definition IO.h:192
unsigned int fCurline
Current line number.
Definition IO.h:154
string fCurkey
Current key.
Definition IO.h:155
void Dump(ostream &out=cout) const
Dumps all options.
Definition IO.cc:77
vector< pair< string, string > > fAllLines
List of lines.
Definition IO.h:152
string GetNextLineData(const char *tag, const char *key)
Returns the next option line defined by a tag and a keyword.
Definition IO.cc:139
virtual ~IO(void)
Destructor of the IO class.
Definition IO.cc:70
string GetLineData(const char *tag, const char *key) const
Returns the option line defined by a tag and a keyword.
Definition IO.cc:109
friend ostream & operator<<(ostream &out, IO &io)
Flux operator wrapper.
Definition IO.cc:84
Monitor a GWOLLUM processing.
Definition Monitor.h:39