diff --git a/src/lib/diff/record.hpp b/src/lib/diff/record.hpp index 764ce2cd1..180312db8 100644 --- a/src/lib/diff/record.hpp +++ b/src/lib/diff/record.hpp @@ -230,6 +230,17 @@ namespace diff{ return extractVal (*found); } + Access + child (size_t idx) const + { + if (children_.size() <= idx) + throw error::Invalid ("Child index " +util::toString(idx) + +" out of bounds [0.."+util::toString(children_.size()) + +"["); + return children_[idx]; + } + + /** * While otherwise immutable, * a Record object can be remoulded diff --git a/tests/library/diff/generic-record-representation-test.cpp b/tests/library/diff/generic-record-representation-test.cpp index a065d49fe..cbe258b0f 100644 --- a/tests/library/diff/generic-record-representation-test.cpp +++ b/tests/library/diff/generic-record-representation-test.cpp @@ -150,6 +150,8 @@ namespace test{ CHECK (enterprise.getType() == "starship"); CHECK (enterprise.get("Registry") == "NCC-1701-D"); + CHECK (enterprise.child(0) == "Picard"); + CHECK (enterprise.child(2) == "Data"); CHECK (enterprise.hasAttribute("Owner")); CHECK (!enterprise.hasAttribute("owner")); @@ -160,6 +162,7 @@ namespace test{ CHECK (util::contains (enterprise, "Worf")); VERIFY_ERROR (INVALID, enterprise.get("warp10")); + VERIFY_ERROR (INVALID, enterprise.child(12)); cout << "enterprise = " << enterprise <