1 // Copyright (C) 2003 Dominique Devriese <devriese@kde.org>
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA
18 #include "python_type.h"
20 #include "python_scripter.h"
22 #include "../objects/object_imp.h"
23 #include "../objects/bogus_imp.h"
25 class PythonCompiledScriptImp
28 mutable CompiledPythonScript mscript
;
30 typedef BogusImp Parent
;
31 static const ObjectImpType
* stype();
32 const ObjectImpType
* type() const;
34 PythonCompiledScriptImp( const CompiledPythonScript
& s
);
36 void visit( ObjectImpVisitor
* vtor
) const;
37 ObjectImp
* copy() const;
38 bool equals( const ObjectImp
& rhs
) const;
42 CompiledPythonScript
& data() const { return mscript
; };
45 PythonCompiledScriptImp::PythonCompiledScriptImp( const CompiledPythonScript
& s
)
46 : BogusImp(), mscript( s
)
51 const ObjectImpType
* PythonCompiledScriptImp::stype()
53 static const ObjectImpType
t( BogusImp::stype(), "python-compiled-script-imp",
54 0, 0, 0, 0, 0, 0, 0, 0, 0 );
58 const ObjectImpType
* PythonCompiledScriptImp::type() const
60 return PythonCompiledScriptImp::stype();
63 void PythonCompiledScriptImp::visit( ObjectImpVisitor
* ) const
68 ObjectImp
* PythonCompiledScriptImp::copy() const
70 return new PythonCompiledScriptImp( mscript
);
73 bool PythonCompiledScriptImp::equals( const ObjectImp
& ) const
79 bool PythonCompiledScriptImp::isCache() const
84 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( PythonCompileType
)
86 PythonCompileType::PythonCompileType()
87 : ObjectType( "PythonCompileType" )
91 PythonCompileType::~PythonCompileType()
95 const PythonCompileType
* PythonCompileType::instance()
97 static const PythonCompileType t
;
101 const ObjectImpType
* PythonCompileType::impRequirement( const ObjectImp
*, const Args
& ) const
103 return StringImp::stype();
106 const ObjectImpType
* PythonCompileType::resultId() const
108 return PythonCompiledScriptImp::stype();
111 ObjectImp
* PythonCompileType::calc( const Args
& parents
, const KigDocument
& ) const
113 assert( parents
.size() == 1 );
114 if ( !parents
[0]->inherits( StringImp::stype() ) ) return new InvalidImp
;
116 const StringImp
* si
= static_cast<const StringImp
*>( parents
[0] );
117 QString s
= si
->data();
119 CompiledPythonScript cs
= PythonScripter::instance()->compile( s
.latin1() );
122 return new PythonCompiledScriptImp( cs
);
124 return new InvalidImp();
127 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( PythonExecuteType
)
129 PythonExecuteType::PythonExecuteType()
130 : ObjectType( "PythonExecuteType" )
134 PythonExecuteType::~PythonExecuteType()
138 const PythonExecuteType
* PythonExecuteType::instance()
140 static const PythonExecuteType t
;
144 ObjectImp
* PythonExecuteType::calc( const Args
& parents
, const KigDocument
& d
) const
146 assert( parents
.size() >= 1 );
147 if( !parents
[0]->inherits( PythonCompiledScriptImp::stype() ) ) return new InvalidImp
;
149 CompiledPythonScript
& script
= static_cast<const PythonCompiledScriptImp
*>( parents
[0] )->data();
151 Args
args( parents
.begin() + 1, parents
.end() );
152 return script
.calc( args
, d
);
155 const ObjectImpType
* PythonExecuteType::impRequirement( const ObjectImp
* o
, const Args
& parents
) const
157 if ( o
== parents
[0] ) return PythonCompiledScriptImp::stype();
158 else return ObjectImp::stype();
161 const ObjectImpType
* PythonExecuteType::resultId() const
163 return ObjectImp::stype();
166 std::vector
<ObjectCalcer
*> PythonCompileType::sortArgs( const std::vector
<ObjectCalcer
*>& args
) const
171 Args
PythonCompileType::sortArgs( const Args
& args
) const
176 std::vector
<ObjectCalcer
*> PythonExecuteType::sortArgs( const std::vector
<ObjectCalcer
*>& args
) const
181 Args
PythonExecuteType::sortArgs( const Args
& args
) const
186 bool PythonCompileType::isDefinedOnOrThrough( const ObjectImp
*, const Args
& ) const
191 bool PythonExecuteType::isDefinedOnOrThrough( const ObjectImp
*, const Args
& ) const