core/systems/CFunction.h
author David Anderson <dvander@alliedmods.net>
Sat Nov 11 11:10:24 2006 +0000 (2006-11-11)
changeset 177 d29ade52d953
child 183 78488edd8873
permissions -rw-r--r--
Fleshed out forward system and extensively documented its design considerations
Implemented and did basic tests on new IPluginFunction type
Split function types into a separate file
     1 #ifndef _INCLUDE_SOURCEMOD_BASEFUNCTION_H_
     2 #define _INCLUDE_SOURCEMOD_BASEFUNCTION_H_
     3 
     4 #include <IPluginFunction.h>
     5 #include "sm_globals.h"
     6 
     7 struct ParamInfo
     8 {
     9 	int flags;			/* Copy-back flags */
    10 	bool marked;		/* Whether this is marked as being used */
    11 	cell_t local_addr;	/* Local address to free */
    12 	cell_t *phys_addr;	/* Physical address of our copy */
    13 	cell_t *orig_addr;	/* Original address to copy back to */
    14 	ucell_t size;		/* Size of array in cells */
    15 };
    16 
    17 class CPlugin;
    18 
    19 class CFunction : public IPluginFunction
    20 {
    21 public:
    22 	CFunction(funcid_t funcid, CPlugin *plugin);
    23 public:
    24 	virtual int PushCell(cell_t cell);
    25 	virtual int PushCellByRef(cell_t *cell, int flags);
    26 	virtual int PushFloat(float number);
    27 	virtual int PushFloatByRef(float *number, int flags);
    28 	virtual int PushCells(cell_t array[], unsigned int numcells, bool each);
    29 	virtual int PushArray(cell_t *inarray, unsigned int cells, cell_t **phys_addr, int copyback);
    30 	virtual int PushString(const char *string);
    31 	virtual int PushStringByRef(char *string, int flags);
    32 	virtual cell_t *GetAddressOfPushedParam(unsigned int param);
    33 	virtual int Execute(cell_t *result, IFunctionCopybackReader *reader);
    34 	virtual void Cancel();
    35 	virtual int CallFunction(const cell_t *params, unsigned int num_params, cell_t *result);
    36 	virtual IPlugin *GetParentPlugin();
    37 public:
    38 	void Set(funcid_t funcid, CPlugin *plugin);
    39 private:
    40 	int _PushString(const char *string, int flags);
    41 	inline int SetError(int err)
    42 	{
    43 		m_errorstate = err;
    44 		return err;
    45 	}
    46 private:
    47 	funcid_t m_funcid;
    48 	CPlugin *m_pPlugin;
    49 	cell_t m_params[SP_MAX_EXEC_PARAMS];
    50 	ParamInfo m_info[SP_MAX_EXEC_PARAMS];
    51 	unsigned int m_curparam;
    52 	int m_errorstate;
    53 };
    54 
    55 #endif //_INCLUDE_SOURCEMOD_BASEFUNCTION_H_