| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- #include <boost/property_tree/ptree.hpp>
- #include "anki/misc/PropertyTree.h"
- #include "anki/util/Exception.h"
- namespace anki {
- namespace PropertyTree {
- //==============================================================================
- // getBool =
- //==============================================================================
- bool getBool(const boost::property_tree::ptree& pt, const char* tag)
- {
- std::string str = pt.get<std::string>(tag);
- if(str == "true")
- {
- return true;
- }
- else if(str == "false")
- {
- return false;
- }
- else
- {
- throw ANKI_EXCEPTION("Expected true or false for tag " + tag +
- " and not " + str);
- }
- }
- //==============================================================================
- // getBoolOptional =
- //==============================================================================
- extern boost::optional<bool> getBoolOptional(
- const boost::property_tree::ptree& pt, const char* tag)
- {
- boost::optional<std::string> str = pt.get_optional<std::string>(tag);
- if(str)
- {
- if(str.get() == "true")
- {
- return boost::optional<bool>(true);
- }
- else if(str.get() == "false")
- {
- return boost::optional<bool>(true);
- }
- else
- {
- throw ANKI_EXCEPTION("Expected true or false for tag " + tag +
- " and not " + str.get());
- }
- }
- return boost::optional<bool>();
- }
- //==============================================================================
- // getFloat =
- //==============================================================================
- float getFloat(const boost::property_tree::ptree& pt)
- {
- return pt.get<float>("float");
- }
- //==============================================================================
- // getVec2 =
- //==============================================================================
- Vec2 getVec2(const boost::property_tree::ptree& pt)
- {
- const boost::property_tree::ptree& tree = pt.get_child("vec2");
- return Vec2(tree.get<float>("x"), tree.get<float>("y"));
- }
- //==============================================================================
- // getVec3 =
- //==============================================================================
- Vec3 getVec3(const boost::property_tree::ptree& pt)
- {
- const boost::property_tree::ptree& tree = pt.get_child("vec3");
- return Vec3(
- tree.get<float>("x"),
- tree.get<float>("y"),
- tree.get<float>("z"));
- }
- //==============================================================================
- // getVec4 =
- //==============================================================================
- Vec4 getVec4(const boost::property_tree::ptree& pt)
- {
- const boost::property_tree::ptree& tree = pt.get_child("vec4");
- return Vec4(
- tree.get<float>("x"),
- tree.get<float>("y"),
- tree.get<float>("z"),
- tree.get<float>("w"));
- }
- } // end namespace
- } // end namespace
|