Nemo  2.4.1
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
paramsparser.h
Go to the documentation of this file.
1 
29 #ifndef PARSER_H
30 #define PARSER_H
31 
32 #include <iostream>
33 #include <vector>
34 #include <string>
35 #include <map>
36 
37 using namespace std;
38 
43 #define MACRO_PRESERVE_TAG '\x01'
44 class MacroCaller {
45 
46 public:
47 
49  virtual ~MacroCaller(){}
50 
51  virtual string call (string) = 0;
52 };
54 class ParamsParser {
55 
56 public:
57 
58  ParamsParser(const char* name); // {_sname = name;}
59  virtual ~ParamsParser(){}
60 
61  void setName(const char* name) {_sname = name;}
62 
63  map< string, string > get_inputParams() {return _inputParams;}
64  map< string, vector< string > >& getParsedParameters(const char* stream_name);
65  map< string, vector< string > >& getParsedParameters( ) {return _parsedParams;}
66  map< string, string >& getParameters(const char* stream_name);
67  map< string, string >& getParameters( ) {return _inputParams;}
68 
71  virtual bool read(const char* stream) = 0;
74  void parse();
75  static void getBlockArgument (istream& IN, char& c, string& arg);
76  static void getArguments (string& arg_str, vector< string >& arg_vect);
77 
79  string replaceMacro (const string& arg);
80  string parseMacroFunctionBlock (const string& in_arg);
81  string callMacro (const string& name, const string& argstr);
84  string expandMacros (const string& arg) {return replaceMacro(arg);}
85  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);
86  string getMacroSepParamChar (const string& sep_in, const string macro_name);
87  string getMacroParamValue (const string& str_in, const string& par_name, const string& macro_name);
89  string quote (const string& argstr);
91  string concat (const string& argstr);
92  string rep (const string& argstr);
93  string seq (const string& argstr);
94  string tempseq (const string& argstr);
95  string matrix (const string& argstr);
96  string diag_matrix (const string& argstr);
97  string sym_matrix (const string& argstr);
98  string runif (const string& argstr);
99  string rnorm (const string& argstr);
100  string rpoiss (const string& argstr);
101  string rbernoul (const string& argstr);
102  string rgamma (const string& argstr);
103  string rlognorm (const string& argstr);
104  string rexp (const string& argstr);
105  string sample (const string& argstr);
106  string sort (const string& argstr);
107  string round (const string& argstr);
108  string ceiling (const string& argstr);
109  string floor (const string& argstr);
110 
111 protected:
112 
113  void reset_inputParams() {_inputParams.clear();}
114  void add_inputParam (string& param, const string& arg) {_inputParams[param] = arg;}
115 
116 private:
120  static size_t matchClosingParen (const string& s);
121 
125  static bool containsPreserveMacro (const string& s);
126 
129  bool _hasPreservedMacro = false;
130 
132  const char* _sname;
133 
135  map< string, string > _inputParams;
136 
138  map< string, vector< string > > _parsedParams;
139 
141  map< string, string (ParamsParser::* )(const string& )> _macroMap;
142 
143 };
144 
146 class StreamParser: public ParamsParser {
147 
148 public:
149  StreamParser(const char* stream) : ParamsParser(stream) {}
150  virtual ~StreamParser(){}
151 
152  virtual bool read (const char* stream);
153  static bool removeComment (istream& IN, int& l_count);
154  static bool removeSpaceAndComment (istream& IN, int& l_count, bool keepLast = false);
155  virtual bool readArguments (istream& IN, int& l_count, string& args);
156  static string readUntilCharacter (istream& IN, int& l_count, const char start_c, const char end_c);
157  static void eatLine (istream& IN, int& l_count);
158  void replaceCR (string& stream, const char rpl = '\n');
159 
160 
161 private:
162 
163 };
164 #endif
Definition: paramsparser.h:44
virtual ~MacroCaller()
Definition: paramsparser.h:49
virtual string call(string)=0
Provides interface to read input parameters from various sources and parses them.
Definition: paramsparser.h:54
map< string, string > get_inputParams()
Definition: paramsparser.h:63
void add_inputParam(string &param, const string &arg)
Definition: paramsparser.h:114
const char * _sname
Attached file of stream name.
Definition: paramsparser.h:132
string expandMacros(const string &arg)
Public entry point to expand macros in a string, used to expand macros that were preserved by P() onc...
Definition: paramsparser.h:84
map< string, string > & getParameters()
Definition: paramsparser.h:67
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:61
void reset_inputParams()
Definition: paramsparser.h:113
map< string, vector< string > > & getParsedParameters()
Definition: paramsparser.h:65
virtual ~ParamsParser()
Definition: paramsparser.h:59
map< string, string > _inputParams
The whole, unparsed set of input parameters.
Definition: paramsparser.h:135
map< string, vector< string > > _parsedParams
The parsed set of simulation parameters after sequential parameters have been separated.
Definition: paramsparser.h:138
Read parameters from a text buffer.
Definition: paramsparser.h:146
virtual ~StreamParser()
Definition: paramsparser.h:150
StreamParser(const char *stream)
Definition: paramsparser.h:149

Generated for Nemo v2.4.1 by  doxygen 1.9.1

Catalogued on GSR