lib

object.cpp

00001 /***************************************************************************
00002  * object.cpp
00003  * This file is part of the KDE project
00004  * copyright (C)2004-2006 by Sebastian Sauer (mail@dipe.org)
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  * You should have received a copy of the GNU Library General Public License
00015  * along with this program; see the file COPYING.  If not, write to
00016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  ***************************************************************************/
00019 
00020 #include "object.h"
00021 #include "list.h"
00022 #include "variant.h"
00023 //#include "function.h"
00024 #include "event.h"
00025 #include "exception.h"
00026 
00027 using namespace Kross::Api;
00028 
00029 Object::Object()
00030     : KShared()
00031 {
00032 #ifdef KROSS_API_OBJECT_CTOR_DEBUG
00033     krossdebug( QString("Kross::Api::Object::Constructor() name='%1' refcount='%2'").arg(m_name).arg(_KShared_count()) );
00034 #endif
00035 }
00036 
00037 Object::~Object()
00038 {
00039 #ifdef KROSS_API_OBJECT_DTOR_DEBUG
00040     krossdebug( QString("Kross::Api::Object::Destructor() name='%1' refcount='%2'").arg(m_name).arg(_KShared_count()) );
00041 #endif
00042     //removeAllChildren(); // not needed cause we use KShared to handle ref-couting and freeing.
00043 }
00044 
00045 const QString Object::toString()
00046 {
00047     return QString("%1").arg(getClassName());
00048 }
00049 
00050 Object::Ptr Object::call(const QString& name, List::Ptr arguments)
00051 {
00052     Q_UNUSED(arguments);
00053 
00054 #ifdef KROSS_API_OBJECT_CALL_DEBUG
00055     krossdebug( QString("Kross::Api::Object::call(%1) name=%2 class=%3").arg(name).arg(getName()).arg(getClassName()) );
00056 #endif
00057 
00058     if(name.isEmpty()) // return a self-reference if no functionname is defined.
00059         return this;
00060 
00061     throw Exception::Ptr( new Exception(QString("No callable object named '%2'").arg(name)) );
00062 }
00063 
KDE Home | KDE Accessibility Home | Description of Access Keys