Class documentation of Concepts

Loading...
Searching...
No Matches
inputOutput.hh
Go to the documentation of this file.
1
6#ifndef inputOutput_hh
7#define inputOutput_hh
8
9#include <iostream>
10#include <string>
11#include <cstring>
12#include <map>
13#include <complex>
14#include <limits.h>
15
16#include "basics/exceptions.hh"
18#include "toolbox/multiArray.hh"
19
20namespace concepts {
21
22 // ****************************************************** MissingParameter **
23
30 public:
34 MissingParameter(const std::string& parameter) throw();
35 protected:
36 virtual std::ostream& info(std::ostream& os) const throw();
37 };
38
39 // ******************************************************* InOutParameters **
40
41 struct ltstr {
42 bool operator()(const char* s1, const char* s2) const {
43 return std::strcmp(s1, s2) < 0;
44 }
45 };
46
47 struct ltidx {
48 bool operator()(const MultiIndex<2>& i1, const MultiIndex<2>& i2) const {
49 return (i1[0] < i2[0]) || (i1[0] == i2[0] && i1[1] < i2[1]);
50 }
51 };
52
75 class InOutParameters : public virtual OutputOperator {
76 public:
81 virtual ~InOutParameters();
86 void append(const InOutParameters& inout, bool arrayAppend = true);
87
89 void addDouble(const char* name, const double value);
91 void addComplex(const char* name, const std::complex<double> value);
93 void addString(const char* name, const char* value);
95 void addInt(const char* name, const int value);
97 void addBool(const char* name, const int value);
98
100 double getDouble(const char* name) const;
105 double getDouble(const char* name, const double value) const;
107 std::complex<double> getComplex(const char* name) const;
112 std::string getString(const char* name, const char* value = 0) const;
117 int getInt(const char* name, const int value = INT_MAX) const;
119 bool getBool(const char* name) const;
124 bool getBool(const char* name, const bool value) const;
125
130 void addArrayDouble(const char* array, const bool newArray = false);
135 void addArrayComplex(const char* array, const bool newArray = false);
140 void addArrayString(const char* array, const bool newArray = false);
145 void addArrayInt(const char* array, const bool newArray = false);
150 void addArrayBool(const char* array, const bool newArray = false);
151
160 void addArrayDouble(const char* array, const int number,
161 const double value);
170 void addArrayComplex(const char* array, const int number,
171 const std::complex<double> value);
180 void addArrayString(const char* array, const int number,
181 const char* value);
190 void addArrayInt(const char* array, const int number, const int value);
199 void addArrayBool(const char* array, const int number, const int value);
200
206 double getArrayDouble(const char* array, const int number) const;
212 std::complex<double> getArrayComplex(const char* array,
213 const int number) const;
219 std::string getArrayString(const char* array, const int number) const;
225 int getArrayInt(const char* array, const int number) const;
231 bool getArrayBool(const char* array, const int number) const;
232
236 const std::map<int, double>& getMapDouble(const char* array) const;
240 const std::map<int, std::complex<double> >&
241 getMapComplex(const char* array) const;
245 const std::map<int, std::string>& getMapString(const char* array) const;
249 const std::map<int, int>& getMapInt(const char* array) const;
253 const std::map<int, bool>& getMapBool(const char* array) const;
254
255
260 void addMatrixDouble(const char* array, const bool newMatrix = false);
265 void addMatrixInt(const char* array, const bool newMatrix = false);
266
276 void addMatrixDouble(const char* matrix, const int i, const int j,
277 const double value);
287 void addMatrixInt(const char* matrix, const int i, const int j,
288 const int value);
289
296 double getMatrixDouble(const char* array, const int i, const int j) const;
303 int getMatrixInt(const char* array, const int i, const int j) const;
304
305
307 void clear();
312 void storeMatlab(const char* filename,
313 const std::string description = "") const;
319 std::ostream& storeMatlab(std::ostream& os, const char* name,
320 const std::string description = "") const;
321 protected:
322 virtual std::ostream& info(std::ostream& os) const;
323 private:
325 std::map<const char*, double, ltstr> double_;
327 std::map<const char*, std::complex<double>, ltstr> complex_;
329 std::map<const char*, std::string, ltstr> string_;
331 std::map<const char*, int, ltstr> int_;
333 std::map<const char*, bool, ltstr> bool_;
334
336 std::map<const char*, std::map<int, double>*, ltstr> doubleArrays_;
338 std::map
339 <const char*, std::map<int, std::complex<double> >*, ltstr> complexArrays_;
341 std::map<const char*, std::map<int, std::string>*, ltstr> stringArrays_;
343 std::map<const char*, std::map<int, int>*, ltstr> intArrays_;
345 std::map<const char*, std::map<int, bool>*, ltstr> boolArrays_;
346
348 std::map<const char*,
349 std::map<MultiIndex<2>, double, ltidx>*, ltstr> doubleMatrices_;
351 std::map<const char*,
352 std::map<MultiIndex<2>, int, ltidx>*, ltstr> intMatrices_;
353
355 template<class F>
356 void mapOutputMatlab_(std::ostream& os,
357 const std::map<const char*, F, ltstr>& map) const;
359 template<class F>
360 void mapArrayOutputMatlab_(std::ostream& os, const std::map
361 <const char*, std::map<int, F>*, ltstr> & map,
362 const std::string brackets = "[]") const;
364 template<class F>
365 void mapMatrixOutputMatlab_
366 (std::ostream& os, const std::map
367 <const char*, std::map<MultiIndex<2>, F, ltidx>*, ltstr> & map,
368 const std::string brackets = "[]") const;
369
371 template<class F>
372 void add_(std::map<const char*, F, ltstr>& map, const char* name,
373 const F value);
374
375 template<class F>
376 F get_(const std::map<const char*, F, ltstr>& map, const char* name) const;
377
378 template<class F, class G, class H>
379 void addArray_(std::map<const char*, std::map<F, G, H>*, ltstr>& map,
380 const char* array, const bool newArray = false);
381
382 template<class F, class G, class H>
383 void addArray_(std::map<const char*, std::map<F, G, H>*, ltstr>& map,
384 const char* array, const F number, const G value);
385
386 template<class F, class G, class H>
387 G getArray_(const std::map<const char*, std::map<F, G, H>*, ltstr>& map,
388 const char* array, const F number) const;
389
390 template<class F>
391 const std::map<int, F>&
392 getMap_(const std::map<const char*, std::map<int, F>*, ltstr>& map,
393 const char* array) const;
394
396 template<class F>
397 void clear_(std::map<const char*, F, ltstr>& map);
398
399 template<class F, class G>
400 void clear_(std::map<const char*, std::map<G, F>*, ltstr>& map);
401 };
402
403 // *********************************************************** InputParser **
404
443 class InputParser : public virtual OutputOperator {
444 public:
451 InputParser(bool quiet = false);
452
453 virtual ~InputParser();
454
456 void parse();
458 void parse(std::string file);
459
461 InOutParameters& inputParameters() { return input_; }
462
464 InOutParameters& outputParameters() { return output_; }
465
468 protected:
469 virtual std::ostream& info(std::ostream& os) const;
470 private:
472 YY_BUFFER_STATE current_buffer_;
473
475 InOutParameters input_;
476
478 InOutParameters output_;
479
481 bool quiet_;
482 };
483
484} // namespace
485
486#endif // inputOutput_hh
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
void addArrayBool(const char *array, const bool newArray=false)
double getDouble(const char *name) const
Returns a double from the hash of doubles.
void addArrayInt(const char *array, const int number, const int value)
bool getBool(const char *name, const bool value) const
void append(const InOutParameters &inout, bool arrayAppend=true)
void addMatrixInt(const char *array, const bool newMatrix=false)
void addMatrixDouble(const char *matrix, const int i, const int j, const double value)
InOutParameters(const InOutParameters &i)
Copy constructor.
void addInt(const char *name, const int value)
Adds an int to the hash of ints.
const std::map< int, std::string > & getMapString(const char *array) const
void addArrayDouble(const char *array, const bool newArray=false)
void addMatrixInt(const char *matrix, const int i, const int j, const int value)
std::ostream & storeMatlab(std::ostream &os, const char *name, const std::string description="") const
std::complex< double > getComplex(const char *name) const
Returns a complex double from the hash of doubles.
int getMatrixInt(const char *array, const int i, const int j) const
void addArrayBool(const char *array, const int number, const int value)
int getInt(const char *name, const int value=INT_MAX) const
void addBool(const char *name, const int value)
Adds a bool to the hash of bools.
std::complex< double > getArrayComplex(const char *array, const int number) const
void addString(const char *name, const char *value)
Adds a string to the hash of strings.
void addArrayDouble(const char *array, const int number, const double value)
double getMatrixDouble(const char *array, const int i, const int j) const
std::string getString(const char *name, const char *value=0) const
void addComplex(const char *name, const std::complex< double > value)
Adds a complex double to the hash of doubles.
double getDouble(const char *name, const double value) const
bool getArrayBool(const char *array, const int number) const
const std::map< int, double > & getMapDouble(const char *array) const
const std::map< int, int > & getMapInt(const char *array) const
void clear()
clears the object
void addMatrixDouble(const char *array, const bool newMatrix=false)
void addArrayComplex(const char *array, const int number, const std::complex< double > value)
const std::map< int, bool > & getMapBool(const char *array) const
int getArrayInt(const char *array, const int number) const
void storeMatlab(const char *filename, const std::string description="") const
void addDouble(const char *name, const double value)
Adds a double to the hash of doubles.
void addArrayString(const char *array, const bool newArray=false)
void addArrayComplex(const char *array, const bool newArray=false)
double getArrayDouble(const char *array, const int number) const
void addArrayInt(const char *array, const bool newArray=false)
bool getBool(const char *name) const
Returns a bool from the hash of bools.
std::string getArrayString(const char *array, const int number) const
InOutParameters()
Constructor.
void addArrayString(const char *array, const int number, const char *value)
const std::map< int, std::complex< double > > & getMapComplex(const char *array) const
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
void parse(std::string file)
Parses the input file.
InputParser(bool quiet=false)
InOutParameters & inputParameters()
Returns the input data.
void parse()
Parses the input file.
InOutParameters & outputParameters()
Returns the output data.
struct yy_buffer_state * YY_BUFFER_STATE
The buffer representing the input file (for the parser)
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
MissingParameter(const std::string &parameter)
Set< F > makeSet(uint n, const F &first,...)
Definition set.hh:320