OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
MetaParser.hpp
1 /*
2  * MetaParser.hpp
3  *
4  * Created on: Mar 3, 2019
5  * Author: i-bird
6  */
7 
8 #ifndef METAPARSER_HPP_
9 #define METAPARSER_HPP_
10 
11 #include <algorithm>
12 #include <iostream>
13 #include <iterator>
14 #include <string>
15 #include <vector>
16 
17 #include <boost/bind/bind.hpp>
18 #include <boost/program_options.hpp>
19 #include <boost/tokenizer.hpp>
20 
21 typedef boost::program_options::options_description MetaParser_options;
22 namespace MetaParser_def = boost::program_options;
23 
25 {
26  boost::program_options::options_description desc;
27 
28  boost::program_options::variables_map vm;
29 
30 public:
31 
32  explicit MetaParser(boost::program_options::options_description & desc)
33  :desc(desc)
34  {
35  }
36 
42  bool parse(std::string & opts)
43  {
44  std::istringstream iss(opts);
45 
46  // Parse mocked up input.
47  boost::program_options::store(boost::program_options::parse_config_file(iss,desc), vm);
48  boost::program_options::notify(vm);
49 
50  return true;
51  }
52 
61  template<typename T>
62  bool getOption(std::string opt,T & value)
63  {
64  if (vm.count(opt))
65  {
66  value = vm[opt].as<T>();
67  return true;
68  }
69 
70  return false;
71  }
72 
77  void clear()
78  {
79  vm.clear();
80  }
81 };
82 
83 
84 #endif /* METAPARSER_HPP_ */
void clear()
clear everything you parsed so far
Definition: MetaParser.hpp:77
bool parse(std::string &opts)
Parse the string of options.
Definition: MetaParser.hpp:42
bool getOption(std::string opt, T &value)
Return the option opt in value.
Definition: MetaParser.hpp:62