lib

object.h

00001 /***************************************************************************
00002  * object.h
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 #ifndef KROSS_API_OBJECT_H
00021 #define KROSS_API_OBJECT_H
00022 
00023 #include <qstring.h>
00024 #include <qvaluelist.h>
00025 #include <qmap.h>
00026 #include <qvariant.h>
00027 //#include <qobject.h>
00028 #include <ksharedptr.h>
00029 
00030 #include "../main/krossconfig.h"
00031 
00032 namespace Kross { namespace Api {
00033 
00034     // Forward declaration.
00035     class List;
00036 
00050     class Object : public KShared
00051     {
00052         public:
00053 
00057             typedef KSharedPtr<Object> Ptr;
00058 
00062             explicit Object();
00063 
00067             virtual ~Object();
00068 
00076             virtual const QString getClassName() const = 0;
00077 
00083             virtual const QString toString();
00084 
00102             virtual Object::Ptr call(const QString& name, KSharedPtr<List> arguments);
00103 
00109             virtual QStringList getCalls() { return QStringList(); }
00110             //FIXME replace function with getChildren() functionality ?
00111 
00121             template<class T> static T* fromObject(Object::Ptr object);
00122 
00131             template<typename TYPE>
00132             static Object::Ptr toObject(TYPE t) { return t; }
00133     };
00134 
00135 }}
00136 
00137 #include "exception.h"
00138 
00139 namespace Kross { namespace Api {
00140 
00141 template<class T> inline T* Object::fromObject(Object::Ptr object)
00142 {
00143     T* t = (T*) object.data();
00144     if(! t)
00145         throw KSharedPtr<Exception>( new Exception(QString("Object \"%1\" invalid.").arg(object ? object->getClassName() : "")) );
00146     return t;
00147 }
00148 
00149 }} 
00150 
00151 #endif
00152 
KDE Home | KDE Accessibility Home | Description of Access Keys