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

Generated for Nemo v2.4.2 by  doxygen 1.9.1

Catalogued on GSR