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

kig

  • sources
  • kde-4.14
  • kdeedu
  • kig
  • scripting
python_type.cc
Go to the documentation of this file.
1 // Copyright (C) 2003 Dominique Devriese <devriese@kde.org>
2 
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
7 
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 // 02110-1301, USA.
17 
18 #include "python_type.h"
19 
20 #include "python_scripter.h"
21 
22 #include "../objects/object_imp.h"
23 #include "../objects/bogus_imp.h"
24 
25 class PythonCompiledScriptImp
26  : public BogusImp
27 {
28  mutable CompiledPythonScript mscript;
29 public:
30  typedef BogusImp Parent;
31  static const ObjectImpType* stype();
32  const ObjectImpType* type() const;
33 
34  PythonCompiledScriptImp( const CompiledPythonScript& s );
35 
36  void visit( ObjectImpVisitor* vtor ) const;
37  ObjectImp* copy() const;
38  bool equals( const ObjectImp& rhs ) const;
39 
40  bool isCache() const;
41 
42  CompiledPythonScript& data() const { return mscript; };
43 };
44 
45 PythonCompiledScriptImp::PythonCompiledScriptImp( const CompiledPythonScript& s )
46  : BogusImp(), mscript( s )
47 {
48 
49 }
50 
51 const ObjectImpType* PythonCompiledScriptImp::stype()
52 {
53  static const ObjectImpType t( BogusImp::stype(), "python-compiled-script-imp",
54  0, 0, 0, 0, 0, 0, 0, 0, 0 );
55  return &t;
56 }
57 
58 const ObjectImpType* PythonCompiledScriptImp::type() const
59 {
60  return PythonCompiledScriptImp::stype();
61 }
62 
63 void PythonCompiledScriptImp::visit( ObjectImpVisitor* ) const
64 {
65  // TODO ?
66 }
67 
68 ObjectImp* PythonCompiledScriptImp::copy() const
69 {
70  return new PythonCompiledScriptImp( mscript );
71 }
72 
73 bool PythonCompiledScriptImp::equals( const ObjectImp& ) const
74 {
75  // problem ?
76  return true;
77 }
78 
79 bool PythonCompiledScriptImp::isCache() const
80 {
81  return true;
82 }
83 
84 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( PythonCompileType )
85 
86 PythonCompileType::PythonCompileType()
87  : ObjectType( "PythonCompileType" )
88 {
89 }
90 
91 PythonCompileType::~PythonCompileType()
92 {
93 }
94 
95 const PythonCompileType* PythonCompileType::instance()
96 {
97  static const PythonCompileType t;
98  return &t;
99 }
100 
101 const ObjectImpType* PythonCompileType::impRequirement( const ObjectImp*, const Args& ) const
102 {
103  return StringImp::stype();
104 }
105 
106 const ObjectImpType* PythonCompileType::resultId() const
107 {
108  return PythonCompiledScriptImp::stype();
109 }
110 
111 ObjectImp* PythonCompileType::calc( const Args& parents, const KigDocument& ) const
112 {
113  assert( parents.size() == 1 );
114  if ( !parents[0]->inherits( StringImp::stype() ) ) return new InvalidImp;
115 
116  const StringImp* si = static_cast<const StringImp*>( parents[0] );
117  QString s = si->data();
118 
119  CompiledPythonScript cs = PythonScripter::instance()->compile( s.toLatin1() );
120 
121  if ( cs.valid() )
122  return new PythonCompiledScriptImp( cs );
123  else
124  return new InvalidImp();
125 }
126 
127 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( PythonExecuteType )
128 
129 PythonExecuteType::PythonExecuteType()
130  : ObjectType( "PythonExecuteType" )
131 {
132 }
133 
134 PythonExecuteType::~PythonExecuteType()
135 {
136 }
137 
138 const PythonExecuteType* PythonExecuteType::instance()
139 {
140  static const PythonExecuteType t;
141  return &t;
142 }
143 
144 ObjectImp* PythonExecuteType::calc( const Args& parents, const KigDocument& d ) const
145 {
146  assert( parents.size() >= 1 );
147  if( !parents[0]->inherits( PythonCompiledScriptImp::stype() ) ) return new InvalidImp;
148 
149  CompiledPythonScript& script = static_cast<const PythonCompiledScriptImp*>( parents[0] )->data();
150 
151  Args args( parents.begin() + 1, parents.end() );
152  return script.calc( args, d );
153 }
154 
155 const ObjectImpType* PythonExecuteType::impRequirement( const ObjectImp* o, const Args& parents ) const
156 {
157  if ( o == parents[0] ) return PythonCompiledScriptImp::stype();
158  else return ObjectImp::stype();
159 }
160 
161 const ObjectImpType* PythonExecuteType::resultId() const
162 {
163  return ObjectImp::stype();
164 }
165 
166 std::vector<ObjectCalcer*> PythonCompileType::sortArgs( const std::vector<ObjectCalcer*>& args ) const
167 {
168  return args;
169 }
170 
171 Args PythonCompileType::sortArgs( const Args& args ) const
172 {
173  return args;
174 }
175 
176 std::vector<ObjectCalcer*> PythonExecuteType::sortArgs( const std::vector<ObjectCalcer*>& args ) const
177 {
178  return args;
179 }
180 
181 Args PythonExecuteType::sortArgs( const Args& args ) const
182 {
183  return args;
184 }
185 
186 bool PythonCompileType::isDefinedOnOrThrough( const ObjectImp*, const Args& ) const
187 {
188  return false;
189 }
190 
191 bool PythonExecuteType::isDefinedOnOrThrough( const ObjectImp*, const Args& ) const
192 {
193  return false;
194 }
195 
ObjectImpType
Instances of this class represent a certain ObjectImp type.
Definition: object_imp.h:95
BogusImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the BogusImp type.
Definition: bogus_imp.cc:286
PythonCompileType::sortArgs
std::vector< ObjectCalcer * > sortArgs(const std::vector< ObjectCalcer * > &args) const
Definition: python_type.cc:166
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE(SegmentAxisType)
PythonExecuteType::isDefinedOnOrThrough
bool isDefinedOnOrThrough(const ObjectImp *o, const Args &parents) const
Supposing that parents would be given as parents to this type's calc function, this function returns ...
Definition: python_type.cc:191
StringImp::data
const QString & data() const
Get hold of the contained data.
Definition: bogus_imp.h:186
StringImp
This ObjectImp is a BogusImp containing only a string value.
Definition: bogus_imp.h:167
ObjectType::inherits
virtual bool inherits(int type) const
Definition: object_type.cc:64
PythonExecuteType::instance
static const PythonExecuteType * instance()
Definition: python_type.cc:138
ObjectImp::visit
virtual void visit(ObjectImpVisitor *vtor) const =0
PythonCompileType
Definition: python_type.h:23
CompiledPythonScript::calc
ObjectImp * calc(const Args &a, const KigDocument &doc)
Definition: python_scripter.cc:439
PythonCompileType::calc
ObjectImp * calc(const Args &parents, const KigDocument &d) const
Definition: python_type.cc:111
PythonCompileType::isDefinedOnOrThrough
bool isDefinedOnOrThrough(const ObjectImp *o, const Args &parents) const
Supposing that parents would be given as parents to this type's calc function, this function returns ...
Definition: python_type.cc:186
PythonScripter::instance
static PythonScripter * instance()
Definition: python_scripter.cc:364
ObjectImp::stype
static const ObjectImpType * stype()
The ObjectImpType representing the base ObjectImp class.
Definition: object_imp.cc:284
BogusImp
This is the base class for the so-called BogusImp's.
Definition: bogus_imp.h:37
PythonCompileType::resultId
const ObjectImpType * resultId() const
returns the ObjectImp id of the ObjectImp's produced by this ObjectType.
Definition: python_type.cc:106
ObjectImp::type
virtual const ObjectImpType * type() const =0
Returns the lowermost ObjectImpType that this object is an instantiation of.
PythonScripter::compile
CompiledPythonScript compile(const char *code)
Definition: python_scripter.cc:457
python_type.h
PythonExecuteType::resultId
const ObjectImpType * resultId() const
returns the ObjectImp id of the ObjectImp's produced by this ObjectType.
Definition: python_type.cc:161
Args
std::vector< const ObjectImp * > Args
Definition: objects/common.h:47
PythonExecuteType::calc
ObjectImp * calc(const Args &parents, const KigDocument &d) const
Definition: python_type.cc:144
python_scripter.h
PythonCompileType::impRequirement
const ObjectImpType * impRequirement(const ObjectImp *o, const Args &parents) const
Supposing that parents would be given as parents to this type's calc function, this function returns ...
Definition: python_type.cc:101
QString
PythonCompileType::instance
static const PythonCompileType * instance()
Definition: python_type.cc:95
CompiledPythonScript
Definition: python_scripter.h:28
ObjectType
The ObjectType class is a thing that represents the "behaviour" for a certain type.
Definition: object_type.h:32
PythonExecuteType::impRequirement
const ObjectImpType * impRequirement(const ObjectImp *o, const Args &parents) const
Supposing that parents would be given as parents to this type's calc function, this function returns ...
Definition: python_type.cc:155
visit
static bool visit(const ObjectCalcer *o, const std::vector< ObjectCalcer * > &from, std::vector< ObjectCalcer * > &ret)
Definition: calcpaths.cc:193
QString::toLatin1
QByteArray toLatin1() const
PythonExecuteType::sortArgs
std::vector< ObjectCalcer * > sortArgs(const std::vector< ObjectCalcer * > &args) const
Definition: python_type.cc:176
KigDocument
KigDocument is the class holding the real data in a Kig document.
Definition: kig_document.h:36
StringImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the StringImp type.
Definition: bogus_imp.cc:220
ObjectImp::copy
virtual ObjectImp * copy() const =0
Returns a copy of this ObjectImp.
PythonExecuteType
Definition: python_type.h:41
ObjectImp
The ObjectImp class represents the behaviour of an object after it is calculated. ...
Definition: object_imp.h:226
ObjectImp::isCache
virtual bool isCache() const
Definition: object_imp.cc:306
ObjectImp::equals
virtual bool equals(const ObjectImp &rhs) const =0
Returns true if this ObjectImp is equal to rhs.
CompiledPythonScript::valid
bool valid()
Definition: python_scripter.cc:602
ObjectImpVisitor
Definition: object_imp.h:56
InvalidImp
This ObjectImp represents an invalid object.
Definition: bogus_imp.h:61
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:12:05 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kig

Skip menu "kig"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

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