PageRenderTime 61ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

/cocos2dx/platform/CCPlatformMacros.h

https://github.com/Macarse/cocos2d-x
C Header | 213 lines | 100 code | 36 blank | 77 comment | 18 complexity | 9e488e04970eaf80dd831565b706f98f MD5 | raw file
  1. /****************************************************************************
  2. Copyright (c) 2010 cocos2d-x.org
  3. http://www.cocos2d-x.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #ifndef __CC_PLATFORM_MACROS_H__
  21. #define __CC_PLATFORM_MACROS_H__
  22. /**
  23. * define some platform specific macros
  24. */
  25. #include "ccConfig.h"
  26. #include "CCPlatformConfig.h"
  27. #define MacGLView void
  28. #define NSWindow void
  29. /** @def CC_ENABLE_CACHE_TEXTTURE_DATA
  30. Enable it if you want to cache the texture data.
  31. Basically,it's only enabled in android
  32. It's new in cocos2d-x since v0.99.5
  33. */
  34. #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
  35. #define CC_ENABLE_CACHE_TEXTTURE_DATA 1
  36. #else
  37. #define CC_ENABLE_CACHE_TEXTTURE_DATA 0
  38. #endif
  39. // generic macros
  40. // namespace cocos2d {}
  41. #define NS_CC_BEGIN namespace cocos2d {
  42. #define NS_CC_END }
  43. #define USING_NS_CC using namespace cocos2d
  44. /** CC_PROPERTY_READONLY is used to declare a protected variable.
  45. We can use getter to read the variable.
  46. @param varType : the type of variable.
  47. @param varName : variable name.
  48. @param funName : "get + funName" is the name of the getter.
  49. @warning : The getter is a public virtual function, you should rewrite it first.
  50. The variables and methods declared after CC_PROPERTY_READONLY are all public.
  51. If you need protected or private, please declare.
  52. */
  53. #define CC_PROPERTY_READONLY(varType, varName, funName)\
  54. protected: varType varName;\
  55. public: virtual varType get##funName(void);
  56. #define CC_PROPERTY_READONLY_PASS_BY_REF(varType, varName, funName)\
  57. protected: varType varName;\
  58. public: virtual const varType& get##funName(void);
  59. /** CC_PROPERTY is used to declare a protected variable.
  60. We can use getter to read the variable, and use the setter to change the variable.
  61. @param varType : the type of variable.
  62. @param varName : variable name.
  63. @param funName : "get + funName" is the name of the getter.
  64. "set + funName" is the name of the setter.
  65. @warning : The getter and setter are public virtual functions, you should rewrite them first.
  66. The variables and methods declared after CC_PROPERTY are all public.
  67. If you need protected or private, please declare.
  68. */
  69. #define CC_PROPERTY(varType, varName, funName)\
  70. protected: varType varName;\
  71. public: virtual varType get##funName(void);\
  72. public: virtual void set##funName(varType var);
  73. #define CC_PROPERTY_PASS_BY_REF(varType, varName, funName)\
  74. protected: varType varName;\
  75. public: virtual const varType& get##funName(void);\
  76. public: virtual void set##funName(const varType& var);
  77. /** CC_SYNTHESIZE_READONLY is used to declare a protected variable.
  78. We can use getter to read the variable.
  79. @param varType : the type of variable.
  80. @param varName : variable name.
  81. @param funName : "get + funName" is the name of the getter.
  82. @warning : The getter is a public inline function.
  83. The variables and methods declared after CC_SYNTHESIZE_READONLY are all public.
  84. If you need protected or private, please declare.
  85. */
  86. #define CC_SYNTHESIZE_READONLY(varType, varName, funName)\
  87. protected: varType varName;\
  88. public: inline varType get##funName(void) const { return varName; }
  89. #define CC_SYNTHESIZE_READONLY_PASS_BY_REF(varType, varName, funName)\
  90. protected: varType varName;\
  91. public: inline const varType& get##funName(void) const { return varName; }
  92. /** CC_SYNTHESIZE is used to declare a protected variable.
  93. We can use getter to read the variable, and use the setter to change the variable.
  94. @param varType : the type of variable.
  95. @param varName : variable name.
  96. @param funName : "get + funName" is the name of the getter.
  97. "set + funName" is the name of the setter.
  98. @warning : The getter and setter are public inline functions.
  99. The variables and methods declared after CC_SYNTHESIZE are all public.
  100. If you need protected or private, please declare.
  101. */
  102. #define CC_SYNTHESIZE(varType, varName, funName)\
  103. protected: varType varName;\
  104. public: inline varType get##funName(void) const { return varName; }\
  105. public: inline void set##funName(varType var){ varName = var; }
  106. #define CC_SYNTHESIZE_PASS_BY_REF(varType, varName, funName)\
  107. protected: varType varName;\
  108. public: inline const varType& get##funName(void) const { return varName; }\
  109. public: inline void set##funName(const varType& var){ varName = var; }
  110. #define CC_SAFE_DELETE(p) if(p) { delete p; p = 0; }
  111. #define CC_SAFE_DELETE_ARRAY(p) if(p) { delete[] p; p = 0; }
  112. #define CC_SAFE_FREE(p) if(p) { free(p); p = 0; }
  113. #define CC_SAFE_RELEASE(p) if(p) { p->release(); }
  114. #define CC_SAFE_RELEASE_NULL(p) if(p) { p->release(); p = 0; }
  115. #define CC_SAFE_RETAIN(p) if(p) { p->retain(); }
  116. #define CC_BREAK_IF(cond) if(cond) break;
  117. // cocos2d debug
  118. #if !defined(COCOS2D_DEBUG) || COCOS2D_DEBUG == 0
  119. #define CCLOG(...)
  120. #define CCLOGINFO(...)
  121. #define CCLOGERROR(...)
  122. #elif COCOS2D_DEBUG == 1
  123. #define CCLOG(format, ...) cocos2d::CCLog(format, ##__VA_ARGS__)
  124. #define CCLOGERROR(format,...) cocos2d::CCLog(format, ##__VA_ARGS__)
  125. #define CCLOGINFO(format,...) do {} while (0)
  126. #elif COCOS2D_DEBUG > 1
  127. #define CCLOG(format, ...) cocos2d::CCLog(format, ##__VA_ARGS__)
  128. #define CCLOGERROR(format,...) cocos2d::CCLog(format, ##__VA_ARGS__)
  129. #define CCLOGINFO(format,...) cocos2d::CCLog(format, ##__VA_ARGS__)
  130. #endif // COCOS2D_DEBUG
  131. // shared library declartor
  132. #define CC_DLL
  133. #if (CC_TARGET_PLATFORM != CC_PLATFORM_BADA)
  134. // assertion
  135. #include <assert.h>
  136. #define CC_ASSERT(cond) assert(cond)
  137. #else
  138. // bada platform
  139. #include <FBaseConfig.h>
  140. #include <FBaseSys.h>
  141. #undef CC_DLL
  142. #define CC_DLL _EXPORT_
  143. #include "CCPlatformFunc_bada.h"
  144. #ifdef _DEBUG
  145. #define CC_ASSERT(cond) (void)( (!!(cond)) || (badaAssert(__PRETTY_FUNCTION__ , __LINE__ , #cond),0) )
  146. #else
  147. #define CC_ASSERT(cond) void(0)
  148. #endif /* _DEBUG */
  149. #endif
  150. #define CC_UNUSED_PARAM(unusedparam) (void)unusedparam
  151. #if (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
  152. #undef CC_UNUSED_PARAM
  153. #define CC_UNUSED_PARAM(unusedparam) //unusedparam
  154. #endif
  155. // platform depended macros
  156. #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
  157. #undef CC_DLL
  158. #if defined(_USRDLL)
  159. #define CC_DLL __declspec(dllexport)
  160. #else /* use a DLL library */
  161. #define CC_DLL __declspec(dllimport)
  162. #endif
  163. #endif // CC_PLATFORM_WIN32
  164. #if (CC_TARGET_PLATFORM == CC_PLATFORM_WOPHONE && defined(_TRANZDA_VM_))
  165. #undef CC_DLL
  166. #if defined(SS_MAKEDLL)
  167. #define CC_DLL __declspec(dllexport)
  168. #else /* use a DLL library */
  169. #define CC_DLL __declspec(dllimport)
  170. #endif
  171. #endif // wophone VM
  172. #endif // __CC_PLATFORM_MACROS_H__