Skip to content

Commit e8f54f4

Browse files
committed
Merge pull request #156 from torbjoernk/feature/split-decl-defs
Splitting up declerations and definitions into separate files
2 parents b31c7dd + 8b0fd93 commit e8f54f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3001
-2055
lines changed

examples/boris/boris_sweeper.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ namespace pfasst
178178
virtual void set_state(shared_ptr<const encap_type> u0, size_t m);
179179
virtual void set_start_state(shared_ptr<const encap_type> u0);
180180
virtual shared_ptr<Encapsulation<time>> get_state(size_t m) const override;
181-
virtual shared_ptr<encap_type> get_start_state() const;
181+
virtual shared_ptr<Encapsulation<time>> get_start_state() const;
182182
virtual shared_ptr<acceleration_type> get_tau_q_as_force(size_t m) const;
183183
virtual shared_ptr<acceleration_type> get_tau_qq_as_force(size_t m) const;
184184
virtual shared_ptr<Encapsulation<time>> get_saved_state(size_t m) const override;

examples/boris/boris_sweeper_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ namespace pfasst
269269
}
270270

271271
template<typename scalar, typename time>
272-
shared_ptr<typename BorisSweeper<scalar, time>::encap_type> BorisSweeper<scalar, time>::get_start_state() const
272+
shared_ptr<Encapsulation<time>> BorisSweeper<scalar, time>::get_start_state() const
273273
{
274274
return this->start_particles;
275275
}

examples/boris/injective_transfer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ namespace pfasst
132132
auto fine = dynamic_pointer_cast<const BorisSweeper<scalar, time>>(src);
133133
assert(fine);
134134
CVLOG(5, "BorisTransfer") << "fine: " << fine->get_start_state();
135-
coarse->set_start_state(fine->get_start_state());
135+
coarse->set_start_state(dynamic_pointer_cast<typename BorisSweeper<scalar, time>::encap_type>(fine->get_start_state()));
136136
CVLOG(5, "BorisTransfer") << "restricted: " << coarse->get_start_state();
137137
}
138138

include/pfasst/config.hpp

Lines changed: 17 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
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>
137
using namespace std;
148

159
#include <boost/program_options.hpp>
1610
namespace po = boost::program_options;
1711

12+
1813
namespace 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_

include/pfasst/config_impl.hpp

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#include "config.hpp"
2+
3+
#include <fstream>
4+
#include <sstream>
5+
#include <utility>
6+
using namespace std;
7+
8+
9+
namespace pfasst
10+
{
11+
namespace config
12+
{
13+
options::options()
14+
{}
15+
16+
options& options::get_instance()
17+
{
18+
static options instance;
19+
return instance;
20+
}
21+
22+
po::variables_map& options::get_variables_map()
23+
{
24+
return this->variables_map;
25+
}
26+
27+
po::options_description& options::get_all_options()
28+
{
29+
return this->all_options;
30+
}
31+
32+
vector<string>& options::get_unrecognized_args()
33+
{
34+
return this->unrecognized_args;
35+
}
36+
37+
void options::add_option(const string& group, const string& option, const string& help)
38+
{
39+
auto& opts = get_instance();
40+
opts.option_groups.emplace(make_pair<string,
41+
po::options_description>(string(group),
42+
po::options_description(string(group),
43+
LINE_WIDTH)));
44+
opts.option_groups[group].add_options()
45+
(option.c_str(), help.c_str());
46+
}
47+
48+
template<typename T>
49+
void options::add_option(const string& group, const string& option, const string& help)
50+
{
51+
auto& opts = get_instance();
52+
53+
opts.option_groups.emplace(make_pair<string,
54+
po::options_description>(string(group),
55+
po::options_description(string(group),
56+
LINE_WIDTH)));
57+
opts.option_groups[group].add_options()
58+
(option.c_str(), po::value<T>(), help.c_str());
59+
}
60+
61+
void options::init()
62+
{
63+
if (!this->initialized) {
64+
for (auto const & kv : this->option_groups) {
65+
this->all_options.add(kv.second);
66+
}
67+
}
68+
this->initialized = true;
69+
}
70+
71+
72+
template<typename T>
73+
static T get_value(const string& name, const T& default_val)
74+
{
75+
return options::get_instance().get_variables_map().count(name)
76+
? options::get_instance().get_variables_map()[name].as<T>() : default_val;
77+
}
78+
79+
template<typename T>
80+
static T get_value(const string& name)
81+
{
82+
return options::get_instance().get_variables_map()[name].as<T>();
83+
}
84+
85+
static string print_help(bool if_no_params)
86+
{
87+
bool no_params_given = options::get_instance().get_variables_map().empty();
88+
89+
if (!if_no_params || (if_no_params && no_params_given)) {
90+
stringstream s;
91+
s << options::get_instance().get_all_options() << endl;
92+
s << "Logging options:" << endl
93+
<< " -v [ --verbose ] activates maximum verbosity" << endl
94+
<< " --v=arg activates verbosity upto verbose level `arg`" << endl
95+
<< " (valid range: 0-9)" << endl
96+
<< " -vmodule=arg actives verbose logging for specific module" << endl
97+
<< " (see [1] for details)" << endl << endl
98+
<< "[1]: https://github.com/easylogging/easyloggingpp#vmodule" << endl;
99+
return s.str();
100+
} else {
101+
return string();
102+
}
103+
}
104+
} // ::pfasst::config
105+
} // ::pfasst

0 commit comments

Comments
 (0)