From 98334b4565d662accbadba7bd089623325a88d30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Wed, 8 Apr 2009 15:01:48 +0000 Subject: [PATCH] extendions and corrections --- install-64-and-32-bit-linux.sh | 6 +++--- src/xml-cxx/xml.hxx | 11 ++++++++++- src/xml.cxx | 14 ++++++++++++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/install-64-and-32-bit-linux.sh b/install-64-and-32-bit-linux.sh index 45d8614..10fef8d 100755 --- a/install-64-and-32-bit-linux.sh +++ b/install-64-and-32-bit-linux.sh @@ -1,19 +1,19 @@ ./bootstrap.sh && \ -LDFLAGS="-L/usr/lib32 -m32" CXXFLAGS="-m32" ./configure \ +LDFLAGS="-L/usr/lib32 -m32" CXXFLAGS="-m32 $DBG" ./configure \ --libdir=/usr/local/lib32 \ --build=x86_64 \ --host=i386 && \ make && \ sudo make install && \ make clean && \ -./configure \ +CXXFLAGS="$DBG" ./configure \ --prefix=/opt/local/i586-mingw32msvc \ --build=x86_64 \ --host=i586-mingw32msvc && \ make && \ sudo make install && \ make clean && \ -./configure && \ +CXXFLAGS="$DBG" ./configure && \ make check && \ sudo make install diff --git a/src/xml-cxx/xml.hxx b/src/xml-cxx/xml.hxx index 27a43c2..d3eaf4f 100644 --- a/src/xml-cxx/xml.hxx +++ b/src/xml-cxx/xml.hxx @@ -163,6 +163,13 @@ namespace xml { Node* _child; }; //---------------------------------------------------------------------------- + class attribute_not_available: public exception { + public: + attribute_not_available(const Node& t, const std::string& attr) throw(): + exception("attribute \""+attr+"\" not set", t) { + } + }; + //---------------------------------------------------------------------------- class stream_error: public exception { public: stream_error(const std::string& reason, const Node& t, @@ -248,7 +255,7 @@ namespace xml { once. This is corect: <node attribute="value">, this is not allowed: <node attribute="value" attribute="value"> */ - class Attributes: public std::map { + class Attributes: public std::map { public: //! Attributes may contain a list of space separated values. typedef std::vector List; @@ -324,6 +331,8 @@ namespace xml { Node& attr(const std::string& name, bool mandatory) 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); 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); diff --git a/src/xml.cxx b/src/xml.cxx index 6cfe109..bbd3366 100644 --- a/src/xml.cxx +++ b/src/xml.cxx @@ -184,9 +184,13 @@ namespace xml { const throw() { List l; for (std::string::size_type it(0), pos(0); - (pos=second.find_first_of(separators, it)), it!=std::string::npos; + it!=std::string::npos && + ((pos=second.find_first_of(separators, it)), true); it=pos!=std::string::npos?++pos:std::string::npos) - l.push_back(std::string(second.begin()+it, second.begin()+pos)); + if (pos==std::string::npos) + l.push_back(second.substr(it)); + else + l.push_back(second.substr(it, pos-it)); return l; } //---------------------------------------------------------------------------- @@ -312,6 +316,12 @@ namespace xml { std::string& Node::attr(const std::string& name) throw() { return _attributes[name]; } + const Attributes::Value Node::attribute(const std::string& name) + const throw(attribute_not_available) { + Attributes::const_iterator it(_attributes.find(name)); + if (it!=_attributes.end()) return *it; + throw attribute_not_available(*this, name); + } Node::List Node::list(const std::string& name) const throw() { List res; for (Contents::const_iterator it(_contents.begin());