summaryrefslogtreecommitdiffstats
path: root/src/kvirc/kvs/kvi_kvs_object_class.h
blob: 6b334ddf2ed4964dd0e7f5f159b8e71d085252df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#ifndef _KVI_KVS_OBJECTCLASS_H_
#define _KVI_KVS_OBJECTCLASS_H_
//=============================================================================
//
//   File : kvi_kvs_objectclass.h
//   Created on Sat 23 Apr 2005 20:31:32 by Szymon Stefanek
//
//   This file is part of the KVIrc IRC client distribution
//   Copyright (C) 2005 Szymon Stefanek <pragma at kvirc dot net>
//
//   This program is FREE software. You can redistribute it and/or
//   modify it under the terms of the GNU General Public License
//   as published by the Free Software Foundation; either version 2
//   of the License, or (at your opinion) any later version.
//
//   This program is distributed in the HOPE that it will be USEFUL,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//   See the GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with this program. If not, write to the Free Software Foundation,
//   Inc. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
//=============================================================================

#include "kvi_settings.h"
#include "kvi_qstring.h"
#include "kvi_pointerlist.h"

#include "kvi_pointerhashtable.h"

#include "kvi_kvs_object_functionhandler.h"

class KviKvsObject;
class KviKvsObjectClass;
class KviKvsRunTimeContext;
class KviKvsVariantList;

// Object allocation function
// parameters are: the class, the tqparent object (eventually 0), the object name (eventually empty)
typedef KviKvsObject * (*KviKvsObjectAllocateInstanceProc)(KviKvsObjectClass *,KviKvsObject *,const TQString &);

// An object function callback
typedef bool (KviKvsObject::*KviKvsObjectFunctionHandlerProc)(KviKvsObjectFunctionCall * pCall);


// The descriptor of a kvirc object class

class KVIRC_API KviKvsObjectClass
{
	friend class KviKvsObject;
	friend class KviKvsObjectController;
public:
	KviKvsObjectClass(
			KviKvsObjectClass * pParent,            // tqparent class
			const TQString & szName,                 // class name
			KviKvsObjectAllocateInstanceProc proc,  // intance allocation proc
			bool bBuiltin = true                    // this is a builtin or script based class ?
		);
	~KviKvsObjectClass();
protected:
	KviKvsObjectClass                           * m_pParentClass;      // the tqparent (base) class
	TQString                                       m_szName;            // the class name
	bool                                          m_bBuiltin;          // is this a builtin or script based class ?
	KviPointerHashTable<TQString,KviKvsObjectFunctionHandler>          * m_pFunctionHandlers; // all our function handlers
	KviPointerList<KviKvsObjectClass>               * m_pChildClasses;     // 
	KviKvsObjectAllocateInstanceProc              m_allocProc;
	bool                                          m_bDirty;            // not yet flushed to disk (only for not builtin classes)
protected:
	void registerChildClass(KviKvsObjectClass *pClass);
	void unregisterChildClass(KviKvsObjectClass *pClass);
	KviPointerHashTable<TQString,KviKvsObjectFunctionHandler> * functionHandlers(){ return m_pFunctionHandlers; };
public:
	void clearDirtyFlag(){ m_bDirty = false; };
	bool isDirty(){ return m_bDirty; };
	bool isBuiltin(){ return m_bBuiltin; };
	const TQString & name(){ return m_szName; };
	KviKvsObjectClass * tqparentClass(){ return m_pParentClass; };
	// pProc CAN'T be zero here!
	void registerFunctionHandler(const TQString & szFunctionName,KviKvsObjectFunctionHandlerProc pProc,unsigned int uFlags = 0);
	void registerFunctionHandler(const TQString & szFunctionName,const TQString &szBuffer,unsigned int uFlags = 0);

	// registers an empty handler that returns "nothing"
	void registerStandardNothingReturnFunctionHandler(const TQString & szFunc);
	// retisters an empty handler that returns $true
	void registerStandardTrueReturnFunctionHandler(const TQString & szFunc);
	// retisters an empty handler that returns $false
	void registerStandardFalseReturnFunctionHandler(const TQString & szFunc);

	KviKvsObjectFunctionHandler * lookupFunctionHandler(const TQString & szFunc){ return m_pFunctionHandlers->tqfind(szFunc); };
	KviKvsObject * allocateInstance(KviKvsObject * pParent,const TQString &szName,KviKvsRunTimeContext * pContext,KviKvsVariantList * pParams);

	bool save(const TQString &szFileName);
	static bool load(const TQString &szFileName);
	void getFunctionCode(TQString &szCode,KviKvsObjectFunctionHandler &h);
	KviPointerHashTable<TQString,KviKvsObjectFunctionHandler> * getHandlers(){return m_pFunctionHandlers;};

};


#endif //!_KVI_KVS_OBJECTCLASS_H_