check node number limits
This commit is contained in:
@@ -118,6 +118,14 @@ namespace xml {
|
||||
Node* _node;
|
||||
};
|
||||
//----------------------------------------------------------------------------
|
||||
class empty_attribute_list: public exception {
|
||||
public:
|
||||
empty_attribute_list(const std::string& name) throw():
|
||||
exception("list of attribute is empty access to first element failed"
|
||||
"\nattribute: "+name) {
|
||||
}
|
||||
};
|
||||
//----------------------------------------------------------------------------
|
||||
class no_parent: public exception {
|
||||
public:
|
||||
no_parent(const Node& t) throw(): exception("node has no parent", t) {}
|
||||
@@ -175,6 +183,8 @@ namespace xml {
|
||||
public:
|
||||
stream_error(const std::string& reason, const Node& t,
|
||||
std::istream& is, const Tag& tag, char c=0) throw();
|
||||
stream_error(const std::string& reason, const Node& t,
|
||||
std::istream& is) throw();
|
||||
~stream_error() throw();
|
||||
const char* what() const throw();
|
||||
private:
|
||||
@@ -264,16 +274,19 @@ namespace xml {
|
||||
class wrong_node_number: public stream_error {
|
||||
public:
|
||||
wrong_node_number(const Node& t, std::istream& is,
|
||||
const Tag& tag, const std::string& name,
|
||||
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) {
|
||||
stream_error("wrong number of child nodes\nname of child: "+name
|
||||
+"\nnumber of nodes: "+conv(num)
|
||||
+"\nminimuml number: "+conv(min)
|
||||
+"\nmaximum number: "+conv(max), t, is) {
|
||||
}
|
||||
private:
|
||||
static std::string conv(unsigned long i) throw() {
|
||||
std::stringstream ss;
|
||||
ss<<i;
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -309,6 +322,8 @@ namespace xml {
|
||||
operator unsigned long() const throw();
|
||||
operator List() const throw();
|
||||
List toList(const std::string& separators=" \t\n\r") const throw();
|
||||
std::string front(const std::string& separators=" \t\n\r") const
|
||||
throw(empty_attribute_list);
|
||||
private:
|
||||
Value(); // not implemented, key must always be given
|
||||
};
|
||||
@@ -358,6 +373,10 @@ namespace xml {
|
||||
virtual Node& set(const Attributes& o) throw();
|
||||
Node& clear() throw ();
|
||||
std::string name() const throw();
|
||||
Node& min(size_type m) throw();
|
||||
size_type min() const throw();
|
||||
Node& max(size_type m) throw();
|
||||
size_type max() const throw();
|
||||
bool isChild() const throw();
|
||||
Node& parent() const throw(no_parent);
|
||||
bool hasAttr(const std::string& name) const throw();
|
||||
@@ -398,14 +417,16 @@ namespace xml {
|
||||
Contents _contents;
|
||||
std::string _name;
|
||||
Node* _parent;
|
||||
typedef std::pair<Node::size_type, Node::size_type> Limits;
|
||||
Limits _limits;
|
||||
size_type _min;
|
||||
size_type _max;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
class String: public Node {
|
||||
public:
|
||||
String(std::string name, const std::string& text = std::string()) throw();
|
||||
String(std::string name, size_type min=0, size_type max=0) throw();
|
||||
String(std::string name, const std::string& text,
|
||||
size_type min=0, size_type max=0) throw();
|
||||
virtual std::auto_ptr<Node> clone() const throw();
|
||||
virtual ~String() throw() {}
|
||||
virtual std::string text() const throw();
|
||||
@@ -422,7 +443,8 @@ namespace xml {
|
||||
//----------------------------------------------------------------------------
|
||||
class UnsignedInteger: public String {
|
||||
public:
|
||||
UnsignedInteger(std::string name, unsigned long i = 0) throw();
|
||||
UnsignedInteger(std::string name, unsigned long i=0,
|
||||
size_type min=0, size_type max=0) throw();
|
||||
virtual std::auto_ptr<Node> clone() const throw();
|
||||
virtual ~UnsignedInteger() throw() {}
|
||||
virtual UnsignedInteger& text(const std::string& txt)
|
||||
@@ -456,12 +478,15 @@ namespace xml {
|
||||
attributes_in_end_tag,
|
||||
illegal_attribute, mandatory_attribute_missing,
|
||||
wrong_node_number);
|
||||
std::auto_ptr<Node> checkChildren(const xml::Node& tpl,
|
||||
std::auto_ptr<Node> node,
|
||||
std::istream& is) const
|
||||
throw(wrong_node_number);
|
||||
Tag tag(std::istream& is, const Node& position)
|
||||
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);
|
||||
illegal_attribute, mandatory_attribute_missing);
|
||||
Node _template;
|
||||
unsigned long _line;
|
||||
long _open;
|
||||
|
Reference in New Issue
Block a user