|
@ -19,7 +19,7 @@ public: |
|
|
|
|
|
|
|
|
// methods
|
|
|
// methods
|
|
|
virtual int implMe(int magic_nr) = 0; |
|
|
virtual int implMe(int magic_nr) = 0; |
|
|
AbstractNode& getSelf() override = 0; |
|
|
AbstractNode *getSelf() override = 0; |
|
|
AbstractNode *clone() override = 0; |
|
|
AbstractNode *clone() override = 0; |
|
|
|
|
|
|
|
|
// fields
|
|
|
// fields
|
|
@ -49,7 +49,7 @@ public: |
|
|
explicit ANode(const std::string &name); |
|
|
explicit ANode(const std::string &name); |
|
|
explicit ANode(const std::string &name, AbstractNode &parent); |
|
|
explicit ANode(const std::string &name, AbstractNode &parent); |
|
|
ANode(const ANode &rhs); |
|
|
ANode(const ANode &rhs); |
|
|
ANode &getSelf() override; |
|
|
ANode *getSelf() override; |
|
|
ANode *clone() override; |
|
|
ANode *clone() override; |
|
|
int implMe(int magic_nr) override; |
|
|
int implMe(int magic_nr) override; |
|
|
}; |
|
|
}; |
|
@ -63,9 +63,9 @@ int ANode::implMe(int magic_nr) |
|
|
return 23; |
|
|
return 23; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ANode &ANode::getSelf() |
|
|
ANode *ANode::getSelf() |
|
|
{ |
|
|
{ |
|
|
return *this; |
|
|
return this; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ANode *ANode::clone() |
|
|
ANode *ANode::clone() |
|
@ -80,7 +80,7 @@ public: |
|
|
explicit BNode(const std::string &name); |
|
|
explicit BNode(const std::string &name); |
|
|
explicit BNode(const std::string &name, AbstractNode &parent); |
|
|
explicit BNode(const std::string &name, AbstractNode &parent); |
|
|
BNode(const BNode &rhs); |
|
|
BNode(const BNode &rhs); |
|
|
BNode &getSelf() override; |
|
|
BNode *getSelf() override; |
|
|
BNode *clone() override; |
|
|
BNode *clone() override; |
|
|
int implMe(int magic_nr) override; |
|
|
int implMe(int magic_nr) override; |
|
|
}; |
|
|
}; |
|
@ -94,9 +94,9 @@ int BNode::implMe(int magic_nr) |
|
|
return 42; |
|
|
return 42; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
BNode &BNode::getSelf() |
|
|
BNode *BNode::getSelf() |
|
|
{ |
|
|
{ |
|
|
return *this; |
|
|
return this; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
BNode *BNode::clone() |
|
|
BNode *BNode::clone() |
|
@ -113,7 +113,7 @@ int main(int argc, char *argv[]) |
|
|
std::cout << a.getPath() << std::endl; |
|
|
std::cout << a.getPath() << std::endl; |
|
|
PITYASSERT(a.isRoot() == true, "a"); |
|
|
PITYASSERT(a.isRoot() == true, "a"); |
|
|
PITYASSERT(a.getName() == "a", "b"); |
|
|
PITYASSERT(a.getName() == "a", "b"); |
|
|
PITYASSERT(&(a.getRoot()) == &a, "c"); |
|
|
PITYASSERT(a.getRoot() == &a, "c"); |
|
|
PITYASSERT(a.getParent() == nullptr, "d"); |
|
|
PITYASSERT(a.getParent() == nullptr, "d"); |
|
|
PITYASSERT(a.getChildRefs().size() == 0, "e"); |
|
|
PITYASSERT(a.getChildRefs().size() == 0, "e"); |
|
|
|
|
|
|
|
@ -121,28 +121,28 @@ int main(int argc, char *argv[]) |
|
|
BNode b{ "b", a }; |
|
|
BNode b{ "b", a }; |
|
|
std::cout << b.getPath() << std::endl; |
|
|
std::cout << b.getPath() << std::endl; |
|
|
PITYASSERT(a.isRoot() == true, "f"); |
|
|
PITYASSERT(a.isRoot() == true, "f"); |
|
|
PITYASSERT(&(a.getRoot()) == &a, "g"); |
|
|
PITYASSERT(a.getRoot() == &a, "g"); |
|
|
PITYASSERT(a.getParent() == nullptr, "1"); |
|
|
PITYASSERT(a.getParent() == nullptr, "1"); |
|
|
PITYASSERT(a.getChildRefs().size() == 1, "2"); |
|
|
PITYASSERT(a.getChildRefs().size() == 1, "2"); |
|
|
|
|
|
|
|
|
PITYASSERT(&b == &(a.getChild("b")), "3"); |
|
|
PITYASSERT(&b == a.getChild("b"), "3"); |
|
|
PITYASSERT_THROWS(a.getChild("invalid"), "4"); |
|
|
PITYASSERT_THROWS(a.getChild("invalid"), "4"); |
|
|
PITYASSERT(b.isRoot() == false, "5"); |
|
|
PITYASSERT(b.isRoot() == false, "5"); |
|
|
PITYASSERT(&(b.getRoot()) == &a, "6"); |
|
|
PITYASSERT(b.getRoot() == &a, "6"); |
|
|
PITYASSERT(b.getParent() == &a, "7"); |
|
|
PITYASSERT(b.getParent() == &a, "7"); |
|
|
PITYASSERT(b.getChildRefs().size() == 0, "8"); |
|
|
PITYASSERT(b.getChildRefs().size() == 0, "8"); |
|
|
|
|
|
|
|
|
// Create a copy of the node in the parent node
|
|
|
// Create a copy of the node in the parent node
|
|
|
b.addNew<ANode>("c").addNew<ANode>("d"); |
|
|
b.addNew<ANode>("c")->addNew<ANode>("d"); |
|
|
std::cout << a.to_string() << std::endl; |
|
|
std::cout << a.to_string() << std::endl; |
|
|
|
|
|
|
|
|
b.addNew<BNode>("c1").addNew<BNode>("e"); |
|
|
b.addNew<BNode>("c1")->addNew<BNode>("e"); |
|
|
std::cout << a.to_string() << std::endl; |
|
|
std::cout << a.to_string() << std::endl; |
|
|
|
|
|
|
|
|
b.getChild("c1").getChild("e").addCopy(ANode(a), "a1"); |
|
|
b.getChild("c1")->getChild("e")->addCopy(ANode(a), "a1"); |
|
|
std::cout << a.to_string() << std::endl; |
|
|
std::cout << a.to_string() << std::endl; |
|
|
|
|
|
|
|
|
a.getChild("b").addCopy(ANode(a), a.getName() + "1"); |
|
|
a.getChild("b")->addCopy(ANode(a), a.getName() + "1"); |
|
|
std::cout << a.to_string() << std::endl; |
|
|
std::cout << a.to_string() << std::endl; |
|
|
|
|
|
|
|
|
ANode a2 = ANode(a); |
|
|
ANode a2 = ANode(a); |
|
|