interpreter.h

00001 /***************************************************************************
00002  * interpreter.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_INTERPRETER_H
00021 #define KROSS_API_INTERPRETER_H
00022 
00023 #include <qstring.h>
00024 #include <qmap.h>
00025 #include <kdebug.h>
00026 
00027 #include "object.h"
00028 
00029 namespace Kross { namespace Api {
00030 
00031     // Forward declaration.
00032     class Manager;
00033     class ScriptContainer;
00034     class Script;
00035     class Interpreter;
00036 
00037     /**
00038      * While the \a Interpreter is the implemented interpreter this class
00039      * is used to provide some abstract informations about each interpreter
00040      * we are able to use within the \a Manager singelton.
00041      */
00042     class InterpreterInfo
00043     {
00044         public:
00045 
00046             /**
00047              * Each interpreter is able to define options we could
00048              * use to manipulate the interpreter behaviour.
00049              */
00050             class Option
00051             {
00052                 public:
00053 
00054                     /**
00055                     * Map of options.
00056                     */
00057                     typedef QMap<QString, Option*> Map;
00058 
00059                     /**
00060                      * Constructor.
00061                      * 
00062                      * \param name The name the option has. This is the
00063                      *        displayed title and isn't used internaly.
00064                      * \param comment A comment that describes the option.
00065                      * \param value The QVariant value this option has.
00066                      */
00067                     Option(const QString& name, const QString& comment, const QVariant& value)
00068                         : name(name), comment(comment), value(value) {}
00069 
00070                     /// The short name of the option.
00071                     QString name;
00072 
00073                     /// A description of the option.
00074                     QString comment;
00075 
00076                     /// The value the option has.
00077                     QVariant value;
00078             };
00079 
00080             /**
00081              * Constructor.
00082              */
00083             InterpreterInfo(const QString& interpretername, const QString& library, const QString& wildcard, QStringList mimetypes, Option::Map options);
00084 
00085             /**
00086              * Destructor.
00087              */
00088             ~InterpreterInfo();
00089 
00090             /**
00091              * \return the name of the interpreter. For example "python" or "kjs".
00092              */
00093             const QString& getInterpretername();
00094 
00095             /**
00096              * \return the file-wildcard used to determinate by this interpreter 
00097              * used scriptingfiles. Those filter will be used e.g. with
00098              * KGlobal::dirs()->findAllResources() as filtermask. For example
00099              * python just defines it as "*py".
00100              */
00101             const QString& getWildcard();
00102 
00103             /**
00104              * List of mimetypes this interpreter supports.
00105              *
00106              * \return QStringList with mimetypes like
00107              *         "application/x-javascript".
00108              */
00109             const QStringList getMimeTypes();
00110 
00111             /**
00112              * \return true if an \a Option with that \p key exists else false.
00113              */
00114             bool hasOption(const QString& key);
00115 
00116             /**
00117              * \return the option defined with \p name .
00118              */
00119             Option* getOption(const QString name);
00120 
00121             /**
00122              * \return the value of the option defined with \p name . If there 
00123              * doesn't exists an option with such a name, the \p defaultvalue 
00124              * is returned.
00125              */
00126             const QVariant& getOptionValue(const QString name, QVariant defaultvalue = QVariant());
00127 
00128             /**
00129              * \return a map of options.
00130              */
00131             Option::Map getOptions();
00132 
00133             /**
00134              * \return the \a Interpreter instance this \a InterpreterInfo
00135              * is the describer for.
00136              */
00137             Interpreter* getInterpreter();
00138 
00139         private:
00140             /// The name the interpreter has. Could be something like "python" or "kjs".
00141             QString m_interpretername;
00142             /// The name of the library to load for the interpreter.
00143             QString m_library;
00144             /// The file wildcard used to determinate extensions.
00145             QString m_wildcard;
00146             /// List of mimetypes this interpreter supports.
00147             QStringList m_mimetypes;
00148             /// A \a Option::Map with options.
00149             Option::Map m_options;
00150             /// The \a Interpreter instance.
00151             Interpreter* m_interpreter;
00152     };
00153 
00154     /**
00155      * Base class for interpreters.
00156      *
00157      * Each scripting backend needs to inheritate it's own
00158      * interpreter from this class and implementate there
00159      * backend related stuff.
00160      * The Interpreter will be managed by the \a Kross::Manager
00161      * class.
00162      */
00163     class Interpreter
00164     {
00165         public:
00166 
00167             /**
00168              * Constructor.
00169              *
00170              * \param info is the \a InterpreterInfo instance
00171              *        that describes this interpreter.
00172              */
00173             Interpreter(InterpreterInfo* info);
00174 
00175             /**
00176              * Destructor.
00177              */
00178             virtual ~Interpreter();
00179 
00180             /**
00181              * Create and return a new interpreter dependend
00182              * \a Script instance.
00183              *
00184              * \param scriptcontainer The \a ScriptContainer
00185              *        to use for the \a Script instance.
00186              * \return The from \a Script inherited instance.
00187              */
00188             virtual Script* createScript(ScriptContainer* scriptcontainer) = 0;
00189 
00190         protected:
00191             /// The \a InterpreterInfo instance this interpreter belongs to.
00192             InterpreterInfo* m_interpreterinfo;
00193     };
00194 
00195 }}
00196 
00197 #endif
00198 

Generated on Thu Feb 9 17:59:10 2006 for Kross by  doxygen 1.4.6