swarm::config Class Reference

Basic dictionary like data structure to hold configuration. More...

#include <config.hpp>

Inherits std::map<std::string, std::string>.

List of all members.

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.
void initialize (const char *const key_value_pairs[][2], const int n)
 Initialize the configuration from key_value_pairs.
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.
template<typename T >
optional (const std::string &key, const T &default_value) const
 Value of an optional parameter key.
template<typename T >
require (const std::string &key, const T &=T()) const
 Value of a mandatory parameter key.

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.
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.


Detailed Description

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.


Constructor & Destructor Documentation

template<class T >
swarm::config::config ( const T &  key_value_pairs  )  [inline]

Simple constructur for inline creation of config objects form 2D arrays of strings.

Example:

const char* pairs[][2] = { { "nsys" , "8000" }, { "nbod", "4" } };
config inline_configuration( pairs );

key_value_pairs 2D array of key-value pairs for initializing the config object

Definition at line 60 of file config.hpp.


Member Function Documentation

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.

Parameters:
[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.

config swarm::config::load ( const std::string &  fn,
config  cfg = config() 
) [static]

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
.
.
.

Parameters:
[out] cfg configuration class
[in] fn file name sting

Definition at line 43 of file config.cpp.

References peyton::util::trim().

template<typename T >
T swarm::config::optional ( const std::string &  key,
const T &  default_value 
) const [inline]

template<typename T >
T swarm::config::require ( const std::string &  key,
const T &  = T() 
) const [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:

  • c.require("key", 0.0)
  • c.require<double>("key")

Parameters:
[in] key Name of the key to retrieve
[in] t Optional value just for template matching.

Definition at line 181 of file config.hpp.

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::gpu::bppt::MVSPropagatorParams::MVSPropagatorParams(), TutorialIntegrator< Monitor, Gravitation >::TutorialIntegrator(), and swarm::gpu::bppt::VerletPropagatorParams::VerletPropagatorParams().

template<typename T >
bool swarm::config::valid ( const std::string &  key,
t 
) const [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.


The documentation for this class was generated from the following files:

doxygen