23 #include <boost/property_tree/json_parser.hpp> 32 using boost::property_tree::ptree;
43 "Could not find the world builder file at the specified location: " + filename);
47 std::ifstream json_input_stream(filename.c_str());
48 boost::property_tree::json_parser::read_json (json_input_stream,
tree);
59 unsigned int location;
60 return this->
load_entry(name, required, type, location);
66 bool found_value =
false;
74 get_relative_path_without_arrays(),
75 (name.front() ==
'[' && name.back() ==
']' ?
"" : name),
79 found_value = value_tree ? true :
false;
81 WBAssertThrow((found_value ==
true && required ==
true) || required ==
false,
82 "Could not find " +
get_full_path() +
", while it is set as required.");
100 get_relative_path_without_arrays(),
101 (name.front() ==
'[' && name.back() ==
']' ?
"" : name),
104 found_value = value_tree ? true :
false;
106 WBAssertThrow((found_value ==
true && required ==
true) || required ==
false,
107 "Could not find " +
get_full_path() +
", while it is set as required.");
123 get_relative_path_without_arrays(),
124 (name.front() ==
'[' && name.back() ==
']' ?
"" : name),
128 found_value = value_tree ? true :
false;
130 WBAssertThrow((found_value ==
true && required ==
true) || required ==
false,
131 "Could not find " +
get_full_path() +
", while it is set as required.");
135 const std::string value = value_tree ? value_tree.get() : natural_type.
default_value;
148 boost::optional<ptree &> child =
local_tree->get_child_optional(path_tmp);
150 found_value = child ? true :
false;
152 WBAssertThrow((found_value ==
false && required ==
true) || required ==
false,
"Could not find " + path_tmp +
", while it is set as required.");
155 std::string system = found_value ==
true ? child.get().begin()->first : natural_type.
default_value;
162 std::string path_tmp = (get_relative_path() ==
"") ? name : (get_relative_path() +
path_seperator + name);
173 features.back()->decare_entries(path_tmp);
185 boost::optional<ptree &> child =
local_tree->get_child_optional(path_plus_name_without_arrays);
187 found_value = child ? true :
false;
189 WBAssertThrow((found_value ==
true && required ==
true) || required ==
false,
202 unsigned int current_size = 0;
203 for (boost::property_tree::ptree::iterator it = child.get().begin(); it != child.get().end(); ++it)
208 unsigned int child_location;
210 vector_list[location].inner_type_index.push_back(child_location);
226 const std::string path_plus_name_without_arrays = ((get_relative_path_without_arrays() ==
"") ?
"" : (get_relative_path_without_arrays() +
path_seperator +
""))
227 + (name.front() ==
'[' && name.back() ==
']' ?
path_seperator : name);
229 boost::optional<ptree &> child =
local_tree->get_child_optional(path_plus_name_without_arrays);
231 found_value = child ? true :
false;
245 unsigned int current_size = 0;
249 for (boost::property_tree::ptree::iterator it = child.get().begin(); it != child.get().end(); ++it)
251 unsigned int diff =
path.size()-path_level;
256 unsigned int child_location;
257 found_value = this->
load_entry(
"["+ std::to_string(current_size) +
"]", required, *natural_type.
inner_type_ptr, child_location);
258 vector_array[location].inner_type_index.push_back(child_location);
274 const std::string path_plus_name_without_arrays = ((get_relative_path_without_arrays() ==
"") ?
"" : (get_relative_path_without_arrays() +
path_seperator +
""))
275 + (name.front() ==
'[' && name.back() ==
']' ?
"" : name);
277 boost::optional<ptree &> child =
local_tree->get_child_optional(path_plus_name_without_arrays);
279 found_value = child ? true :
false;
281 WBAssertThrow((found_value ==
true && required ==
true) || required ==
false,
284 unsigned int diff =
path.size()-path_level;
287 if (found_value ==
true)
290 unsigned int current_size = 0;
291 for (boost::property_tree::ptree::iterator it = child.get().begin(); it != child.get().end(); ++it)
296 get_relative_path_without_arrays(),
299 found_value = value_tree ? true :
false;
301 WBAssertThrow((found_value ==
true && required ==
true) || required ==
false,
302 "Could not find " +
get_full_path() +
", while it is set as required.");
305 point[current_size] = value;
310 " should represent a 2d point, but the size was not 2, it was " 311 << current_size <<
".");
327 const std::string path_plus_name_without_arrays = ((get_relative_path_without_arrays() ==
"") ?
"" : (get_relative_path_without_arrays() +
path_seperator +
""))
328 + (name.front() ==
'[' && name.back() ==
']' ?
"" : name);
330 boost::optional<ptree &> child =
local_tree->get_child_optional(path_plus_name_without_arrays);
332 found_value = child ? true :
false;
334 WBAssertThrow((found_value ==
true && required ==
true) || required ==
false,
337 unsigned int diff =
path.size()-path_level;
340 if (found_value ==
true)
343 unsigned int current_size = 0;
344 for (boost::property_tree::ptree::iterator it = child.get().begin(); it != child.get().end(); ++it)
349 get_relative_path_without_arrays(),
352 found_value = value_tree ? true :
false;
354 WBAssertThrow((found_value ==
true && required ==
true) || required ==
false,
355 "Could not find " +
get_full_path() +
", while it is set as required.");
358 point[current_size] = value;
363 " should represent a 3d point, but the size was not 3, it was " 364 << current_size <<
".");
389 unsigned int location;
428 WBAssert(
false,
"A Coordinate system can not be directly set, use the load_entry function.");
436 WBAssert(
false,
"A Feature can not be directly set, use the load_entry function.");
466 unsigned int child_location;
468 vector_array[location].inner_type_index.push_back(child_location);
497 path.push_back(name);
511 WBAssert(
string_to_type_map.count(path_plus_name) > 0,
"Could not find entry \'" << name <<
"\' not found. Make sure it is loaded or set.");
519 WBAssert(
string_to_type_map.count(path_plus_name) > 0,
"Could not find entry \'" << name <<
"\' not found. Make sure it is loaded or set.");
527 WBAssert(
string_to_type_map.count(path_plus_name) > 0,
"Could not find entry \'" << name <<
"\' not found. Make sure it is loaded or set.");
536 WBAssert(
string_to_type_map.count(path_plus_name) > 0,
"Could not find entry \'" << name <<
"\' not found. Make sure it is loaded or set.");
545 WBAssert(
string_to_type_map.count(path_plus_name) > 0,
"Could not find entry \'" << name <<
"\' not found. Make sure it is loaded or set.");
555 WBAssert(
string_to_type_map.count(path_plus_name) > 0,
"Could not find entry \'" << name <<
"\' not found. Make sure it is loaded or set.");
561 const std::vector<T *>
566 WBAssert(
string_to_type_map.count(path_plus_name) > 0,
"Could not find entry \'" << name <<
"\' not found. Make sure it is loaded or set.");
570 std::vector<T *> array(typed_array.inner_type_index.size());
572 for (
unsigned int i = 0; i < typed_array.inner_type_index.size(); ++i)
576 array[i] =
dynamic_cast<T *
>(&
vector_double[typed_array.inner_type_index[i]]);
581 array[i] =
dynamic_cast<T *
>(&
vector_point_2d[typed_array.inner_type_index[i]]);
586 array[i] =
dynamic_cast<T *
>(&
vector_point_3d[typed_array.inner_type_index[i]]);
591 WBAssert(
false,
"type conversion not implemented for type with number " << (
int)typed_array.inner_type <<
".");
610 std::string collapse =
"";
611 for (
unsigned int i = 0; i <
path.size(); i++)
619 Parameters::get_relative_path()
const 621 std::string collapse =
"";
622 for (
unsigned int i = path_level; i <
path.size(); i++)
632 std::string collapse =
"";
633 for (
unsigned int i = 0; i <
path.size(); i++)
642 Parameters::get_relative_path_without_arrays()
const 644 std::string collapse =
"";
645 for (
unsigned int i = path_level; i <
path.size(); i++)
652 template Point<2> Parameters::get_point<2>(
const std::string &name)
const;
653 template Point<3> Parameters::get_point<3>(
const std::string &name)
const;
654 template const std::vector<const Types::Double * > Parameters::get_array<const Types::Double >(
const std::string &name)
const;
655 template const std::vector<const Types::Point<2>* > Parameters::get_array<const Types::Point<2> >(
const std::string &name)
const;
656 template const std::vector<const Types::Point<3>* > Parameters::get_array<const Types::Point<3> >(
const std::string &name)
const;
std::vector< Types::Array > vector_array
unsigned int default_value
std::vector< Types::List > vector_list
std::vector< unsigned int > inner_type_index
std::unique_ptr< Interface > create_feature(const std::string name, World *world)
std::vector< Types::Double > vector_double
const Types::Array & get_array(const std::string &name) const
const std::string path_seperator
double string_to_unsigned_int(const std::string &string)
std::string get_full_path_without_arrays() const
std::vector< Types::String > vector_string
#define WBAssert(condition, message)
WorldBuilder::Point< dim > default_value
std::unique_ptr< Interface > inner_type_ptr
std::unordered_map< std::string, unsigned int > string_to_type_map
std::vector< Types::Point< 2 > > vector_point_2d
std::string get_string(const std::string &name) const
void enter_subsection(const std::string name)
boost::optional< std::string > get_from_ptree_abs(const ptree &tree, const std::string &path, const std::string &key, const bool required, const std::string &path_separator)
std::unique_ptr< Interface > inner_type_ptr
std::string default_value
virtual type get_type() const
bool load_entry(const std::string &name, const bool required, const Types::Interface &type)
Parameters(std::string &filename, World &)
#define WBAssertThrow(condition, message)
std::string default_value
double string_to_double(const std::string &string)
Point< dim > get_point(const std::string &name) const
std::vector< std::unique_ptr< WorldBuilder::Features::Interface > > features
std::unique_ptr< WorldBuilder::CoordinateSystems::Interface > coordinate_system
std::unique_ptr< Interface > create_coordinate_system(const std::string name)
std::string get_full_path() const
std::vector< std::string > path
std::vector< Types::Point< 3 > > vector_point_3d
std::vector< Types::UnsignedInt > vector_unsigned_int
bool set_entry(const std::string &name, const Types::Interface &type)
unsigned int get_unsigned_int(const std::string &name) const
double get_double(const std::string &name) const