1
0

CCSet.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /****************************************************************************
  2. Copyright (c) 2010-2012 cocos2d-x.org
  3. Copyright (c) 2013-2017 Chukong Technologies
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #ifndef __CC_SET_H__
  22. #define __CC_SET_H__
  23. /// @cond DO_NOT_SHOW
  24. #include <set>
  25. #include "base/CCRef.h"
  26. #include "base/CCDataVisitor.h"
  27. NS_CC_BEGIN
  28. /**
  29. * @addtogroup data_structures
  30. * @{
  31. */
  32. typedef std::set<Ref *>::iterator __SetIterator;
  33. class CC_DLL __Set : public Ref
  34. {
  35. public:
  36. /**
  37. * @js ctor
  38. */
  39. __Set(void);
  40. __Set(const __Set &rSetObject);
  41. /**
  42. * @js NA
  43. * @lua NA
  44. */
  45. virtual ~__Set(void);
  46. /**
  47. * @brief Create and return a new empty set.
  48. */
  49. static __Set * create();
  50. /**
  51. *@brief Return a copy of the Set, it will copy all the elements.
  52. */
  53. __Set* copy();
  54. /**
  55. *@brief It is the same as copy().
  56. */
  57. __Set* mutableCopy();
  58. /**
  59. *@brief Return the number of elements the Set contains.
  60. */
  61. int count();
  62. /**
  63. *@brief Add a element into Set, it will retain the element.
  64. */
  65. void addObject(Ref *pObject);
  66. /**
  67. *@brief Remove the given element, nothing todo if no element equals pObject.
  68. */
  69. void removeObject(Ref *pObject);
  70. /**
  71. *@brief Remove all elements of the set
  72. */
  73. void removeAllObjects();
  74. /**
  75. *@brief Check if Set contains a element equals pObject.
  76. */
  77. bool containsObject(Ref *pObject);
  78. /**
  79. *@brief Return the iterator that points to the first element.
  80. * @js NA
  81. * @lua NA
  82. */
  83. __SetIterator begin();
  84. /**
  85. *@brief Return the iterator that points to the position after the last element.
  86. * @js NA
  87. * @lua NA
  88. */
  89. __SetIterator end();
  90. /**
  91. *@brief Return the first element if it contains elements, or null if it doesn't contain any element.
  92. */
  93. Ref* anyObject();
  94. /**
  95. * @js NA
  96. * @lua NA
  97. */
  98. virtual void acceptVisitor(DataVisitor &visitor);
  99. private:
  100. std::set<Ref *> *_set;
  101. };
  102. // end of data_structure group
  103. /// @}
  104. NS_CC_END
  105. /// @endcond
  106. #endif // __CC_SET_H__