|
|
@ -1135,130 +1135,75 @@ namespace xml { |
|
|
|
} |
|
|
|
} |
|
|
|
template<typename TYPE> bool assignFromNode(boost::any member, |
|
|
|
template<typename TYPE> bool assignFromNode(boost::any member, |
|
|
|
const xml::Node& node) { |
|
|
|
const xml::Node& node) { |
|
|
|
if (member.type()==typeid(TYPE*)) { |
|
|
|
if (member.type()!=typeid(TYPE*)) return false; |
|
|
|
*boost::any_cast<TYPE*>(member) = |
|
|
|
*boost::any_cast<TYPE*>(member) = |
|
|
|
(TYPE)dynamic_cast<const xml::String&>(node); |
|
|
|
(TYPE)dynamic_cast<const xml::String&>(node); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
template<typename TYPE> bool assignToNode(const boost::any member, |
|
|
|
template<typename TYPE> bool assignToNode(const boost::any member, |
|
|
|
xml::Node& node) { |
|
|
|
xml::Node& node) { |
|
|
|
if (member.type()==typeid(TYPE*)) { |
|
|
|
if (member.type()!=typeid(TYPE*)) return false; |
|
|
|
std::stringstream ss; |
|
|
|
std::stringstream ss; |
|
|
|
ss<<*boost::any_cast<TYPE*>(member); |
|
|
|
ss<<*boost::any_cast<TYPE*>(member); |
|
|
|
node.text(ss.str()); |
|
|
|
node.text(ss.str()); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
template<> bool assignFromNode<bool>(boost::any member, |
|
|
|
template<> bool assignFromNode<bool>(boost::any member, |
|
|
|
const xml::Node& node) { |
|
|
|
const xml::Node& node) { |
|
|
|
if (member.type()==typeid(bool*)) { |
|
|
|
if (member.type()!=typeid(bool*)) return false; |
|
|
|
std::string s(*dynamic_cast<const xml::String&>(node)); |
|
|
|
std::string s(*dynamic_cast<const xml::String&>(node)); |
|
|
|
std::string::size_type |
|
|
|
std::string::size_type |
|
|
|
start(s.find_first_not_of(" \t\n\r")), |
|
|
|
start(s.find_first_not_of(" \t\n\r")), |
|
|
|
end(s.find_last_not_of(" \t\n\r")); |
|
|
|
end(s.find_last_not_of(" \t\n\r")); |
|
|
|
if (start==std::string::npos) { |
|
|
|
if (start==std::string::npos) { |
|
|
|
*boost::any_cast<bool*>(member) = false; |
|
|
|
*boost::any_cast<bool*>(member) = false; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
s = s.substr(start, end-start+1); |
|
|
|
s = s.substr(start, end-start+1); |
|
|
|
*boost::any_cast<bool*>(member) =
|
|
|
|
*boost::any_cast<bool*>(member) =
|
|
|
|
s!="0" && s!="false" && s!="no" && s!="off"; |
|
|
|
s!="0" && s!="false" && s!="no" && s!="off"; |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
template<> bool assignToNode<bool>(const boost::any member, |
|
|
|
template<> bool assignToNode<bool>(const boost::any member, |
|
|
|
xml::Node& node) { |
|
|
|
xml::Node& node) { |
|
|
|
if (member.type()==typeid(bool*)) { |
|
|
|
if (member.type()!=typeid(bool*)) return false; |
|
|
|
node.text(*boost::any_cast<bool*>(member)?"true":"false"); |
|
|
|
node.text(*boost::any_cast<bool*>(member)?"true":"false"); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
template<> bool assignFromNode<Serialize>(boost::any member, |
|
|
|
template<> bool assignFromNode<Serialize>(boost::any member, |
|
|
|
const xml::Node& node) { |
|
|
|
const xml::Node& node) { |
|
|
|
if (member.type()==typeid(Serialize*)) { |
|
|
|
if (member.type()!=typeid(Serialize*)) return false; |
|
|
|
//! @todo improve this (inefficient)
|
|
|
|
//! @todo improve this (inefficient)
|
|
|
|
std::stringstream ss; // simple but inefficient: rewrite and reread
|
|
|
|
std::stringstream ss; // simple but inefficient: rewrite and reread
|
|
|
|
ss<<node; |
|
|
|
ss<<node; |
|
|
|
boost::any_cast<Serialize*>(member)->loadXml(ss, node.name()); |
|
|
|
boost::any_cast<Serialize*>(member)->loadXml(ss, node.name()); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
template<> bool assignToNode<Serialize>(const boost::any member, |
|
|
|
template<> bool assignToNode<Serialize>(const boost::any member, |
|
|
|
xml::Node& node) { |
|
|
|
xml::Node& node) { |
|
|
|
if (member.type()==typeid(Serialize*)) { |
|
|
|
if (member.type()!=typeid(Serialize*)) return false; |
|
|
|
std::stringstream ss; |
|
|
|
std::stringstream ss; |
|
|
|
boost::any_cast<Serialize*>(member)->saveXml(ss, node.name()); |
|
|
|
boost::any_cast<Serialize*>(member)->saveXml(ss, node.name()); |
|
|
|
xml::Factory factory(node); |
|
|
|
xml::Factory factory(node); |
|
|
|
node = *factory.read(ss); |
|
|
|
node = *factory.read(ss); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
// template<typename TYPE, template<class TYPE> class CONTAINER>
|
|
|
|
} |
|
|
|
// bool containerFromNode(boost::any member,
|
|
|
|
template<typename TYPE, class ALLOC> |
|
|
|
// const xml::Node& node) {
|
|
|
|
bool containerFromNode(boost::any member, |
|
|
|
// if (member.type()!=typeid(TYPE*)) return false;
|
|
|
|
const xml::Node& node) { |
|
|
|
// LOG("ASSIGN List");
|
|
|
|
LOG("ASSIGN List"); |
|
|
|
// return false;
|
|
|
|
} |
|
|
|
// }
|
|
|
|
// template<typename TYPE, class ALLOC>
|
|
|
|
// template<typename TYPE, class ALLOC>
|
|
|
|
// bool assignToNode(const boost::any member, xml::Node& node) {
|
|
|
|
// bool assignToNode(const boost::any member, xml::Node& node) {
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
void Serialize::registerFromNode(Serialize::FromNodeFunc fromNodeFunc) { |
|
|
|
void Serialize::registerFromNode(Serialize::FromNodeFunc fromNodeFunc) { |
|
|
|
if (!_fromNode.size()) { // initial initialization
|
|
|
|
|
|
|
|
_fromNode.insert(&assignFromNode<Serialize>); |
|
|
|
|
|
|
|
_fromNode.insert(&assignFromNode<std::string>); |
|
|
|
|
|
|
|
_fromNode.insert(&assignFromNode<float>); |
|
|
|
|
|
|
|
_fromNode.insert(&assignFromNode<double>); |
|
|
|
|
|
|
|
_fromNode.insert(&assignFromNode<bool>); |
|
|
|
|
|
|
|
_fromNode.insert(&assignFromNode<char>); |
|
|
|
|
|
|
|
_fromNode.insert(&assignFromNode<signed char>); |
|
|
|
|
|
|
|
_fromNode.insert(&assignFromNode<unsigned char>); |
|
|
|
|
|
|
|
_fromNode.insert(&assignFromNode<short>); |
|
|
|
|
|
|
|
_fromNode.insert(&assignFromNode<signed short>); |
|
|
|
|
|
|
|
_fromNode.insert(&assignFromNode<unsigned short>); |
|
|
|
|
|
|
|
_fromNode.insert(&assignFromNode<int>); |
|
|
|
|
|
|
|
_fromNode.insert(&assignFromNode<signed int>); |
|
|
|
|
|
|
|
_fromNode.insert(&assignFromNode<unsigned int>); |
|
|
|
|
|
|
|
_fromNode.insert(&assignFromNode<long>); |
|
|
|
|
|
|
|
_fromNode.insert(&assignFromNode<signed long>); |
|
|
|
|
|
|
|
_fromNode.insert(&assignFromNode<unsigned long>); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
_fromNode.insert(fromNodeFunc); |
|
|
|
_fromNode.insert(fromNodeFunc); |
|
|
|
} |
|
|
|
} |
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//typedef boost::mpl::vector<Serialize, std::string, float, double, bool, char, signed char, unsigned char, short, signed short, unsigned short, int, signed int, unsigned int, long, signed long, unsigned long> BasicTypes;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//typedef boost::mpl::vector<Serialize, std::string, float, double, bool, char, signed char, unsigned char, short, signed short, unsigned short, int, signed int, unsigned int, long, signed long, unsigned long> BasicTypes;
|
|
|
|
|
|
|
|
template<typename TYPE> class RegisterAssignToNode { |
|
|
|
|
|
|
|
RegisterAssignToNode() { |
|
|
|
|
|
|
|
registerToNode(&assignToNode<TYPE>); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
void Serialize::registerToNode(Serialize::ToNodeFunc toNodeFunc) { |
|
|
|
void Serialize::registerToNode(Serialize::ToNodeFunc toNodeFunc) { |
|
|
|
if (!_toNode.size()) { // initial initialization
|
|
|
|
|
|
|
|
_toNode.insert(&assignToNode<Serialize>); |
|
|
|
|
|
|
|
_toNode.insert(&assignToNode<std::string>); |
|
|
|
|
|
|
|
_toNode.insert(&assignToNode<float>); |
|
|
|
|
|
|
|
_toNode.insert(&assignToNode<double>); |
|
|
|
|
|
|
|
_toNode.insert(&assignToNode<bool>); |
|
|
|
|
|
|
|
_toNode.insert(&assignToNode<char>); |
|
|
|
|
|
|
|
_toNode.insert(&assignToNode<signed char>); |
|
|
|
|
|
|
|
_toNode.insert(&assignToNode<unsigned char>); |
|
|
|
|
|
|
|
_toNode.insert(&assignToNode<short>); |
|
|
|
|
|
|
|
_toNode.insert(&assignToNode<signed short>); |
|
|
|
|
|
|
|
_toNode.insert(&assignToNode<unsigned short>); |
|
|
|
|
|
|
|
_toNode.insert(&assignToNode<int>); |
|
|
|
|
|
|
|
_toNode.insert(&assignToNode<signed int>); |
|
|
|
|
|
|
|
_toNode.insert(&assignToNode<unsigned int>); |
|
|
|
|
|
|
|
_toNode.insert(&assignToNode<long>); |
|
|
|
|
|
|
|
_toNode.insert(&assignToNode<signed long>); |
|
|
|
|
|
|
|
_toNode.insert(&assignToNode<unsigned long>); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
_toNode.insert(toNodeFunc); |
|
|
|
_toNode.insert(toNodeFunc); |
|
|
|
} |
|
|
|
} |
|
|
|
void Serialize::initXmlMembers() {} |
|
|
|
void Serialize::initXmlMembers() {} |
|
|
@ -1287,4 +1232,40 @@ namespace xml { |
|
|
|
std::set<Serialize::FromNodeFunc> Serialize::_fromNode; |
|
|
|
std::set<Serialize::FromNodeFunc> Serialize::_fromNode; |
|
|
|
std::set<Serialize::ToNodeFunc> Serialize::_toNode; |
|
|
|
std::set<Serialize::ToNodeFunc> Serialize::_toNode; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Register for all simple Types =============================================
|
|
|
|
|
|
|
|
template<int NUM> struct SimpleTypes {}; |
|
|
|
|
|
|
|
template<> struct SimpleTypes<1> {typedef std::string Type;}; |
|
|
|
|
|
|
|
template<> struct SimpleTypes<2> {typedef Serialize Type;}; |
|
|
|
|
|
|
|
template<> struct SimpleTypes<3> {typedef bool Type;}; |
|
|
|
|
|
|
|
template<> struct SimpleTypes<4> {typedef unsigned char Type;}; |
|
|
|
|
|
|
|
template<> struct SimpleTypes<5> {typedef signed char Type;}; |
|
|
|
|
|
|
|
template<> struct SimpleTypes<6> {typedef char Type;}; |
|
|
|
|
|
|
|
template<> struct SimpleTypes<7> {typedef unsigned short Type;}; |
|
|
|
|
|
|
|
template<> struct SimpleTypes<8> {typedef signed short Type;}; |
|
|
|
|
|
|
|
template<> struct SimpleTypes<9> {typedef short Type;}; |
|
|
|
|
|
|
|
template<> struct SimpleTypes<10> {typedef unsigned int Type;}; |
|
|
|
|
|
|
|
template<> struct SimpleTypes<11> {typedef signed int Type;}; |
|
|
|
|
|
|
|
template<> struct SimpleTypes<12> {typedef int Type;}; |
|
|
|
|
|
|
|
template<> struct SimpleTypes<13> {typedef unsigned long Type;}; |
|
|
|
|
|
|
|
template<> struct SimpleTypes<14> {typedef signed long Type;}; |
|
|
|
|
|
|
|
template<> struct SimpleTypes<15> {typedef long Type;}; |
|
|
|
|
|
|
|
template<> struct SimpleTypes<16> {typedef float Type;}; |
|
|
|
|
|
|
|
template<> struct SimpleTypes<17> {typedef double Type;}; |
|
|
|
|
|
|
|
const int START_NUM(17); |
|
|
|
|
|
|
|
// Init To and From Node ---------------------------------------------------
|
|
|
|
|
|
|
|
namespace { |
|
|
|
|
|
|
|
template<int NUM=START_NUM> struct RegisterTemplateForStdTypes { |
|
|
|
|
|
|
|
RegisterTemplateForStdTypes<NUM-1> next; // recurse to next until 0
|
|
|
|
|
|
|
|
RegisterTemplateForStdTypes() { |
|
|
|
|
|
|
|
Serialize::registerToNode |
|
|
|
|
|
|
|
(&assignToNode<typename SimpleTypes<NUM>::Type>); |
|
|
|
|
|
|
|
Serialize::registerFromNode |
|
|
|
|
|
|
|
(&assignFromNode<typename SimpleTypes<NUM>::Type>); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
template<> struct RegisterTemplateForStdTypes<0> {}; // stop recursion
|
|
|
|
|
|
|
|
static RegisterTemplateForStdTypes<> init; // execute initialisation
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|