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
21typedef boost::program_options::options_description MetaParser_options;
22namespace MetaParser_def = boost::program_options;
23
24class MetaParser
25{
26 boost::program_options::options_description desc;
27
28 boost::program_options::variables_map vm;
29
30public:
31
32 explicit MetaParser(boost::program_options::options_description & desc)
33 :desc(desc)
34 {
35 }
36
37 /*! \brief Parse the string of options
38 *
39 * \param string of options
40 *
41 */
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
53 /*! \brief Return the option opt in value
54 *
55 * \param opt option to check
56 * \param value where to store the value of the option
57 *
58 * \return true if the option has been set
59 *
60 */
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
73 /*! \brief clear everything you parsed so far
74 *
75 *
76 */
77 void clear()
78 {
79 vm.clear();
80 }
81};
82
83
84#endif /* METAPARSER_HPP_ */
85