fix for C++17, requires at least C+17

This commit is contained in:
Marc Wäckerlin
2018-11-21 22:23:14 +00:00
parent 99b12cb4d9
commit b7b5c2d3ff
11 changed files with 1761 additions and 619 deletions

View File

@@ -23,26 +23,27 @@
#include <cassert>
#include <iostream>
#include <iomanip>
class MethodTrace {
public:
MethodTrace(const void* addr, const std::string& name) throw():
_addr(addr), _name(name) {
std::clog<<std::hex<<std::setw(15)<<_addr<<": "
<<std::dec<<std::setw(2+_level)
<<std::setfill(' ')<<"\\ "<<_name<<std::endl;
++_level;
}
~MethodTrace() throw() {
namespace xml {
class MethodTrace {
public:
MethodTrace(const void* addr, const std::string& name) noexcept:
_addr(addr), _name(name) {
std::clog<<std::hex<<std::setw(15)<<_addr<<": "
<<std::dec<<std::setw(2+_level)
<<std::setfill(' ')<<"\\ "<<_name<<std::endl;
++_level;
}
~MethodTrace() noexcept {
--_level;
std::clog<<std::hex<<std::setw(15)<<_addr<<": "<<std::dec
<<std::setw(2+_level)<<std::setfill(' ')
<<"/ "<<_name<<std::endl;
}
private:
const void* _addr;
const std::string _name;
static unsigned int _level;
};
}
private:
const void* _addr;
const std::string _name;
static unsigned int _level;
};
#define TRACE MethodTrace XXX_METHOD(this, __PRETTY_FUNCTION__)
#define LOG(X) std::clog<<__PRETTY_FUNCTION__<<"\t**** "<<X<<std::endl
#define ASSERT(X, Y) { \
@@ -50,8 +51,9 @@ class MethodTrace {
LOG(X); \
} \
assert(Y); \
}
//! @endcond
}
//! @endcond
/*! @mainpage
@@ -495,11 +497,11 @@ namespace xml {
//----------------------------------------------------------------------------
class exception: public std::exception {
public:
exception(std::string reason) throw();
exception(std::string reason, const Node& t) throw();
~exception() throw();
void line(unsigned long line) throw();
const char* what() const throw();
exception(std::string reason) noexcept;
exception(std::string reason, const Node& t) noexcept;
~exception() noexcept;
void line(unsigned long line) noexcept;
const char* what() const noexcept;
private:
std::string _what;
Node* _node;
@@ -518,7 +520,7 @@ namespace xml {
//----------------------------------------------------------------------------
class empty_attribute_list: public exception {
public:
empty_attribute_list(const std::string& name) throw():
empty_attribute_list(const std::string& name) noexcept:
exception("list of attribute is empty access to first element failed"
"\nattribute: "+name) {
}
@@ -526,60 +528,60 @@ namespace xml {
//----------------------------------------------------------------------------
class factory_not_valid: public exception {
public:
factory_not_valid() throw():
factory_not_valid() noexcept:
exception("a factory must be given a template node") {
}
};
//----------------------------------------------------------------------------
class no_parent: public exception {
public:
no_parent(const Node& t) throw(): exception("node has no parent", t) {}
no_parent(const Node& t) noexcept: exception("node has no parent", t) {}
};
//----------------------------------------------------------------------------
class tag_expected: public exception {
public:
tag_expected(const Node& t, const std::string& txt) throw():
tag_expected(const Node& t, const std::string& txt) noexcept:
exception("tag ('<') expected, text not allowed\ntext: "+txt, t) {}
};
//----------------------------------------------------------------------------
class type_mismatch: public exception {
public:
type_mismatch(const Node& t, const std::string& txt,
const std::string& comment) throw():
const std::string& comment) noexcept:
exception("wrong type, text contains mismatching character\n"+comment
+"\ntext: "+txt, t) {}
};
//----------------------------------------------------------------------------
class access_error: public exception {
public:
access_error(const Node& t, const std::string& name) throw();
~access_error() throw() {}
const char* what() const throw();
access_error(const Node& t, const std::string& name) noexcept;
~access_error() noexcept {}
const char* what() const noexcept;
private:
std::string _name;
};
//----------------------------------------------------------------------------
class out_of_range: public exception {
public:
out_of_range(const Node& t, size_t pos) throw();
~out_of_range() throw() {}
const char* what() const throw();
out_of_range(const Node& t, size_t pos) noexcept;
~out_of_range() noexcept {}
const char* what() const noexcept;
private:
size_t _pos;
};
//----------------------------------------------------------------------------
class cannot_have_children: public exception {
public:
cannot_have_children(const Node& parent, const Node& child) throw();
~cannot_have_children() throw();
const char* what() const throw();
cannot_have_children(const Node& parent, const Node& child) noexcept;
~cannot_have_children() noexcept;
const char* what() const noexcept;
private:
Node* _child;
};
//----------------------------------------------------------------------------
class attribute_not_available: public exception {
public:
attribute_not_available(const Node& t, const std::string& attr) throw():
attribute_not_available(const Node& t, const std::string& attr) noexcept:
exception("attribute \""+attr+"\" not set", t) {
}
};
@@ -587,11 +589,11 @@ namespace xml {
class stream_error: public exception {
public:
stream_error(const std::string& reason, const Node& t,
std::istream& is, const Tag& tag, char c=0) throw();
std::istream& is, const Tag& tag, char c=0) noexcept;
stream_error(const std::string& reason, const Node& t,
std::istream& is) throw();
~stream_error() throw();
const char* what() const throw();
std::istream& is) noexcept;
~stream_error() noexcept;
const char* what() const noexcept;
private:
std::istream::streampos _pos;
Tag* _tag;
@@ -601,7 +603,7 @@ namespace xml {
class wrong_end_tag: public stream_error {
public:
wrong_end_tag(const Node& t, std::istream& is, const Tag& tag, char c=0)
throw():
noexcept:
stream_error("mismatching end tag", t, is, tag, c) {
}
};
@@ -609,7 +611,7 @@ namespace xml {
class missing_end_tag: public stream_error {
public:
missing_end_tag(const Node& t, std::istream& is, const Tag& tag, char c=0)
throw():
noexcept:
stream_error("missing end tag, end of file reached", t, is, tag, c) {
}
};
@@ -617,7 +619,7 @@ namespace xml {
class wrong_start_tag: public stream_error {
public:
wrong_start_tag(const Node& t, std::istream& is, const Tag& tag, char c=0)
throw():
noexcept:
stream_error("start tag does not match expected tag", t, is, tag, c) {
}
};
@@ -626,7 +628,7 @@ namespace xml {
public:
second_slash_in_tag(const Node& t, std::istream& is, const Tag& tag,
char c=0)
throw():
noexcept:
stream_error("a tag may have no more than one slash", t, is, tag, c) {
}
};
@@ -635,7 +637,7 @@ namespace xml {
public:
character_after_slash(const Node& t, std::istream& is, const Tag& tag,
char c=0)
throw():
noexcept:
stream_error("unexpected character after empty-slash",
t, is, tag, c) {
}
@@ -644,7 +646,7 @@ namespace xml {
class attributes_in_end_tag: public stream_error {
public:
attributes_in_end_tag(const Node& t, std::istream& is, const Tag& tag)
throw():
noexcept:
stream_error("attributes are not allowed in end tags",t, is, tag) {
}
};
@@ -653,7 +655,7 @@ namespace xml {
public:
attribute_value_not_quoted(const Node& t, std::istream& is,
const Tag& tag,
char c, std::string attr) throw():
char c, std::string attr) noexcept:
stream_error("attribute values must be quoted (\")\nattribute: "+attr,
t, is, tag, c) {
}
@@ -662,7 +664,7 @@ namespace xml {
class duplicate_attribute: public stream_error {
public:
duplicate_attribute(const Node& t, std::istream& is, const Tag& tag,
std::string attr) throw():
std::string attr) noexcept:
stream_error("attribute duplicated\nattribute: "+attr,
t, is, tag, 0) {
}
@@ -671,7 +673,7 @@ namespace xml {
class illegal_attribute: public stream_error {
public:
illegal_attribute(const Node& t, std::istream& is, const Tag& tag,
std::string attr) throw():
std::string attr) noexcept:
stream_error("illegal attribute found\nattribute: "+attr,
t, is, tag, 0) {
}
@@ -680,7 +682,7 @@ namespace xml {
class mandatory_attribute_missing: public stream_error {
public:
mandatory_attribute_missing(const Node& t, std::istream& is,
const Tag& tag, std::string attr) throw():
const Tag& tag, std::string attr) noexcept:
stream_error("mandatory attribute missing\nattribute: "+attr,
t, is, tag, 0) {
}
@@ -691,14 +693,14 @@ namespace xml {
wrong_node_number(const Node& t, std::istream& is,
const std::string& name,
unsigned long num,
unsigned long min, unsigned long max) throw():
unsigned long min, unsigned long max) noexcept:
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() {
static std::string conv(unsigned long i) noexcept {
std::stringstream ss;
ss<<i;
return ss.str();
@@ -730,29 +732,28 @@ namespace xml {
@note Simply use xml::Attr instead of xml::Attributes::Value. */
class Value: public value_type {
public:
Value(const value_type& o) throw();
Value(const std::string& name) throw();
Value(const std::string& name, const std::string& namevalue) throw();
Value& operator=(const std::string& value) throw();
const std::string& name() const throw();
const std::string& value() const throw();
std::string& value() throw();
operator bool() const throw();
bool toBool() const throw();
operator unsigned long() const throw();
unsigned long toNumber() 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);
Value(const value_type& o) noexcept;
Value(const std::string& name) noexcept;
Value(const std::string& name, const std::string& namevalue) noexcept;
Value& operator=(const std::string& value) noexcept;
const std::string& name() const noexcept;
const std::string& value() const noexcept;
std::string& value() noexcept;
operator bool() const noexcept;
bool toBool() const noexcept;
operator unsigned long() const noexcept;
unsigned long toNumber() const noexcept;
operator List() const noexcept;
List toList(const std::string& separators=" \t\n\r") const noexcept;
std::string front(const std::string& separators=" \t\n\r") const;
private:
Value(); // not implemented, key must always be given
};
Attributes() throw();
Attributes(const std::string& empty) throw();
Attributes(const std::string& key, const std::string& value) throw();
Attributes& operator<<(const Value& v) throw();
Attributes& operator<<(const std::string& key) throw();
Attributes() noexcept;
Attributes(const std::string& empty) noexcept;
Attributes(const std::string& key, const std::string& value) noexcept;
Attributes& operator<<(const Value& v) noexcept;
Attributes& operator<<(const std::string& key) noexcept;
};
//! Simplification: Use xml::Attr instead of xml::Attributes::Value.
typedef Attributes::Value Attr;
@@ -780,63 +781,59 @@ namespace xml {
public:
typedef Contents::size_type size_type;
typedef std::vector<Node*> List;
Node(std::string name, size_type min=0, size_type max=0) throw();
Node(const Node& o) throw();
virtual ~Node() throw();
virtual Node& operator=(const Node& o) throw();
virtual std::unique_ptr<Node> clone() const throw();
Node(std::string name, size_type min=0, size_type max=0) noexcept;
Node(const Node& o) noexcept;
virtual ~Node() noexcept;
virtual Node& operator=(const Node& o) noexcept;
virtual std::unique_ptr<Node> clone() const noexcept;
virtual std::ostream& out(std::ostream& o, unsigned int level=0) const
throw();
virtual std::string text() const throw();
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();
noexcept;
virtual std::string text() const noexcept;
virtual Node& text(const std::string& txt);
virtual Node& append(const Node& o);
virtual Node& remove(Node& n);
virtual Node& remove(const std::string& n);
virtual Node& remove(size_type n);
virtual Node& set(const Attributes& o) noexcept;
Node& clear() throw ();
std::string name() const throw();
Node& name(const std::string& n) 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();
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();
const Node& first() const throw(out_of_range);
Node& first() throw(out_of_range);
const Node& last() const throw(out_of_range);
Node& last() throw(out_of_range);
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);
Node& operator<<(const Attributes& o) throw();
size_type children() const throw();
const Node& operator[](size_type child) const throw(out_of_range);
Node& operator[](size_type child) throw(out_of_range);
const Node& operator[](const std::string& child) const
throw(access_error);
Node& operator[](const std::string& child) throw(access_error);
std::string operator*() const throw();
Node& operator=(const std::string& contents) throw(tag_expected,
type_mismatch);
friend std::ostream& operator<<(std::ostream& o, const Node& t) throw();
std::string name() const noexcept;
Node& name(const std::string& n) noexcept;
Node& min(size_type m) noexcept;
size_type min() const noexcept;
Node& max(size_type m) noexcept;
size_type max() const noexcept;
bool isChild() const noexcept;
Node& parent() const;
bool hasAttr(const std::string& name) const noexcept;
Node& attr(const std::string& name, bool mandatory) noexcept;
Node& attr(const std::string& name, const std::string& deflt) noexcept;
std::string attr(const std::string& name) const noexcept;
std::string& attr(const std::string& name) noexcept;
const Attributes::Value attribute(const std::string& name) const;
const Attributes& attributes() const noexcept;
Attributes& attributes() noexcept;
const Node& first() const;
Node& first();
const Node& last() const;
Node& last();
Node& limits(size_type min=0, size_type max=0) noexcept;
List list(const std::string& name) const noexcept;
bool operator()(const std::string& child) const noexcept;
Node& operator<<(const Node& o);
Node& operator<<(const Attributes& o) noexcept;
size_type children() const noexcept;
const Node& operator[](size_type child) const;
Node& operator[](size_type child);
const Node& operator[](const std::string& child) const;
Node& operator[](const std::string& child);
std::string operator*() const noexcept;
Node& operator=(const std::string& contents);
friend std::ostream& operator<<(std::ostream& o, const Node& t) noexcept;
protected:
Attributes _attributes;
private:
Node* find(const std::string& child) const throw();
virtual std::unique_ptr<Node> clone(Node* p) const throw();
Node* find(const std::string& child) const noexcept;
virtual std::unique_ptr<Node> clone(Node* p) const noexcept;
Node(); // not implemented
Contents _contents;
std::string _name;
@@ -850,31 +847,30 @@ namespace xml {
class String: public Node {
public:
String(std::string name,
Node::size_type min=0, Node::size_type max=0) throw();
Node::size_type min=0, Node::size_type max=0) noexcept;
String(std::string name, const std::string& text,
Node::size_type min=0, Node::size_type max=0) throw();
virtual ~String() throw() {}
virtual std::unique_ptr<Node> clone() const throw();
virtual std::string text() const throw();
virtual String& text(const std::string& txt) throw(tag_expected,
type_mismatch);
Node::size_type min=0, Node::size_type max=0) noexcept;
virtual ~String() noexcept {}
virtual std::unique_ptr<Node> clone() const noexcept;
virtual std::string text() const noexcept;
virtual String& text(const std::string& txt);
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();
operator std::string() const throw();
operator bool() const throw();
operator char() const throw();
operator signed char() const throw();
operator unsigned char() const throw();
operator signed short() const throw();
operator unsigned short() const throw();
operator signed int() const throw();
operator unsigned int() const throw();
operator signed long() const throw();
operator unsigned long() const throw();
operator float() const throw();
operator double() const throw();
noexcept;
virtual String& append(const Node& o);
Node& operator=(const std::string& contents) noexcept;
operator std::string() const noexcept;
operator bool() const noexcept;
operator char() const noexcept;
operator signed char() const noexcept;
operator unsigned char() const noexcept;
operator signed short() const noexcept;
operator unsigned short() const noexcept;
operator signed int() const noexcept;
operator unsigned int() const noexcept;
operator signed long() const noexcept;
operator unsigned long() const noexcept;
operator float() const noexcept;
operator double() const noexcept;
protected:
std::string _text;
};
@@ -884,13 +880,12 @@ namespace xml {
class UnsignedInteger: public String {
public:
UnsignedInteger(std::string name, unsigned long i=0,
size_type min=0, size_type max=0) throw();
virtual std::unique_ptr<Node> clone() const throw();
virtual ~UnsignedInteger() throw() {}
virtual UnsignedInteger& text(const std::string& txt)
throw(tag_expected, type_mismatch);
unsigned long number() const throw();
static unsigned long number(const Node& node) throw();
size_type min=0, size_type max=0) noexcept;
virtual std::unique_ptr<Node> clone() const noexcept;
virtual ~UnsignedInteger() noexcept {}
virtual UnsignedInteger& text(const std::string& txt);
unsigned long number() const noexcept;
static unsigned long number(const Node& node) noexcept;
};
//----------------------------------------------------------------------------
@@ -942,26 +937,19 @@ namespace xml {
@endverbatim */
class Factory {
public:
Factory(const Node& t) throw();
Factory() throw();
Factory& operator=(const Node& t) throw();
Factory& append(const Node& node) throw();
const Node& operator*() const throw(factory_not_valid);
const Node*const operator->() const throw(factory_not_valid);
operator bool() const throw();
Factory(const Node& t) noexcept;
Factory() noexcept;
Factory& operator=(const Node& t) noexcept;
Factory& append(const Node& node) noexcept;
const Node& operator*() const;
const Node* operator->() const;
operator bool() const noexcept;
friend std::ostream& operator<<(std::ostream& os,
const Factory& factory)
throw(factory_not_valid);
const Factory& factory);
static std::ostream& print(std::ostream& os, const Node& node,
unsigned int level=0) throw();
std::unique_ptr<Node> read(std::istream& is)
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,
illegal_attribute, mandatory_attribute_missing,
wrong_node_number, factory_not_valid);
void reset() throw();
unsigned int level=0) noexcept;
std::unique_ptr<Node> read(std::istream& is);
void reset() noexcept;
private:
friend class stream_error;
friend class Serialize;
@@ -969,33 +957,21 @@ namespace xml {
template<class T> friend class Container;
template<class T> friend class AssociativeContainer;
template<class T> friend class AssociativeMap;
Node& operator*() throw(factory_not_valid);
Node*const operator->() throw(factory_not_valid);
bool ws(char c) throw();
std::unique_ptr<Node> read(std::istream& is, const Node& position)
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,
illegal_attribute, mandatory_attribute_missing,
wrong_node_number);
Node& operator*();
Node* operator->();
bool ws(char c) noexcept;
std::unique_ptr<Node> read(std::istream& is, const Node& position);
std::unique_ptr<Node> checkChildren(const xml::Node& tpl,
std::unique_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);
std::istream& is) const;
Tag tag(std::istream& is, const Node& position);
Node _template;
unsigned long _line;
long _open;
};
//@}
/*! @defgroup serialization Class Serialization
/*! @defgroup groupserialization Class Serialization
@section serIntro Introduction
@@ -1096,7 +1072,7 @@ namespace xml {
- ... the child does not inherit xml::Serialize, but a child of it
- ... the child must first call xml::Serialize::initXmlMembers of
the parent in it's own xml::Serialize::initXmlMembers */
//! @addtogroup serialization
//! @addtogroup groupserialization
//@{
class Serialize {
@@ -1105,50 +1081,50 @@ namespace xml {
typedef bool(*ToNodeFunc)(const Any, xml::Node&);
typedef bool(*ClearFunc)(Any);
//! You must call Serialize::className() if you use this constructor!
Serialize() throw();
Serialize(const std::string& className) throw();
Serialize(const Serialize& other) throw();
Serialize() noexcept;
Serialize(const std::string& className) noexcept;
Serialize(const Serialize& other) noexcept;
virtual ~Serialize();
Serialize& operator=(const Serialize& other) throw();
virtual Serialize& className(const std::string& name) throw();
Serialize& operator=(const Serialize& other) noexcept;
virtual Serialize& className(const std::string& name) noexcept;
Serialize& persist(Serialize& member,
const std::string& name) throw();
const std::string& name) noexcept;
Serialize& persist(bool& member,
const std::string& name) throw();
const std::string& name) noexcept;
Serialize& persist(char& member,
const std::string& name) throw();
const std::string& name) noexcept;
Serialize& persist(unsigned char& member,
const std::string& name) throw();
const std::string& name) noexcept;
Serialize& persist(signed char& member,
const std::string& name) throw();
const std::string& name) noexcept;
Serialize& persist(unsigned short& member,
const std::string& name) throw();
const std::string& name) noexcept;
Serialize& persist(signed short& member,
const std::string& name) throw();
const std::string& name) noexcept;
Serialize& persist(unsigned int& member,
const std::string& name) throw();
const std::string& name) noexcept;
Serialize& persist(signed int& member,
const std::string& name) throw();
const std::string& name) noexcept;
Serialize& persist(unsigned long& member,
const std::string& name) throw();
const std::string& name) noexcept;
Serialize& persist(signed long& member,
const std::string& name) throw();
const std::string& name) noexcept;
Serialize& persist(float& member,
const std::string& name) throw();
const std::string& name) noexcept;
Serialize& persist(double& member,
const std::string& name) throw();
const std::string& name) noexcept;
Serialize& persist(std::string& member,
const std::string& name) throw();
const std::string& name) noexcept;
virtual std::ostream& saveXml(std::ostream& os,
const std::string& name = std::string())
const throw();
const noexcept;
virtual std::istream& loadXml(std::istream& is,
const std::string& name = std::string());
std::string schema() const throw();
std::string schema() const noexcept;
static void registerFromNode(FromNodeFunc fromNodeFunc);
static void registerToNode(ToNodeFunc toNodeFunc);
static void registerClear(ClearFunc clearFunc);
virtual void clear() throw();
virtual void clear();
protected:
virtual void initXmlMembers();
void checkInit(const Serialize* const ser=0) const {
@@ -1166,13 +1142,13 @@ namespace xml {
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();
virtual bool optional() const noexcept;
void clear(Any member);
void reset() noexcept;
void copy(const Serialize& o) noexcept;
template<typename TYPE>
Serialize& persistSimpleType(TYPE& member,
const std::string& name) throw() {
const std::string& name) noexcept {
_xmlNames[name] = &member;
xml::Node schema(*_xmlFactory);
schema<<xml::String(name).limits(1,1);
@@ -1191,43 +1167,43 @@ namespace xml {
template <class TYPE> class Optional: public Serialize {
public:
Optional() throw(): _valid(false) {}
Optional(const Optional& o) throw():
Optional() noexcept: _valid(false) {}
Optional(const Optional& o) noexcept:
_member(o._member), _valid(o.valid) {
}
Optional(const TYPE& mem) throw():
Optional(const TYPE& mem) noexcept:
_member(mem), _valid(true) {
}
virtual ~Optional() throw() {}
Optional& operator=(const Optional& o) throw() {
virtual ~Optional() noexcept {}
Optional& operator=(const Optional& o) noexcept {
_member = o._member;
_valid = o._valid;
return *this;
}
Optional& operator=(const TYPE& mem) throw() {
Optional& operator=(const TYPE& mem) noexcept {
_member = mem;
_valid = true;
return *this;
}
operator bool() const throw() {
operator bool() const noexcept {
return _valid;
}
const TYPE& operator*() const throw() {
const TYPE& operator*() const noexcept {
return _member;
}
TYPE& operator*() throw() {
TYPE& operator*() noexcept {
return _member;
}
const TYPE*const operator->() const throw() {
const TYPE* operator->() const noexcept {
return &_member;
}
TYPE*const operator->() throw() {
TYPE* operator->() noexcept {
return &_member;
}
virtual void clear() throw() {
virtual void clear() noexcept {
_valid = false;
}
virtual Optional& className(const std::string& name) throw() {
virtual Optional& className(const std::string& name) noexcept {
if (!_xmlFactory) {
Serialize::className(name);
persist(_member, name);
@@ -1238,7 +1214,7 @@ namespace xml {
return *this;
}
protected:
virtual bool optional() const throw() {
virtual bool optional() const noexcept {
return true;
}
virtual void fromNode(Any member, const xml::Node& node) {
@@ -1258,7 +1234,7 @@ namespace xml {
bool _valid;
};
//! @addtogroup serialization
//! @addtogroup groupserialization
//@{
/*! @defgroup serContainer Serialization of Container
@@ -1295,7 +1271,7 @@ namespace xml {
public:
Container() {}
Container(const Container& o): CONTAINER_TYPE(o), Serialize(o) {}
Container(const std::string& className) throw(): Serialize(className) {}
Container(const std::string& className) noexcept: Serialize(className) {}
virtual ~Container() {}
virtual std::istream& loadXml(std::istream& is,
const std::string& name = std::string()) {
@@ -1313,7 +1289,7 @@ namespace xml {
}
virtual std::ostream& saveXml(std::ostream& os,
const std::string& name = std::string())
const throw() {
const noexcept {
checkInit();
xml::Node node(*_xmlFactory);
if (name.size()) node.name(name);
@@ -1344,7 +1320,7 @@ namespace xml {
persist(tmp, itemName); // add as child of dummyroot
(*_xmlFactory)[0].limits(0, 0); // any number of children possible
}
virtual void clear() throw() {
virtual void clear() noexcept {
CONTAINER_TYPE::clear();
}
};
@@ -1357,7 +1333,7 @@ namespace xml {
AssociativeContainer(const AssociativeContainer& o):
CONTAINER_TYPE(o), Serialize(o) {
}
AssociativeContainer(const std::string& className) throw():
AssociativeContainer(const std::string& className) noexcept:
Serialize(className) {
}
virtual ~AssociativeContainer() {}
@@ -1377,7 +1353,7 @@ namespace xml {
}
virtual std::ostream& saveXml(std::ostream& os,
const std::string& name = std::string())
const throw() {
const noexcept {
checkInit();
xml::Node node(*_xmlFactory);
if (name.size()) node.name(name);
@@ -1411,7 +1387,7 @@ namespace xml {
persist(tmp, itemName); // add as child of dummyroot
(*_xmlFactory)[0].limits(0, 0); // any number of children possible
}
virtual void clear() throw() {
virtual void clear() noexcept {
CONTAINER_TYPE::clear();
}
};
@@ -1424,7 +1400,7 @@ namespace xml {
AssociativeMap(const AssociativeMap& o):
CONTAINER_TYPE(o), Serialize(o) {
}
AssociativeMap(const std::string& className) throw():
AssociativeMap(const std::string& className) noexcept:
Serialize(className) {
}
virtual ~AssociativeMap() {}
@@ -1446,7 +1422,7 @@ namespace xml {
}
virtual std::ostream& saveXml(std::ostream& os,
const std::string& name = std::string())
const throw() {
const noexcept {
checkInit();
xml::Node node(*_xmlFactory);
if (name.size()) node.name(name);
@@ -1492,7 +1468,7 @@ namespace xml {
(*_xmlFactory)[0].limits(0, 0); // any number of children possible
(*_xmlFactory)[1].limits(0, 0); // any number of children possible
}
virtual void clear() throw() {
virtual void clear() noexcept {
CONTAINER_TYPE::clear();
}
};
@@ -1516,18 +1492,18 @@ namespace xml {
CONTAINER(const CONTAINER& o): \
Container<STD_CONTAINER<TYPE, ALLOC> >(o) { \
} \
CONTAINER(const std::string& className) throw(): \
CONTAINER(const std::string& className) noexcept: \
Container<STD_CONTAINER<TYPE, ALLOC> >(className) { \
} \
virtual ~CONTAINER() {} \
}; \
}
# include <list>
__XML_CXX_DECLARE_CONTAINER_CLASS__(List, std::list);
__XML_CXX_DECLARE_CONTAINER_CLASS__(List, std::list)
# include <vector>
__XML_CXX_DECLARE_CONTAINER_CLASS__(Vector, std::vector);
__XML_CXX_DECLARE_CONTAINER_CLASS__(Vector, std::vector)
# include <deque>
__XML_CXX_DECLARE_CONTAINER_CLASS__(Deque, std::deque);
__XML_CXX_DECLARE_CONTAINER_CLASS__(Deque, std::deque)
# undef __XML_CXX_DECLARE_CONTAINER_CLASS__
# define __XML_CXX_DECLARE_CONTAINER_CLASS__(CONTAINER, STD_CONTAINER) \
namespace xml { \
@@ -1541,7 +1517,7 @@ __XML_CXX_DECLARE_CONTAINER_CLASS__(Deque, std::deque);
AssociativeContainer \
<STD_CONTAINER<TYPE, CONT> >(o) { \
} \
CONTAINER(const std::string& className) throw(): \
CONTAINER(const std::string& className) noexcept: \
AssociativeContainer \
<STD_CONTAINER<TYPE, CONT> > \
(className) { \
@@ -1550,9 +1526,9 @@ __XML_CXX_DECLARE_CONTAINER_CLASS__(Deque, std::deque);
}; \
}
# include <stack>
__XML_CXX_DECLARE_CONTAINER_CLASS__(Stack, std::stack);
__XML_CXX_DECLARE_CONTAINER_CLASS__(Stack, std::stack)
# include <queue>
__XML_CXX_DECLARE_CONTAINER_CLASS__(Queue, std::queue);
__XML_CXX_DECLARE_CONTAINER_CLASS__(Queue, std::queue)
# undef __XML_CXX_DECLARE_CONTAINER_CLASS__
# define __XML_CXX_DECLARE_CONTAINER_CLASS__(CONTAINER, STD_CONTAINER) \
namespace xml { \
@@ -1569,7 +1545,7 @@ __XML_CXX_DECLARE_CONTAINER_CLASS__(Queue, std::queue);
AssociativeContainer \
<STD_CONTAINER<TYPE, COMPARE, ALLOC> >(o) { \
} \
CONTAINER(const std::string& className) throw(): \
CONTAINER(const std::string& className) noexcept: \
AssociativeContainer \
<STD_CONTAINER<TYPE, COMPARE, ALLOC> > \
(className) { \
@@ -1577,7 +1553,7 @@ __XML_CXX_DECLARE_CONTAINER_CLASS__(Queue, std::queue);
virtual ~CONTAINER() {} \
}; \
}
__XML_CXX_DECLARE_CONTAINER_CLASS__(PriorityQueue, std::priority_queue);
__XML_CXX_DECLARE_CONTAINER_CLASS__(PriorityQueue, std::priority_queue)
# undef __XML_CXX_DECLARE_CONTAINER_CLASS__
# define __XML_CXX_DECLARE_CONTAINER_CLASS__(CONTAINER, STD_CONTAINER) \
namespace xml { \
@@ -1592,7 +1568,7 @@ __XML_CXX_DECLARE_CONTAINER_CLASS__(PriorityQueue, std::priority_queue);
AssociativeContainer \
<STD_CONTAINER<TYPE, COMPARE, ALLOC> >(o) { \
} \
CONTAINER(const std::string& className) throw(): \
CONTAINER(const std::string& className) noexcept: \
AssociativeContainer \
<STD_CONTAINER<TYPE, COMPARE, ALLOC> > \
(className) { \
@@ -1601,8 +1577,8 @@ __XML_CXX_DECLARE_CONTAINER_CLASS__(PriorityQueue, std::priority_queue);
}; \
}
# include <set>
__XML_CXX_DECLARE_CONTAINER_CLASS__(Set, std::set);
__XML_CXX_DECLARE_CONTAINER_CLASS__(MultiSet, std::multiset);
__XML_CXX_DECLARE_CONTAINER_CLASS__(Set, std::set)
__XML_CXX_DECLARE_CONTAINER_CLASS__(MultiSet, std::multiset)
# undef __XML_CXX_DECLARE_CONTAINER_CLASS__
# define __XML_CXX_DECLARE_CONTAINER_CLASS__(CONTAINER, STD_CONTAINER) \
namespace xml { \
@@ -1616,7 +1592,7 @@ __XML_CXX_DECLARE_CONTAINER_CLASS__(MultiSet, std::multiset);
AssociativeMap \
<STD_CONTAINER<KEY, VALUE, COMPARE, ALLOC> >(o) { \
} \
CONTAINER(const std::string& className) throw(): \
CONTAINER(const std::string& className) noexcept: \
AssociativeMap \
<STD_CONTAINER<KEY, VALUE, COMPARE, ALLOC> > \
(className) { \
@@ -1625,8 +1601,8 @@ __XML_CXX_DECLARE_CONTAINER_CLASS__(MultiSet, std::multiset);
}; \
}
# include <map>
__XML_CXX_DECLARE_CONTAINER_CLASS__(Map, std::map);
__XML_CXX_DECLARE_CONTAINER_CLASS__(MultiMap, std::multimap);
__XML_CXX_DECLARE_CONTAINER_CLASS__(Map, std::map)
__XML_CXX_DECLARE_CONTAINER_CLASS__(MultiMap, std::multimap)
# undef __XML_CXX_DECLARE_CONTAINER_CLASS__
//@}
//! @endcond

View File

@@ -12,28 +12,29 @@
#include <cstdlib>
#include <algorithm>
unsigned int MethodTrace::_level(0);
namespace xml {
unsigned int MethodTrace::_level(0);
//================================================================= EXCEPTIONS
//----------------------------------------------------------------------------
exception::exception(std::string reason) throw():
exception::exception(std::string reason) noexcept:
_what(reason), _node(0) {
}
exception::exception(std::string reason, const Node& t) throw():
exception::exception(std::string reason, const Node& t) noexcept:
_what(reason), _node(t.clone().release()) {
}
exception::~exception() throw() {
exception::~exception() noexcept {
delete _node;
}
void exception::line(unsigned long line) throw() {
void exception::line(unsigned long line) noexcept {
std::stringstream ss;
ss<<line;
_what += "\nat line: "+ss.str();
}
const char* exception::what() const throw() {
const char* exception::what() const noexcept {
static std::string w;
if (!w.size()) {
if (_node)
@@ -47,33 +48,33 @@ namespace xml {
return w.c_str();
}
//----------------------------------------------------------------------------
access_error::access_error(const Node& t, const std::string& name) throw():
access_error::access_error(const Node& t, const std::string& name) noexcept:
exception("child not available", t), _name(name) {
}
const char* access_error::what() const throw() {
const char* access_error::what() const noexcept {
static std::string w;
if (!w.size()) w = std::string(exception::what())+"\nchild name: "+_name;
return w.c_str();
}
//----------------------------------------------------------------------------
out_of_range::out_of_range(const Node& t, size_t pos) throw():
out_of_range::out_of_range(const Node& t, size_t pos) noexcept:
exception("child not available", t), _pos(pos) {
}
const char* out_of_range::what() const throw() {
const char* out_of_range::what() const noexcept {
static std::stringstream w;
if (!w.str().size()) w<<exception::what()<<"\nchild number: "<<_pos;
return w.str().c_str();
}
//----------------------------------------------------------------------------
cannot_have_children::cannot_have_children(const Node& parent,
const Node& child) throw():
const Node& child) noexcept:
exception("node does not accept child nodes", parent),
_child(child.clone().release()) {
}
cannot_have_children::~cannot_have_children() throw() {
cannot_have_children::~cannot_have_children() noexcept {
delete _child;
}
const char* cannot_have_children::what() const throw() {
const char* cannot_have_children::what() const noexcept {
static std::string w;
if (!w.size())
w = std::string(exception::what())+"\nchild name: "+_child->name();
@@ -81,17 +82,17 @@ namespace xml {
}
//----------------------------------------------------------------------------
stream_error::stream_error(const std::string& reason, const Node& t,
std::istream& is, const Tag& tag, char c) throw():
std::istream& is, const Tag& tag, char c) noexcept:
exception(reason, t), _pos(is.tellg()), _tag(new Tag(tag)), _char(c) {
}
stream_error::stream_error(const std::string& reason, const Node& t,
std::istream& is) throw():
std::istream& is) noexcept:
exception(reason, t), _pos(is.tellg()), _tag(0), _char(0) {
}
stream_error::~stream_error() throw() {
stream_error::~stream_error() noexcept {
delete _tag;
}
const char* stream_error::what() const throw() {
const char* stream_error::what() const noexcept {
static std::string w;
if (!w.size()) {
std::stringstream ss;
@@ -117,67 +118,67 @@ namespace xml {
//----------------------------------------------------------------------------
//! Copy an attribute.
Attributes::Value::Value(const value_type& o) throw():
Attributes::Value::Value(const value_type& o) noexcept:
Attributes::value_type(o) {
}
//! Construct an empty attribute.
Attributes::Value::Value(const std::string& name) throw():
Attributes::Value::Value(const std::string& name) noexcept:
Attributes::value_type(name, std::string()) {
}
//! Construct an attribute with name an value.
Attributes::Value::Value(const std::string& name,
const std::string& value) throw():
const std::string& value) noexcept:
Attributes::value_type(name, value) {
}
//! Assign a value.
Attributes::Value& Attributes::Value::operator=(const std::string& value)
throw() {
noexcept {
second = value;
return *this;
}
//! Get the attribute name.
const std::string& Attributes::Value::name() const throw() {
const std::string& Attributes::Value::name() const noexcept {
return first;
}
//! Get the attribute value.
const std::string& Attributes::Value::value() const throw() {
const std::string& Attributes::Value::value() const noexcept {
return second;
}
//! Get the attribute value.
std::string& Attributes::Value::value() throw() {
std::string& Attributes::Value::value() noexcept {
return second;
}
//! Convert the attribute to a boolean.
/*! @return @c true if the value is set and not equal to one of:
@c false @c no @c 0. */
Attributes::Value::operator bool() const throw() {
Attributes::Value::operator bool() const noexcept {
return bool();
}
//! Convert the attribute to a boolean.
/*! @return @c true if the value is set and not equal to one of:
@c false @c no @c 0. */
bool Attributes::Value::toBool() const throw() {
bool Attributes::Value::toBool() const noexcept {
return !(!second.size()||second=="false"||second=="no"||second=="0");
}
//! Convert the attribute to a number.
Attributes::Value::operator unsigned long() const throw() {
Attributes::Value::operator unsigned long() const noexcept {
return toNumber();
}
//! Convert the attribute to a number.
unsigned long Attributes::Value::toNumber() const throw() {
unsigned long Attributes::Value::toNumber() const noexcept {
std::stringstream ss(second);
int i(0);
ss>>i;
return i;
}
//! Convert the attribute to a space separated list.
Attributes::Value::operator List() const throw() {
Attributes::Value::operator List() const noexcept {
return toList();
}
//! Convert the attribute to list.
/*! @param separators a string containing a list of valid separators */
Attributes::List Attributes::Value::toList(const std::string& separators)
const throw() {
const noexcept {
List l;
for (std::string::size_type it(0), pos(0);
it!=std::string::npos &&
@@ -193,30 +194,30 @@ namespace xml {
/*! @copydoc xml::Attributes::Value::toList
@return the first element of the list. */
std::string Attributes::Value::front(const std::string& separators) const
throw(empty_attribute_list) {
{
List l(toList(separators));
if (!l.size()) throw empty_attribute_list(first);
return l.front();
}
//----------------------------------------------------------------------------
//! Empty attribute list
Attributes::Attributes() throw() {}
Attributes::Attributes() noexcept {}
//! Attribute list with first one empty attribute given.
Attributes::Attributes(const std::string& empty) throw() {
Attributes::Attributes(const std::string& empty) noexcept {
insert(Value(empty));
}
//! Attribute list with first attribute given.
Attributes::Attributes(const std::string& key,
const std::string& value) throw() {
const std::string& value) noexcept {
insert(Value(key, value));
}
//! Add a new key-value pair to the attribute list.
Attributes& Attributes::operator<<(const Attributes::Value& v) throw() {
Attributes& Attributes::operator<<(const Attributes::Value& v) noexcept {
insert(v);
return *this;
}
//! Add a new empty key to the attribute list.
Attributes& Attributes::operator<<(const std::string& key) throw() {
Attributes& Attributes::operator<<(const std::string& key) noexcept {
insert(Value(key));
return *this;
}
@@ -226,28 +227,28 @@ namespace xml {
constructor.
@copydoc xml::Node::limits */
Node::Node(std::string name,
Node::size_type min, Node::size_type max) throw():
Node::size_type min, Node::size_type max) noexcept:
_name(name), _parent(0), _min(min), _max(max) {
}
//! Copy node, reset parent.
/*! The parent is reset, the node does not belong to the same parent
as the source of the copy.
@see xml::Node::clone() for more information on the parenting. */
Node::Node(const Node& o) throw():
Node::Node(const Node& o) noexcept:
_attributes(o._attributes), _name(o.name()), _parent(0),
_min(o._min), _max(o._max) {
for (Contents::const_iterator it(o._contents.begin());
it!=o._contents.end(); ++it)
_contents.push_back((*it)->clone(this).release());
}
Node::~Node() throw() {
Node::~Node() noexcept {
clear();
}
//! Assign new node, keep parent.
/*! The parent remains unchanged, the node does not belong to the
same parent as the source of the copy.
@see xml::Node::clone() for more information on the parenting. */
Node& Node::operator=(const Node& o) throw() {
Node& Node::operator=(const Node& o) noexcept {
clear();
_attributes=o._attributes;
_name = o.name();
@@ -272,7 +273,7 @@ namespace xml {
The user of this library doesn't have to and is not able to care
about the parenting. */
std::unique_ptr<Node> Node::clone() const throw() {
std::unique_ptr<Node> Node::clone() const noexcept {
std::unique_ptr<Node> res(new Node(*this));
res->_parent = 0;
return res;
@@ -281,7 +282,7 @@ namespace xml {
/*! Streams the node including all attributes and children. It is
formatted with new-lines and tabulator indentation for human
readability. */
std::ostream& Node::out(std::ostream& o, unsigned int level) const throw() {
std::ostream& Node::out(std::ostream& o, unsigned int level) const noexcept {
if (_contents.size()) {
o<<std::string(level, '\t')<<'<'<<name();
for (Attributes::const_iterator it(_attributes.begin());
@@ -303,7 +304,7 @@ namespace xml {
}
//! Get the textual contents of a node.
/*! By default this is the concatenation of all child nodes' texts. */
std::string Node::text() const throw() {
std::string Node::text() const noexcept {
std::string s;
for (Contents::const_iterator it(_contents.begin());
it!=_contents.end(); ++it)
@@ -315,36 +316,36 @@ namespace xml {
reimplemented. In xml::Node, the parent of all nodes, it throws
xml::tag_expected, since a xml::Node may only contain sub-nodes
(formatted as xml-tags) and no plain text. */
Node& Node::text(const std::string& txt) throw(tag_expected, type_mismatch) {
Node& Node::text(const std::string& txt) {
throw tag_expected(*this, txt);
}
//! Appends a new node at the end of all children.
Node& Node::append(const Node& o) throw(cannot_have_children) {
Node& Node::append(const Node& o) {
_contents.push_back(o.clone(this).release());
return *this;
}
//! Removes a given child node.
Node& Node::remove(Node& n) throw(access_error) {
Node& Node::remove(Node& n) {
Contents::iterator it(std::find(_contents.begin(), _contents.end(), &n));
if (it==_contents.end()) throw access_error(*this, n.name());
_contents.erase(it);
return *this;
}
//! Removes the first child node of a given name.
Node& Node::remove(const std::string& n) throw(access_error) {
Node& Node::remove(const std::string& n) {
Node* t(find(n));
if (!t) throw access_error(*this, n);
return remove(*t);
}
//! Removes the child node of a given position.
Node& Node::remove(size_type n) throw(out_of_range) {
Node& Node::remove(size_type n) {
if (n>=children()) throw out_of_range(*this, n);
_contents.erase(_contents.begin()+n);
return *this;
}
//! Set a list of attributes.
/*! Existing attributes with the same name are overwritten. */
Node& Node::set(const Attributes& o) throw() {
Node& Node::set(const Attributes& o) noexcept {
_attributes.clear();
_attributes.insert(o.begin(), o.end());
return *this;
@@ -359,47 +360,47 @@ namespace xml {
return *this;
}
//! Get the node's tag name.
std::string Node::name() const throw() {
std::string Node::name() const noexcept {
return _name;
}
//! Set a new node's tag name.
Node& Node::name(const std::string& n) throw() {
Node& Node::name(const std::string& n) noexcept {
_name = n;
return *this;
}
//! Set minimum number of instances (in a xml::Factory).
/*! @copydoc limits */
Node& Node::min(Node::size_type m) throw() {
Node& Node::min(Node::size_type m) noexcept {
_min = m;
return *this;
}
//! Get minimum number of instances (in a xml::Factory).
/*! @copydoc limits */
Node::size_type Node::min() const throw() {
Node::size_type Node::min() const noexcept {
return _min;
}
//! Set maximum number of instances (in a xml::Factory).
/*! @copydoc limits */
Node& Node::max(Node::size_type m) throw() {
Node& Node::max(Node::size_type m) noexcept {
_max = m;
return *this;
}
//! Get maximum number of instances (in a xml::Factory).
/*! @copydoc limits */
Node::size_type Node::max() const throw() {
Node::size_type Node::max() const noexcept {
return _max;
}
//! @c true if node has a parent.
bool Node::isChild() const throw() {
bool Node::isChild() const noexcept {
return _parent;
}
//! Get the parent node.
Node& Node::parent() const throw(no_parent) {
Node& Node::parent() const {
if (!_parent) throw no_parent(*this);
return *_parent;
}
//! Check if a specific attribute is set or not.
bool Node::hasAttr(const std::string& name) const throw() {
bool Node::hasAttr(const std::string& name) const noexcept {
return _attributes.find(name)!=_attributes.end();
}
//! Declare an attribute template and specify whether it is mandatory
@@ -410,8 +411,8 @@ namespace xml {
If a factory reads from a stream, it verifies that only optional
or mandatory attributes are given and that mandatory attributes
are specified. Otherwise reading throws an exception. */
Node& Node::attr(const std::string& name, bool mandatory) throw() {
_attributes[name] = mandatory?"xml::mandatory":"xml::optional";
Node& Node::attr(const std::string& name, bool m) noexcept {
_attributes[name] = m?"xml::mandatory":"xml::optional";
return *this;
}
//! Declare an attribute with given value.
@@ -422,20 +423,20 @@ namespace xml {
@endcode
If a factory reads from a stream and the specified attribute is
not given, it is set to @c deflt. */
Node& Node::attr(const std::string& name, const std::string& deflt) throw() {
Node& Node::attr(const std::string& name, const std::string& deflt) noexcept {
_attributes[name] = deflt;
return *this;
}
//! Get an attribute.
/*! Returns the attribute's value (empty if the attribute is not set) */
std::string Node::attr(const std::string& name) const throw() {
std::string Node::attr(const std::string& name) const noexcept {
Attributes::const_iterator it(_attributes.find(name));
if (it!=_attributes.end()) return it->second;
return std::string();
}
//! Get an attribute.
/*! Returns the attribute's value (empty if the attribute is not set) */
std::string& Node::attr(const std::string& name) throw() {
std::string& Node::attr(const std::string& name) noexcept {
return _attributes[name];
}
//! Get an attribute.
@@ -444,23 +445,23 @@ namespace xml {
conversions or other methods as specified in
xml::Attributes::Value. */
const Attributes::Value Node::attribute(const std::string& name)
const throw(attribute_not_available) {
const {
Attributes::const_iterator it(_attributes.find(name));
if (it!=_attributes.end()) return *it;
throw attribute_not_available(*this, name);
}
//! Get the list of attributes.
const Attributes& Node::attributes() const throw() {
const Attributes& Node::attributes() const noexcept {
return _attributes;
}
//! Get the list of attributes.
Attributes& Node::attributes() throw() {
Attributes& Node::attributes() noexcept {
return _attributes;
}
//! Get the first child node
/*! Returns the first child node or throws an exception, if there are
no children. */
Node& Node::first() throw(out_of_range) {
Node& Node::first() {
Contents::iterator it(_contents.begin());
if (it==_contents.end()) throw out_of_range(*this, 0);
return **it;
@@ -468,7 +469,7 @@ namespace xml {
//! Get the first child node
/*! Returns the first child node or throws an exception, if there are
no children. */
const Node& Node::first() const throw(out_of_range) {
const Node& Node::first() const {
Contents::const_iterator it(_contents.begin());
if (it==_contents.end()) throw out_of_range(*this, 0);
return **it;
@@ -476,7 +477,7 @@ namespace xml {
//! Get the last child node
/*! Returns the last child node or throws an exception, if there are
no children. */
const Node& Node::last() const throw(out_of_range) {
const Node& Node::last() const {
Contents::const_reverse_iterator it(_contents.rbegin());
if (it==_contents.rend()) throw out_of_range(*this, 0);
return **it;
@@ -484,7 +485,7 @@ namespace xml {
//! Get the last child node
/*! Returns the last child node or throws an exception, if there are
no children. */
Node& Node::last() throw(out_of_range) {
Node& Node::last() {
Contents::reverse_iterator it(_contents.rbegin());
if (it==_contents.rend()) throw out_of_range(*this, 0);
return **it;
@@ -513,13 +514,13 @@ namespace xml {
Default is no limits: <code>0..n</code>,
which means that the node is optional and may be instatiated
multiple (infinite, unlimited) times. */
Node& Node::limits(size_type min, size_type max) throw() {
Node& Node::limits(size_type min, size_type max) noexcept {
_min = min;
_max = max;
return *this;
}
//! Get all immediate children of a given node name.
Node::List Node::list(const std::string& name) const throw() {
Node::List Node::list(const std::string& name) const noexcept {
List res;
for (Contents::const_iterator it(_contents.begin());
it!=_contents.end(); ++it)
@@ -527,34 +528,34 @@ namespace xml {
return res;
}
//! Check if at least one child node of a given name exists.
bool Node::operator()(const std::string& child) const throw() {
bool Node::operator()(const std::string& child) const noexcept {
return find(child);
}
//! Append a child at the end.
/*! @copydoc xml::Node::append */
Node& Node::operator<<(const Node& o) throw(cannot_have_children) {
Node& Node::operator<<(const Node& o) {
return append(o);
}
//! Add an empty attribute.
/*! @copydoc xml::Node::set */
Node& Node::operator<<(const Attributes& o) throw() {
Node& Node::operator<<(const Attributes& o) noexcept {
return set(o);
}
//! Get the number of children.
Node::size_type Node::children() const throw() {
Node::size_type Node::children() const noexcept {
return _contents.size();
}
//! Get a child by child-number (the n-th child).
/*! @param child number of the child to return: <code>child&gt;=0</code> and
<code>child&lt;xml::Node::children()</code> */
const Node& Node::operator[](Node::size_type child) const
throw(out_of_range) try {
try {
return *_contents.at(child);
} catch (...) {
throw out_of_range(*this, child);
}
/*! @copydoc xml::Node::operator[](Node::size_type child) const */
Node& Node::operator[](Node::size_type child) throw(out_of_range) try {
Node& Node::operator[](Node::size_type child) try {
return *_contents.at(child);
} catch (...) {
throw out_of_range(*this, child);
@@ -562,37 +563,36 @@ namespace xml {
//! Get the first child of a given node name.
/*! @return the first child with matching node name */
const Node& Node::operator[](const std::string& child) const
throw(access_error) {
{
const Node* const t(find(child));
if (!t) throw access_error(*this, child);
return *t;
}
/*! @copydoc xml::Node::operator[](const std::string& child) const */
Node& Node::operator[](const std::string& child) throw(access_error) {
Node& Node::operator[](const std::string& child) {
Node* const t(find(child));
if (!t) throw access_error(*this, child);
return *t;
}
//! Get the textual contents of a node.
/*! @copydoc xml::Node::text() */
std::string Node::operator*() const throw() {
std::string Node::operator*() const noexcept {
return text();
}
//! Set a text (forbidden in xml::Node)
/*! @copydoc xml::Node::text(const std::string& txt) */
Node& Node::operator=(const std::string& contents) throw(tag_expected,
type_mismatch) {
Node& Node::operator=(const std::string& contents) {
return text(contents);
}
//! Write node in XML format to a stream.
/*! @copydoc xml::Node::out */
std::ostream& operator<<(std::ostream& o, const Node& t) throw() {
std::ostream& operator<<(std::ostream& o, const Node& t) noexcept {
return t.out(o);
}
//! Get a pointer to the first child of a given node name.
/*! This method does not throw an exception if the element does not
exist, but returns @c 0. */
Node* Node::find(const std::string& child) const throw() {
Node* Node::find(const std::string& child) const noexcept {
for (Contents::const_iterator it(_contents.begin());
it!=_contents.end(); ++it) {
if ((*it)->name()==child) return *it;
@@ -600,7 +600,7 @@ namespace xml {
return 0;
}
//! Clone a node, but assign a new parent.
std::unique_ptr<Node> Node::clone(Node* p) const throw() {
std::unique_ptr<Node> Node::clone(Node* p) const noexcept {
std::unique_ptr<Node> c(clone());
c->_parent = p;
return c;
@@ -610,30 +610,29 @@ namespace xml {
/*! @copydoc Node::Node(std::string name,
Node::size_type min, Node::size_type max) */
String::String(std::string name,
Node::size_type min, Node::size_type max) throw():
Node::size_type min, Node::size_type max) noexcept:
Node(name, min, max) {
}
//! Pass the text in the node.
/*! @copydoc Node::Node(std::string name,
Node::size_type min, Node::size_type max) */
String::String(std::string name, const std::string& text,
Node::size_type min, Node::size_type max) throw():
Node::size_type min, Node::size_type max) noexcept:
Node(name, min, max), _text(text) {
}
std::unique_ptr<Node> String::clone() const throw() {
std::unique_ptr<Node> String::clone() const noexcept {
return std::unique_ptr<Node>(new String(*this));
}
std::string String::text() const throw() {
std::string String::text() const noexcept {
return _text;
}
//! An xml::String contains text: Set the text.
/*! Never throws an exception. */
String& String::text(const std::string& txt) throw(tag_expected,
type_mismatch) {
String& String::text(const std::string& txt) {
_text = txt;
return *this;
}
std::ostream& String::out(std::ostream& o, unsigned int level) const throw() {
std::ostream& String::out(std::ostream& o, unsigned int level) const noexcept {
if (_text.size()) {
o<<std::string(level, '\t')<<'<'<<name();
for (Attributes::const_iterator it(_attributes.begin());
@@ -650,83 +649,83 @@ namespace xml {
return o;
}
//! An xml::String has no child nodes: Always throws an exception.
String& String::append(const Node& o) throw(cannot_have_children) {
String& String::append(const Node& o) {
throw cannot_have_children(*this, o);
}
//! An xml::String contains text: Set the text.
Node& String::operator=(const std::string& contents) throw() {
Node& String::operator=(const std::string& contents) noexcept {
return text(contents);
}
String::operator std::string() const throw() {
String::operator std::string() const noexcept {
return text();
}
String::operator bool() const throw() {
String::operator bool() const noexcept {
bool res;
std::stringstream ss(text());
ss>>res;
return res;
}
String::operator char() const throw() {
String::operator char() const noexcept {
char res;
std::stringstream ss(text());
ss>>res;
return res;
}
String::operator signed char() const throw() {
String::operator signed char() const noexcept {
signed char res;
std::stringstream ss(text());
ss>>res;
return res;
}
String::operator unsigned char() const throw() {
String::operator unsigned char() const noexcept {
unsigned char res;
std::stringstream ss(text());
ss>>res;
return res;
}
String::operator signed short() const throw() {
String::operator signed short() const noexcept {
signed short res;
std::stringstream ss(text());
ss>>res;
return res;
}
String::operator unsigned short() const throw() {
String::operator unsigned short() const noexcept {
unsigned short res;
std::stringstream ss(text());
ss>>res;
return res;
}
String::operator signed int() const throw() {
String::operator signed int() const noexcept {
signed int res;
std::stringstream ss(text());
ss>>res;
return res;
}
String::operator unsigned int() const throw() {
String::operator unsigned int() const noexcept {
unsigned int res;
std::stringstream ss(text());
ss>>res;
return res;
}
String::operator signed long() const throw() {
String::operator signed long() const noexcept {
signed long res;
std::stringstream ss(text());
ss>>res;
return res;
}
String::operator unsigned long() const throw() {
String::operator unsigned long() const noexcept {
unsigned long res;
std::stringstream ss(text());
ss>>res;
return res;
}
String::operator float() const throw() {
String::operator float() const noexcept {
float res;
std::stringstream ss(text());
ss>>res;
return res;
}
String::operator double() const throw() {
String::operator double() const noexcept {
double res;
std::stringstream ss(text());
ss>>res;
@@ -737,16 +736,16 @@ namespace xml {
/*! @copydoc Node::Node(std::string name,
Node::size_type min, Node::size_type max) */
UnsignedInteger::UnsignedInteger(std::string name, unsigned long i,
size_type min, size_type max) throw():
size_type min, size_type max) noexcept:
String(name, mrw::string(i), min, max) {
}
std::unique_ptr<Node> UnsignedInteger::clone() const throw() {
std::unique_ptr<Node> UnsignedInteger::clone() const noexcept {
return std::unique_ptr<Node>(new UnsignedInteger(*this));
}
//! An xml::UnsignedInteger must only contain an number.
/*! En exception is thrown, if the contents does not match a number. */
UnsignedInteger& UnsignedInteger::text(const std::string& txt)
throw(tag_expected, type_mismatch) {
{
std::string::size_type
start(txt.find_first_not_of(" \t\n\r")),
last(txt.find_last_not_of(" \t\n\r"));
@@ -766,11 +765,11 @@ namespace xml {
return *this;
}
//! Returns the contents as number.
unsigned long UnsignedInteger::number() const throw() {
unsigned long UnsignedInteger::number() const noexcept {
return number(*this);
}
//! Returns the contents as number.
unsigned long UnsignedInteger::number(const Node& node) throw() {
unsigned long UnsignedInteger::number(const Node& node) noexcept {
unsigned long i(0);
std::stringstream ss(node.text());
ss>>i;
@@ -779,50 +778,51 @@ namespace xml {
//----------------------------------------------------------------------------
//! To instanciate a factory, a template must be given.
Factory::Factory(const Node& t) throw():
Factory::Factory(const Node& t) noexcept:
_template(xml::Node("<xml::start>")<<t), _line(0) {
_template[0].min(1);
_template[0].max(1);
}
//! Instanciates an invalid factory. A template must be assigned later.
Factory::Factory() throw():
Factory::Factory() noexcept:
_template(xml::Node("<xml::start>")), _line(0) {
}
//! Assign a template.
/*! If you don't pass a template at instanciation, you must call
this method later, or you will get xml::factory_not_valid
exceptions when you try to use the factory. */
Factory& Factory::operator=(const Node& t) throw() {
Factory& Factory::operator=(const Node& t) noexcept {
_template = xml::Node("<xml::start>")<<t;
_template[0].min(1);
_template[0].max(1);
return *this;
}
//! Get the template.
const Node& Factory::operator*() const throw(factory_not_valid) try {
const Node& Factory::operator*() const try {
return _template[0];
} catch (...) {
throw factory_not_valid();
}
//! Access the (root node of the) template.
const Node*const Factory::operator->() const throw(factory_not_valid) try {
const Node* Factory::operator->() const try {
return &_template[0];
} catch (...) {
throw factory_not_valid();
}
//! Check whether the factory has been given a valid template.
Factory::operator bool() const throw() {
Factory::operator bool() const noexcept {
return _template.children()>0;
}
//! Print the factory template's schema in human readable format.
/*! Calls xml::Factory::print */
std::ostream& operator<<(std::ostream& os, const Factory& factory)
throw(factory_not_valid) {
{
return factory.print(os, *factory);
}
//! Print a node's schema description in human readable format.
/*! @todo May be changed to a XML Schema output later. */
std::ostream& Factory::print(std::ostream& os, const Node& node,
unsigned int level) throw() {
unsigned int level) noexcept {
if (node.children()) {
os<<std::string(level, '\t')<<'<'<<node.name();
for (Attributes::const_iterator it(node.attributes().begin());
@@ -876,14 +876,7 @@ namespace xml {
return os;
}
//! Restore a xml::Node tree from a stream, according to the given schema.
std::unique_ptr<Node> Factory::read(std::istream& is)
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,
illegal_attribute, mandatory_attribute_missing,
wrong_node_number, factory_not_valid) {
std::unique_ptr<Node> Factory::read(std::istream& is) {
if (_template.children()==0) throw factory_not_valid();
try {
_line=1;
@@ -898,34 +891,28 @@ namespace xml {
throw;
}
}
void Factory::reset() throw() {
void Factory::reset() noexcept {
_line = 0;
_open = 0;
_template = xml::Node("<xml::start>");
}
Node& Factory::operator*() throw(factory_not_valid) try {
Node& Factory::operator*() try {
return _template[0];
} catch (...) {
throw factory_not_valid();
}
Node*const Factory::operator->() throw(factory_not_valid) try {
Node* Factory::operator->() try {
return &_template[0];
} catch (...) {
throw factory_not_valid();
}
bool Factory::ws(char c) throw() {
bool Factory::ws(char c) noexcept {
static char last(0);
if ((c=='\n'||c=='\r')&&last!='\n'&&last!='\r') ++_line;
last = c;
return c==' '||c=='\t'||c=='\n'||c=='\r';
}
std::unique_ptr<Node> Factory::read(std::istream& is, const Node& node)
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,
illegal_attribute, mandatory_attribute_missing,
wrong_node_number) {
std::unique_ptr<Node> Factory::read(std::istream& is, const Node& node) {
std::unique_ptr<Node> result(node.clone());
result->clear();
while (true) {
@@ -955,7 +942,7 @@ namespace xml {
std::unique_ptr<Node> Factory::checkChildren(const xml::Node& tpl,
std::unique_ptr<Node> node,
std::istream& is) const
throw(wrong_node_number) {
{
for (Node::size_type i(0); i<tpl.children(); ++i)
if ((tpl[i].min()>0 && node->list(tpl[i].name()).size()<tpl[i].min())
|| (0<tpl[i].max() && tpl[i].max()<node->list(tpl[i].name()).size()))
@@ -964,14 +951,9 @@ namespace xml {
tpl[i].min(), tpl[i].max());
return std::move(node);
}
Tag Factory::tag(std::istream& is, const Node& position)
throw(second_slash_in_tag, character_after_slash, tag_expected,
missing_end_tag, attribute_value_not_quoted,
access_error, duplicate_attribute, attributes_in_end_tag,
illegal_attribute, mandatory_attribute_missing,
wrong_start_tag) {
Tag Factory::tag(std::istream& is, const Node& position) {
char c(0);
Tag tag((Tag){"", START, "", Attributes(), "", false});
Tag tag{"", START, "", Attributes(), "", false};
while (is && is.get(c) && ws(c)); // skip ws
if (is.eof()) {
if (_open>0)
@@ -985,6 +967,8 @@ namespace xml {
for (char last(c); is && is.get(c) && c!='>'; last=c) switch (c) {
case '\n': case '\r':
if (last!='\n'&&last!='\r') ++_line;
// no break; fall through to non line breaking white spaces
[[fallthrough]];
case ' ': case '\t':
if (!nameRead && tag.name.size()) nameRead=true;
break;
@@ -1000,6 +984,8 @@ namespace xml {
tag.type=SPECIAL;
return tag;
}
// no break; not matched, fall through to error handling
[[fallthrough]];
default:
if (tag.type==EMPTY) throw character_after_slash(position, is, tag, c);
if (nameRead) { // read attribute
@@ -1056,21 +1042,21 @@ namespace xml {
//----------------------------------------------------------------------------
Serialize::Serialize() throw() {}
Serialize::Serialize(const std::string& className) throw():
Serialize::Serialize() noexcept {}
Serialize::Serialize(const std::string& className) noexcept:
_xmlFactory(xml::Node(xml::String(className).limits(1,1))) {
}
Serialize::Serialize(const Serialize& other) throw() {
Serialize::Serialize(const Serialize& other) noexcept {
copy(other);
}
Serialize::~Serialize() {
reset();
}
Serialize& Serialize::operator=(const Serialize& other) throw() {
Serialize& Serialize::operator=(const Serialize& other) noexcept {
copy(other);
return *this;
}
Serialize& Serialize::className(const std::string& name) throw() {
Serialize& Serialize::className(const std::string& name) noexcept {
xml::Node node(xml::Node(xml::String(name).limits(1,1)));
if (_xmlFactory) {
for (xml::Node::size_type i(0); i<_xmlFactory->children(); ++i)
@@ -1080,7 +1066,7 @@ namespace xml {
return *this;
}
Serialize& Serialize::persist(Serialize& ser,
const std::string& name) throw() {
const std::string& name) noexcept {
if (ser.optional()) {
_xmlNames[name] = &ser;
ser.className(name);
@@ -1099,59 +1085,59 @@ namespace xml {
return *this;
}
Serialize& Serialize::persist(bool& member,
const std::string& name) throw() {
const std::string& name) noexcept {
return persistSimpleType(member, name);
}
Serialize& Serialize::persist(char& member,
const std::string& name) throw() {
const std::string& name) noexcept {
return persistSimpleType(member, name);
}
Serialize& Serialize::persist(unsigned char& member,
const std::string& name) throw() {
const std::string& name) noexcept {
return persistSimpleType(member, name);
}
Serialize& Serialize::persist(signed char& member,
const std::string& name) throw() {
const std::string& name) noexcept {
return persistSimpleType(member, name);
}
Serialize& Serialize::persist(unsigned short& member,
const std::string& name) throw() {
const std::string& name) noexcept {
return persistSimpleType(member, name);
}
Serialize& Serialize::persist(signed short& member,
const std::string& name) throw() {
const std::string& name) noexcept {
return persistSimpleType(member, name);
}
Serialize& Serialize::persist(unsigned int& member,
const std::string& name) throw() {
const std::string& name) noexcept {
return persistSimpleType(member, name);
}
Serialize& Serialize::persist(signed int& member,
const std::string& name) throw() {
const std::string& name) noexcept {
return persistSimpleType(member, name);
}
Serialize& Serialize::persist(unsigned long& member,
const std::string& name) throw() {
const std::string& name) noexcept {
return persistSimpleType(member, name);
}
Serialize& Serialize::persist(signed long& member,
const std::string& name) throw() {
const std::string& name) noexcept {
return persistSimpleType(member, name);
}
Serialize& Serialize::persist(float& member,
const std::string& name) throw() {
const std::string& name) noexcept {
return persistSimpleType(member, name);
}
Serialize& Serialize::persist(double& member,
const std::string& name) throw() {
const std::string& name) noexcept {
return persistSimpleType(member, name);
}
Serialize& Serialize::persist(std::string& member,
const std::string& name) throw() {
const std::string& name) noexcept {
return persistSimpleType(member, name);
}
std::ostream& Serialize::saveXml(std::ostream& os,
const std::string& name) const throw() {
const std::string& name) const noexcept {
checkInit();
xml::Node node(*_xmlFactory);
if (name.size()) node.name(name);
@@ -1176,7 +1162,7 @@ namespace xml {
clear(it->second);
return is;
}
std::string Serialize::schema() const throw() {
std::string Serialize::schema() const noexcept {
checkInit();
std::stringstream ss;
ss<<*_xmlFactory;
@@ -1193,17 +1179,17 @@ namespace xml {
_clear.insert(clearFunc);
}
void Serialize::initXmlMembers() {}
void Serialize::clear() throw() {
void Serialize::clear() {
for (std::map<std::string, Any>::const_iterator
it(_xmlNames.begin());
it!=_xmlNames.end(); ++it)
clear(it->second);
}
void Serialize::reset() throw() {
void Serialize::reset() noexcept {
_xmlFactory.reset();
_xmlNames.clear();
}
void Serialize::copy(const Serialize& o) throw() {
void Serialize::copy(const Serialize&) noexcept {
reset();
initXmlMembers();
}
@@ -1219,13 +1205,13 @@ namespace xml {
if ((**it)(member, node)) return; // found match
throw type_not_registered(member.type().name(), node.name(), node);
}
void Serialize::clear(Any member) throw() {
void Serialize::clear(Any member) {
for (std::set<ClearFunc>::const_iterator it(_clear.begin());
it!=_clear.end(); ++it)
if ((**it)(member)) return; // found match
throw type_not_registered(member.type().name());
}
bool Serialize::optional() const throw() {
bool Serialize::optional() const noexcept {
return false;
}