00001 /*************************************************************************** 00002 * callable.h 00003 * This file is part of the KDE project 00004 * copyright (C)2004-2005 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_CALLABLE_H 00021 #define KROSS_API_CALLABLE_H 00022 00023 #include "object.h" 00024 #include "list.h" 00025 //#include "exception.h" 00026 #include "argument.h" 00027 00028 #include <qstring.h> 00029 #include <qvaluelist.h> 00030 #include <ksharedptr.h> 00031 #include <kdebug.h> 00032 00033 namespace Kross { namespace Api { 00034 00035 /** 00036 * Base class for callable objects. Classes like 00037 * \a Event or \a Class are inherited from this class 00038 * and implement the \a Object::call() method to handle 00039 * the call. 00040 */ 00041 class Callable : public Object 00042 { 00043 public: 00044 00045 /** 00046 * Shared pointer to implement reference-counting. 00047 */ 00048 typedef KSharedPtr<Callable> Ptr; 00049 00050 /** 00051 * Constructor. 00052 * 00053 * \param name The name this callable object has and 00054 * it is reachable as via \a Object::getChild() . 00055 * \param parent The parent \a Object this instance is 00056 * child of. 00057 * \param arglist A list of arguments the callable 00058 * object expects if it got called. 00059 */ 00060 Callable(const QString& name, Object::Ptr parent, const ArgumentList& arglist); 00061 00062 /** 00063 * Destructor. 00064 */ 00065 virtual ~Callable(); 00066 00067 /** 00068 * Return the class name. This could be something 00069 * like "Kross::Api::Callable" for this object. The 00070 * value is mainly used for display purposes. 00071 * 00072 * \return The name of this class. 00073 */ 00074 virtual const QString getClassName() const; 00075 00076 /** 00077 * Call the object. 00078 */ 00079 virtual Object::Ptr call(const QString& name, List::Ptr arguments); 00080 00081 /** 00082 * Wrapper for the \a Kross::Api::Object::hasChild() method 00083 * to check if this object has children. 00084 */ 00085 Object::Ptr hasChild(List::Ptr args); 00086 00087 /** 00088 * Wrapper for the \a Kross::Api::Object::getChild() method 00089 * to return a children this object has. 00090 */ 00091 Object::Ptr getChild(List::Ptr args); 00092 00093 //Object::Ptr setChild(List::Ptr args); 00094 00095 /** 00096 * Wrapper for the \a Kross::Api::Object::getChildren() method 00097 * to return a list of childrennames this object has. 00098 * 00099 * \return a \a List filled with a list of names of the 00100 * children this object has. 00101 */ 00102 Object::Ptr getChildrenList(List::Ptr args); 00103 00104 /** 00105 * Wrapper for the \a Kross::Api::Object::getChild() method 00106 * to return a dictonary of children this object has. 00107 * 00108 * \return a \a Dict filled with the children. 00109 */ 00110 Object::Ptr getChildrenDict(List::Ptr args); 00111 00112 /** 00113 * Wrapper for the \a Kross::Api::Object::call() method 00114 * to call a children. 00115 */ 00116 Object::Ptr callChild(List::Ptr args); 00117 00118 protected: 00119 00120 /** 00121 * List of arguments this callable object supports. 00122 */ 00123 ArgumentList m_arglist; 00124 00125 /** 00126 * Check the passed arguments against the \a m_arglist and throws 00127 * an exception if failed. 00128 */ 00129 //void checkArguments(KSharedPtr<List> arguments); 00130 00131 }; 00132 00133 }} 00134 00135 #endif 00136
1.4.6