first approach to list - requires work -> are the items xml::Serialize?

This commit is contained in:
Marc Wäckerlin
2009-04-30 08:28:52 +00:00
parent a750bfc1c3
commit 0871fd927f
3 changed files with 117 additions and 73 deletions

View File

@@ -324,6 +324,14 @@ namespace xml {
Node* _node;
};
//----------------------------------------------------------------------------
class type_not_registered: public exception {
public:
type_not_registered(std::string type, std::string name, const Node& t):
exception("serialized node type is not registered\ntype: "
+type+"\nname: "+name, t) {
}
};
//----------------------------------------------------------------------------
class empty_attribute_list: public exception {
public:
empty_attribute_list(const std::string& name) throw():
@@ -701,6 +709,7 @@ namespace xml {
private:
friend class stream_error;
friend class Serialize;
template<class T, class A> friend class List;
Node& operator*() throw(factory_not_valid);
Node*const operator->() throw(factory_not_valid);
bool ws(char c) throw();
@@ -867,9 +876,16 @@ namespace xml {
static void registerToNode(ToNodeFunc toNodeFunc);
protected:
virtual void initXmlMembers();
void checkInit(const Serialize* const ser=0) const {
if (ser) {
if (!ser->_xmlFactory) const_cast<Serialize*>(ser)->initXmlMembers();
} else {
if (!_xmlFactory) const_cast<Serialize*>(this)->initXmlMembers();
}
}
private:
public: //! @todo
void clear() throw();
void reset() throw();
void copy(const Serialize& o) throw();
template<typename TYPE>
Serialize& persistSimpleType(TYPE& member,
@@ -903,25 +919,41 @@ namespace xml {
List(const std::string& className) throw(): Serialize(className) {}
virtual ~List() {}
protected:
/*virtual void initXmlMembers() {
LOG("initXmlMembers std::list");
//_xmlNames[list] = this;
TYPE dummy;
virtual void initXmlMembers() {
std::string itemName("item");
TYPE tmp;
LOG("initXmlMembers List for: "<<typeid(TYPE).name());
if (typeid(TYPE*)==typeid(Serialize*)) {
Serialize* ser((Serialize*)&dummy);
if (!ser->_xmlFactory) ser->initXmlMembers();
LOG("Liste von Serialize");
Serialize* ser((Serialize*)&tmp);
checkInit(ser);
itemName = **ser->_xmlFactory;
}
persist(dummy, itemName);
_xmlFactory->limits(0, 0);
_xmlFactory = xml::Node("dummyroot"); // dummy root, (uninitialized exc)
persist(tmp, itemName); // add _reference as child of dummyroot
(*_xmlFactory)[0].limits(0, 0); // any number of children possible
}
virtual void fromNode(boost::any member, const xml::Node& node) {
LOG("fromNode std::list");
this->clear();
for (xml::Node::size_type i(0); i<node.parent().children(); ++i) {
TYPE tmp;
Serialize::fromNode(&tmp, node.parent()[i]); // reads into tmp
push_back(tmp);
}
}
virtual void toNode(const boost::any member, xml::Node& node) const {
LOG("toNode std::list");
}*/
std::auto_ptr<xml::Node> tpl(node.clone());
xml::Node& parent(node.parent());
parent.clear(); // "node" is now invalid
for (typename List::const_iterator it = this->begin();
it!=this->end(); ++it) {
TYPE tmp;
tmp = *it;
std::auto_ptr<xml::Node> item(tpl->clone());
Serialize::toNode(&tmp, *item);
parent<<*item;
}
}
};
//@}