diff options
Diffstat (limited to 'tests/libsample/kindergarten.cpp')
-rw-r--r-- | tests/libsample/kindergarten.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/libsample/kindergarten.cpp b/tests/libsample/kindergarten.cpp new file mode 100644 index 000000000..8332e4fe7 --- /dev/null +++ b/tests/libsample/kindergarten.cpp @@ -0,0 +1,64 @@ +#include <iostream> +#include "kindergarten.h" + +using namespace std; + +KinderGarten::~KinderGarten() +{ + cout << __PRETTY_FUNCTION__ << " ---- BEGIN" << endl; + killChildren(); + cout << __PRETTY_FUNCTION__ << " ---- END" << endl; +} + +void +KinderGarten::addChild(Abstract* child) +{ + m_children.push_back(child); +} + +void +KinderGarten::killChildren() +{ + cout << __PRETTY_FUNCTION__ << endl; + while (!m_children.empty()) { + m_children.back()->show(); + cout << endl; + delete m_children.back(); + m_children.pop_back(); + } +} + +void +KinderGarten::killChild(Abstract* child) +{ + cout << __PRETTY_FUNCTION__ << endl; + if (child) { + m_children.remove(child); +// delete child; + } +} + +Abstract* +KinderGarten::releaseChild(Abstract* child) +{ + for(ChildList::iterator child_iter = m_children.begin(); + child_iter != m_children.end(); child_iter++) { + if (child == *child_iter) { + m_children.erase(child_iter); + return child; + } + } +} + +void +KinderGarten::show() +{ + cout << "["; + for(ChildList::iterator child_iter = m_children.begin(); + child_iter != m_children.end(); child_iter++) { + if (child_iter != m_children.begin()) + cout << ", "; + (*child_iter)->show(); + } + cout << "]"; +} |