30 #ifndef _GranOO_libCore_XmlObjectManager_hpp_
31 #define _GranOO_libCore_XmlObjectManager_hpp_
43 #define GRANOO_XML_READ_SHAPE(CLASS) \
45 CLASS::new_object(const TiXmlElement* el) \
47 Core::XmlParser& parser = Core::XmlParser::get(); \
48 const std::string id = parser.read_attribute<std::string>(Core::Attribute::GRANOO_OPTIONAL, "ID"); \
50 parser.CheckAllowedAttributeValue("Type", Core::ObjectFactory< CLASS >::get_ID()); \
51 const std::string shapeType = parser.read_attribute<std::string>(Attr::GRANOO_REQUIRED, "Type"); \
52 CLASS* mf = Core::ObjectFactory< CLASS >::new_object(shapeType); \
53 const_cast<std::string&>(mf->_ID) = id; \
54 mf->read_xml_element(parser.get_current_element()); \
59 CLASS::read_xml_element(const TiXmlElement* el) \
61 Core::XmlParser& parser = Core::XmlParser::get(); \
62 parser.set_current_element(el); \
64 if (parser.attribute_exist("FrameID")) \
66 parser.CheckAllowedAttributeValue("FrameID", Core::XmlObjectManager< Geom::Frame >::get_ID()); \
67 const std::string frameId = parser.read_attribute<std::string>("FrameID", ""); \
68 Geom::Frame* f = Core::XmlObjectManager< Geom::Frame >::get_item(frameId); \
69 set_center(f->get_center()); \
70 set_quaternion(f->get_quaternion()); \
75 CLASS::glob(const std::string& id) \
77 return Core::XmlObjectManager<CLASS>::get(id); \
93 template<
typename T> std::string
95 std::string list =
"";
96 for (
auto& it : get_ID())
101 template<
typename T>
void
104 "XmlObjectManager<" + T::class_ID() +
">. Can't add item, the id=" +
Core::String::quote(key) +
109 template<
typename T>
bool
111 return (map_.count(key) == 1);
114 template<
typename T> T&
117 "XmlObjectManager<" + T::class_ID() +
">. Can't get item, the id=" +
Core::String::quote(key) +
118 " is unknown, please use instead the following id " +
123 template<
typename T> T *
125 if (map_.count(key) == 0)
132 template<
typename T>
void
137 template<
typename T> std::string
139 typename std::map<const std::string, T*>::iterator it;
140 for ( it = map_.begin(); it != map_.end(); it++ ) {
141 if ((*it).second==item)
147 template<
typename T>
void
149 typename std::map<const std::string, T*>::iterator it;
150 for ( it = map_.begin(); it != map_.end(); it++ ) {
151 if ((*it).second==item)
156 UserAssert(0,
"can't erase the required item");
159 template<
typename T> T*
167 parser.
read_attribute<std::string>(Attribute::GRANOO_REQUIRED,
"ID", id);
169 parser.
read_attribute<std::string>(Attribute::GRANOO_OPTIONAL,
"ID", id);
171 T* item = T::new_object(el);
174 parser.XmlAssert(map_.count(
id) == 0,
"The id " +
Core::String::quote(
id) +
" must be unique");
176 map_[id]->add_glob(
id);
189 template<
typename T> std::vector<std::string>
191 typedef std::map<const std::string, T *> MAP;
193 std::vector<std::string> vec;
194 for (
typename MAP::iterator it = map_.begin(); it!=map_.end(); ++it)
195 vec.push_back(it->first);
#define SafeModeAssert(condition, message)
Definition: Macro.hpp:47
#define UserAssert(condition, message)
Definition: Macro.hpp:54
static void add_item(const std::string &, T *)
Definition: XmlObjectManager.hpp:102
static T * read_element(const TiXmlElement *, bool ID_required=true)
Definition: XmlObjectManager.hpp:160
static bool exist(const std::string &)
Definition: XmlObjectManager.hpp:110
static void clear()
Definition: XmlObjectManager.hpp:133
static std::vector< std::string > get_ID()
Definition: XmlObjectManager.hpp:190
static void erase_item(const T *)
Definition: XmlObjectManager.hpp:148
static T & get(const std::string &)
Definition: XmlObjectManager.hpp:115
static std::string get_list()
Definition: XmlObjectManager.hpp:94
static std::map< const std::string, T * > map_
Definition: XmlParser.hpp:100
static T * get_item(const std::string &)
Definition: XmlObjectManager.hpp:124
Definition: XmlParser.hpp:122
void read_attribute(const Attribute::State, const std::string &, T &)
void set_current_element(const TiXmlElement *)
static granoo_endl endl
Definition: Out.hpp:106
static GranOO3::Core::Out cout
Definition: Out.hpp:100
Definition: Common.hpp:198
static std::string quote(const std::string &str)
Definition: String.cpp:73
static const std::string empty_string
Definition: String.hpp:45