boost::any instead of macros - first pieces of meta template programming

This commit is contained in:
Marc Wäckerlin
2009-04-28 07:36:07 +00:00
parent 1e09b8a696
commit 933208f849
3 changed files with 167 additions and 83 deletions

View File

@@ -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;
};
//@}