00001 /*************************************************************************** 00002 * script.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_SCRIPT_H 00021 #define KROSS_API_SCRIPT_H 00022 00023 #include <qstring.h> 00024 #include <qstringlist.h> 00025 00026 #include "class.h" 00027 00028 namespace Kross { namespace Api { 00029 00030 // Forward declarations. 00031 class Object; 00032 class Interpreter; 00033 class ScriptContainer; 00034 class List; 00035 class Exception; 00036 00037 /** 00038 * Base class for interpreter dependend functionality 00039 * each script provides. 00040 * 00041 * Each \a ScriptContainer holds a pointer to a class 00042 * that implements the \a Script functionality for the 00043 * defined \a Interpreter . 00044 */ 00045 class Script 00046 { 00047 public: 00048 00049 /** 00050 * Constructor. 00051 * 00052 * \param interpreter The \a Interpreter instance 00053 * that uses this \a Script instance. 00054 * \param scriptcontainer The \a ScriptContainer instance 00055 * this script is associated with. 00056 */ 00057 Script(Interpreter* const interpreter, ScriptContainer* const scriptcontainer); 00058 00059 /** 00060 * Destructor. 00061 */ 00062 virtual ~Script(); 00063 00064 /** 00065 * \return true if the script throwed an exception 00066 * else false. 00067 */ 00068 bool hadException(); 00069 00070 /** 00071 * \return the \a Exception the script throwed. 00072 */ 00073 Exception::Ptr getException(); 00074 00075 /** 00076 * Set a new exception this script throwed. 00077 * 00078 * \param e The \a Exception . 00079 */ 00080 void setException(Exception::Ptr e); 00081 00082 /** 00083 * Clear previous exceptions. If called \a hadException() 00084 * will return false again. 00085 */ 00086 void clearException(); 00087 00088 /** 00089 * Execute the script. 00090 * 00091 * \throws Exception on error. 00092 * \return The execution result. Could be NULL too. 00093 */ 00094 virtual Kross::Api::Object::Ptr execute() = 0; 00095 00096 /** 00097 * \return a list of callable functionnames this 00098 * script spends. 00099 */ 00100 virtual const QStringList& getFunctionNames() = 0; 00101 00102 /** 00103 * Call a function. 00104 * 00105 * \throws Exception on error. 00106 * \param name The name of the function to execute. 00107 * \param args Optional arguments passed to the function. 00108 * \return The result of the called function. Could be NULL. 00109 */ 00110 virtual Kross::Api::Object::Ptr callFunction(const QString& name, Kross::Api::List::Ptr args) = 0; 00111 00112 /** 00113 * \return a list of classnames. 00114 */ 00115 virtual const QStringList& getClassNames() = 0; 00116 00117 /** 00118 * Create and return a new class instance. 00119 * 00120 * \throws Exception on error. 00121 * \param name The name of the class to create a instance of. 00122 * \return The new classinstance. 00123 */ 00124 virtual Kross::Api::Object::Ptr classInstance(const QString& name) = 0; 00125 00126 protected: 00127 /// The \a Interpreter used to create this Script instance. 00128 Interpreter* const m_interpreter; 00129 /// The \a ScriptContainer associated with this Script. 00130 ScriptContainer* const m_scriptcontainer; 00131 00132 private: 00133 /// The \a Exception this script throwed. 00134 Exception::Ptr m_exception; 00135 }; 00136 00137 }} 00138 00139 #endif 00140
1.4.6