add accessor for Nth child to our Record type
This commit is contained in:
parent
a95103eb3b
commit
f743784bc9
2 changed files with 14 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue