diff options
Diffstat (limited to 'zenXml')
-rw-r--r-- | zenXml/zenxml/cvrt_struc.h | 6 | ||||
-rw-r--r-- | zenXml/zenxml/cvrt_text.h | 1 | ||||
-rw-r--r-- | zenXml/zenxml/dom.h | 17 | ||||
-rw-r--r-- | zenXml/zenxml/parser.h | 15 | ||||
-rw-r--r-- | zenXml/zenxml/xml.h | 6 |
5 files changed, 17 insertions, 28 deletions
diff --git a/zenXml/zenxml/cvrt_struc.h b/zenXml/zenxml/cvrt_struc.h index 40277556..57a5d09d 100644 --- a/zenXml/zenxml/cvrt_struc.h +++ b/zenXml/zenxml/cvrt_struc.h @@ -124,9 +124,7 @@ struct ConvertElement<T, ValueType::stlContainer> value.clear(); bool success = true; - auto [it, itEnd] = input.getChildren(); - - std::for_each(it, itEnd, [&](const XmlElement& xmlChild) + for (const XmlElement& xmlChild : input.getChildren()) { typename T::value_type childVal; if (zen::readStruc(xmlChild, childVal)) @@ -134,7 +132,7 @@ struct ConvertElement<T, ValueType::stlContainer> else success = false; //should we support insertion of partially-loaded struct?? - }); + } return success; } }; diff --git a/zenXml/zenxml/cvrt_text.h b/zenXml/zenxml/cvrt_text.h index b4f6fa2d..4fa4ec83 100644 --- a/zenXml/zenxml/cvrt_text.h +++ b/zenXml/zenxml/cvrt_text.h @@ -8,7 +8,6 @@ #define CVRT_TEXT_H_018727339083427097434 #include <chrono> -//#include <zen/utf.h> #include <zen/string_tools.h> diff --git a/zenXml/zenxml/dom.h b/zenXml/zenxml/dom.h index 89320db1..cbac4dff 100644 --- a/zenXml/zenxml/dom.h +++ b/zenXml/zenxml/dom.h @@ -131,21 +131,18 @@ public: return const_cast<XmlElement*>(static_cast<const XmlElement*>(this)->getChild(name)); } - using ChildIter = std::list<XmlElement>::iterator; - using ChildIterConst = std::list<XmlElement>::const_iterator; - - ///Access all child elements sequentially via STL iterators. + ///Access all child elements sequentially /** \code - auto [it, itEnd] = elem.getChildren(); - std::for_each(it, itEnd, [](const XmlElement& child) { ... }); + for (const XmlElement& child : elem.getChildren()) + { ... } \endcode - \return A pair of STL begin/end iterators to access all child elements sequentially. */ - std::pair<ChildIterConst, ChildIterConst> getChildren() const { return {childElements_.begin(), childElements_.end()}; } + \return A range object supporting begin/end functions to access all child elements sequentially. */ + Range<std::list<XmlElement>::const_iterator> getChildren() const { return {childElements_.begin(), childElements_.end()}; } ///\sa getChildren - std::pair<ChildIter, ChildIter> getChildren() { return {childElements_.begin(), childElements_.end()}; } - + Range<std::list<XmlElement>::iterator> getChildren() { return {childElements_.begin(), childElements_.end()}; } + ///Get parent XML element, may be nullptr for root element XmlElement* parent() { return parent_; } ///Get parent XML element, may be nullptr for root element diff --git a/zenXml/zenxml/parser.h b/zenXml/zenxml/parser.h index 6c7959b4..f60a3906 100644 --- a/zenXml/zenxml/parser.h +++ b/zenXml/zenxml/parser.h @@ -7,7 +7,6 @@ #ifndef PARSER_H_81248670213764583021432 #define PARSER_H_81248670213764583021432 -//#include <cstdio> #include <cstddef> //ptrdiff_t; req. on Linux #include <zen/string_tools.h> #include "dom.h" @@ -206,14 +205,14 @@ void serialize(const XmlElement& element, std::string& stream, for (auto it = attr.first; it != attr.second; ++it) stream += ' ' + normalizeName(it->name) + "=\"" + normalizeAttribValue(it->value) + '"'; - auto [it, itEnd] = element.getChildren(); - if (it != itEnd) //structured element + const auto& children = element.getChildren(); + if (!children.empty()) //structured element { //no support for mixed-mode content stream += '>' + lineBreak; - std::for_each(it, itEnd, [&](const XmlElement& el) - { serialize(el, stream, lineBreak, indent, indentLevel + 1); }); + for (const XmlElement& el : children) + serialize(el, stream, lineBreak, indent, indentLevel + 1); for (size_t i = 0; i < indentLevel; ++i) stream += indent; @@ -483,9 +482,9 @@ public: XmlElement dummy; parseChildElements(dummy); - auto [it, itEnd] = dummy.getChildren(); - if (it != itEnd) - doc.root().swapSubtree(*it); + const auto& children = dummy.getChildren(); + if (!children.empty()) + doc.root().swapSubtree(*children.begin()); expectToken(Token::TK_END); //throw XmlParsingError return doc; diff --git a/zenXml/zenxml/xml.h b/zenXml/zenxml/xml.h index f14a9f0b..03974fad 100644 --- a/zenXml/zenxml/xml.h +++ b/zenXml/zenxml/xml.h @@ -7,7 +7,6 @@ #ifndef XML_H_349578228034572457454554 #define XML_H_349578228034572457454554 -//#include <set> #include <zen/file_io.h> #include <zen/file_access.h> #include "cvrt_struc.h" @@ -258,12 +257,9 @@ public: logConversionError(); //have XML value element, not container! else { - auto [it, itEnd] = elem_->getChildren(); size_t childIdx = 0; - std::for_each(it, itEnd, [&](const XmlElement& child) - { + for (const XmlElement& child : elem_->getChildren()) fun(XmlIn(&child, elementNameFmt_ + " <" + child.getName() + ">[" + numberTo<std::string>(++childIdx) + ']', log_)); - }); } } |