1 #ifndef _INCLUDE_SOURCEMOD_FORWARDSYSTEM_H_
2 #define _INCLUDE_SOURCEMOD_FORWARDSYSTEM_H_
4 #include <IForwardSys.h>
5 #include <IPluginSys.h>
6 #include "sm_globals.h"
11 using namespace SourceHook;
13 typedef List<IPluginFunction *>::iterator FuncIter;
15 //:TODO: a global name max define for sourcepawn, should mirror compiler's sNAMEMAX
16 #define FORWARDS_NAME_MAX 64
33 class CForward : public IChangeableForward
36 virtual int PushCell(cell_t cell);
37 virtual int PushCellByRef(cell_t *cell, int flags);
38 virtual int PushFloat(float number);
39 virtual int PushFloatByRef(float *number, int flags);
40 virtual int PushArray(cell_t *inarray, unsigned int cells, cell_t **phys_addr, int flags);
41 virtual int PushString(const char *string);
42 virtual int PushStringEx(char *buffer, size_t length, int sz_flags, int cp_flags);
43 virtual void Cancel();
45 virtual const char *GetForwardName();
46 virtual unsigned int GetFunctionCount();
47 virtual ExecType GetExecType();
48 virtual int Execute(cell_t *result, IForwardFilter *filter);
49 public: //IChangeableForward
50 virtual bool RemoveFunction(IPluginFunction *func);
51 virtual unsigned int RemoveFunctionsOfPlugin(IPlugin *plugin);
52 virtual bool AddFunction(IPluginFunction *func);
53 virtual bool AddFunction(sp_context_t *ctx, funcid_t index);
55 static CForward *CreateForward(const char *name,
57 unsigned int num_params,
61 void _Int_PushArray(cell_t *inarray, unsigned int cells, int flags);
62 void _Int_PushString(cell_t *inarray, unsigned int cells, int sz_flags, int cp_flags);
63 inline int SetError(int err)
69 /* :TODO: I want a caching list type here.
70 * Destroying these things and using new/delete for their members feels bad.
72 List<IPluginFunction *> m_functions;
74 /* Type and name information */
75 FwdParamInfo m_params[SP_MAX_EXEC_PARAMS];
76 ParamType m_types[SP_MAX_EXEC_PARAMS];
77 char m_name[FORWARDS_NAME_MAX+1];
78 unsigned int m_numparams;
79 unsigned int m_varargs;
82 /* State information */
83 unsigned int m_curparam;
87 class CForwardManager :
88 public IForwardManager,
89 public IPluginsListener,
92 friend class CForward;
93 public: //IForwardManager
94 virtual IForward *CreateForward(const char *name,
96 unsigned int num_params,
99 virtual IChangeableForward *CreateForwardEx(const char *name,
104 virtual IForward *FindForward(const char *name, IChangeableForward **ifchng);
105 virtual void ReleaseForward(IForward *forward);
106 public: //IPluginsListener
107 virtual void OnPluginLoaded(IPlugin *plugin);
108 virtual void OnPluginUnloaded(IPlugin *plugin);
109 public: //SMGlobalClass
110 virtual void OnSourceModAllInitialized();
111 virtual void OnSourceModShutdown();
113 CForward *ForwardMake();
114 void ForwardFree(CForward *fwd);
116 CStack<CForward *> m_FreeForwards;
117 List<CForward *> m_managed;
118 List<CForward *> m_unmanaged;
121 extern CForwardManager g_Forwards;
123 #endif //_INCLUDE_SOURCEMOD_FORWARDSYSTEM_H_