closes #1
This commit is contained in:
@@ -165,9 +165,9 @@ class MethodTrace {
|
||||
- most standard containers, but in their xml-form,
|
||||
e.g. xml::List instead of @c std::list
|
||||
(xml::List inherits @c std::list)
|
||||
- Optional values through xml::Optional
|
||||
- @c std::bitset, @c std::priority_queue, @c std::queue and
|
||||
@c std::stack are not implemented
|
||||
- Optional values are not yet implemented
|
||||
- Polymorfic serialisation is not yet implemented
|
||||
|
||||
@page rationale Rationale - Limitations of other libraries
|
||||
@@ -787,6 +787,9 @@ namespace xml {
|
||||
virtual Node& text(const std::string& txt) throw(tag_expected,
|
||||
type_mismatch);
|
||||
virtual Node& append(const Node& o) throw(cannot_have_children);
|
||||
virtual Node& remove(Node& n) throw(access_error);
|
||||
virtual Node& remove(const std::string& n) throw(access_error);
|
||||
virtual Node& remove(size_type n) throw(out_of_range);
|
||||
virtual Node& set(const Attributes& o) throw();
|
||||
Node& clear() throw ();
|
||||
std::string name() const throw();
|
||||
@@ -954,6 +957,7 @@ namespace xml {
|
||||
private:
|
||||
friend class stream_error;
|
||||
friend class Serialize;
|
||||
template<class T> friend class Optional;
|
||||
template<class T> friend class Container;
|
||||
template<class T> friend class AssociativeContainer;
|
||||
template<class T> friend class AssociativeMap;
|
||||
@@ -1098,9 +1102,9 @@ namespace xml {
|
||||
Serialize(const Serialize& other) throw();
|
||||
virtual ~Serialize();
|
||||
Serialize& operator=(const Serialize& other) throw();
|
||||
Serialize& className(const std::string& name) throw();
|
||||
virtual Serialize& persist(Serialize& member,
|
||||
const std::string& name) throw();
|
||||
virtual Serialize& className(const std::string& name) throw();
|
||||
Serialize& persist(Serialize& member,
|
||||
const std::string& name) throw();
|
||||
Serialize& persist(bool& member,
|
||||
const std::string& name) throw();
|
||||
Serialize& persist(char& member,
|
||||
@@ -1136,6 +1140,7 @@ namespace xml {
|
||||
static void registerFromNode(FromNodeFunc fromNodeFunc);
|
||||
static void registerToNode(ToNodeFunc toNodeFunc);
|
||||
static void registerClear(ClearFunc clearFunc);
|
||||
virtual void clear() throw();
|
||||
protected:
|
||||
virtual void initXmlMembers();
|
||||
void checkInit(const Serialize* const ser=0) const {
|
||||
@@ -1145,11 +1150,15 @@ namespace xml {
|
||||
if (!_xmlFactory) const_cast<Serialize*>(this)->initXmlMembers();
|
||||
}
|
||||
}
|
||||
virtual void clear() throw();
|
||||
/*! @todo Why does @c protected: not work here?!? Children can't
|
||||
access the members if they are protected! */
|
||||
public:
|
||||
//! @cond INTERNAL
|
||||
template<typename TYPE> friend bool assignFromNode(Any member,
|
||||
const xml::Node& node);
|
||||
template<typename TYPE> friend bool assigntoNode(Any member,
|
||||
const xml::Node& node);
|
||||
virtual bool optional() const throw();
|
||||
void clear(Any member) throw();
|
||||
void reset() throw();
|
||||
void copy(const Serialize& o) throw();
|
||||
@@ -1162,8 +1171,8 @@ namespace xml {
|
||||
_xmlFactory = schema;
|
||||
return *this;
|
||||
}
|
||||
void fromNode(Any member, const xml::Node& node);
|
||||
void toNode(const Any member, xml::Node& node) const;
|
||||
virtual void fromNode(Any member, const xml::Node& node);
|
||||
virtual void toNode(const Any member, xml::Node& node) const;
|
||||
std::map<std::string, Any> _xmlNames;
|
||||
xml::Factory _xmlFactory;
|
||||
static std::set<FromNodeFunc> _fromNode;
|
||||
@@ -1174,54 +1183,71 @@ namespace xml {
|
||||
|
||||
template <class TYPE> class Optional: public Serialize {
|
||||
public:
|
||||
Optional() throw() {}
|
||||
Optional(const Optional& o) throw(): _member(new TYPE(*o._member)) {}
|
||||
Optional(const TYPE& mem) throw(): _member(new TYPE(mem)) {}
|
||||
Optional() throw(): _valid(false) {}
|
||||
Optional(const Optional& o) throw():
|
||||
_member(o._member), _valid(o.valid) {
|
||||
}
|
||||
Optional(const TYPE& mem) throw():
|
||||
_member(mem), _valid(true) {
|
||||
}
|
||||
virtual ~Optional() throw() {}
|
||||
Optional& operator=(const Optional& o) throw() {
|
||||
_member = new TYPE(*o._member);
|
||||
_member = o._member;
|
||||
_valid = o._valid;
|
||||
return *this;
|
||||
}
|
||||
Optional& operator=(const TYPE& mem) throw() {
|
||||
_member = new TYPE(mem);
|
||||
_member = mem;
|
||||
_valid = true;
|
||||
return *this;
|
||||
}
|
||||
operator bool() const throw() {
|
||||
return _member.get();
|
||||
return _valid;
|
||||
}
|
||||
const TYPE& operator*() const throw() {
|
||||
return *_member;
|
||||
return _member;
|
||||
}
|
||||
TYPE& operator*() throw() {
|
||||
return *_member;
|
||||
return _member;
|
||||
}
|
||||
const TYPE*const operator->() const throw() {
|
||||
return _member.get();
|
||||
return &_member;
|
||||
}
|
||||
TYPE*const operator->() throw() {
|
||||
return _member.get();
|
||||
return &_member;
|
||||
}
|
||||
Optional& reset() throw() {
|
||||
_member.reset();
|
||||
virtual void clear() throw() {
|
||||
_valid = false;
|
||||
}
|
||||
virtual Optional& className(const std::string& name) throw() {
|
||||
if (!_xmlFactory) {
|
||||
Serialize::className(name);
|
||||
persist(_member, name);
|
||||
// make the child the root, and it's optional
|
||||
_xmlFactory = (*_xmlFactory)[0];
|
||||
_xmlFactory->limits(0, 1);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
protected:
|
||||
virtual void clear() throw() {
|
||||
_member.reset();
|
||||
virtual bool optional() const throw() {
|
||||
return true;
|
||||
}
|
||||
virtual std::ostream& saveXml(std::ostream& os,
|
||||
const std::string& name = std::string())
|
||||
const throw() {
|
||||
if (!_member.get()) return os;
|
||||
checkInit();
|
||||
xml::Node node(*_xmlFactory);
|
||||
if (name.size()) node.name(name);
|
||||
toNode(*_member, node);
|
||||
os<<node;
|
||||
return os;
|
||||
virtual void fromNode(Any member, const xml::Node& node) {
|
||||
_valid = true;
|
||||
Serialize::fromNode(Any(&_member), node);
|
||||
}
|
||||
virtual void toNode(const Any member, xml::Node& node) const {
|
||||
if (!_valid) {
|
||||
node.parent().remove(node);
|
||||
return;
|
||||
}
|
||||
const Any mem(&const_cast<Optional*>(this)->_member);
|
||||
Serialize::toNode(mem, node);
|
||||
}
|
||||
private:
|
||||
std::auto_ptr<TYPE> _member;
|
||||
TYPE _member;
|
||||
bool _valid;
|
||||
};
|
||||
|
||||
//! @addtogroup serialization
|
||||
@@ -1400,17 +1426,13 @@ namespace xml {
|
||||
if (name.size()) factory->name(name);
|
||||
std::auto_ptr<xml::Node> node(factory.read(is));
|
||||
CONTAINER_TYPE::clear();
|
||||
LOG("READING: "<<*node);
|
||||
for (xml::Node::size_type i(0); i<node->children(); ++i) {
|
||||
typename CONTAINER_TYPE::key_type key;
|
||||
typename CONTAINER_TYPE::mapped_type data;
|
||||
LOG("READING Key: "<<(*node)[i]<<"Value:"<<(*node)[1+i]);
|
||||
Serialize::fromNode(&key, (*node)[i]); // reads into tmp
|
||||
Serialize::fromNode(&data, (*node)[++i]); // key&value
|
||||
insert(typename CONTAINER_TYPE::value_type(key, data));
|
||||
LOG("READ");
|
||||
}
|
||||
LOG("DONE");
|
||||
return is;
|
||||
}
|
||||
virtual std::ostream& saveXml(std::ostream& os,
|
||||
|
Reference in New Issue
Block a user