group.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #if defined(Hiro_Group)
  2. auto mGroup::allocate() -> pObject* {
  3. return new pGroup(*this);
  4. }
  5. //
  6. auto mGroup::append(sObject object) -> type& {
  7. if(auto group = instance.acquire()) {
  8. state.objects.append(object);
  9. object->setGroup(group);
  10. }
  11. return *this;
  12. }
  13. auto mGroup::object(unsigned position) const -> Object {
  14. if(position < objectCount()) {
  15. if(auto object = state.objects[position].acquire()) {
  16. return object;
  17. }
  18. }
  19. return {};
  20. }
  21. auto mGroup::objectCount() const -> unsigned {
  22. return state.objects.size();
  23. }
  24. auto mGroup::objects() const -> vector<Object> {
  25. vector<Object> objects;
  26. for(auto& weak : state.objects) {
  27. if(auto object = weak.acquire()) objects.append(object);
  28. }
  29. return objects;
  30. }
  31. auto mGroup::remove(sObject object) -> type& {
  32. object->setGroup();
  33. for(auto offset : range(state.objects.size())) {
  34. if(auto shared = state.objects[offset].acquire()) {
  35. if(object == shared) {
  36. state.objects.remove(offset);
  37. break;
  38. }
  39. }
  40. }
  41. return *this;
  42. }
  43. #endif