|
|
@ -993,18 +993,55 @@ namespace xml { |
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
template<> void Serialize::fromNode<Serialize>(Serialize* member, |
|
|
|
template<> void Serialize::fromNode<Serialize>(Serialize* member, |
|
|
|
xml::Node& node) { |
|
|
|
xml::Node& node) { |
|
|
|
member->_xmlFactory = node[member->_xmlFactory->name()]; |
|
|
|
//! @todo improve this (inefficient)
|
|
|
|
|
|
|
|
std::stringstream ss; // simple but inefficient: rewrite and reread
|
|
|
|
|
|
|
|
ss<<node[member->_xmlFactory->name()]; |
|
|
|
|
|
|
|
member->loadXml(ss); |
|
|
|
} |
|
|
|
} |
|
|
|
template<> void Serialize::toNode<Serialize>(Serialize* member, |
|
|
|
template<> void Serialize::toNode<Serialize>(Serialize* member, |
|
|
|
xml::Node& node) const { |
|
|
|
xml::Node& node) const { |
|
|
|
node[member->_xmlFactory->name()] = *member->_xmlFactory; |
|
|
|
//! @todo improve this (inefficient)
|
|
|
|
|
|
|
|
std::stringstream ss; // simple but inefficient: write and reread
|
|
|
|
|
|
|
|
member->saveXml(ss); |
|
|
|
|
|
|
|
node[member->_xmlFactory->name()] = *member->_xmlFactory.read(ss); |
|
|
|
} |
|
|
|
} |
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
Serialize::Serialize() throw() {} |
|
|
|
Serialize::Serialize() throw() {} |
|
|
|
Serialize::Serialize(const std::string& className) throw(): |
|
|
|
Serialize::Serialize(const std::string& className) throw(): |
|
|
|
_xmlFactory(xml::Node(xml::String(className).limits(1,1))) { |
|
|
|
_xmlFactory(xml::Node(xml::String(className).limits(1,1))) { |
|
|
|
} |
|
|
|
} |
|
|
|
Serialize::~Serialize() {}; |
|
|
|
Serialize::~Serialize() { |
|
|
|
|
|
|
|
// Remove my entries from the maps
|
|
|
|
|
|
|
|
for (std::map<std::string, const std::type_info*>::const_iterator |
|
|
|
|
|
|
|
it(_xmlNames.begin()); |
|
|
|
|
|
|
|
it!=_xmlNames.end(); ++it) { |
|
|
|
|
|
|
|
#define QWERTZ_CHECK_TYPE_ZTREWQ___XXX(TYPE) \ |
|
|
|
|
|
|
|
if (*it->second==typeid(TYPE)) { \
|
|
|
|
|
|
|
|
mapMember<TYPE>() \
|
|
|
|
|
|
|
|
.erase(mapName<TYPE>()[std::make_pair(this, it->first)]); \
|
|
|
|
|
|
|
|
mapName<TYPE>().erase(std::make_pair(this, it->first)); \
|
|
|
|
|
|
|
|
} else |
|
|
|
|
|
|
|
QWERTZ_CHECK_TYPE_ZTREWQ___XXX(Serialize) |
|
|
|
|
|
|
|
QWERTZ_CHECK_TYPE_ZTREWQ___XXX(std::string) |
|
|
|
|
|
|
|
QWERTZ_CHECK_TYPE_ZTREWQ___XXX(float) |
|
|
|
|
|
|
|
QWERTZ_CHECK_TYPE_ZTREWQ___XXX(double) |
|
|
|
|
|
|
|
QWERTZ_CHECK_TYPE_ZTREWQ___XXX(bool) |
|
|
|
|
|
|
|
QWERTZ_CHECK_TYPE_ZTREWQ___XXX(char) |
|
|
|
|
|
|
|
QWERTZ_CHECK_TYPE_ZTREWQ___XXX(signed char) |
|
|
|
|
|
|
|
QWERTZ_CHECK_TYPE_ZTREWQ___XXX(unsigned char) |
|
|
|
|
|
|
|
QWERTZ_CHECK_TYPE_ZTREWQ___XXX(short) |
|
|
|
|
|
|
|
QWERTZ_CHECK_TYPE_ZTREWQ___XXX(signed short) |
|
|
|
|
|
|
|
QWERTZ_CHECK_TYPE_ZTREWQ___XXX(unsigned short) |
|
|
|
|
|
|
|
QWERTZ_CHECK_TYPE_ZTREWQ___XXX(int) |
|
|
|
|
|
|
|
QWERTZ_CHECK_TYPE_ZTREWQ___XXX(signed int) |
|
|
|
|
|
|
|
QWERTZ_CHECK_TYPE_ZTREWQ___XXX(unsigned int) |
|
|
|
|
|
|
|
QWERTZ_CHECK_TYPE_ZTREWQ___XXX(long) |
|
|
|
|
|
|
|
QWERTZ_CHECK_TYPE_ZTREWQ___XXX(signed long) |
|
|
|
|
|
|
|
QWERTZ_CHECK_TYPE_ZTREWQ___XXX(unsigned long) |
|
|
|
|
|
|
|
{} // ignore coding error here, but memory leaks - better abort?
|
|
|
|
|
|
|
|
#undef QWERTZ_CHECK_TYPE_ZTREWQ___XXX |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
Serialize& Serialize::className(const std::string& name) throw() { |
|
|
|
Serialize& Serialize::className(const std::string& name) throw() { |
|
|
|
_xmlFactory=xml::Node(xml::String(name).limits(1,1)); |
|
|
|
_xmlFactory=xml::Node(xml::String(name).limits(1,1)); |
|
|
|
return *this; |
|
|
|
return *this; |
|
|
@ -1012,7 +1049,7 @@ namespace xml { |
|
|
|
Serialize& Serialize::persist(Serialize& ser) throw() { |
|
|
|
Serialize& Serialize::persist(Serialize& ser) throw() { |
|
|
|
ser.initXmlMembers(); |
|
|
|
ser.initXmlMembers(); |
|
|
|
std::string name(ser._xmlFactory->name()); |
|
|
|
std::string name(ser._xmlFactory->name()); |
|
|
|
mapName<Serialize>()[name] = &ser; |
|
|
|
mapName<Serialize>()[std::make_pair(this, name)] = &ser; |
|
|
|
mapMember<Serialize>()[&ser] = name; |
|
|
|
mapMember<Serialize>()[&ser] = name; |
|
|
|
_xmlNames[name] = &typeid(Serialize); |
|
|
|
_xmlNames[name] = &typeid(Serialize); |
|
|
|
xml::Node schema(*_xmlFactory); |
|
|
|
xml::Node schema(*_xmlFactory); |
|
|
@ -1026,9 +1063,9 @@ namespace xml { |
|
|
|
for (std::map<std::string, const std::type_info*>::const_iterator |
|
|
|
for (std::map<std::string, const std::type_info*>::const_iterator |
|
|
|
it(_xmlNames.begin()); |
|
|
|
it(_xmlNames.begin()); |
|
|
|
it!=_xmlNames.end(); ++it) { |
|
|
|
it!=_xmlNames.end(); ++it) { |
|
|
|
#define QWERTZ_CHECK_TYPE_ZTREWQ___XXX(TYPE) \ |
|
|
|
#define QWERTZ_CHECK_TYPE_ZTREWQ___XXX(TYPE) \ |
|
|
|
if (*it->second==typeid(TYPE)) \
|
|
|
|
if (*it->second==typeid(TYPE)) \
|
|
|
|
toNode(mapName<TYPE>()[it->first], node); \
|
|
|
|
toNode(mapName<TYPE>()[std::make_pair(this, it->first)], node); \
|
|
|
|
else |
|
|
|
else |
|
|
|
QWERTZ_CHECK_TYPE_ZTREWQ___XXX(Serialize) |
|
|
|
QWERTZ_CHECK_TYPE_ZTREWQ___XXX(Serialize) |
|
|
|
QWERTZ_CHECK_TYPE_ZTREWQ___XXX(std::string) |
|
|
|
QWERTZ_CHECK_TYPE_ZTREWQ___XXX(std::string) |
|
|
@ -1059,9 +1096,9 @@ namespace xml { |
|
|
|
for (std::map<std::string, const std::type_info*>::const_iterator |
|
|
|
for (std::map<std::string, const std::type_info*>::const_iterator |
|
|
|
it(_xmlNames.begin()); |
|
|
|
it(_xmlNames.begin()); |
|
|
|
it!=_xmlNames.end(); ++it) { |
|
|
|
it!=_xmlNames.end(); ++it) { |
|
|
|
#define QWERTZ_CHECK_TYPE_ZTREWQ___XXX(TYPE) \ |
|
|
|
#define QWERTZ_CHECK_TYPE_ZTREWQ___XXX(TYPE) \ |
|
|
|
if (*it->second==typeid(TYPE)) \
|
|
|
|
if (*it->second==typeid(TYPE)) \
|
|
|
|
fromNode(mapName<TYPE>()[it->first], *node); \
|
|
|
|
fromNode(mapName<TYPE>()[std::make_pair(this, it->first)], *node); \
|
|
|
|
else |
|
|
|
else |
|
|
|
QWERTZ_CHECK_TYPE_ZTREWQ___XXX(Serialize) |
|
|
|
QWERTZ_CHECK_TYPE_ZTREWQ___XXX(Serialize) |
|
|
|
QWERTZ_CHECK_TYPE_ZTREWQ___XXX(std::string) |
|
|
|
QWERTZ_CHECK_TYPE_ZTREWQ___XXX(std::string) |
|
|
|