• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Kross

interpreter.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  * interpreter.cpp
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 #include "interpreter.h"
00021 #include "script.h"
00022 #include "action.h"
00023 #include "manager.h"
00024 
00025 extern "C"
00026 {
00027     typedef void* (*def_interpreter_func)(int version, Kross::InterpreterInfo*);
00028 }
00029 
00030 using namespace Kross;
00031 
00032 /*************************************************************************
00033  * InterpreterInfo
00034  */
00035 
00036 namespace Kross {
00037 
00039     class InterpreterInfo::Private
00040     {
00041         public:
00043             QString interpretername;
00045             void* funcPtr;
00047             QString wildcard;
00049             QStringList mimetypes;
00051             Option::Map options;
00053             Interpreter* interpreter;
00054     };
00055 
00056 }
00057 
00058 InterpreterInfo::InterpreterInfo(const QString& interpretername, void* funcPtr, const QString& wildcard, const QStringList& mimetypes, const Option::Map& options)
00059     : d( new Private() )
00060 {
00061     d->interpretername = interpretername;
00062     d->funcPtr = funcPtr;
00063     d->wildcard = wildcard;
00064     d->mimetypes = mimetypes;
00065     d->options = options;
00066     d->interpreter = 0;
00067 }
00068 
00069 InterpreterInfo::~InterpreterInfo()
00070 {
00071     delete d->interpreter;
00072     d->interpreter = 0;
00073     delete d;
00074 }
00075 
00076 const QString InterpreterInfo::interpreterName() const
00077 {
00078     return d->interpretername;
00079 }
00080 
00081 const QString InterpreterInfo::wildcard() const
00082 {
00083     return d->wildcard;
00084 }
00085 
00086 const QStringList InterpreterInfo::mimeTypes() const
00087 {
00088     return d->mimetypes;
00089 }
00090 
00091 bool InterpreterInfo::hasOption(const QString& name) const
00092 {
00093     return d->options.contains(name);
00094 }
00095 
00096 InterpreterInfo::Option* InterpreterInfo::option(const QString& name) const
00097 {
00098     return d->options.contains(name) ? d->options[name] : 0;
00099 }
00100 
00101 InterpreterInfo::Option::Map& InterpreterInfo::options()
00102 {
00103     return d->options;
00104 }
00105 
00106 const QVariant InterpreterInfo::optionValue(const QString& name, const QVariant& defaultvalue) const
00107 {
00108     return d->options.contains(name) ? d->options[name]->value : defaultvalue;
00109 }
00110 
00111 Interpreter* InterpreterInfo::interpreter()
00112 {
00113     if(d->interpreter) // buffered
00114         return d->interpreter;
00115 
00116     //#ifdef KROSS_INTERPRETER_DEBUG
00117         krossdebug( QString("Loading the interpreter library for %1").arg(d->interpretername) );
00118     //#endif
00119 
00120     // Get the extern "C" krosspython_instance function.
00121     def_interpreter_func interpreter_func = (def_interpreter_func) d->funcPtr;
00122 
00123     // and execute the extern krosspython_instance function.
00124     d->interpreter = interpreter_func
00125         ? (Interpreter*) (interpreter_func)(KROSS_VERSION, this)
00126         : 0;
00127 
00128     if(! d->interpreter) {
00129         //#ifdef KROSS_INTERPRETER_DEBUG
00130             krosswarning("Incompatible interpreter library.");
00131         //#endif
00132     }
00133     else {
00134         // Job done. The library is loaded and our Interpreter* points
00135         // to the external Kross::Python::Interpreter* instance.
00136         //#ifdef KROSS_INTERPRETER_DEBUG
00137             krossdebug("Successfully loaded Interpreter instance from library.");
00138         //#endif
00139     }
00140 
00141     return d->interpreter;
00142 }
00143 
00144 /*************************************************************************
00145  * Interpreter
00146  */
00147 
00148 namespace Kross {
00149 
00151     class Interpreter::Private
00152     {
00153         public:
00154             InterpreterInfo* interpreterinfo;
00155             Private(InterpreterInfo* info) : interpreterinfo(info) {}
00156     };
00157 
00158 }
00159 
00160 Interpreter::Interpreter(InterpreterInfo* info)
00161     : QObject()
00162     , ErrorInterface()
00163     , d( new Private(info) )
00164 {
00165 }
00166 
00167 Interpreter::~Interpreter()
00168 {
00169     delete d;
00170 }
00171 
00172 InterpreterInfo* Interpreter::interpreterInfo() const
00173 {
00174     return d->interpreterinfo;
00175 }
00176 
00177 #include "interpreter.moc"

Kross

Skip menu "Kross"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal