soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
sobject-i.h
Go to the documentation of this file.
1/**
2 * Copyright (C) 2014-2050
3 * All rights reserved.
4 *
5 * @file sobject-i.h
6 * @brief
7 * @version v1.0
8 * @author SOUI group
9 * @date 2014/08/01
10 *
11 * Describe the base class used in SOUI, which provides type identify of class in runtime
12 * and implement attributes dispatcher described in XML.
13 */
14
15#ifndef __SOBJECT_I__H__
16#define __SOBJECT_I__H__
17#include <interface/obj-ref-i.h>
18#include <interface/sstring-i.h>
19#include <interface/sxml-i.h>
20#include <stdint.h>
21
22#pragma warning(disable : 4275)
23//////////////////////////////////////////////////////////////////////////
24SNSBEGIN
25
26#define WIDESTR_HELPER(x) L##x
27#define WIDESTR(x) WIDESTR_HELPER(#x)
28
29#ifdef __cplusplus
30#define DEF_OBJ_BASE(clsName, clsType) \
31 static int GetClassType() \
32 { \
33 return clsType; \
34 } \
35 static LPCWSTR GetClassName() \
36 { \
37 return WIDESTR(clsName); \
38 } \
39 static LPCWSTR GetClassAlias() \
40 { \
41 return NULL; \
42 }
43
44#else
45#define DEF_OBJ_BASE(clsName, clsType)
46#endif
47
48// SObject Class Name Declaration
49#define DEF_SOBJECT_EX(baseCls, clsName, clsAlise) \
50 public: \
51 typedef baseCls __baseCls; \
52 static LPCWSTR GetClassName() \
53 { \
54 return clsName; \
55 } \
56 static int GetClassType() \
57 { \
58 return __baseCls::GetClassType(); \
59 } \
60 static LPCWSTR GetClassAlise() \
61 { \
62 return clsAlise; \
63 } \
64 \
65 static LPCWSTR BaseClassName() \
66 { \
67 return __baseCls::GetClassName(); \
68 } \
69 \
70 virtual LPCWSTR WINAPI GetObjectClass() const \
71 { \
72 return clsName; \
73 } \
74 \
75 virtual BOOL WINAPI IsClass(LPCWSTR lpszName) const \
76 { \
77 if (wcscmp(GetClassName(), lpszName) == 0) \
78 return TRUE; \
79 return __baseCls::IsClass(lpszName); \
80 }
81
82#define DEF_SOBJECT(baseCls, clsName) DEF_SOBJECT_EX(baseCls, clsName, NULL)
83
84typedef struct IObject IObject;
85
86typedef HRESULT (*FunAttrHandler)(IObject *pObj, const IStringW *attrName, const IStringW *attrValue, BOOL bLoading);
87
88typedef enum _SObjectType
89{
90 Undef = 0,
91 Window,
92 Skin,
93 Layout,
94 LayoutParam,
95 Event,
96 Interpolator,
97 Animation,
98 ValueAnimator,
99 UserType,
100} SObjectType;
101
102/**
103 * @class SObject
104 * @brief SOUI系统中的对象基类
105 *
106 * Describe 提供类RTTI机制,实现从XML节点中给派生类对象设置属性
107 */
108#undef INTERFACE
109#define INTERFACE IObject
110DECLARE_INTERFACE_(IObject, IObjRef){ DEF_OBJ_BASE(IObject, Undef)
111#include <interface/SobjectApi.h>
112};
113
114#ifdef __cplusplus
115/**
116 * sobj_cast
117 * @brief SOUI Object 的类型安全的类型转换接口
118 * @param SObject * pObj -- 源对象
119 * @return T * -- 转换后的对象
120 * Describe 如果源对象不是待转换对象类型,返回NULL
121 */
122template <class T>
123T *sobj_cast(const IObject *pObj)
124{
125 if (!pObj)
126 return NULL;
127
128 if (pObj->IsClass(T::GetClassName()))
129 return (T *)pObj;
130 else
131 return NULL;
132}
133
134#endif
135
136SNSEND
137
138#endif // __SOBJECT_I__H__
Interface for reference counting.
Definition obj-ref-i.h:19