lib
object.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "object.h"
00021 #include "list.h"
00022 #include "variant.h"
00023
00024 #include "event.h"
00025 #include "exception.h"
00026
00027 #include <kdebug.h>
00028
00029 using namespace Kross::Api;
00030
00031 Object::Object(const QString& name, Object::Ptr parent)
00032 : KShared()
00033 , m_name(name)
00034 , m_parent(parent)
00035 {
00036 #ifdef KROSS_API_OBJECT_CTOR_DEBUG
00037 kdDebug() << QString("Kross::Api::Object::Constructor() name='%1' refcount='%2'").arg(m_name).arg(_KShared_count()) << endl;
00038 #endif
00039 }
00040
00041 Object::~Object()
00042 {
00043 #ifdef KROSS_API_OBJECT_DTOR_DEBUG
00044 kdDebug() << QString("Kross::Api::Object::Destructor() name='%1' refcount='%2'").arg(m_name).arg(_KShared_count()) << endl;
00045 #endif
00046
00047 }
00048
00049 const QString& Object::getName() const
00050 {
00051 return m_name;
00052 }
00053
00054 const QString Object::toString()
00055 {
00056 return QString("%1 (%2)").arg(m_name).arg(getClassName());
00057 }
00058
00059 Object::Ptr Object::getParent() const
00060 {
00061 return m_parent;
00062 }
00063
00064 bool Object::hasChild(const QString& name) const
00065 {
00066 return m_children.contains(name);
00067 }
00068
00069 Object::Ptr Object::getChild(const QString& name) const
00070 {
00071 return m_children[name];
00072 }
00073
00074 QMap<QString, Object::Ptr> Object::getChildren() const
00075 {
00076 return m_children;
00077 }
00078
00079 bool Object::addChild(Object::Ptr object, const QString& name)
00080 {
00081 QString n = name.isNull() ? object->getName() : name;
00082
00083 #ifdef KROSS_API_OBJECT_ADDCHILD_DEBUG
00084 kdDebug() << QString("Kross::Api::Object::addChild() object.name='%2' object.classname='%3'")
00085 .arg(n).arg(object->getClassName()) << endl;
00086 #endif
00087
00088 if(n.isEmpty())
00089 return false;
00090
00091 object->m_parent = this;
00092 m_children.replace(n, object);
00093 return true;
00094 }
00095
00096 void Object::removeChild(const QString& name)
00097 {
00098 #ifdef KROSS_API_OBJECT_REMCHILD_DEBUG
00099 kdDebug() << QString("Kross::Api::Object::removeChild() name='%1'").arg(name) << endl;
00100 #endif
00101 m_children.remove(name);
00102 }
00103
00104 void Object::removeAllChildren()
00105 {
00106 #ifdef KROSS_API_OBJECT_REMCHILD_DEBUG
00107 kdDebug() << "Kross::Api::Object::removeAllChildren()" << endl;
00108 #endif
00109 m_children.clear();
00110 }
00111
00112 Object::Ptr Object::call(const QString& name, List::Ptr arguments)
00113 {
00114 #ifdef KROSS_API_OBJECT_CALL_DEBUG
00115 kdDebug() << QString("Kross::Api::Object::call(%1) name=%2 class=%3").arg(name).arg(getName()).arg(getClassName()) << endl;
00116 #endif
00117
00118 if(name.isEmpty())
00119 return this;
00120
00121
00122 Object::Ptr object = getChild(name);
00123 if(object) {
00124
00125 return object->call(name, arguments);
00126 }
00127
00128
00129 kdDebug() << QString("Object '%1' has no callable object named '%2'.").arg(getName()).arg(name) << endl;
00130 return 0;
00131 }
00132
|