boost::any instead of macros - first pieces of meta template programming
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <typeinfo>
|
||||
@@ -819,6 +820,8 @@ namespace xml {
|
||||
|
||||
class Serialize {
|
||||
public:
|
||||
typedef bool(*FromNodeFunc)(boost::any, const xml::Node&);
|
||||
typedef bool(*ToNodeFunc)(const boost::any, xml::Node&);
|
||||
//! You must call Serialize::className() if you use this constructor!
|
||||
Serialize() throw();
|
||||
Serialize(const std::string& className) throw();
|
||||
@@ -872,10 +875,13 @@ namespace xml {
|
||||
Serialize& persist(std::string& member,
|
||||
const std::string& name) throw();
|
||||
std::ostream& saveXml(std::ostream& os,
|
||||
const std::string& name = std::string()) const throw();
|
||||
const std::string& name = std::string())
|
||||
const throw();
|
||||
std::istream& loadXml(std::istream& is,
|
||||
const std::string& name = std::string());
|
||||
std::string schema() const throw();
|
||||
static void registerFromNode(FromNodeFunc fromNodeFunc);
|
||||
static void registerToNode(ToNodeFunc toNodeFunc);
|
||||
protected:
|
||||
virtual void initXmlMembers();
|
||||
private:
|
||||
@@ -890,9 +896,8 @@ namespace xml {
|
||||
_xmlFactory = schema;
|
||||
return *this;
|
||||
}
|
||||
template<typename TYPE> void fromNode(TYPE* member, xml::Node& node) {
|
||||
*member = (TYPE)dynamic_cast<xml::String&>(node);
|
||||
}
|
||||
void fromNode(boost::any member, const xml::Node& node);
|
||||
void toNode(const boost::any member, xml::Node& node) const;
|
||||
/*
|
||||
template<typename TYPE, class ALLOC>
|
||||
void fromNode(std::list<TYPE, ALLOC>* member, xml::Node& node) {
|
||||
@@ -900,13 +905,10 @@ namespace xml {
|
||||
for (xml::Node::size_type i(0); i<node.children(); ++i)
|
||||
...
|
||||
}*/
|
||||
template<typename TYPE> void toNode(TYPE* member, xml::Node& node) const {
|
||||
std::stringstream ss;
|
||||
ss<<*member;
|
||||
node.text(ss.str());
|
||||
}
|
||||
std::map<std::string, boost::any> _xmlNames;
|
||||
xml::Factory _xmlFactory;
|
||||
static std::set<FromNodeFunc> _fromNode;
|
||||
static std::set<ToNodeFunc> _toNode;
|
||||
};
|
||||
|
||||
//@}
|
||||
|
Reference in New Issue
Block a user