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 <ksharedptr.h>
28
29#include "koffice_export.h"
30
31namespace Kross { namespace Api {
32
33 // Forward declaration.
34 class List;
35
49 class KOFFICE_EXPORT Object : public TDEShared
50 {
51 public:
52
56 typedef TDESharedPtr<Object> Ptr;
57
61 explicit Object();
62
66 virtual ~Object();
67
75 virtual const TQString getClassName() const = 0;
76
82 virtual const TQString toString();
83
101 virtual Object::Ptr call(const TQString& name, TDESharedPtr<List> arguments);
102
108 virtual TQStringList getCalls() { return TQStringList(); }
109 //FIXME replace function with getChildren() functionality ?
110
120 template<class T> static T* fromObject(Object::Ptr object);
121
130 template<typename TYPE>
131 static Object::Ptr toObject(TYPE t) { return t; }
132 };
133
134}}
135
136#include "exception.h"
137
138namespace Kross { namespace Api {
139
140template<class T> inline T* Object::fromObject(Object::Ptr object)
141{
142 T* t = (T*) object.data();
143 if(! t)
144 throw TDESharedPtr<Exception>( new Exception(TQString("Object \"%1\" invalid.").arg(object ? object->getClassName() : "")) );
145 return t;
146}
147
148}}
149
150#endif
151
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:39
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:131
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:108
static T * fromObject(Object::Ptr object)
Try to convert the Object instance to the template class T.
Definition object.h:140
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
The Kross scripting bridge to embed scripting functionality into an application.
Definition callable.h:33