World Builder
0.1.0-pre
A geodyanmic initial conditions generator
|
#include <parameters.h>
Public Member Functions | |
Parameters (std::string &filename, World &) | |
~Parameters () | |
bool | load_entry (const std::string &name, const bool required, const Types::Interface &type) |
bool | set_entry (const std::string &name, const Types::Interface &type) |
void | enter_subsection (const std::string name) |
void | leave_subsection () |
unsigned int | get_unsigned_int (const std::string &name) const |
double | get_double (const std::string &name) const |
std::string | get_string (const std::string &name) const |
template<int dim> | |
Point< dim > | get_point (const std::string &name) const |
const Types::Array & | get_array (const std::string &name) const |
template<class T > | |
const std::vector< T * > | get_array (const std::string &name) const |
std::string | get_full_path () const |
std::string | get_full_path_without_arrays () const |
template<> | |
Point< 2 > | get_point (const std::string &name) const |
template<> | |
Point< 3 > | get_point (const std::string &name) const |
Public Attributes | |
World & | world |
const std::string | path_seperator = "." |
std::vector< std::string > | path |
ptree | tree |
ptree * | local_tree |
std::unordered_map< std::string, unsigned int > | string_to_type_map |
std::vector< Types::UnsignedInt > | vector_unsigned_int |
std::vector< Types::Double > | vector_double |
std::vector< Types::String > | vector_string |
std::vector< Types::Array > | vector_array |
std::vector< Types::List > | vector_list |
std::vector< Types::Point< 2 > > | vector_point_2d |
std::vector< Types::Point< 3 > > | vector_point_3d |
std::vector< std::unique_ptr< WorldBuilder::Features::Interface > > | features |
std::unique_ptr< WorldBuilder::CoordinateSystems::Interface > | coordinate_system |
A class to hold all the parameters needed by the world builder. Internally it holds all values in the form of vectors of class Types. Values can be entered in two ways into this class. The first way is through the load_entry function which load the value from the provided world builder file. The second way is through the set_entry function, through which values can be directly entered into the parameter class. Values can be retrieved through the get functions which take the name of the value with which it was set. It is also required for bot loading, setting and getting values to do it in the correct subsection. Subsections can be entered with the enter_subsection function and left with the leave_subsection function. The current path can be retrieved through the function get_current_path() and get_current_path_without_arrays().
Definition at line 70 of file parameters.h.
WorldBuilder::Parameters::Parameters | ( | std::string & | filename, |
World & | world | ||
) |
Constructor
filename | A string with the path to the world builder file |
world | A reference to the World class |
Definition at line 36 of file parameters.cc.
WorldBuilder::Parameters::~Parameters | ( | ) |
Destructor
Definition at line 52 of file parameters.cc.
void WorldBuilder::Parameters::enter_subsection | ( | const std::string | name | ) |
This function is used to enter a subsection. It appends to the path variable. This action is revesed by the leave subsection function.
name | The name of the subsection to be entered. |
Definition at line 495 of file parameters.cc.
const Types::Array & WorldBuilder::Parameters::get_array | ( | const std::string & | name | ) | const |
This function retrieves a Type::Array from the parameter class with the key in variable name, based on the path. Note the path rules for called classes explained in the parameter class explanation.
name | The key where the variable is stored. The array contains the underlying type and the indeces where the values are stored. |
Definition at line 551 of file parameters.cc.
const std::vector< T * > WorldBuilder::Parameters::get_array | ( | const std::string & | name | ) | const |
Returns the array with pointers to the requested type. The reason a raw pointer is returned is that caller is not responsible for the classes pointed at in the return vector or has ownership on them.
name | The key where the variable is stored. The array contains |
Definition at line 562 of file parameters.cc.
double WorldBuilder::Parameters::get_double | ( | const std::string & | name | ) | const |
This function retrieves a double from the parameter class with the key in variable name, based on the path. Note the path rules for called classes explained in the parameter class explanation.
name | The key where the variable is stored. |
Definition at line 516 of file parameters.cc.
std::string WorldBuilder::Parameters::get_full_path | ( | ) | const |
This function return the current path as stored in the path variable as a string.
Definition at line 608 of file parameters.cc.
std::string WorldBuilder::Parameters::get_full_path_without_arrays | ( | ) | const |
This function return the current path as stored in the path variable as a string, but the arrays are striped. This is useful for working with the boost property tree.
Definition at line 630 of file parameters.cc.
Point<dim> WorldBuilder::Parameters::get_point | ( | const std::string & | name | ) | const |
This function retrieves a point from the parameter class with the key in variable name, based on the path. Note the path rules for called classes explained in the parameter class explanation.
name | The key where the variable is stored. |
Point<2> WorldBuilder::Parameters::get_point | ( | const std::string & | name | ) | const |
template Point< 3 > WorldBuilder::Parameters::get_point< 3 > | ( | const std::string & | name | ) | const |
std::string WorldBuilder::Parameters::get_string | ( | const std::string & | name | ) | const |
This function retrieves astring from the parameter class with the key in variable name, based on the path. Note the path rules for called classes explained in the parameter class explanation.
name | The key where the variable is stored. |
Definition at line 524 of file parameters.cc.
unsigned int WorldBuilder::Parameters::get_unsigned_int | ( | const std::string & | name | ) | const |
This function retrieves an unsigned int from the parameter class with the key in variable name, based on the path. Note the path rules for called classes explained in the parameter class explanation.
name | The key where the variable is stored. |
Definition at line 508 of file parameters.cc.
void WorldBuilder::Parameters::leave_subsection | ( | ) |
This function is used to leave a subsection by removing the last element of the path variable. It reverses the action of the enter subsection function.
Definition at line 502 of file parameters.cc.
bool WorldBuilder::Parameters::load_entry | ( | const std::string & | name, |
const bool | required, | ||
const Types::Interface & | type | ||
) |
Loads an entry into the parameter class from the world builder file, where the name is the key in the file relative to the nesting in the world builder file. Note that classes receive the subtree which is relevant for them, so the they only have to account for their nesting.
Note that for the array and list, default values are not implemented.
name | The name of the parameter which should be loaded |
required | Determines whether a value is required to be present. When it isn't present, and the value is set to true, an assert is thrown. If it is set to false and the value is not found, the default value is used. |
type | A value of class Type. Note that these may be nested. |
Definition at line 56 of file parameters.cc.
bool WorldBuilder::Parameters::set_entry | ( | const std::string & | name, |
const Types::Interface & | type | ||
) |
Sets an entry into the parameter class, where the name is the key in the file relative to the nesting defined by the enter_subsection and leave_subsection functions. Note that classes receive the subtree which is relevant for them, so the they only have to account for their nesting.
Note that for the array and list, default values are not implemented.
Definition at line 387 of file parameters.cc.
std::unique_ptr<WorldBuilder::CoordinateSystems::Interface> WorldBuilder::Parameters::coordinate_system |
A pointers to the corodinate system. This variable is responsible for the coordinate system and has ownership over it. Therefore a unique pointer are used.
Definition at line 321 of file parameters.h.
std::vector<std::unique_ptr<WorldBuilder::Features::Interface> > WorldBuilder::Parameters::features |
A vector containing all the pointers to the features. This vector is responsible for the features and has ownership over them. Therefore unique pointers are used.
Definition at line 313 of file parameters.h.
ptree* WorldBuilder::Parameters::local_tree |
This variable ontains a pointer to the a part of the tree. This variable is not repsonsible for the tree, so using a raw pointer.
Definition at line 228 of file parameters.h.
std::vector<std::string> WorldBuilder::Parameters::path |
This variable stores the path in a vector of strings.
Definition at line 215 of file parameters.h.
const std::string WorldBuilder::Parameters::path_seperator = "." |
This variable stores what path separtor is used in the property tree and in this class.
Definition at line 208 of file parameters.h.
std::unordered_map<std::string,unsigned int> WorldBuilder::Parameters::string_to_type_map |
An unordered map used to store and retrieve the indices where the variables in this class are stored based on the path key.
Definition at line 236 of file parameters.h.
ptree WorldBuilder::Parameters::tree |
The boost property tree, used to read in the data from a json file.
Definition at line 221 of file parameters.h.
std::vector<Types::Array> WorldBuilder::Parameters::vector_array |
A vector which stores all the Array types. These can be retrieved with the help of the string_to_type_map and the get_array() function.
Definition at line 276 of file parameters.h.
std::vector<Types::Double> WorldBuilder::Parameters::vector_double |
A vector which stores all the Double types. These can be retrieved with the help of the string_to_type_map and the get_double() function.
Definition at line 256 of file parameters.h.
std::vector<Types::List> WorldBuilder::Parameters::vector_list |
A vector which stores all the List types. These can be retrieved with the help of the string_to_type_map.
Definition at line 284 of file parameters.h.
std::vector<Types::Point<2> > WorldBuilder::Parameters::vector_point_2d |
A vector which stores all the Point<2> types. These can be retrieved with the help of the string_to_type_map and the get_Point<2>() function.
Definition at line 294 of file parameters.h.
std::vector<Types::Point<3> > WorldBuilder::Parameters::vector_point_3d |
A vector which stores all the Point<3> types. These can be retrieved with the help of the string_to_type_map and the get_Point<3>() function.
Definition at line 304 of file parameters.h.
std::vector<Types::String> WorldBuilder::Parameters::vector_string |
A vector which stores all the String types. These can be retrieved with the help of the string_to_type_map and the get_string() function.
Definition at line 266 of file parameters.h.
std::vector<Types::UnsignedInt> WorldBuilder::Parameters::vector_unsigned_int |
A vector which stores all the UnsignedInt types. These can be retrieved with the help of the string_to_type_map and the get_unsigned_int() function.
Definition at line 246 of file parameters.h.
World& WorldBuilder::Parameters::world |
A reference to the World class. This is needed to create the features.
Definition at line 202 of file parameters.h.