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

Kross

  • sources
  • kde-4.12
  • kdelibs
  • kross
  • core
core/interpreter.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * interpreter.cpp
3  * This file is part of the KDE project
4  * copyright (C)2004-2006 by Sebastian Sauer (mail@dipe.org)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  * You should have received a copy of the GNU Library General Public License
15  * along with this program; see the file COPYING. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  ***************************************************************************/
19 
20 #include "interpreter.h"
21 #include "script.h"
22 #include "action.h"
23 #include "manager.h"
24 
25 extern "C"
26 {
27  typedef void* (*def_interpreter_func)(int version, Kross::InterpreterInfo*);
28 }
29 
30 using namespace Kross;
31 
32 /*************************************************************************
33  * InterpreterInfo
34  */
35 
36 namespace Kross {
37 
39  class InterpreterInfo::Private
40  {
41  public:
43  QString interpretername;
45  void* funcPtr;
47  QString wildcard;
49  QStringList mimetypes;
51  Option::Map options;
53  Interpreter* interpreter;
54  };
55 
56 }
57 
58 InterpreterInfo::InterpreterInfo(const QString& interpretername, void* funcPtr, const QString& wildcard, const QStringList& mimetypes, const Option::Map& options)
59  : d( new Private() )
60 {
61  d->interpretername = interpretername;
62  d->funcPtr = funcPtr;
63  d->wildcard = wildcard;
64  d->mimetypes = mimetypes;
65  d->options = options;
66  d->interpreter = 0;
67 }
68 
69 InterpreterInfo::~InterpreterInfo()
70 {
71  delete d->interpreter;
72  d->interpreter = 0;
73  delete d;
74 }
75 
76 const QString InterpreterInfo::interpreterName() const
77 {
78  return d->interpretername;
79 }
80 
81 const QString InterpreterInfo::wildcard() const
82 {
83  return d->wildcard;
84 }
85 
86 const QStringList InterpreterInfo::mimeTypes() const
87 {
88  return d->mimetypes;
89 }
90 
91 bool InterpreterInfo::hasOption(const QString& name) const
92 {
93  return d->options.contains(name);
94 }
95 
96 InterpreterInfo::Option* InterpreterInfo::option(const QString& name) const
97 {
98  return d->options.contains(name) ? d->options[name] : 0;
99 }
100 
101 InterpreterInfo::Option::Map& InterpreterInfo::options()
102 {
103  return d->options;
104 }
105 
106 const QVariant InterpreterInfo::optionValue(const QString& name, const QVariant& defaultvalue) const
107 {
108  return d->options.contains(name) ? d->options[name]->value : defaultvalue;
109 }
110 
111 Interpreter* InterpreterInfo::interpreter()
112 {
113  if(d->interpreter) // buffered
114  return d->interpreter;
115 
116  //#ifdef KROSS_INTERPRETER_DEBUG
117  krossdebug( QString("Loading the interpreter library for %1").arg(d->interpretername) );
118  //#endif
119 
120  // Get the extern "C" krosspython_instance function.
121  def_interpreter_func interpreter_func = (def_interpreter_func) d->funcPtr;
122 
123  // and execute the extern krosspython_instance function.
124  d->interpreter = interpreter_func
125  ? (Interpreter*) (interpreter_func)(KROSS_VERSION, this)
126  : 0;
127 
128  if(! d->interpreter) {
129  //#ifdef KROSS_INTERPRETER_DEBUG
130  krosswarning("Incompatible interpreter library.");
131  //#endif
132  }
133  else {
134  // Job done. The library is loaded and our Interpreter* points
135  // to the external Kross::Python::Interpreter* instance.
136  //#ifdef KROSS_INTERPRETER_DEBUG
137  krossdebug("Successfully loaded Interpreter instance from library.");
138  //#endif
139  }
140 
141  return d->interpreter;
142 }
143 
144 /*************************************************************************
145  * Interpreter
146  */
147 
148 namespace Kross {
149 
151  class Interpreter::Private
152  {
153  public:
154  InterpreterInfo* interpreterinfo;
155  Private(InterpreterInfo* info) : interpreterinfo(info) {}
156  };
157 
158 }
159 
160 Interpreter::Interpreter(InterpreterInfo* info)
161  : QObject()
162  , ErrorInterface()
163  , d( new Private(info) )
164 {
165 }
166 
167 Interpreter::~Interpreter()
168 {
169  delete d;
170 }
171 
172 InterpreterInfo* Interpreter::interpreterInfo() const
173 {
174  return d->interpreterinfo;
175 }
176 
177 #include "interpreter.moc"
QVariant
def_interpreter_func
void *(* def_interpreter_func)(int version, Kross::InterpreterInfo *)
Definition: core/interpreter.cpp:27
Kross::ErrorInterface
Interface for error-handling.
Definition: errorinterface.h:32
Kross::InterpreterInfo::option
Option * option(const QString &name) const
Definition: core/interpreter.cpp:96
Kross::InterpreterInfo::Option
Each interpreter is able to define options we could use to manipulate the interpreter behaviour...
Definition: core/interpreter.h:51
Kross::Interpreter::interpreterInfo
InterpreterInfo * interpreterInfo() const
Definition: core/interpreter.cpp:172
QString
QObject
Kross::InterpreterInfo::InterpreterInfo
InterpreterInfo(const QString &interpretername, void *funcPtr, const QString &wildcard, const QStringList &mimetypes, const Option::Map &options=Option::Map())
Constructor.
Definition: core/interpreter.cpp:58
Kross::InterpreterInfo
The InterpreterInfo class provides abstract information about a Interpreter before the interpreter-ba...
Definition: core/interpreter.h:43
Kross::InterpreterInfo::hasOption
bool hasOption(const QString &name) const
Definition: core/interpreter.cpp:91
interpreter.h
Kross::InterpreterInfo::options
Option::Map & options()
Definition: core/interpreter.cpp:101
script.h
action.h
QStringList
KROSS_VERSION
#define KROSS_VERSION
Definition: krossconfig.h:61
Kross::InterpreterInfo::interpreter
Interpreter * interpreter()
Definition: core/interpreter.cpp:111
Kross::Interpreter::~Interpreter
virtual ~Interpreter()
Destructor.
Definition: core/interpreter.cpp:167
Kross::InterpreterInfo::optionValue
const QVariant optionValue(const QString &name, const QVariant &defaultvalue=QVariant()) const
Definition: core/interpreter.cpp:106
manager.h
Kross::Interpreter
Base class for interpreter implementations.
Definition: core/interpreter.h:177
Kross::krosswarning
void krosswarning(const QString &s)
Warning function.
Definition: krossconfig.cpp:34
Kross::Interpreter::Interpreter
Interpreter(InterpreterInfo *info)
Constructor.
Definition: core/interpreter.cpp:160
Kross::InterpreterInfo::Option::Map
QMap< QString, Option * > Map
Map of options.
Definition: core/interpreter.h:58
Kross::InterpreterInfo::~InterpreterInfo
~InterpreterInfo()
Destructor.
Definition: core/interpreter.cpp:69
Kross::InterpreterInfo::wildcard
const QString wildcard() const
Definition: core/interpreter.cpp:81
version
unsigned int version()
Kross::InterpreterInfo::interpreterName
const QString interpreterName() const
Definition: core/interpreter.cpp:76
Kross::InterpreterInfo::mimeTypes
const QStringList mimeTypes() const
List of mimetypes this interpreter supports.
Definition: core/interpreter.cpp:86
Kross::krossdebug
void krossdebug(const QString &s)
Debugging function.
Definition: krossconfig.cpp:28
QMap< QString, Option * >
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:49:54 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Kross

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal