Nemo  2.4.0b
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
paramsparser.h
Go to the documentation of this file.
1 
30 #ifndef PARSER_H
31 #define PARSER_H
32 
33 #include <iostream>
34 #include <vector>
35 #include <string>
36 #include <map>
37 
38 using namespace std;
39 
40 class MacroCaller {
41 
42 public:
43 
45  virtual ~MacroCaller(){}
46 
47  virtual string call (string) = 0;
48 };
50 class ParamsParser {
51 
52 public:
53 
54  ParamsParser(const char* name); // {_sname = name;}
55  virtual ~ParamsParser(){}
56 
57  void setName(const char* name) {_sname = name;}
58 
59  map< string, string > get_inputParams() {return _inputParams;}
60  map< string, vector< string > >& getParsedParameters(const char* stream_name);
61  map< string, vector< string > >& getParsedParameters( ) {return _parsedParams;}
62  map< string, string >& getParameters(const char* stream_name);
63  map< string, string >& getParameters( ) {return _inputParams;}
64 
67  virtual bool read(const char* stream) = 0;
70  void parse();
71  static void getBlockArgument (istream& IN, char& c, string& arg);
72  static void getArguments (string& arg_str, vector< string >& arg_vect);
73 
75  string replaceMacro (const string& arg);
76  string parseMacroFunctionBlock (const string& in_arg);
77  string callMacro (const string& name, const string& argstr);
78  vector<string> getMacroArgs (const string& args, const int min_arg, const size_t max_arg, const string macro_name, const string syntax, bool lastArgIsSeparatorChar = true);
79  string getMacroSepParamChar (const string& sep_in, const string macro_name);
80  string getMacroParamValue (const string& str_in, const string& par_name, const string& macro_name);
82  string quote (const string& argstr);
84  string concat (const string& argstr);
85  string rep (const string& argstr);
86  string seq (const string& argstr);
87  string tempseq (const string& argstr);
88  string matrix (const string& argstr);
89  string diag_matrix (const string& argstr);
90  string sym_matrix (const string& argstr);
91  string runif (const string& argstr);
92  string rnorm (const string& argstr);
93  string rpoiss (const string& argstr);
94  string rbernoul (const string& argstr);
95  string rgamma (const string& argstr);
96  string rlognorm (const string& argstr);
97  string rexp (const string& argstr);
98 
99 protected:
100 
101  void reset_inputParams() {_inputParams.clear();}
102  void add_inputParam (string& param, const string& arg) {_inputParams[param] = arg;}
103 
104 private:
106  const char* _sname;
107 
109  map< string, string > _inputParams;
110 
112  map< string, vector< string > > _parsedParams;
113 
115  map< string, string (ParamsParser::* )(const string& )> _macroMap;
116 
117 };
118 
120 class StreamParser: public ParamsParser {
121 
122 public:
123  StreamParser(const char* stream) : ParamsParser(stream) {}
124  virtual ~StreamParser(){}
125 
126  virtual bool read (const char* stream);
127  static bool removeComment (istream& IN, int& l_count);
128  static bool removeSpaceAndComment (istream& IN, int& l_count, bool keepLast = false);
129  virtual bool readArguments (istream& IN, int& l_count, string& args);
130  static string readUntilCharacter (istream& IN, int& l_count, const char start_c, const char end_c);
131  static void eatLine (istream& IN, int& l_count);
132  void replaceCR (string& stream, const char rpl = '\n');
133 
134 
135 private:
136 
137 };
138 #endif
Definition: paramsparser.h:40
virtual ~MacroCaller()
Definition: paramsparser.h:45
virtual string call(string)=0
Provides interface to read input parameters from various sources and parses them.
Definition: paramsparser.h:50
map< string, string > get_inputParams()
Definition: paramsparser.h:59
void add_inputParam(string &param, const string &arg)
Definition: paramsparser.h:102
const char * _sname
Attached file of stream name.
Definition: paramsparser.h:106
map< string, string > & getParameters()
Definition: paramsparser.h:63
virtual bool read(const char *stream)=0
Read/parse params & args from a file or a string or an R object.
void setName(const char *name)
Definition: paramsparser.h:57
void reset_inputParams()
Definition: paramsparser.h:101
map< string, vector< string > > & getParsedParameters()
Definition: paramsparser.h:61
virtual ~ParamsParser()
Definition: paramsparser.h:55
map< string, string > _inputParams
The whole, unparsed set of input parameters.
Definition: paramsparser.h:109
map< string, vector< string > > _parsedParams
The parsed set of simulation parameters after sequential parameters have been separated.
Definition: paramsparser.h:112
Read parameters from a text buffer.
Definition: paramsparser.h:120
virtual ~StreamParser()
Definition: paramsparser.h:124
StreamParser(const char *stream)
Definition: paramsparser.h:123

Generated for Nemo v2.4.0b by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR