Use std::vector instead of std::list.
authorCarl Hetherington <cth@carlh.net>
Fri, 8 Jan 2021 13:09:08 +0000 (14:09 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 8 Jan 2021 13:13:41 +0000 (14:13 +0100)
src/cxml.cc
src/cxml.h
test/tests.cc

index 356e1df5546908711ca4245c3825c16007aeaf83..c21bd19f8e7a3e6d50ef1b5da32dae4b06570d79 100644 (file)
@@ -24,9 +24,9 @@
 #include <boost/algorithm/string.hpp>
 #include <cstdio>
 
-using std::string;
-using std::list;
 using std::shared_ptr;
+using std::string;
+using std::vector;
 using boost::optional;
 
 cxml::Node::Node ()
@@ -76,14 +76,14 @@ cxml::Node::optional_node_child (string name) const
        return n.front ();
 }
 
-list<shared_ptr<cxml::Node>>
+vector<shared_ptr<cxml::Node>>
 cxml::Node::node_children () const
 {
        if (!_node) {
                throw Error ("No node to read children from");
        }
 
-       list<shared_ptr<cxml::Node> > n;
+       vector<shared_ptr<cxml::Node> > n;
        for (auto i: _node->get_children()) {
                n.push_back (shared_ptr<Node> (new Node (i)));
        }
@@ -91,14 +91,14 @@ cxml::Node::node_children () const
        return n;
 }
 
-list<shared_ptr<cxml::Node>>
+vector<shared_ptr<cxml::Node>>
 cxml::Node::node_children (string name) const
 {
        /* XXX: using find / get_path should work here, but I can't follow
           how get_path works.
        */
 
-       list<shared_ptr<cxml::Node> > n;
+       vector<shared_ptr<cxml::Node> > n;
        for (auto i: _node->get_children()) {
                if (i->get_name() == name) {
                        n.push_back (shared_ptr<Node> (new Node (i)));
index 2bdde74709cda7e6f1ff90d70de4921f77060e74..4fccbaed68c8687b44d5397bb8eaa4d82b60ece8 100644 (file)
@@ -26,7 +26,7 @@
 #include <boost/algorithm/string/erase.hpp>
 #include <stdint.h>
 #include <string>
-#include <list>
+#include <vector>
 
 /* Hack for OS X compile failure; see https://bugs.launchpad.net/hugin/+bug/910160 */
 #ifdef check
@@ -223,8 +223,8 @@ public:
        std::shared_ptr<Node> node_child (std::string) const;
        std::shared_ptr<Node> optional_node_child (std::string) const;
 
-       std::list<std::shared_ptr<Node> > node_children () const;
-       std::list<std::shared_ptr<Node> > node_children (std::string) const;
+       std::vector<std::shared_ptr<Node>> node_children () const;
+       std::vector<std::shared_ptr<Node>> node_children (std::string) const;
 
        xmlpp::Node* node () const {
                return _node;
@@ -234,7 +234,7 @@ protected:
        xmlpp::Node* _node;
 
 private:
-       mutable std::list<std::string> _taken;
+       mutable std::vector<std::string> _taken;
 };
 
 typedef std::shared_ptr<cxml::Node> NodePtr;
index 6867ac05805606418a53219b750d1a492aff1e15..633aaa2b9bf4369246838f490fb9aad493cc729e 100644 (file)
 #define BOOST_TEST_MODULE libcxml_test
 #include <boost/test/unit_test.hpp>
 
+using std::shared_ptr;
 using std::string;
 using std::vector;
-using std::list;
-using std::shared_ptr;
 
 BOOST_AUTO_TEST_CASE (test)
 {
@@ -68,7 +67,7 @@ BOOST_AUTO_TEST_CASE (test)
 
        BOOST_CHECK (!document.optional_bool_child("G"));
 
-       list<shared_ptr<cxml::Node> > h = document.node_children ("H");
+       vector<shared_ptr<cxml::Node>> h = document.node_children ("H");
        BOOST_CHECK_EQUAL (h.size(), 1);
        BOOST_CHECK_EQUAL (h.front()->node_children("I").size(), 2);
        BOOST_CHECK_EQUAL (h.front()->node_children("I").front()->content(), "testing");