new tests, cleanup, prepared for node-limits

This commit is contained in:
Marc Wäckerlin
2009-04-09 07:01:25 +00:00
parent 98334b4565
commit f9389d1082
3 changed files with 187 additions and 42 deletions

View File

@@ -9,6 +9,7 @@
#define LIB_XML_CXX_HXX
#include <istream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
@@ -244,6 +245,37 @@ namespace xml {
t, is, tag, 0) {
}
};
class illegal_attribute: public stream_error {
public:
illegal_attribute(const Node& t, std::istream& is, const Tag& tag,
std::string attr) throw():
stream_error("illegal attribute found\nattribute: "+attr,
t, is, tag, 0) {
}
};
class mandatory_attribute_missing: public stream_error {
public:
mandatory_attribute_missing(const Node& t, std::istream& is,
const Tag& tag, std::string attr) throw():
stream_error("mandatory attribute missing\nattribute: "+attr,
t, is, tag, 0) {
}
};
class wrong_node_number: public stream_error {
public:
wrong_node_number(const Node& t, std::istream& is,
const Tag& tag, const std::string& name,
unsigned long num,
unsigned long min, unsigned long max) throw():
stream_error(((std::stringstream&)
(std::stringstream()
<<"wrong number of child nodes\nname of child: "<<name
<<"\nnumber of nodes: "<<num
<<"\nminimuml number: "<<min
<<"\nmaximum number: "<<max)).str(),
t, is, tag, 0) {
}
};
//============================================================================
@@ -298,6 +330,7 @@ namespace xml {
std::string text;
Attributes attributes;
std::string special;
bool found;
};
//----------------------------------------------------------------------------
@@ -311,7 +344,7 @@ namespace xml {
public:
typedef Contents::size_type size_type;
typedef std::vector<Node*> List;
Node(std::string name) throw();
Node(std::string name, size_type min=0, size_type max=0) throw();
Node(const Node& o) throw();
Node& operator=(const Node& o) throw();
virtual ~Node() throw();
@@ -329,10 +362,14 @@ namespace xml {
Node& parent() const throw(no_parent);
bool hasAttr(const std::string& name) const throw();
Node& attr(const std::string& name, bool mandatory) throw();
Node& attr(const std::string& name, const std::string& deflt) throw();
std::string attr(const std::string& name) const throw();
std::string& attr(const std::string& name) throw();
const Attributes::Value attribute(const std::string& name)
const throw(attribute_not_available);
const Attributes& attributes() const throw();
Attributes& attributes() throw();
Node& limits(size_type min=0, size_type max=0) throw();
List list(const std::string& name) const throw();
bool operator()(const std::string& child) const throw();
Node& operator<<(const Node& o) throw(cannot_have_children);
@@ -340,9 +377,9 @@ namespace xml {
//! Get the number of children.
size_type children() const throw();
//! Get the n-th child.
const Node& operator[](size_type child) const throw(access_error);
const Node& operator[](size_type child) const throw(out_of_range);
//! Get the n-th child.
Node& operator[](size_type child) throw(access_error);
Node& operator[](size_type child) throw(out_of_range);
//! Get the first named child.
const Node& operator[](const std::string& child) const
throw(access_error);
@@ -361,6 +398,8 @@ namespace xml {
Contents _contents;
std::string _name;
Node* _parent;
typedef std::pair<Node::size_type, Node::size_type> Limits;
Limits _limits;
};
//----------------------------------------------------------------------------
@@ -401,7 +440,9 @@ namespace xml {
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);
duplicate_attribute, attributes_in_end_tag,
illegal_attribute, mandatory_attribute_missing,
wrong_node_number);
private:
friend class stream_error;
Factory(); // not implemented
@@ -412,13 +453,18 @@ namespace xml {
second_slash_in_tag, character_after_slash,
missing_end_tag,
attribute_value_not_quoted, access_error, duplicate_attribute,
attributes_in_end_tag);
attributes_in_end_tag,
illegal_attribute, mandatory_attribute_missing,
wrong_node_number);
Tag tag(std::istream& is, const Node& position)
throw(second_slash_in_tag, character_after_slash,
missing_end_tag,
attribute_value_not_quoted, access_error, duplicate_attribute);
std::auto_ptr<Node> _template;
throw(second_slash_in_tag, wrong_start_tag, character_after_slash,
missing_end_tag, attributes_in_end_tag, tag_expected,
attribute_value_not_quoted, access_error, duplicate_attribute,
illegal_attribute, mandatory_attribute_missing,
wrong_node_number);
Node _template;
unsigned long _line;
long _open;
};
}