1
#ifndef _KVI_KVS_OBJECTCLASS_H_
2
#define _KVI_KVS_OBJECTCLASS_H_
3
//=============================================================================
5
// File : kvi_kvs_objectclass.h
6
// Creation date : Sat 23 Apr 2005 20:31:32 by Szymon Stefanek
8
// This file is part of the KVIrc IRC client distribution
9
// Copyright (C) 2005-2008 Szymon Stefanek <pragma at kvirc dot net>
11
// This program is FREE software. You can redistribute it and/or
12
// modify it under the terms of the GNU General Public License
13
// as published by the Free Software Foundation; either version 2
14
// of the License, or (at your opinion) any later version.
16
// This program is distributed in the HOPE that it will be USEFUL,
17
// but WITHOUT ANY WARRANTY; without even the implied warranty of
18
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19
// See the GNU General Public License for more details.
21
// You should have received a copy of the GNU General Public License
22
// along with this program. If not, write to the Free Software Foundation,
23
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25
//=============================================================================
27
#include "kvi_settings.h"
28
#include "kvi_qstring.h"
29
#include "kvi_pointerlist.h"
31
#include "kvi_pointerhashtable.h"
33
#include "kvi_kvs_object_functionhandler.h"
36
class KviKvsObjectClass;
37
class KviKvsRunTimeContext;
38
class KviKvsVariantList;
40
// Object allocation function
41
// parameters are: the class, the parent object (eventually 0), the object name (eventually empty)
42
typedef KviKvsObject * (*KviKvsObjectAllocateInstanceProc)(KviKvsObjectClass *,KviKvsObject *,const QString &);
44
// An object function callback
45
typedef bool (KviKvsObject::*KviKvsObjectFunctionHandlerProc)(KviKvsObjectFunctionCall * pCall);
48
// The descriptor of a kvirc object class
50
class KVIRC_API KviKvsObjectClass
52
friend class KviKvsObject;
53
friend class KviKvsObjectController;
56
KviKvsObjectClass * pParent, // parent class
57
const QString & szName, // class name
58
KviKvsObjectAllocateInstanceProc proc, // intance allocation proc
59
bool bBuiltin = true // this is a builtin or script based class ?
63
KviKvsObjectClass * m_pParentClass; // the parent (base) class
64
QString m_szName; // the class name
65
bool m_bBuiltin; // is this a builtin or script based class ?
66
KviPointerHashTable<QString,KviKvsObjectFunctionHandler> * m_pFunctionHandlers; // all our function handlers
67
KviPointerList<KviKvsObjectClass> * m_pChildClasses; //
68
KviKvsObjectAllocateInstanceProc m_allocProc;
69
bool m_bDirty; // not yet flushed to disk (only for not builtin classes)
71
void registerChildClass(KviKvsObjectClass *pClass);
72
void unregisterChildClass(KviKvsObjectClass *pClass);
73
KviPointerHashTable<QString,KviKvsObjectFunctionHandler> * functionHandlers(){ return m_pFunctionHandlers; };
75
void clearDirtyFlag(){ m_bDirty = false; };
76
bool isDirty(){ return m_bDirty; };
77
bool isBuiltin(){ return m_bBuiltin; };
78
bool isScriptHandler(const QString & szFunctionName)
80
KviKvsObjectFunctionHandler *pFunctionHandler=m_pFunctionHandlers->find(szFunctionName);
81
if (pFunctionHandler) return pFunctionHandler->isScriptHandler();
84
const QString & name(){ return m_szName; };
85
KviKvsObjectClass * parentClass(){ return m_pParentClass; };
86
// pProc CAN'T be zero here!
87
void registerFunctionHandler(const QString & szFunctionName,KviKvsObjectFunctionHandlerProc pProc,unsigned int uFlags = 0);
88
void registerFunctionHandler(const QString & szFunctionName,const QString &szBuffer,unsigned int uFlags = 0);
90
// registers an empty handler that returns "nothing"
91
void registerStandardNothingReturnFunctionHandler(const QString & szFunc);
92
// retisters an empty handler that returns $true
93
void registerStandardTrueReturnFunctionHandler(const QString & szFunc);
94
// retisters an empty handler that returns $false
95
void registerStandardFalseReturnFunctionHandler(const QString & szFunc);
97
KviKvsObjectFunctionHandler * lookupFunctionHandler(const QString & szFunc){ return m_pFunctionHandlers->find(szFunc); };
98
KviKvsObject * allocateInstance(KviKvsObject * pParent,const QString &szName,KviKvsRunTimeContext * pContext,KviKvsVariantList * pParams);
100
bool save(const QString &szFileName);
101
static bool load(const QString &szFileName);
102
void getFunctionCode(QString &szCode,KviKvsObjectFunctionHandler &h);
103
KviPointerHashTable<QString,KviKvsObjectFunctionHandler> * getHandlers(){return m_pFunctionHandlers;};
108
#endif //!_KVI_KVS_OBJECTCLASS_H_