REDMemberVariableAssigner.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef _RED_REDMEMBERVARIABLEASSIGNER_H_
  2. #define _RED_REDMEMBERVARIABLEASSIGNER_H_
  3. namespace redream {
  4. #define RED_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 RED_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 REDMemberVariableAssigner {
  22. public:
  23. /**
  24. * @js NA
  25. * @lua NA
  26. */
  27. virtual ~REDMemberVariableAssigner() {};
  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 onAssignREDMemberVariable(cocos2d::Ref* target, const char* memberVariableName, cocos2d::Node* node) = 0;
  37. virtual void onAssignREDMemberVariableWithClass(cocos2d::Ref* target, const char* memberVariableName, cocos2d::Node* node, const std::string className){};
  38. /**
  39. * The callback function of assigning custom properties.
  40. * @note The member variable must be Integer, Float, Boolean or String.
  41. * @param target The custom class.
  42. * @param memberVariableName The name of the member variable.
  43. * @param value The value of the property.
  44. * @return Whether the assignment was successful.
  45. */
  46. virtual bool onAssignREDCustomProperty(cocos2d::Ref* target, const char* memberVariableName, const cocos2d::Value& value) { return false; };
  47. };
  48. }
  49. #endif