add accessor for Nth child to our Record type

This commit is contained in:
Fischlurch 2016-01-23 17:10:44 +01:00
parent a95103eb3b
commit f743784bc9
2 changed files with 14 additions and 0 deletions

View file

@ -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

View file

@ -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 <<endl;