PluginOCMacros.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /****************************************************************************
  2. Copyright (c) 2012-2013 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 __PLUGIN_OC_MACROS_H__
  21. #define __PLUGIN_OC_MACROS_H__
  22. #define return_if_fails(cond) if (!(cond)) return;
  23. #define return_val_if_fails(cond, ret) if(!(cond)) return (ret);
  24. #define CALL_OC_FUNC_WITH_VALIST(retCode) \
  25. std::vector<PluginParam*> allParams; \
  26. if (NULL != param) \
  27. { \
  28. allParams.push_back(param); \
  29. \
  30. va_list argp; \
  31. PluginParam* pArg = NULL; \
  32. va_start( argp, param ); \
  33. while (1) \
  34. { \
  35. pArg = va_arg(argp, PluginParam*); \
  36. if (pArg == NULL) \
  37. break; \
  38. \
  39. allParams.push_back(pArg); \
  40. } \
  41. va_end(argp); \
  42. } \
  43. \
  44. return call##retCode##FuncWithParam(funcName, allParams); \
  45. #define CALL_OC_FUNC(retType, defaultRet, retCode) \
  46. retType ret = defaultRet; \
  47. PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); \
  48. if (NULL == pData) { \
  49. PluginUtilsIOS::outputLog("Can't find OC data for plugin : %s", this->getPluginName()); \
  50. return ret; \
  51. } \
  52. \
  53. size_t nParamNum = params.size(); \
  54. if (0 == nParamNum) \
  55. { \
  56. ret = PluginUtilsIOS::callOC##retCode##FunctionWithName(this, funcName); \
  57. } else \
  58. { \
  59. PluginParam* pRetParam = NULL; \
  60. bool needDel = false; \
  61. if (nParamNum == 1) { \
  62. pRetParam = params[0]; \
  63. } else { \
  64. std::map<std::string, PluginParam*> allParams; \
  65. for (int i = 0; i < nParamNum; i++) \
  66. { \
  67. PluginParam* pArg = params[i]; \
  68. if (pArg == NULL) \
  69. { \
  70. break; \
  71. } \
  72. \
  73. char strKey[8] = { 0 }; \
  74. sprintf(strKey, "Param%d", i + 1); \
  75. allParams[strKey] = pArg; \
  76. } \
  77. \
  78. pRetParam = new PluginParam(allParams); \
  79. needDel = true; \
  80. } \
  81. \
  82. id ocParam = PluginUtilsIOS::getOCObjFromParam(pRetParam); \
  83. ret = PluginUtilsIOS::callOC##retCode##FunctionWithName_oneParam(this, funcName, ocParam); \
  84. \
  85. if (needDel && NULL != pRetParam) { \
  86. delete pRetParam; \
  87. pRetParam = NULL; \
  88. } \
  89. } \
  90. return ret; \
  91. #endif // __PLUGIN_OC_MACROS_H__