Nemo  2.3.56
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
38using namespace std;
39
41
42public:
43
45 virtual ~MacroCaller(){}
46
47 virtual string call (string) = 0;
48};
51
52public:
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
99protected:
100
102 void add_inputParam (string& param, const string& arg) {_inputParams[param] = arg;}
103
104private:
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
121
122public:
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
135private:
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 > & getParameters()
Definition: paramsparser.h:63
string rexp(const string &argstr)
Definition: paramsparser.cc:1204
map< string, string > get_inputParams()
Definition: paramsparser.h:59
void add_inputParam(string &param, const string &arg)
Definition: paramsparser.h:102
string rlognorm(const string &argstr)
Definition: paramsparser.cc:1339
string getMacroSepParamChar(const string &sep_in, const string macro_name)
Definition: paramsparser.cc:433
string tempseq(const string &argstr)
Definition: paramsparser.cc:669
string replaceMacro(const string &arg)
Macros.
Definition: paramsparser.cc:228
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)
Definition: paramsparser.cc:385
string rnorm(const string &argstr)
Definition: paramsparser.cc:1016
string matrix(const string &argstr)
Definition: paramsparser.cc:735
const char * _sname
Attached file of stream name.
Definition: paramsparser.h:106
string sym_matrix(const string &argstr)
Definition: paramsparser.cc:848
string concat(const string &argstr)
Macro "c" returns a character-delimited string of atomic arguments.
Definition: paramsparser.cc:482
map< string, string(ParamsParser::*)(const string &)> _macroMap
The macro table, mapping call name to caller.
Definition: paramsparser.h:115
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
string parseMacroFunctionBlock(const string &in_arg)
Definition: paramsparser.cc:254
string rbernoul(const string &argstr)
Definition: paramsparser.cc:1145
string seq(const string &argstr)
Definition: paramsparser.cc:607
map< string, vector< string > > & getParsedParameters()
Definition: paramsparser.h:61
string getMacroParamValue(const string &str_in, const string &par_name, const string &macro_name)
Definition: paramsparser.cc:470
static void getArguments(string &arg_str, vector< string > &arg_vect)
Definition: paramsparser.cc:171
string runif(const string &argstr)
Definition: paramsparser.cc:939
string quote(const string &argstr)
Macro "q" returns a quoted string.
Definition: paramsparser.cc:509
static void getBlockArgument(istream &IN, char &c, string &arg)
Definition: paramsparser.cc:205
string callMacro(const string &name, const string &argstr)
Definition: paramsparser.cc:360
virtual ~ParamsParser()
Definition: paramsparser.h:55
string rep(const string &argstr)
Definition: paramsparser.cc:534
map< string, string > _inputParams
The whole, unparsed set of input parameters.
Definition: paramsparser.h:109
string rpoiss(const string &argstr)
Definition: paramsparser.cc:1086
void parse()
Builds the _parsedParams from the _inputParams.
Definition: paramsparser.cc:121
map< string, vector< string > > _parsedParams
The parsed set of simulation parameters after sequential parameters have been separated.
Definition: paramsparser.h:112
string rgamma(const string &argstr)
Definition: paramsparser.cc:1263
string diag_matrix(const string &argstr)
Definition: paramsparser.cc:781
Read parameters from a text buffer.
Definition: paramsparser.h:120
static string readUntilCharacter(istream &IN, int &l_count, const char start_c, const char end_c)
Definition: paramsparser.cc:1660
virtual bool readArguments(istream &IN, int &l_count, string &args)
Definition: paramsparser.cc:1602
static bool removeSpaceAndComment(istream &IN, int &l_count, bool keepLast=false)
Removes whitespace char on a line until a non-ws or EOL is reached.
Definition: paramsparser.cc:1510
static bool removeComment(istream &IN, int &l_count)
Recusively removes comments until the end of a line/of the file, or of a block comment is reached.
Definition: paramsparser.cc:1545
virtual ~StreamParser()
Definition: paramsparser.h:124
StreamParser(const char *stream)
Definition: paramsparser.h:123
void replaceCR(string &stream, const char rpl='\n')
Definition: paramsparser.cc:1717
static void eatLine(istream &IN, int &l_count)
Definition: paramsparser.cc:1708
virtual bool read(const char *stream)
Definition: paramsparser.cc:1408

Generated for Nemo v2.3.56 by  doxygen 1.9.0 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR