Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cExpressionExec.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cExpressionExec_H
7 #define _INC_cExpressionExec_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "cExpressionContext.h"
13 #include "cExpressionBase.h"
14 
15 #ifdef USE_EXPRESSION
16 #include "../Variant/cVariant.h"
17 
18 namespace GrayLib
19 {
20  enum EXP_PARSE_TYPE_ // flags
21  {
25  EXP_PARSE_STR1 = 0x08,
26  EXP_PARSE_PROP = 0x10,
27  EXP_PARSE_FUNC = 0x20,
28  EXP_PARSE_SLOP = 0x40,
29 
32 
33  };
34  typedef WORD EXP_PARSE_MASK_t;
35 
37  {
41 
42  typedef cExpressionBase SUPER_t;
43 
44  public:
45  // default to use cExpressionBase if there is no other exec engine.
47 
48  protected:
50 
51  private:
52  // Get the current expression Context (thread safe).
53  // Used to parse expression strings passed into sub functions.
54  cExpressionContext* m_pExpContext;
55  cExpressionContext* m_pExpContextPrev;
56 
57  protected:
58  // This appears to be a symbolic of some sort.
59  HRESULT ParseArgV(const ATOMCHAR_t*& rpszExp, OUT cVariant& vArgsRet, EXP_PARSE_MASK_t uParseFlags);
60 
62  {
64  if (m_pExpContext != nullptr)
65  {
66  return m_pExpContext;
67  }
69  }
70 
71  public:
72  explicit cExpressionExec(cExpressionContext* pContext);
73  virtual ~cExpressionExec();
74 
76  virtual HRESULT ExecuteFunctionInt(const ATOMCHAR_t*& rpszExp, OUT cVariant& vValRet, EXP_PARSE_MASK_t uParseFlags);
77 
79  HRESULT ExecuteCommand(const ATOMCHAR_t* pszCommand, OUT cVariant& vValRet);
80 
81  HRESULT GetVarRef1(const ATOMCHAR_t*& rpszExp, OUT cVariant& vValRet);
82 
85  static HRESULT GRAYCALL DoMathOp2(cVariant& vVal, const cVariant& vVal2, ATOMCHAR_t chOp);
86  HRESULT DoMathOp1(cVariant& vVal, const ATOMCHAR_t*& rpszExp);
87 
88  virtual HRESULT GetVarRef2(const ATOMCHAR_t*& rpszExp, OUT cVariant& vValRet, bool bInArray) override;
89 
92  {
94  return GetVarComplexRef(pszExp);
95  }
96 
98 #define EXP_GET_TYPE(a,b) a GetComplex##b( const ATOMCHAR_t* pszExp ) { return GetVarComplexRef( pszExp ).get_##b(); }
99  EXP_GET_TYPE(bool, Bool)
100  EXP_GET_TYPE(int, Int)
101  EXP_GET_TYPE(UINT32, DWord)
102  EXP_GET_TYPE(float, Float)
103  EXP_GET_TYPE(double, Double)
104 #undef EXP_GET_TYPE
105 
107 #define EXP_GET_X_TYPE(a,b) static inline a GetX##b( const ATOMCHAR_t* pszExp ) { return sm_pExpExecBest->GetVarComplexRef( pszExp ).get_##b(); }
108  EXP_GET_X_TYPE(int, Int)
109  EXP_GET_X_TYPE(UINT32, DWord)
110  EXP_GET_X_TYPE(float, Float)
111 #undef EXP_GET_X_TYPE
112  };
113 }
114 
115 #endif // USE_EXPRESSION
116 #endif // _INC_cExpressionExec_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
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define EXP_GET_X_TYPE(a, b)
Define static version that doesn't advance the pointer.
Definition: cExpressionExec.h:107
#define EXP_GET_TYPE(a, b)
Define version that doesn't advance the pointer.
Definition: cExpressionExec.h:98
Definition: cExpressionBase.h:27
static cExpressionContext *GRAYCALL GetContextCurrent()
Definition: cExpressionContext.cpp:292
Definition: cExpressionContext.h:18
Definition: cExpressionExec.h:37
static cExpressionExec * sm_pExpExecBest
allow cScriptExec (or other engine) to be used as default.
Definition: cExpressionExec.h:46
cVariant GetVarComplexRef(const ATOMCHAR_t *&rpszExp)
static HRESULT GRAYCALL DoMathOp2(cVariant &vVal, const cVariant &vVal2, ATOMCHAR_t chOp)
HRESULT ParseArgV(const ATOMCHAR_t *&rpszExp, OUT cVariant &vArgsRet, EXP_PARSE_MASK_t uParseFlags)
EXP_PARSE_MASK_t m_wParseFlags
EXP_PARSE_IGNORE_EXTRA.
Definition: cExpressionExec.h:49
virtual HRESULT ExecuteFunctionInt(const ATOMCHAR_t *&rpszExp, OUT cVariant &vValRet, EXP_PARSE_MASK_t uParseFlags)
Parse and exec a function returning a variant.
cExpressionContext * get_ContextCurrent() const
Definition: cExpressionExec.h:61
HRESULT GetVarRef1(const ATOMCHAR_t *&rpszExp, OUT cVariant &vValRet)
cVariant GetVarComplex(const ATOMCHAR_t *pszExp)
Definition: cExpressionExec.h:91
cExpressionExec(cExpressionContext *pContext)
virtual HRESULT GetVarRef2(const ATOMCHAR_t *&rpszExp, OUT cVariant &vValRet, bool bInArray) override
HRESULT DoMathOp1(cVariant &vVal, const ATOMCHAR_t *&rpszExp)
HRESULT ExecuteCommand(const ATOMCHAR_t *pszCommand, OUT cVariant &vValRet)
Execute a single command line. as typed by some user.
Definition: cVariant.h:26
Definition: cMesh.h:22
EXP_PARSE_TYPE_
Definition: cExpressionExec.h:21
@ EXP_PARSE_FUNC
Allow syntax like "FUNCTION(ARGS)".
Definition: cExpressionExec.h:27
@ EXP_PARSE_IGNORE_EXTRA
ignore/allow extra junk at the end of expression we don't parse and don't call an error.
Definition: cExpressionExec.h:30
@ EXP_PARSE_SLOP
Allow sloppy syntax with just a space. "PROP ARGS".
Definition: cExpressionExec.h:28
@ EXP_PARSE_STR1
Assume arguments are just a single string. quotes not required.
Definition: cExpressionExec.h:25
@ EXP_PARSE_PROP
Allow syntax like "PROP=ARGS".
Definition: cExpressionExec.h:26
@ EXP_PARSE_0
defaults.
Definition: cExpressionExec.h:24
@ EXP_PARSE_GLOBALS
Use Globals.
Definition: cExpressionExec.h:31
WORD EXP_PARSE_MASK_t
EXP_PARSE_TYPE_ Flags.
Definition: cExpressionExec.h:34
char ATOMCHAR_t
the char form (UNICODE or not) for an atom. (for symbolic names)
Definition: StrConst.h:15