lib

object.h
1/***************************************************************************
2 * object.h
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#ifndef KROSS_API_OBJECT_H
21#define KROSS_API_OBJECT_H
22
23#include <tqstring.h>
24#include <tqvaluelist.h>
25#include <tqmap.h>
26#include <tqvariant.h>
27//#include <tqobject.h>
28#include <ksharedptr.h>
29
30#include "../main/krossconfig.h"
31
32namespace Kross { namespace Api {
33
34 // Forward declaration.
35 class List;
36
50 class Object : public TDEShared
51 {
52 public:
53
57 typedef TDESharedPtr<Object> Ptr;
58
62 explicit Object();
63
67 virtual ~Object();
68
76 virtual const TQString getClassName() const = 0;
77
83 virtual const TQString toString();
84
102 virtual Object::Ptr call(const TQString& name, TDESharedPtr<List> arguments);
103
109 virtual TQStringList getCalls() { return TQStringList(); }
110 //FIXME replace function with getChildren() functionality ?
111
121 template<class T> static T* fromObject(Object::Ptr object);
122
131 template<typename TYPE>
132 static Object::Ptr toObject(TYPE t) { return t; }
133 };
134
135}}
136
137#include "exception.h"
138
139namespace Kross { namespace Api {
140
141template<class T> inline T* Object::fromObject(Object::Ptr object)
142{
143 T* t = (T*) object.data();
144 if(! t)
145 throw TDESharedPtr<Exception>( new Exception(TQString("Object \"%1\" invalid.").arg(object ? object->getClassName() : "")) );
146 return t;
147}
148
149}}
150
151#endif
152
Common exception class used for representing exceptions in Kross.
Definition exception.h:39
The List class implementates Value to handle lists and collections.
Definition list.h:37
static Object::Ptr toObject(TYPE t)
This method got used by the ProxyFunction classes to translate an unknown TYPE to a Object instance.
Definition object.h:132
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 TQStringList getCalls()
Return a list of supported callable objects.
Definition object.h:109
static T * fromObject(Object::Ptr object)
Try to convert the Object instance to the template class T.
Definition object.h:141
virtual ~Object()
Destructor.
Definition object.cpp:37
TDESharedPtr< Object > Ptr
Shared pointer to implement reference-counting.
Definition object.h:57
virtual const TQString toString()
Definition object.cpp:45
The common Kross API used as common codebase.
Definition callable.h:31
The Kross scripting bridge to embed scripting functionality into an application.
Definition callable.h:31