11#ifndef _PFASST__CONFIG_HPP_
22#define _PFASST__CONFIG_HPP_
33
4- #include < algorithm>
5- #include < cassert>
6- #include < exception>
74#include < fstream>
8- #include < functional>
9- #include < iostream>
10- #include < sstream>
115#include < string>
126#include < map>
137using namespace std ;
148
159#include < boost/program_options.hpp>
1610namespace po = boost::program_options;
1711
12+
1813namespace pfasst
1914{
20-
2115 namespace config
2216 {
2317 /* *
@@ -36,103 +30,35 @@ namespace pfasst
3630 vector<string> unrecognized_args;
3731 bool initialized = false ;
3832
39- options () {}
33+ options ();
4034 options (const options&) = delete ;
4135 void operator =(const options&) = delete ;
4236
4337 public:
44- static options& get_instance ()
45- {
46- static options instance;
47- return instance;
48- }
49-
50- po::variables_map& get_variables_map ()
51- {
52- return this ->variables_map ;
53- }
54-
55- po::options_description& get_all_options ()
56- {
57- return this ->all_options ;
58- }
59-
60- vector<string>& get_unrecognized_args ()
61- {
62- return this ->unrecognized_args ;
63- }
64-
65- static void add_option (string group, string option, string help)
66- {
67- auto & opts = get_instance ();
68- opts.option_groups .emplace (make_pair<string,
69- po::options_description>(string (group),
70- po::options_description (string (group), LINE_WIDTH)));
71- opts.option_groups [group].add_options ()
72- (option.c_str (), help.c_str ());
73- }
38+ static options& get_instance ();
39+ po::variables_map& get_variables_map ();
40+ po::options_description& get_all_options ();
41+ vector<string>& get_unrecognized_args ();
42+ static void add_option (const string& group, const string& option, const string& help);
7443
7544 template <typename T>
76- static void add_option (string group, string option, string help)
77- {
78- auto & opts = get_instance ();
79-
80- opts.option_groups .emplace (make_pair<string,
81- po::options_description>(string (group),
82- po::options_description (string (group), LINE_WIDTH)));
83- opts.option_groups [group].add_options ()
84- (option.c_str (), po::value<T>(), help.c_str ());
85- }
86-
87- void init ()
88- {
89- if (!this ->initialized ) {
90- for (auto const & kv : this ->option_groups ) {
91- this ->all_options .add (kv.second );
92- }
93- }
94- this ->initialized = true ;
95- }
45+ static void add_option (const string& group, const string& option, const string& help);
9646
47+ void init ();
9748 };
9849
9950 template <typename T>
100- inline static T get_value (const string& name, const T& default_val)
101- {
102- return options::get_instance ().get_variables_map ().count (name)
103- ? options::get_instance ().get_variables_map ()[name].as <T>() : default_val;
104- }
51+ static T get_value (const string& name, const T& default_val);
10552
10653 template <typename T>
107- inline static T get_value (const string& name)
108- {
109- return options::get_instance ().get_variables_map ()[name].as <T>();
110- }
54+ static T get_value (const string& name);
11155
11256 /* *
11357 * @returns empty string if params are set and `if_no_params` is `true`
11458 */
115- inline static string print_help (bool if_no_params = false )
116- {
117- bool no_params_given = options::get_instance ().get_variables_map ().empty ();
118-
119- if (!if_no_params || (if_no_params && no_params_given)) {
120- stringstream s;
121- s << options::get_instance ().get_all_options () << endl;
122- s << " Logging options:" << endl
123- << " -v [ --verbose ] activates maximum verbosity" << endl
124- << " --v=arg activates verbosity upto verbose level 2" << endl
125- << " (valid range: 0-9)" << endl
126- << " -vmodule=arg actives verbose logging for specific module" << endl
127- << " (see [1] for details)" << endl;
128- s << " [1]: https://github.com/easylogging/easyloggingpp#vmodule" << endl;
129- return s.str ();
130- } else {
131- return string ();
132- }
133- }
59+ static string print_help (bool if_no_params = false );
13460
135- inline static void read_commandline (int argc, char * argv[], bool exit_on_help = true )
61+ static inline void read_commandline (int argc, char * argv[], bool exit_on_help = true )
13662 {
13763 po::parsed_options parsed = po::command_line_parser (argc, argv)
13864 .options (options::get_instance ().get_all_options ())
@@ -151,7 +77,7 @@ namespace pfasst
15177 /* *
15278 * @throws invalid_argument if the given file could not be opened
15379 */
154- inline static void read_config_file (string file_name)
80+ static inline void read_config_file (const string& file_name)
15581 {
15682 ifstream ifs (file_name.c_str (), ios_base::in);
15783 if (!ifs) {
@@ -163,7 +89,7 @@ namespace pfasst
16389 }
16490 }
16591
166- inline static void init ()
92+ static inline void init ()
16793 {
16894 options::add_option (" Global" , " help,h" , " display this help message" );
16995
@@ -176,9 +102,9 @@ namespace pfasst
176102
177103 options::get_instance ().init ();
178104 }
179-
180105 } // ::pfasst::config
181-
182106} // ::pfasst
183107
108+ #include " config_impl.hpp"
109+
184110#endif // _PFASST__CONFIG_HPP_
0 commit comments