added Node::first() and Node::last() to get the first or last child

master
Marc Wäckerlin 9 years ago
parent ad7d4cddeb
commit 72be1818f1
  1. 15
      ChangeLog
  2. 4
      src/xml-cxx/xml.hxx
  3. 32
      src/xml.cxx

@ -1,3 +1,18 @@
2015-03-24 08:03 marc
* README: typo
2015-03-03 10:22 marc
* configure.ac: a=\\PACKAGEPACKAGE_VERSION\; b=\\PACKAGE_VERSION\;
for f in $(grep --exclude-dir=.svn --exclude=\\*~\ -lr "$a"); do
sed -i "s,$a,$b,g" "$f"; done
2015-02-23 10:29 marc
* ChangeLog, src/xml-cxx/xml.hxx: make check fixed - now warnings
deprecated std::auto_ptr → to be fixed later; refs #14
2015-02-19 08:45 marc
* AUTHORS, ChangeLog, INSTALL, README, ax_cxx_compile_stdcxx_11.m4,

@ -813,6 +813,10 @@ namespace xml {
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();

@ -455,6 +455,38 @@ namespace xml {
Attributes& Node::attributes() throw() {
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) {
Contents::iterator it(_contents.begin());
if (it==_contents.end()) throw out_of_range(*this, 0);
return **it;
}
//! 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) {
Contents::const_iterator it(_contents.begin());
if (it==_contents.end()) throw out_of_range(*this, 0);
return **it;
}
//! 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) {
Contents::const_reverse_iterator it(_contents.rbegin());
if (it==_contents.rend()) throw out_of_range(*this, 0);
return **it;
}
//! 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) {
Contents::reverse_iterator it(_contents.rbegin());
if (it==_contents.rend()) throw out_of_range(*this, 0);
return **it;
}
//! Pass a minimal and maximal number for this node in a xml file.
/*! Minimal and maximal values are verified when you use the node as
a template in a xml::Factory. When the factory reads a stucture

Loading…
Cancel
Save