lib

object.cpp
1/***************************************************************************
2 * object.cpp
3 * This file is part of the KDE project
4 * copyright (C)2004-2006 by Sebastian Sauer (mail@dipe.org)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this program; see the file COPYING. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 ***************************************************************************/
19
20#include "object.h"
21#include "list.h"
22#include "variant.h"
23//#include "function.h"
24#include "event.h"
25#include "exception.h"
26
27using namespace Kross::Api;
28
30 : TDEShared()
31{
32#ifdef KROSS_API_OBJECT_CTOR_DEBUG
33 krossdebug( TQString("Kross::Api::Object::Constructor() name='%1' refcount='%2'").arg(m_name).arg(_TDEShared_count()) );
34#endif
35}
36
38{
39#ifdef KROSS_API_OBJECT_DTOR_DEBUG
40 krossdebug( TQString("Kross::Api::Object::Destructor() name='%1' refcount='%2'").arg(m_name).arg(_TDEShared_count()) );
41#endif
42 //removeAllChildren(); // not needed cause we use TDEShared to handle ref-couting and freeing.
43}
44
45const TQString Object::toString()
46{
47 return TQString("%1").arg(getClassName());
48}
49
50Object::Ptr Object::call(const TQString& name, List::Ptr arguments)
51{
52 Q_UNUSED(arguments);
53
54#ifdef KROSS_API_OBJECT_CALL_DEBUG
55 krossdebug( TQString("Kross::Api::Object::call(%1) name=%2 class=%3").arg(name).arg(getName()).arg(getClassName()) );
56#endif
57
58 if(name.isEmpty()) // return a self-reference if no functionname is defined.
59 return this;
60
61 throw Exception::Ptr( new Exception(TQString("No callable object named '%2'").arg(name)) );
62}
63
Common exception class used for representing exceptions in Kross.
Definition exception.h:39
TDESharedPtr< Exception > Ptr
Shared pointer to implement reference-counting.
Definition exception.h:45
TDESharedPtr< List > Ptr
Shared pointer to implement reference-counting.
Definition list.h:46
virtual const TQString getClassName() const =0
Return the class name.
virtual Object::Ptr call(const TQString &name, TDESharedPtr< List > arguments)
Pass a call to the object and evaluated it recursive down the object-hierachy.
Definition object.cpp:50
Object()
Constructor.
Definition object.cpp:29
virtual ~Object()
Destructor.
Definition object.cpp:37
TDESharedPtr< Object > Ptr
Shared pointer to implement reference-counting.
Definition object.h:56
virtual const TQString toString()
Definition object.cpp:45
The common Kross API used as common codebase.
Definition callable.h:33
KOFFICE_EXPORT void krossdebug(const TQString &s)
Debugging function.