39 #include <drain/RegExp.h>
55 template <
class K,
class V>
67 MapReader() : limited(false), m(defaultMap) {};
69 MapReader(std::map<K,V> &target) : limited(false), m(&target) {
89 virtual ~MapReader(){};
91 void setMap(std::map<K,V> &target){
97 configLineParser.setExpression(std::string(
"^[ \t]*(")+regExp+
")[ \t]*(=(.*))?$");
98 commandLineParser.setExpression(std::string(
"^\\-\\-?(")+regExp+
")(=(.*))?$");
104 void trim(std::string &s){
105 std::string::size_type pos1 = s.find_first_not_of(
trimChars);
106 std::string::size_type pos2 = s.find_last_not_of(
trimChars);
107 if (pos1 != std::string::npos)
108 s = s.substr(pos1,pos2-pos1 + 1);
125 void read(
const std::string &filename){
127 ifstr.open(filename.c_str());
135 void read(std::istream &istr = std::cin){
137 while (getline(istr,line)){
157 void readPendingCommandLineArgument(
const std::string &s){
161 argumentRegistered =
true;
172 const std::vector<std::string> &result = regExp.
result;
188 if (!result.empty()){
199 if (!result[2].empty()){
203 argumentRegistered =
true;
207 argumentRegistered =
false;
214 argumentRegistered =
true;
225 void read(
int argc,
char **argv){
226 for (
int i = 1; i < argc; ++i) {
234 inline const std::string &getKey(){
return key;};
235 inline const std::string &getValue(){
return value;};
238 inline bool hasArgument(){
return argumentRegistered;};
242 std::map<K,V> defaultMap;
254 bool argumentRegistered;
General utility for reading text entries of type KEY=VALUE into a map.
Definition: MapReader.h:57
void read(std::istream &istr=std::cin)
Definition: MapReader.h:135
void readConfigEntry(const std::string &line)
Definition: MapReader.h:146
void readEntry(const std::string &line, drain::RegExp ®Exp)
Definition: MapReader.h:168
void setKeySyntax(const std::string ®Exp)
Defines the std::strings recognized (accepted) as keys. By default: [a-zA-Z][a-zA-Z0-9_\....
Definition: MapReader.h:96
std::string trimChars
Leading and trailing characters to be pruned.
Definition: MapReader.h:61
void read(const std::string &filename)
Definition: MapReader.h:125
void readCommandLineEntry(const std::string &s)
Definition: MapReader.h:153
void read(int argc, char **argv)
Definition: MapReader.h:225
const std::vector< std::string > & result
Public interface for the result.
Definition: RegExp.h:107
int execute(const std::string &str, T &result) const
Apply regexp matching in a string. Returns 0 on success, REG_NOMATCH on failure.
Definition: RegExp.h:187
Definition: DataSelector.cpp:1277