From 6393bf7b037ca014cd1a41c10308b7ee46dc1c51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Fri, 3 Apr 2009 07:07:49 +0000 Subject: [PATCH] Accept but ignore special tags: clone() const throw(); virtual ~String() throw() {} virtual std::string text() const throw(); - virtual String& text(const std::string& txt) throw(tag_expected); + virtual String& text(const std::string& txt) throw(tag_expected, + type_mismatch); + virtual std::ostream& out(std::ostream& o, unsigned int level=0) const + throw(); + virtual String& append(const Node& o) throw(cannot_have_children); + Node& operator=(const std::string& contents) throw(); + private: + std::string _text; + }; + + //---------------------------------------------------------------------------- + class UnsignedInteger: public Node { + public: + String(std::string name, const std::string& text = std::string()) throw(); + virtual std::auto_ptr clone() const throw(); + virtual ~String() throw() {} + virtual std::string text() const throw(); + virtual String& text(const std::string& txt) throw(tag_expected, + type_mismatch); virtual std::ostream& out(std::ostream& o, unsigned int level=0) const throw(); virtual String& append(const Node& o) throw(cannot_have_children); @@ -268,7 +296,7 @@ namespace xml { Factory(const Node& t) throw(); const Node& operator*() const throw(); std::auto_ptr read(std::istream& is) - throw(wrong_end_tag, wrong_start_tag, tag_expected, + throw(wrong_end_tag, wrong_start_tag, tag_expected, type_mismatch, second_slash_in_tag, character_after_slash, missing_end_tag, attribute_value_not_quoted, access_error, empty_stream, duplicate_attribute, attributes_in_end_tag); @@ -278,7 +306,7 @@ namespace xml { Factory(const Factory&); // not implemented bool ws(char c) const throw(); std::auto_ptr read(std::istream& is, const Node& position) - throw(wrong_end_tag, wrong_start_tag, tag_expected, + throw(wrong_end_tag, wrong_start_tag, tag_expected, type_mismatch, second_slash_in_tag, character_after_slash, missing_end_tag, attribute_value_not_quoted, access_error, duplicate_attribute, diff --git a/src/xml.cxx b/src/xml.cxx index ee8b471..cb1741f 100644 --- a/src/xml.cxx +++ b/src/xml.cxx @@ -200,7 +200,7 @@ namespace xml { s+=***it; return s; } - Node& Node::text(const std::string& txt) throw(tag_expected) { + Node& Node::text(const std::string& txt) throw(tag_expected, type_mismatch) { throw tag_expected(*this, txt); } Node& Node::append(const Node& o) throw(cannot_have_children) { @@ -281,7 +281,8 @@ namespace xml { std::string Node::operator*() const throw() { return text(); } - Node& Node::operator=(const std::string& contents) throw(tag_expected) { + Node& Node::operator=(const std::string& contents) throw(tag_expected, + type_mismatch) { return text(contents); } std::ostream& operator<<(std::ostream& o, const Node& t) throw() { @@ -310,7 +311,8 @@ namespace xml { std::string String::text() const throw() { return _text; } - String& String::text(const std::string& txt) throw(tag_expected) { + String& String::text(const std::string& txt) throw(tag_expected, + type_mismatch) { _text = txt; return *this; } @@ -337,13 +339,52 @@ namespace xml { return text(contents); } + //---------------------------------------------------------------------------- + UnsingedInteger::UnsingedInteger(std::string name, const std::string& text) throw(): + Node(name), _text(text) { + } + std::auto_ptr UnsingedInteger::clone() const throw() { + return std::auto_ptr(new UnsingedInteger(*this)); + } + std::string UnsingedInteger::text() const throw() { + return _text; + } + UnsingedInteger& UnsingedInteger::text(const std::string& txt) throw(tag_expected, + type_mismatch) { + _text = txt; + return *this; + } + std::ostream& UnsingedInteger::out(std::ostream& o, unsigned int level) const throw() { + if (_text.size()) { + o<first<<"=\""<second<<'"'; + o<<'>'<<_text<<"'; + } else { + o<first<<"=\""<second<<'"'; + o<<"/>"; + } + return o; + } + UnsingedInteger& UnsingedInteger::append(const Node& o) throw(cannot_have_children) { + throw cannot_have_children(*this, o); + } + Node& UnsingedInteger::operator=(const std::string& contents) throw() { + return text(contents); + } + //---------------------------------------------------------------------------- Factory::Factory(const Node& t) throw(): _template(t.clone()) {} const Node& Factory::operator*() const throw() { return *_template; } std::auto_ptr Factory::read(std::istream& is) - throw(wrong_end_tag, wrong_start_tag, tag_expected, second_slash_in_tag, + throw(wrong_end_tag, wrong_start_tag, tag_expected, type_mismatch, + second_slash_in_tag, character_after_slash, missing_end_tag, attribute_value_not_quoted, access_error, empty_stream, duplicate_attribute, attributes_in_end_tag) { @@ -356,18 +397,19 @@ namespace xml { throw empty_stream(*node, is, res); } *node< Factory::read(std::istream& is, const Node& node) - throw(wrong_end_tag, wrong_start_tag, tag_expected, second_slash_in_tag, + throw(wrong_end_tag, wrong_start_tag, tag_expected, type_mismatch, + second_slash_in_tag, character_after_slash, missing_end_tag, attribute_value_not_quoted, access_error, duplicate_attribute, attributes_in_end_tag) { std::auto_ptr result(node.clone()); @@ -387,6 +429,7 @@ namespace xml { case START: { *result<<(*read(is, node[res.name])<