7 #ifndef _INC_cScriptableInterface_H
8 #define _INC_cScriptableInterface_H
13 #include "../GrayLibBase.h"
14 #include "../Auth/PrivLevel.h"
15 #include "../Misc/cStructElem.h"
16 #include "../Variant/cVariant.h"
150 return (m_wFlags & wFlags) != 0;
159 return (m_nMethodStub != 0) && !isFunction();
163 return m_nMethodStub == 0;
173 return GetARGS(m_wFlags);
187 return ePrivLevel >= m_PrivLevelRead;
192 return ePrivLevel >= m_PrivLevelWrite;
199 if (this->get_Name() ==
nullptr)
203 if (this->m_pInterfaceDef ==
nullptr)
255 #ifndef CSCRIPT_PROP_HELP
256 #define CSCRIPT_PROP_HELP(c) c
260 #define CSCRIPT_PROP_IMP(a,b,c) { { #a, { VARTYPE_NoType, 0, 0 } }, b, PLEVEL_GM, PLEVEL_GM, CSCRIPT_PROP_HELP(c), false, &sm_ScriptInterfaceDef }
261 #define CSCRIPT_METHOD_IMP(a,b,c) { { #a, { VARTYPE_NoType, 0, 0 } }, b, PLEVEL_GM, PLEVEL_QTY, CSCRIPT_PROP_HELP(c), true, &sm_ScriptInterfaceDef }
262 #define CSCRIPT_METHOD_IMP2(a,b,c,d) { { #a, { VARTYPE_NoType, 0, 0 } }, b, c, PLEVEL_QTY, CSCRIPT_PROP_HELP(d), true, &sm_ScriptInterfaceDef }
264 #define CSCRIPT_PROP_END { { nullptr, { VARTYPE_NoType, 0, 0 } }, 0 }
269 #define CSCRIPT_CLASS_DEF0_N static cScriptableInterfaceDef sm_ScriptInterfaceDef;
271 #define CSCRIPT_CLASS_DEF0(TYPE) CSCRIPT_CLASS_DEF0_N virtual cScriptableInterfaceDefPtr _stdcall get_ScriptInterfaceDef() const { return(&sm_ScriptInterfaceDef); }
273 #define CSCRIPT_CLASS_IMP0(TYPE,_PROPS,_METHODS,_HELP) cScriptableInterfaceDef c##TYPE::sm_ScriptInterfaceDef(typeid(c##TYPE),#TYPE,_PROPS,_METHODS,nullptr,CSCRIPT_PROP_HELP(_HELP));
277 #define CSCRIPT_CLASS_DEF1(TYPE,_BASETYPE) \
278 CSCRIPT_CLASS_DEF0(TYPE) \
279 typedef _BASETYPE CSCRIPTABLE_SUPER_t; \
281 #define CSCRIPT_CLASS_IMP1(TYPE,_PROPS,_METHODS,_HELP) \
282 cScriptableInterfaceDef c##TYPE::sm_ScriptInterfaceDef(typeid(c##TYPE),#TYPE,_PROPS,_METHODS,&c##TYPE::CSCRIPTABLE_SUPER_t::sm_ScriptInterfaceDef,CSCRIPT_PROP_HELP(_HELP));
286 #define CSCRIPT_CLASS_DEF2(TYPE,_BASETYPE) \
287 static cScriptableInterfaceTemplate<c##TYPE> sm_ScriptInterfaceDef; \
288 typedef _BASETYPE CSCRIPTABLE_SUPER_t; \
289 virtual cScriptableInterfaceDefPtr _stdcall get_ScriptInterfaceDef() const \
290 { return(&sm_ScriptInterfaceDef); }
292 #define CSCRIPT_CLASS_IMP2(TYPE,_PROPS,_METHODS,_HELP) \
293 template class cScriptableInterfaceTemplate<c##TYPE>; \
294 cScriptableInterfaceTemplate<c##TYPE> c##TYPE::sm_ScriptInterfaceDef(typeid(c##TYPE),#TYPE,_PROPS,_METHODS,&c##TYPE::CSCRIPTABLE_SUPER_t::sm_ScriptInterfaceDef,CSCRIPT_PROP_HELP(_HELP));
327 SCRIPT_METHOD_FUNC* m_pfMethod;
328 SCRIPT_PROP_FUNC* m_pfPropGet;
329 SCRIPT_PROP_FUNC* m_pfPropSet;
334 #define cScriptableInterfaceProp(a,b,c) P_##a,
336 #undef cScriptableInterfaceProp
365 virtual bool isValidCheck() const noexcept;
376 return m_nInterfaceID;
387 return &m_pMethods[
index];
401 int index = FindMethodIndex(pszName);
404 return &m_pMethods[
index];
416 return &m_pProps[
index];
430 int index = FindPropIndex(pszName);
433 return &m_pProps[
index];
442 return m_bInitInterface;
449 virtual void InitScriptInterfaceDef();
452 void InitSubInterfaces();
527 return m_aInterfaceDefs[nInterfaceID];
530 static void GRAYCALL InitInterfaces();
531 void InitInterfaceDefs();
536 return(m_nInitInterfaces > 0);
554 #define CSCRIPT_PROP(_CLASS,_PROP) (_CLASS::sm_Props[_CLASS::P_##_PROP])
555 #define CSCRIPT_PROP_NAME(_CLASS,_PROP) (CSCRIPT_PROP(_CLASS,_PROP).m_a.m_pszKey)
556 #define CSCRIPT_PROP_NAMEA(_CLASS,_PROP) (CSCRIPT_PROP(_CLASS,_PROP).get_NamePropA())
558 #define CSCRIPT_METHOD(_CLASS,_PROP) (_CLASS::sm_Methods[_CLASS::M_##_PROP])
559 #define CSCRIPT_METHOD_NAME(_CLASS,_PROP) (CSCRIPT_METHOD(_CLASS,_PROP).m_a.m_pszKey)
560 #define CSCRIPT_METHOD_NAMEA(_CLASS,_PROP) (CSCRIPT_METHOD(_CLASS,_PROP).get_NamePropA())
565 template class GRAYLIB_LINK cArrayPtr<GrayLib::cScriptableInterfaceDef>;
566 template class GRAYLIB_LINK cArraySorted<GrayLib::SCRIPTINTERFACEID_t, GrayLib::SCRIPTINTERFACEID_t, GrayLib::SCRIPTINTERFACEID_t>;
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
#define IS_INDEX_GOOD(i, q)
cast the (likely) int to unsigned to check for negatives.
Definition: Index.h:35
#define IS_INDEX_BAD(i, q)
cast the (likely) int to unsigned to check for negatives.
Definition: Index.h:34
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define ASSERT(exp)
Definition: cDebugAssert.h:87
#define CHEAPOBJECT_IMPL
Definition: cHeapObject.h:32
#define CSCRIPT_CLASS_DEF0(TYPE)
Definition: cScriptableInterface.h:271
Definition: cScriptContext.h:24
Definition: cScriptableInterface.h:300
UINT m_nInstances
define get_ScriptInterfaceDef()
Definition: cScriptableInterface.h:340
SCRIPTPROPID_t get_MethodQty() const noexcept
Definition: cScriptableInterface.h:379
virtual SCRIPTPROPID_t GetMethodIndex(const cScriptableMethod *pMethod) const
Definition: cScriptableInterface.h:389
cScriptableInterfaceDef * m_pSubInterface
primary sub class. (can actually be multi(m_aSubInterfacesAll) or none(nullptr))
Definition: cScriptableInterface.h:307
SCRIPTPROPID_t FindPropIndex(const ATOMCHAR_t *pszName) const
Definition: cScriptableInterface.h:424
cArraySortPtrHash< const cScriptableProp, ATOMCODE_t > m_aPropsAllHash
We may search by hash code.
Definition: cScriptableInterface.h:319
SCRIPTPROPID_t m_iMethodQty
get_MethodQty()
Definition: cScriptableInterface.h:355
cArraySortPtrName< const cScriptableMethod, ATOMCHAR_t > m_aMethodsAll
Complete list of all Methods. (includes sub class methods)
Definition: cScriptableInterface.h:316
const char * m_pszHelp
helpful description for human readers.
Definition: cScriptableInterface.h:308
SCRIPTPROPID_t FindMethodIndex(const ATOMCHAR_t *pszName) const
Definition: cScriptableInterface.h:395
cScriptableProp * FindPropPtrI(const ATOMCHAR_t *pszName) const
Definition: cScriptableInterface.h:428
SCRIPTPROPID_t m_iPropQty
get_PropQty()
Definition: cScriptableInterface.h:351
cArraySortVal< SCRIPTINTERFACEID_t > m_aSubInterfacesAll
List of interfaces I'm based on (Already added to m_aMethodsAll and m_aPropsAll.
Definition: cScriptableInterface.h:323
virtual SCRIPTPROPID_t GetPropIndex(const cScriptableProp *pProp) const
Definition: cScriptableInterface.h:418
cArraySortPtrHash< const cScriptableMethod, ATOMCODE_t > m_aMethodsAllHash
Definition: cScriptableInterface.h:320
SCRIPTINTERFACEID_t m_nInterfaceID
enum id to define the class. similar to XOBJTIDX_TYPE ?
Definition: cScriptableInterface.h:311
virtual cScriptableMethod * GetMethodPtr(SCRIPTPROPID_t index) const noexcept
Definition: cScriptableInterface.h:383
const ATOMCHAR_t * m_pszName
Interface Name.
Definition: cScriptableInterface.h:306
P_TYPE_
< if the InterfaceDef is itself an interface.
Definition: cScriptableInterface.h:333
@ P_QTY
Definition: cScriptableInterface.h:337
bool m_bInitInterface
has this been synchronized with the base classes.
Definition: cScriptableInterface.h:345
SCRIPTPROPID_t get_PropQty() const
Definition: cScriptableInterface.h:407
bool IsInterfaceInit() const
Definition: cScriptableInterface.h:439
SCRIPTINTERFACEID_t get_InterfaceID() const noexcept
Definition: cScriptableInterface.h:371
virtual cScriptableProp * GetPropPtr(SCRIPTPROPID_t index) const
Definition: cScriptableInterface.h:411
cArraySortPtrName< const cScriptableProp, ATOMCHAR_t > m_aPropsAll
Definition: cScriptableInterface.h:314
cScriptableMethod * FindMethodPtrI(const ATOMCHAR_t *pszName) const
Definition: cScriptableInterface.h:399
const TYPEINFO_t & m_TypeInfo
The C++ typeid(class type) this refers to. (we could derive m_pszName?) MUST HAVE RTTI on!
Definition: cScriptableInterface.h:305
Definition: cScriptableInterface.h:503
UNITTEST_FRIEND(cScriptableInterface)
cScriptableInterfaceDefPtr GetInterfaceDef(SCRIPTINTERFACEID_t nInterfaceID) const
Definition: cScriptableInterface.h:523
bool isInitInterfaces() const
Definition: cScriptableInterface.h:533
Definition: cScriptableInterface.h:470
cScriptableInterfaceTemplate(const TYPEINFO_t &TypeInfo, const ATOMCHAR_t *pszName, cScriptableProp *pProps, cScriptableMethod *pMethods, cScriptableInterfaceDef *pSubInterface, const ATOMCHAR_t *pszHelp)
Definition: cScriptableInterface.h:478
virtual void InitScriptInterfaceDef()
things that cannot be done at static construct time.
Definition: cScriptableInterface.h:97
int get_NumArgs() const noexcept
Definition: cScriptableInterface.h:170
bool HasKnownArgs() const noexcept
Definition: cScriptableInterface.h:180
cScriptableInterfaceDef * m_pInterfaceDef
point back to my root class. (not used for context functions)
Definition: cScriptableInterface.h:116
HRESULT SetElementCheck(void *pBaseInst, const cVariant &vVal) const
Definition: cScriptableInterface.h:231
const ATOMCHAR_t * get_Name() const noexcept
Definition: cScriptableInterface.h:134
bool IsPropFlags(CSCRIPTPROP_MASK_t wFlags) const noexcept
Definition: cScriptableInterface.h:148
bool isValidProp() const noexcept
Definition: cScriptableInterface.h:194
static bool isNOARGS(CSCRIPTPROP_MASK_t flag) noexcept
Definition: cScriptableInterface.h:126
cStructNamedElem m_a
(key,type,offset,extra)
Definition: cScriptableInterface.h:105
bool isDeprecated() const noexcept
Definition: cScriptableInterface.h:165
CSCRIPTPROP_MASK_t m_wFlags
CSCRIPTPROP_RETNUL (apply slightly diff to cScriptableMethod, cScriptableMethod, cScriptableMethod.
Definition: cScriptableInterface.h:111
bool SetElementVal(void *pBaseInst, const cVariant &vVal) const
Definition: cScriptableInterface.h:223
SCRIPTPROPID_t get_MethodIndex() const
Definition: cScriptableInterface.h:493
VARTYPE_TYPE get_ElementType() const
Definition: cScriptableInterface.h:241
SCRIPTPROPID_t get_PropIndex() const
the index of the prop in the interface.
Definition: cScriptableInterface.h:487
bool GetElementVal(const void *pBaseInst, OUT cVariant &vValRet) const
Definition: cScriptableInterface.h:217
BYTE m_PrivLevelRead
What PLEVEL_TYPE required to read this prop. (does not apply to methods)
Definition: cScriptableInterface.h:113
bool isFunction() const noexcept
Definition: cScriptableInterface.h:152
bool HasPrivLevelWrite(PLEVEL_TYPE ePrivLevel) const noexcept
Definition: cScriptableInterface.h:189
static BYTE GetARGS(CSCRIPTPROP_MASK_t flag) noexcept
Definition: cScriptableInterface.h:121
ATOMCODE_t m_nHashCode
The cAtomRef hash = StrT::GetHashCode32(m_a.key) (can't init this at static time. do it later InitPro...
Definition: cScriptableInterface.h:117
ATOMCODE_t get_HashCode() const noexcept
Definition: cScriptableInterface.h:139
bool HasPrivLevelRead(PLEVEL_TYPE ePrivLevel) const noexcept
Definition: cScriptableInterface.h:185
bool HasNoArgs() const noexcept
Definition: cScriptableInterface.h:175
bool isProp() const noexcept
Definition: cScriptableInterface.h:161
const ATOMCHAR_t * m_pszHelp
short piece of help text on this prop/method. CSCRIPT_PROP_HELP
Definition: cScriptableInterface.h:114
BYTE m_PrivLevelWrite
What PLEVEL_TYPE required to write this prop or exec/invoke this method.
Definition: cScriptableInterface.h:112
bool isMethod() const noexcept
Definition: cScriptableInterface.h:157
UINT_PTR m_nMethodStub
just identifies it as a method or not. although m_PrivLevelRead==PLEVEL_QTY does as well.
Definition: cScriptableInterface.h:115
VARTYPE_TYPE m_eVarType
effective type of the data in the mapped structure.
Definition: cStructElem.h:33
bool GetValVar(const void *pBaseInst, cVariant &vVal) const
Definition: cStructElem.cpp:251
Definition: cStructElem.h:87
const ATOMCHAR_t * get_Name() const noexcept
Definition: cStructElem.h:103
bool SetValVar(void *pBaseInst, const cVariant &vVal) const
Definition: cStructElem.h:117
HRESULT SetValCheck(void *pBaseInst, const cVariant &vVal) const
Definition: cStructElem.h:121
cStructElem m_elem
(type,offset,extra)
Definition: cStructElem.h:96
Definition: cVariant.h:26
Definition: cArraySort.h:613
Definition: cArraySort.h:620
bool IsValidIndex(ITERATE_t i) const noexcept
Definition: cArray.h:495
Definition: cSingleton.h:127
Definition: cStream.h:126
Definition: IScriptableObj.h:51
Definition: IScriptableObj.h:62
cScriptableProp cScriptableMethod
Methods are really similar to Props.
Definition: cScriptableInterface.h:253
class __DECL_IMPORT cScriptableInterfaceDef
Definition: cScriptableEventsMask.h:31
VARTYPE_TYPE
< define types of structure/record elements. (COM uses VARTYPE=VARENUM for this) stored as BYTE
Definition: cVariantType.h:19
@ VARTYPE_NoType
Definition: cVariantType.h:24
XOBJ_DUMP_MASK_
Definition: cScriptableInterface.h:41
@ XOBJ_DUMP_NAME
Definition: cScriptableInterface.h:44
@ XOBJ_DUMP_INTERFACE
what interface is this based on?
Definition: cScriptableInterface.h:48
@ XOBJ_DUMP_FLAGS
Definition: cScriptableInterface.h:47
@ XOBJ_DUMP_VALUE
Definition: cScriptableInterface.h:45
@ XOBJ_DUMP_UNUSED
flag to show even the unused stuff.
Definition: cScriptableInterface.h:49
@ XOBJ_DUMP_HELP
Definition: cScriptableInterface.h:46
UNITTEST2_PREDEF(cQuadtree)
CSCRIPTPROP_MASK_
Definition: cScriptableInterface.h:55
@ CSCRIPTPROPP_WRITEO
Write only prop. (array props need method for read.)
Definition: cScriptableInterface.h:67
@ CSCRIPTPROPM_DISPAT
Method is a special dispatch method. hide from normal display.
Definition: cScriptableInterface.h:69
@ CSCRIPTPROPM_DELETE
this method could delete the object. must update to verify
Definition: cScriptableInterface.h:79
@ CSCRIPTPROP_ARG4
Definition: cScriptableInterface.h:85
@ CSCRIPTPROP_ARG1S
Just takes 1 string argument. allow sloppy syntax.
Definition: cScriptableInterface.h:68
@ CSCRIPTPROP_RETREF
method could return a ref. (but may not)
Definition: cScriptableInterface.h:62
@ CSCRIPTPROPI_STATIC
a single static entity. (not the same as CONST)
Definition: cScriptableInterface.h:77
@ CSCRIPTPROPP_NOPRIV
not high enough priv level to read this!
Definition: cScriptableInterface.h:70
@ CSCRIPTPROP_DEFAULT
First 4 bits is the number of REQUIRED arguments.
Definition: cScriptableInterface.h:58
@ CSCRIPTPROP_RETNUL
method returns nothing. (or prop is unused)
Definition: cScriptableInterface.h:60
@ CSCRIPTPROPP_KEY
this prop is a key for the record
Definition: cScriptableInterface.h:76
@ CSCRIPTPROP_NARG1
exactly 1 arg.
Definition: cScriptableInterface.h:89
@ CSCRIPTPROP_DUPE
This is redundant for another key. m_pszHelp. MUST be static for Send_Props to work.
Definition: cScriptableInterface.h:73
@ CSCRIPTPROP_NARG3
Definition: cScriptableInterface.h:91
@ CSCRIPTPROPP_TEMP
just a temporary prop, don't bother saving this.
Definition: cScriptableInterface.h:75
@ CSCRIPTPROP_NARG5
Definition: cScriptableInterface.h:93
@ CSCRIPTPROP_UNUSED
Obsolete or reserved keyword. MUST be static for Send_Props to work.
Definition: cScriptableInterface.h:72
@ CSCRIPTPROP_NARGS
Method needs exactly this number of args. cScriptableProp::GetARGS.
Definition: cScriptableInterface.h:66
@ CSCRIPTPROPI_PRIVNAME
private namespace. (for cScriptableInterfaceDef and resourcedef)
Definition: cScriptableInterface.h:78
@ CSCRIPTPROP_EXTPROP
special syntax for script such that method looks like a ref syntactically but is really just an arg (...
Definition: cScriptableInterface.h:63
@ CSCRIPTPROP_NARG4
Definition: cScriptableInterface.h:92
@ CSCRIPTPROP_ARG1
It MUST have at least this number of args.
Definition: cScriptableInterface.h:82
@ CSCRIPTPROPM_FUNC
global function. (not really a method)
Definition: cScriptableInterface.h:80
@ CSCRIPTPROP_RETVAL
method returns some sort of val.
Definition: cScriptableInterface.h:61
@ CSCRIPTPROP_ARG3
Definition: cScriptableInterface.h:84
@ CSCRIPTPROP_ARG5
Definition: cScriptableInterface.h:86
@ CSCRIPTPROP_NARG2
Definition: cScriptableInterface.h:90
@ CSCRIPTPROPP_READO
prop is read only. (or method takes no args)
Definition: cScriptableInterface.h:65
@ CSCRIPTPROP_ARG2
Definition: cScriptableInterface.h:83
@ CSCRIPTPROP_ARGS_MASK
Definition: cScriptableInterface.h:87
BYTE SCRIPTINTERFACEID_t
enumerate all the defined interface definitions.
Definition: cScriptableInterface.h:35
const SCRIPTPROPID_t SCRIPTPROPINDEX_MAX
Definition: cScriptableInterface.h:38
WORD CSCRIPTPROP_MASK_t
Definition: cScriptableInterface.h:53
PLEVEL_TYPE
Definition: PrivLevel.h:16
cScriptableInterfaceDef * cScriptableInterfaceDefPtr
Definition: cScriptableInterface.h:33
const SCRIPTINTERFACEID_t SCRIPTINTERFACEID_MAX
Definition: cScriptableInterface.h:36
UINT XOBJ_DUMP_MASK_t
enum XOBJ_DUMP_MASK_
Definition: cScriptableInterface.h:51
BYTE SCRIPTPROPID_t
index to method or prop.
Definition: cScriptableEventsMask.h:28
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
int StrLen_t
the length of a string in chars (bytes for UTF8, wchar_t for UNICODE). or offset in characters....
Definition: StrConst.h:32
HASHCODE32_t ATOMCODE_t
Encode a atom as a 32 bit hashcode instead of using its name/pointer. StrT::GetHashCode32()
Definition: cAtom.h:18
int ITERATE_t
like size_t but signed
Definition: Index.h:28
char ATOMCHAR_t
the char form (UNICODE or not) for an atom. (for symbolic names)
Definition: StrConst.h:15
std::type_info TYPEINFO_t
Definition: cTypeInfo.h:29
uint16 index
Definition: sample3.cpp:29
static bool IsCSymF(wchar_t ch) noexcept
Definition: StrChar.h:194
static __DECL_IMPORT ITERATE_t __stdcall TableFindHeadSorted(const TYPE *pszFindHead, const void *ppszTableInit, ITERATE_t iCountMax, size_t nElemSize=sizeof(const TYPE *))
static bool IsValidApp(const void *pData) noexcept
Definition: cMem.h:42