summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2009-11-27 20:27:43 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2009-11-30 13:11:11 -0300
commit22fb6d89c445174e77afe698d247c72d05e1576a (patch)
tree1adc464052b4287f78cf4ca0517d368e96d3c12f
parent1dffc65e80f7ed87d51322de10492c7aec7106ca (diff)
downloadshiboken-22fb6d89c445174e77afe698d247c72d05e1576a.tar.gz
shiboken-22fb6d89c445174e77afe698d247c72d05e1576a.tar.xz
shiboken-22fb6d89c445174e77afe698d247c72d05e1576a.zip
Some fixing and refactoring for the ObjectType test class.
-rw-r--r--tests/libsample/objecttype.cpp63
-rw-r--r--tests/libsample/objecttype.h4
2 files changed, 35 insertions, 32 deletions
diff --git a/tests/libsample/objecttype.cpp b/tests/libsample/objecttype.cpp
index 711a72f5..867d61cc 100644
--- a/tests/libsample/objecttype.cpp
+++ b/tests/libsample/objecttype.cpp
@@ -33,32 +33,47 @@
*/
#include "objecttype.h"
+#include <algorithm>
using namespace std;
ObjectType::ObjectType(ObjectType* parent) : m_parent(0)
{
- m_objectName = new Str("");
setParent(parent);
}
ObjectType::~ObjectType()
{
- while (!m_children.empty()) {
- delete m_children.back();
- m_children.pop_back();
- }
+ for (ObjectTypeList::iterator child_iter = m_children.begin();
+ child_iter != m_children.end(); ++child_iter)
+ delete *child_iter;
+}
- delete m_objectName;
+void
+ObjectType::removeChild(ObjectType* child)
+{
+ if (!child)
+ return;
+
+ ObjectTypeList::iterator child_iter = std::find(m_children.begin(), m_children.end(), child);
+ if (child_iter != m_children.end()) {
+ m_children.erase(child_iter);
+ child->m_parent = 0;
+ }
}
void
-ObjectType::removeChild(const ObjectType *child)
+ObjectType::killChild(const Str& name)
{
- for(ObjectTypeList::iterator child_iter = m_children.begin();
- child_iter != m_children.end(); child_iter++) {
- if (this == *child_iter)
- m_children.erase(child_iter);
+ for (ObjectTypeList::iterator child_iter = m_children.begin();
+ child_iter != m_children.end(); ++child_iter) {
+
+ if ((*child_iter)->objectName() == name) {
+ ObjectType* child = *child_iter;
+ removeChild(child);
+ delete child;
+ break;
+ }
}
}
@@ -76,39 +91,27 @@ ObjectType::setParent(ObjectType* parent)
m_parent->m_children.push_back(this);
}
-void ObjectType::killChild(const Str &name)
-{
- for (ObjectTypeList::iterator child_iter = m_children.begin();
- child_iter != m_children.end(); child_iter++) {
-
- if ((*child_iter)->objectName() == name) {
- this->removeChild(*child_iter);
- delete *child_iter;
- break;
- }
- }
-}
-
void
ObjectType::setObjectName(const Str& name)
{
- delete m_objectName;
- m_objectName = new Str(name);
+ m_objectName = name;
}
Str
ObjectType::objectName() const
{
- return *m_objectName;
+ return m_objectName;
}
-bool ObjectType::causeEvent(Event::EventType eventType)
+bool
+ObjectType::causeEvent(Event::EventType eventType)
{
Event e(eventType);
- return this->event(&e);
+ return event(&e);
}
-bool ObjectType::event(Event* event)
+bool
+ObjectType::event(Event* event)
{
return true;
}
diff --git a/tests/libsample/objecttype.h b/tests/libsample/objecttype.h
index 74b6e40e..7ed9c5e0 100644
--- a/tests/libsample/objecttype.h
+++ b/tests/libsample/objecttype.h
@@ -69,7 +69,7 @@ public:
ObjectType* parent() const { return m_parent; }
const ObjectTypeList& children() const { return m_children; }
void killChild(const Str& name);
- void removeChild(const ObjectType *child);
+ void removeChild(ObjectType* child);
Str objectName() const;
void setObjectName(const Str& name);
@@ -83,7 +83,7 @@ private:
ObjectType(const ObjectType&);
ObjectType& operator=(const ObjectType&);
- Str* m_objectName;
+ Str m_objectName;
ObjectType* m_parent;
ObjectTypeList m_children;
};