Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cScriptableObj.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cScriptableObj_H
7 #define _INC_cScriptableObj_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "cScriptableInterface.h"
13 #include "IScriptableObj.h"
14 
15 namespace Gray
16 {
17  class cAppArgs;
18 }
19 namespace GrayLib
20 {
22 
24  : public IScriptableObj // IUnknown, get_HashCodeX, get_Name
25  , public IDispatch // IUnknown, Allow reflection/self description script ability. GetIDsOfNames, Invoke
26  {
32 
33  private:
34  HRESULT s_PropGetSecure(const cScriptableProp& rProp, OUT cVariant& vValRet);
35 
36  public:
37  virtual ~cScriptableObj()
38  {}
39 
40  STDMETHOD_(cScriptableInterfaceDefPtr, get_ScriptInterfaceDef)() const
41  {
43  return nullptr;
44  }
45 
46  // Basic object Loading/Query services.
47  STDMETHOD(s_PropGet)(const cScriptableProp* pProp, OUT cVariant& vValRet) override;
48  STDMETHOD(s_PropPut)(const cScriptableProp* pProp, const cVariant& vVal) override;
49  STDMETHOD(s_Invoke)(const cScriptableMethod* pMethod, const cVariant& vArgs, OUT cVariant& vValRet) override
50  {
51  UNREFERENCED_PARAMETER(pMethod);
53  UNREFERENCED_REFERENCE(vValRet);
54  return HRESULT_WIN32_C(ERROR_UNKNOWN_PROPERTY);
55  }
56 
57  const cScriptableProp* FindPropStr(const ATOMCHAR_t* pszPropName) const;
58  const cScriptableMethod* FindMethodStr(const ATOMCHAR_t* pszPropName) const;
59 
60  HRESULT s_InvokeKey(const ATOMCHAR_t* pszMethodKey, const cVariant& vArgs, OUT cVariant& vValRet);
61  STDMETHOD_(cVariant, s_Exec)(const ATOMCHAR_t* pszMethodKey, const cVariant& vArgs = cVariant::k_VarNULL);
62 
63  // Helpers for scripting. IScriptableSetter and IScriptableObj
64  // Immediate types of data returned just use the current thread context.
65  STDMETHOD(s_GetEnum)(ITERATE_t i, OUT cStringA& rsPropName, OUT cVariant& rvValRet) override;
66  STDMETHOD(s_GetByName)(const ATOMCHAR_t* pszPropName, OUT cVariant& rvValRet) override;
67  STDMETHOD(s_Put)(const ATOMCHAR_t* pszPropName, const cVariant& vValSet) override;
68 
69  void s_LoadPropsCommandLine(cAppArgs& args);
70  HRESULT s_LoadPropsBase(IScriptableEnumerator& rProps);
71  HRESULT s_LoadPropVar(const ATOMCHAR_t* pszPropName, const cVariant& vVal);
72 
73  HRESULT s_WritePropNULL(IScriptableSetter& s, const cScriptableProp* pProp);
74  HRESULT s_WriteProp(IScriptableSetter& s, const cScriptableProp* pProp);
75  HRESULT s_WritePropsClass(IScriptableSetter& s, const cScriptableInterfaceDef* pClass);
76  HRESULT s_WritePropsArray(IScriptableSetter& s, const cScriptableProp* pProps, IScriptableObj* pDefaultSkip = nullptr);
77  STDMETHOD(s_WriteProps)(IScriptableSetter& s);
78 
79  static HRESULT GRAYCALL CopyAllProps(IScriptableSetter* pObjDest, IScriptableEnumerator& rProps, int iStart = 0);
80 
81  STDMETHOD_(cVariant, s_Get)(const ATOMCHAR_t* pszPropName);
82  cVariant s_Get(const cScriptableProp& rProp);
83 
84  // Type cast helper versions of s_Put, s_Get
85  STDMETHOD_(cString, s_GetStr)(const ATOMCHAR_t* pszPropName);
86  STDMETHOD_(float, s_GetFloat)(const ATOMCHAR_t* pszPropName);
87 #if 0
88  STDMETHOD_(bool, s_GetBool)(const ATOMCHAR_t* pszPropName);
89  STDMETHOD(s_PutBool)(const ATOMCHAR_t* pszPropName, bool bVal);
90  STDMETHOD_(int, s_GetInt)(const ATOMCHAR_t* pszPropName);
91 #endif
92 
93  // IDispatch support
94  STDMETHOD(GetTypeInfoCount)( /* [out] */ UINT *pctinfo);
95 #if defined(_WIN32)
96  STDMETHOD(GetTypeInfo)( /* [in] */ UINT iTInfo, /* [in] */ LCID lcid, /* [out] */ ITypeInfo **ppTInfo);
97  STDMETHOD(GetIDsOfNames)( /* [in] */ const IID& riid, /* [size_is][in] */ LPOLESTR *rgszNames, /* [in] */ UINT cNames, /* [in] */ LCID lcid, /* [size_is][out] */ DISPID *rgDispId);
98  STDMETHOD(Invoke)( /* [in] */ DISPID dispIdMember, /* [in] */ const IID& riid, /* [in] */ LCID lcid, /* [in] */ WORD wFlags, /* [out][in] */ DISPPARAMS *pDispParams, /* [out] */ VARIANT *pVarResult, /* [out] */ EXCEPINFO *pExcepInfo, /* [out] */ UINT *puArgErr);
99 #endif // _WIN32
100 
101  };
102 }
103 #endif // _INC_cScriptableObj_H
#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 HRESULT_WIN32_C(x)
a constant LSTATUS/error_status_t with no check, unlike HRESULT_FROM_WIN32()
Definition: HResult.h:79
#define UNREFERENCED_PARAMETER(P)
< _WIN32 type thing. get rid of stupid warning.
Definition: SysTypes.h:299
#define UNREFERENCED_REFERENCE(x)
Definition: SysTypes.h:318
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
Definition: cScriptableInterface.h:300
Definition: cScriptableObj.h:26
virtual ~cScriptableObj()
Definition: cScriptableObj.h:37
STDMETHOD_(cScriptableInterfaceDefPtr, get_ScriptInterfaceDef)() const
Definition: cScriptableObj.h:40
STDMETHOD_(cVariant, s_Exec)(const ATOMCHAR_t *pszMethodKey
STDMETHOD_(float, s_GetFloat)(const ATOMCHAR_t *pszPropName)
STDMETHOD_(cVariant, s_Get)(const ATOMCHAR_t *pszPropName)
STDMETHOD_(cString, s_GetStr)(const ATOMCHAR_t *pszPropName)
Definition: cScriptableInterface.h:97
Definition: cVariant.h:26
static const cVariant k_VarNULL
VARTYPE_NoType isNoType()
Definition: cVariant.h:39
Definition: cAppState.h:42
Definition: IScriptableObj.h:38
Definition: IScriptableObj.h:71
Definition: IScriptableObj.h:62
Definition: cMesh.h:22
DECLARE_INTERFACE(IScriptableSetter)
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
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
Definition: IUnknown.h:34