Swarm-NG
1.1
|
Basic dictionary like data structure to hold configuration. More...
#include <config.hpp>
Public Member Functions | |
template<class T > | |
config (const T &key_value_pairs) | |
Simple constructur for inline creation of config objects form 2D arrays of strings. More... | |
void | initialize (const char *const key_value_pairs[][2], const int n) |
Initialize the configuration from key_value_pairs. More... | |
bool | valid (const std::string &key) const |
Query if the value for specified key exists and is a valid entry. | |
template<typename T > | |
bool | valid (const std::string &key, T t) const |
Query if the value for specified key exists and is a valid value of type T. More... | |
template<typename T > | |
T | optional (const std::string &key, const T &default_value) const |
Value of an optional parameter key. More... | |
template<typename T > | |
T | require (const std::string &key, const T &=T()) const |
Value of a mandatory parameter key. More... | |
Static Public Member Functions | |
static config | load (const std::string &fn, config cfg=config()) |
Load a new configuration from a text file and merge it with cfg. More... | |
static bool | valid_value (const std::string &v, std::string) |
Is v a valid string. | |
static std::string | parse (const std::string &v, std::string) |
Parse a string. | |
static bool | valid_value (const std::string &v, double) |
Is v a valid double. | |
static double | parse (const std::string &v, double) |
Parse a double value. | |
static bool | valid_value (const std::string &v, float) |
Is v a valid float. | |
static float | parse (const std::string &v, float) |
Parse a float value. | |
static bool | valid_value (const std::string &v, int) |
Is v a valid integer. | |
static int | parse (const std::string &v, int) |
Parse an integer. | |
Additional Inherited Members | |
Public Attributes inherited from std::map< K, T > | |
K | keys |
STL member. | |
T | elements |
STL member. | |
Basic dictionary like data structure to hold configuration.
It is basically a standard C++ map with enhanced accessors. This features inline initialization, loading from a text file and automatic parsers to floating and integer types. In addition to specific accessors for optional and required parameters.
It is sometimes used in the code to simulate named parameter calling convention.
Definition at line 44 of file config.hpp.
|
inline |
Simple constructur for inline creation of config objects form 2D arrays of strings.
Example:
\args key_value_pairs 2D array of key-value pairs for initializing the config object
Definition at line 60 of file config.hpp.
References initialize().
void swarm::config::initialize | ( | const char *const | key_value_pairs[][2], |
const int | n | ||
) |
Initialize the configuration from key_value_pairs.
Initialize the config objects.
[in] | key_value_pairs | 2D array of key_value_pairs. key_value_pairs[i][0] is a key and key_value_pairs[i][1] is the corresponding value. |
[in] | n | number of items in key_value_pairs array. |
Definition at line 35 of file config.cpp.
Referenced by config().
Load a new configuration from a text file and merge it with cfg.
Load the configuration file and check for format errors.
Syntax:
key=value key2=value2 . . .
[out] | cfg | configuration class |
[in] | fn | file name sting |
Definition at line 43 of file config.cpp.
References peyton::util::trim().
Referenced by main().
|
inline |
Value of an optional parameter key.
If the key does not exists, then returns the default_value. The values are converted to type T on return.
[in] | key | Name of the key to retrieve |
[in] | default_value | The default_value in case that key is not found. |
Definition at line 159 of file config.hpp.
References parse(), and valid_value().
Referenced by swarm::log::writer::create(), generate_ensemble(), generate_ensemble_with_initial_conditions_cartesian_from_file(), generate_ensemble_with_initial_conditions_keplerian_from_file(), generate_ensemble_with_randomized_initial_conditions(), swarm::log::host_array_writer::host_array_writer(), swarm::init(), swarm::integrator::integrator(), swarm::gpu::bppt::integrator::integrator(), swarm::monitors::log_transit_params::log_transit_params(), main(), print_system(), swarm::monitors::stop_on_all_but_two_at_large_distance_params::stop_on_all_but_two_at_large_distance_params(), swarm::monitors::stop_on_any_large_distance_params::stop_on_any_large_distance_params(), swarm::monitors::stop_on_close_encounter_param::stop_on_close_encounter_param(), swarm::monitors::stop_on_collision_param::stop_on_collision_param(), swarm::monitors::stop_on_crossing_orbit_params::stop_on_crossing_orbit_params(), swarm::monitors::stop_on_ejection_params::stop_on_ejection_params(), validate_configuration(), and write_stable_systems().
|
inline |
Value of a mandatory parameter key.
If the key does not exists or the value is not a valid value for type T an error is raised. Otherwise text is parsed as a value of type T and is returned This function can be used in two ways. For retrieving the double value of a key "number" you can use either alternatives:
[in] | key | Name of the key to retrieve |
[in] | t | Optional value just for template matching. |
Definition at line 181 of file config.hpp.
References parse(), and valid_value().
Referenced by swarm::log::bdb_writer::bdb_writer(), swarm::gpu::bppt::EulerPropagatorParams::EulerPropagatorParams(), generate_ensemble(), generate_ensemble_with_initial_conditions_cartesian_from_file(), generate_ensemble_with_initial_conditions_keplerian_from_file(), generate_ensemble_with_randomized_initial_conditions(), swarm::gpu::bppt::hermite< Monitor, Gravitation >::hermite(), swarm::gpu::bppt::hermite_adap< Monitor, Gravitation >::hermite_adap(), swarm::cpu::hermite_cpu< Monitor >::hermite_cpu(), swarm::gpu::bppt::HermitePropagatorParams::HermitePropagatorParams(), swarm::log::host_array_writer::host_array_writer(), swarm::monitors::log_time_interval_params::log_time_interval_params(), swarm::monitors::log_transit_params::log_transit_params(), swarm::gpu::bppt::MidpointPropagatorParams::MidpointPropagatorParams(), swarm::cpu::mvs_cpu< Monitor >::mvs_cpu(), swarm::gpu::bppt::MVSPropagatorParams::MVSPropagatorParams(), TutorialIntegrator< Monitor, Gravitation >::TutorialIntegrator(), and swarm::gpu::bppt::VerletPropagatorParams::VerletPropagatorParams().
|
inline |
Query if the value for specified key exists and is a valid value of type T.
Example: vaild("log interval", 0.0) makes sure that "log interval" exists and is a valid double value ( same type as 0.0 )
Definition at line 148 of file config.hpp.
References valid(), and valid_value().