lib Library API Documentation

koscript_struct.h

00001 /* This file is part of the KDE project 00002 Copyright (C) 1998, 1999, 2000 Torben Weis <weis@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 Boston, MA 02111-1307, USA. 00018 */ 00019 00020 #ifndef __KSCRIPT_STRUCT_H__ 00021 #define __KSCRIPT_STRUCT_H__ 00022 00023 #include <qshared.h> 00024 #include <qstring.h> 00025 #include <qstringlist.h> 00026 #include <qcstring.h> 00027 #include <qmap.h> 00028 00029 #include "koscript_value.h" 00030 #include "koscript_context.h" 00031 00032 class KSParseNode; 00033 class KSStruct; 00034 00035 class KSStructClass : public QShared 00036 { 00037 public: 00038 typedef KSSharedPtr<KSStructClass> Ptr; 00039 00040 KSStructClass( KSModule* module, const QString& name /*, const KSParseNode* n*/ ); 00041 virtual ~KSStructClass() { } 00042 00043 virtual bool constructor( KSContext& c ); 00048 KSStruct* constructor(); 00049 00050 KSModule* module() { return m_module; } 00051 00052 KSNamespace* nameSpace() { return &m_space; } 00053 const KSNamespace* nameSpace() const { return &m_space; } 00054 virtual KSValue::Ptr member( KSContext& context, const QString& name ); 00055 00056 const QStringList& vars() const { return m_vars; } 00057 void addVariable( const QString& v ) { m_vars.append( v ); } 00058 void setVariables( const QStringList& l ) { m_vars = l; } 00059 bool hasVariable( const QString& v ) { return m_vars.contains( v ); } 00060 00066 QString name() const { return m_name; } 00073 QString fullName() const; 00074 00079 virtual bool inherits( const char* name ) { return ( strcmp( name, "KSStructClass" ) == 0 ); } 00080 00081 private: 00082 QString m_name; 00083 KSNamespace m_space; 00084 // const KSParseNode* m_node; 00085 QStringList m_vars; 00086 KSModule* m_module; 00087 }; 00088 00089 class KSStruct : public QShared 00090 { 00091 public: 00092 typedef KSSharedPtr<KSStruct> Ptr; 00093 00094 KSStruct( KSStructClass* c ) { m_class = c; } 00095 virtual ~KSStruct() { } 00096 00100 bool isA( KSContext& context ); 00101 00102 virtual KSValue::Ptr member( KSContext&, const QString& name ); 00103 virtual bool setMember( KSContext&, const QString& name, const KSValue::Ptr& v ); 00104 00105 const KSStructClass* getClass() const { return m_class; } 00106 KSStructClass* getClass() { return m_class; } 00107 00111 QString className() const { return m_class->name(); } 00112 00113 // ########## Torben: Make real copies of the menus. 00114 virtual KSStruct* clone() { KSStruct *s = new KSStruct( m_class ); s->m_space = m_space; return s; } 00115 00116 KSModule* module() { return m_class->module(); } 00117 KSNamespace* instanceNameSpace() { return &m_space; } 00118 const KSNamespace* instanceNameSpace() const { return &m_space; } 00119 00124 virtual void* object() { return 0; } 00125 virtual const void* object() const { return 0; } 00126 00127 private: 00128 KSStructClass* m_class; 00129 KSNamespace m_space; 00130 }; 00131 00132 class KSBuiltinStruct; 00133 00134 class KSBuiltinStructClass : public KSStructClass 00135 { 00136 friend class KSBuiltinStruct; 00137 public: 00138 KSBuiltinStructClass( KSModule* module, const QString& name ); 00139 virtual ~KSBuiltinStructClass() { } 00140 00141 virtual bool constructor( KSContext& c ) = 0; 00142 virtual bool destructor( void* object ) = 0; 00143 virtual KSStruct* clone( KSBuiltinStruct* ) = 0; 00144 00145 typedef bool (*MethodPtr)( void* object, KSContext&, const QValueList<KSValue::Ptr>& args ); 00146 00152 void addMethod( const QString& name, MethodPtr func, const QCString& signature ); 00153 bool hasMethod( const QString& ) const; 00154 00155 bool call( void* instance, KSContext& context, const QString& name ); 00156 00157 protected: 00158 /* 00159 * It can not happen that @p name is not the name of a variable, since @ref KSBuiltinStruct 00160 * checks wether @p name is really a variable of this struct before calling. 00161 */ 00162 virtual KSValue::Ptr property( KSContext& context, void* object, const QString& name ) = 0; 00170 virtual bool setProperty( KSContext& context, void* object, const QString& name, const KSValue::Ptr value ) = 0; 00171 00172 private: 00173 struct Method 00174 { 00175 MethodPtr m_method; 00176 QCString m_signature; 00177 }; 00178 00179 QMap<QString,Method> m_methods; 00180 }; 00181 00182 00183 class KSBuiltinStruct : public KSStruct 00184 { 00185 public: 00186 KSBuiltinStruct( KSStructClass* c, void* object ); 00192 virtual ~KSBuiltinStruct(); 00193 00194 virtual KSValue::Ptr member( KSContext&, const QString& name ); 00195 virtual bool setMember( KSContext&, const QString& name, const KSValue::Ptr& v ); 00196 00202 bool call( KSContext& context, const QString& name ); 00203 00210 KSStruct* clone(); 00211 00215 void* object(); 00216 const void* object() const; 00217 00218 private: 00219 void* m_object; 00220 }; 00221 00222 #endif
KDE Logo
This file is part of the documentation for lib Library Version 1.3.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Sep 24 18:22:26 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003