Nemo  2.4.0
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 
39 class MacroCaller {
40 
41 public:
42 
44  virtual ~MacroCaller(){}
45 
46  virtual string call (string) = 0;
47 };
49 class ParamsParser {
50 
51 public:
52 
53  ParamsParser(const char* name); // {_sname = name;}
54  virtual ~ParamsParser(){}
55 
56  void setName(const char* name) {_sname = name;}
57 
58  map< string, string > get_inputParams() {return _inputParams;}
59  map< string, vector< string > >& getParsedParameters(const char* stream_name);
60  map< string, vector< string > >& getParsedParameters( ) {return _parsedParams;}
61  map< string, string >& getParameters(const char* stream_name);
62  map< string, string >& getParameters( ) {return _inputParams;}
63 
66  virtual bool read(const char* stream) = 0;
69  void parse();
70  static void getBlockArgument (istream& IN, char& c, string& arg);
71  static void getArguments (string& arg_str, vector< string >& arg_vect);
72 
74  string replaceMacro (const string& arg);
75  string parseMacroFunctionBlock (const string& in_arg);
76  string callMacro (const string& name, const string& argstr);
77  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);
78  string getMacroSepParamChar (const string& sep_in, const string macro_name);
79  string getMacroParamValue (const string& str_in, const string& par_name, const string& macro_name);
81  string quote (const string& argstr);
83  string concat (const string& argstr);
84  string rep (const string& argstr);
85  string seq (const string& argstr);
86  string tempseq (const string& argstr);
87  string matrix (const string& argstr);
88  string diag_matrix (const string& argstr);
89  string sym_matrix (const string& argstr);
90  string runif (const string& argstr);
91  string rnorm (const string& argstr);
92  string rpoiss (const string& argstr);
93  string rbernoul (const string& argstr);
94  string rgamma (const string& argstr);
95  string rlognorm (const string& argstr);
96  string rexp (const string& argstr);
97 
98 protected:
99 
100  void reset_inputParams() {_inputParams.clear();}
101  void add_inputParam (string& param, const string& arg) {_inputParams[param] = arg;}
102 
103 private:
105  const char* _sname;
106 
108  map< string, string > _inputParams;
109 
111  map< string, vector< string > > _parsedParams;
112 
114  map< string, string (ParamsParser::* )(const string& )> _macroMap;
115 
116 };
117 
119 class StreamParser: public ParamsParser {
120 
121 public:
122  StreamParser(const char* stream) : ParamsParser(stream) {}
123  virtual ~StreamParser(){}
124 
125  virtual bool read (const char* stream);
126  static bool removeComment (istream& IN, int& l_count);
127  static bool removeSpaceAndComment (istream& IN, int& l_count, bool keepLast = false);
128  virtual bool readArguments (istream& IN, int& l_count, string& args);
129  static string readUntilCharacter (istream& IN, int& l_count, const char start_c, const char end_c);
130  static void eatLine (istream& IN, int& l_count);
131  void replaceCR (string& stream, const char rpl = '\n');
132 
133 
134 private:
135 
136 };
137 #endif
Definition: paramsparser.h:39
virtual ~MacroCaller()
Definition: paramsparser.h:44
virtual string call(string)=0
Provides interface to read input parameters from various sources and parses them.
Definition: paramsparser.h:49
map< string, string > get_inputParams()
Definition: paramsparser.h:58
void add_inputParam(string &param, const string &arg)
Definition: paramsparser.h:101
const char * _sname
Attached file of stream name.
Definition: paramsparser.h:105
map< string, string > & getParameters()
Definition: paramsparser.h:62
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:56
void reset_inputParams()
Definition: paramsparser.h:100
map< string, vector< string > > & getParsedParameters()
Definition: paramsparser.h:60
virtual ~ParamsParser()
Definition: paramsparser.h:54
map< string, string > _inputParams
The whole, unparsed set of input parameters.
Definition: paramsparser.h:108
map< string, vector< string > > _parsedParams
The parsed set of simulation parameters after sequential parameters have been separated.
Definition: paramsparser.h:111
Read parameters from a text buffer.
Definition: paramsparser.h:119
virtual ~StreamParser()
Definition: paramsparser.h:123
StreamParser(const char *stream)
Definition: paramsparser.h:122

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

Locations of visitors to this page
Catalogued on GSR