CCBMemberVariableAssigner.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #ifndef _CCB_CCBMEMBERVARIABLEASSIGNER_H_
  2. #define _CCB_CCBMEMBERVARIABLEASSIGNER_H_
  3. namespace cocosbuilder {
  4. #define CCB_MEMBERVARIABLEASSIGNER_GLUE(TARGET, MEMBERVARIABLENAME, MEMBERVARIABLETYPE, MEMBERVARIABLE) \
  5. if (pTarget == TARGET && 0 == strcmp(pMemberVariableName, (MEMBERVARIABLENAME))) { \
  6. MEMBERVARIABLETYPE pOldVar = MEMBERVARIABLE; \
  7. MEMBERVARIABLE = dynamic_cast<MEMBERVARIABLETYPE>(pNode); \
  8. CC_ASSERT(MEMBERVARIABLE); \
  9. if (pOldVar != MEMBERVARIABLE) { \
  10. CC_SAFE_RELEASE(pOldVar); \
  11. MEMBERVARIABLE->retain(); \
  12. } \
  13. return true; \
  14. }
  15. #define CCB_MEMBERVARIABLEASSIGNER_GLUE_WEAK(TARGET, MEMBERVARIABLENAME, MEMBERVARIABLETYPE, MEMBERVARIABLE) \
  16. if (pTarget == TARGET && 0 == strcmp(pMemberVariableName, MEMBERVARIABLENAME)) { \
  17. MEMBERVARIABLE = dynamic_cast<MEMBERVARIABLETYPE>(pNode); \
  18. CC_ASSERT(MEMBERVARIABLE); \
  19. return true; \
  20. }
  21. class CC_DLL CCBMemberVariableAssigner {
  22. public:
  23. /**
  24. * @js NA
  25. * @lua NA
  26. */
  27. virtual ~CCBMemberVariableAssigner() {};
  28. /**
  29. * The callback function of assigning member variable.
  30. * @note The member variable must be Node or its subclass.
  31. * @param target The custom class.
  32. * @param memberVariableName The name of the member variable.
  33. * @param node The member variable.
  34. * @return Whether the assignment was successful.
  35. */
  36. virtual bool onAssignCCBMemberVariable(cocos2d::Ref* target, const char* memberVariableName, cocos2d::Node* node) = 0;
  37. /**
  38. * The callback function of assigning custom properties.
  39. * @note The member variable must be Integer, Float, Boolean or String.
  40. * @param target The custom class.
  41. * @param memberVariableName The name of the member variable.
  42. * @param value The value of the property.
  43. * @return Whether the assignment was successful.
  44. */
  45. virtual bool onAssignCCBCustomProperty(cocos2d::Ref* target, const char* memberVariableName, const cocos2d::Value& value) { return false; };
  46. };
  47. }
  48. #endif