Gazebo Rendering

API Reference

9.0.0~pre2
BaseStorage.hh
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Open Source Robotics Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17#ifndef GZ_RENDERING_BASE_BASESTORAGE_HH_
18#define GZ_RENDERING_BASE_BASESTORAGE_HH_
19
20#include <map>
21#include <memory>
22#include <string>
23#include <vector>
24
25#include <gz/common/Console.hh>
26#include <gz/utils/SuppressWarning.hh>
27
29
30namespace gz
31{
32 namespace rendering
33 {
34 inline namespace GZ_RENDERING_VERSION_NAMESPACE {
35 //
37 template <class T, class U>
38 class BaseMap :
39 public Map<T>
40 {
42
44
46
48
49 typedef typename UMap::iterator UIter;
50
51 typedef typename UMap::const_iterator ConstUIter;
52
53 public: BaseMap();
54
55 public: virtual ~BaseMap();
56
57 public: virtual unsigned int Size() const;
58
59 public: virtual bool ContainsKey(const std::string &_key) const;
60
61 public: virtual bool ContainsValue(ConstTPtr _value) const;
62
63 GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
64 public: virtual TPtr Get(const std::string &_key) const;
65
66 public: virtual TPtr GetByIndex(unsigned int _index) const;
67 GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
68
69 public: virtual bool Put(const std::string &_key, TPtr _value);
70
71 public: virtual void Remove(const std::string &_key);
72
73 public: virtual void Remove(TPtr _value);
74
75 public: virtual void RemoveAll();
76
77 public: virtual UPtr Derived(const std::string &_key) const;
78
79 public: virtual UPtr DerivedByIndex(unsigned int _index) const;
80
81 protected: virtual bool IsValidIter(ConstUIter _iter) const;
82
83 protected: UMap map;
84 };
85
87 template <class T, class U>
88 class BaseStore :
89 public Store<T>
90 {
92
94
96
99
100 typedef typename UStore::iterator UIter;
101
102 typedef typename UStore::const_iterator ConstUIter;
103
104 public: BaseStore();
105
106 public: virtual ~BaseStore();
107
108 public: virtual unsigned int Size() const;
109
110 public: virtual bool Contains(ConstTPtr _object) const;
111
112 public: virtual bool ContainsId(unsigned int _id) const;
113
114 public: virtual bool ContainsName(const std::string &_name) const;
115
116 public: virtual TPtr GetById(unsigned int _id) const;
117
118 public: virtual TPtr GetByName(const std::string &_name) const;
119
120 public: virtual TPtr GetByIndex(unsigned int _index) const;
121
122 public: virtual bool Add(TPtr _object);
123
124 public: virtual TPtr Remove(TPtr _object);
125
126 public: virtual TPtr RemoveById(unsigned int _id);
127
128 public: virtual TPtr RemoveByName(const std::string &_name);
129
130 public: virtual TPtr RemoveByIndex(unsigned int _index);
131
132 public: virtual void RemoveAll();
133
134 public: virtual void Destroy(TPtr _object);
135
136 public: virtual void DestroyById(unsigned int _id);
137
138 public: virtual void DestroyByName(const std::string &_name);
139
140 public: virtual void DestroyByIndex(unsigned int _index);
141
142 public: virtual void DestroyAll();
143
144 public: virtual UPtr DerivedById(unsigned int _id) const;
145
146 public: virtual UPtr DerivedByName(const std::string &_name) const;
147
148 public: virtual UPtr DerivedByIndex(unsigned int _index) const;
149
150 public: virtual bool AddDerived(UPtr _object);
151
152 public: virtual UPtr RemoveDerived(UPtr _object);
153
154 public: virtual UPtr RemoveDerivedById(unsigned int _id);
155
156 public: virtual UPtr RemoveDerivedByName(const std::string &_name);
157
158 public: virtual UPtr RemoveDerivedByIndex(unsigned int _index);
159
162 public: virtual UIter Begin();
163
166 public: virtual UIter End();
167
173 protected: virtual ConstUIter ConstIter(ConstTPtr _object) const;
174
180 protected: virtual ConstUIter ConstIterById(unsigned int _id) const;
181
187 protected: virtual ConstUIter ConstIterByName(
188 const std::string &_name) const;
189
195 protected: virtual ConstUIter ConstIterByIndex(unsigned int _index) const;
196
202 protected: virtual UIter Iter(ConstTPtr _object);
203
209 protected: virtual UIter IterById(unsigned int _id);
210
216 protected: virtual UIter IterByName(const std::string &_name);
217
223 protected: virtual UIter IterByIndex(unsigned int _index);
224
225 protected: virtual bool AddImpl(UPtr _object);
226
227 protected: virtual UPtr RemoveImpl(UIter _iter);
228
229 protected: virtual void DestroyImpl(UIter _iter);
230
231 protected: virtual bool IsValidIter(ConstUIter _iter) const;
232
233 protected: virtual UIter RemoveConstness(ConstUIter _iter);
234
235 protected: UStore store;
236 protected: UStoreMap storeMap;
237 };
238
240 template <class T>
242 public CompositeStore<T>
243 {
244 typedef std::shared_ptr<T> TPtr;
245
247
248 typedef Store<T> TStore;
249
251
253
255
256 typedef typename TStoreList::iterator TStoreIter;
257
259
260 public: virtual ~BaseCompositeStore();
261
262 public: virtual unsigned int Size() const;
263
264 public: virtual bool Contains(ConstTPtr _object) const;
265
266 public: virtual bool ContainsId(unsigned int _id) const;
267
268 public: virtual bool ContainsName(const std::string &_name) const;
269
270 public: virtual TPtr GetById(unsigned int _id) const;
271
272 public: virtual TPtr GetByName(const std::string &_name) const;
273
274 public: virtual TPtr GetByIndex(unsigned int _index) const;
275
276 public: virtual bool Add(TPtr _object);
277
278 public: virtual TPtr Remove(TPtr _object);
279
280 public: virtual TPtr RemoveById(unsigned int _id);
281
282 public: virtual TPtr RemoveByName(const std::string &_name);
283
284 public: virtual TPtr RemoveByIndex(unsigned int _index);
285
286 public: virtual void RemoveAll();
287
288 public: virtual void Destroy(TPtr _object);
289
290 public: virtual void DestroyById(unsigned int _id);
291
292 public: virtual void DestroyByName(const std::string &_name);
293
294 public: virtual void DestroyByIndex(unsigned int _index);
295
296 public: virtual void DestroyAll();
297
298 public: virtual unsigned int GetStoreCount() const;
299
300 public: virtual bool ContainsStore(ConstTStorePtr _store) const;
301
302 public: virtual TStorePtr GetStore(unsigned int _index) const;
303
304 public: virtual bool AddStore(TStorePtr _store);
305
306 public: virtual TStorePtr RemoveStore(TStorePtr _store);
307
308 public: virtual TStorePtr RemoveStore(unsigned int _index);
309
310 public: virtual TStorePtr RemoveStoreImpl(TStoreIter _iter);
311
312 GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
313 protected: TStoreList stores;
314 GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
315 };
316
318 template <class T, class U>
320 public StoreWrapper<T, U>
321 {
322 typedef std::shared_ptr<T> TPtr;
323
325
326 typedef std::shared_ptr<U> UPtr;
327
329
330 typedef Store<U> UStore;
331
333
334 public: explicit BaseStoreWrapper(UStorePtr _store);
335
336 public: virtual ~BaseStoreWrapper();
337
338 public: virtual unsigned int Size() const;
339
340 public: virtual bool Contains(ConstTPtr _object) const;
341
342 public: virtual bool ContainsId(unsigned int _id) const;
343
344 public: virtual bool ContainsName(const std::string &_name) const;
345
346 public: virtual TPtr GetById(unsigned int _id) const;
347
348 public: virtual TPtr GetByName(const std::string &_name) const;
349
350 public: virtual TPtr GetByIndex(unsigned int _index) const;
351
352 public: virtual bool Add(TPtr _object);
353
354 public: virtual TPtr Remove(TPtr _object);
355
356 public: virtual TPtr RemoveById(unsigned int _id);
357
358 public: virtual TPtr RemoveByName(const std::string &_name);
359
360 public: virtual TPtr RemoveByIndex(unsigned int _index);
361
362 public: virtual void RemoveAll();
363
364 public: virtual void Destroy(TPtr _object);
365
366 public: virtual void DestroyById(unsigned int _id);
367
368 public: virtual void DestroyByName(const std::string &_name);
369
370 public: virtual void DestroyByIndex(unsigned int _index);
371
372 public: virtual void DestroyAll();
373
374 protected: UStorePtr store;
375 };
376
379 public BaseCompositeStore<Node>
380 {
381 };
382
383 template <class T>
385 public BaseStore<Scene, T>
386 {
387 };
388
389 template <class T>
391 public BaseStore<Node, T>
392 {
393 };
394
395 template <class T>
397 public BaseStore<Light, T>
398 {
399 };
400
401 template <class T>
403 public BaseStore<Sensor, T>
404 {
405 };
406
407 template <class T>
409 public BaseStore<Visual, T>
410 {
411 };
412
413 template <class T>
415 public BaseStore<Geometry, T>
416 {
417 };
418
419 template <class T>
421 public BaseStore<SubMesh, T>
422 {
423 };
424
425 template <class T>
427 public BaseMap<Material, T>
428 {
429 };
430
432 template <class T, class U>
436
438 template <class T, class U>
442
444 template <class T, class U>
445 unsigned int BaseMap<T, U>::Size() const
446 {
447 return this->map.size();
448 }
449
451 template <class T, class U>
453 {
454 return this->map.count(_key) > 0;
455 }
456
458 template <class T, class U>
460 {
461 for (auto pair : this->map)
462 {
463 if (pair.second == _value) return true;
464 }
465
466 return false;
467 }
468
470 template <class T, class U>
471 typename BaseMap<T, U>::TPtr
473 {
474 return this->Derived(_key);
475 }
476
478 template <class T, class U>
479 typename BaseMap<T, U>::TPtr
480 BaseMap<T, U>::GetByIndex(unsigned int _index) const
481 {
482 return this->DerivedByIndex(_index);
483 }
484
486 template <class T, class U>
487 bool BaseMap<T, U>::Put(const std::string &_key, TPtr _value)
488 {
489 if (_key.empty())
490 {
491 gzerr << "Cannot store item with empty key" << std::endl;
492 return false;
493 }
494
495 if (!_value)
496 {
497 gzerr << "Cannot store null pointer value" << std::endl;
498 return false;
499 }
500
501 if (this->ContainsKey(_key))
502 {
503 gzerr << "Item already registered with key: " << _key << std::endl;
504 return false;
505 }
506
507 UPtr derived = std::dynamic_pointer_cast<U>(_value);
508
509 if (!derived)
510 {
511 gzerr << "Cannot add item created by another render-engine"
512 << std::endl;
513
514 return false;
515 }
516
517 this->map[_key] = derived;
518 return true;
519 }
520
522 template <class T, class U>
524 {
525 auto iter = this->map.find(_key);
526
527 if (this->IsValidIter(iter))
528 {
529 this->map.erase(iter);
530 }
531 }
532
534 template <class T, class U>
536 {
537 auto iter = this->map.begin();
538
539 while (this->IsValidIter(iter))
540 {
541 if (iter->second == _value)
542 {
543 this->map.erase(iter);
544 continue;
545 }
546
547 ++iter;
548 }
549 }
550
552 template <class T, class U>
554 {
555 this->map.clear();
556 }
557
559 template <class T, class U>
560 typename BaseMap<T, U>::UPtr
562 {
563 auto iter = this->map.find(_key);
564 return (this->IsValidIter(iter)) ? iter->second : nullptr;
565 }
566
568 template <class T, class U>
569 typename BaseMap<T, U>::UPtr
570 BaseMap<T, U>::DerivedByIndex(unsigned int _index) const
571 {
572 if (_index >= this->Size())
573 {
574 gzerr << "Invalid index: " << _index << std::endl;
575 return nullptr;
576 }
577
578 auto iter = this->map.begin();
579 std::advance(iter, _index);
580 return iter->second;
581 }
582
584 template <class T, class U>
585 bool BaseMap<T, U>::IsValidIter(ConstUIter _iter) const
586 {
587 return _iter != this->map.end();
588 }
589
591 template <class T, class U>
595
597 template <class T, class U>
601
603 template <class T, class U>
604 unsigned int BaseStore<T, U>::Size() const
605 {
606 return this->store.size();
607 }
608
610 template <class T, class U>
611 typename BaseStore<T, U>::UIter
613 {
614 return this->store.begin();
615 }
616
618 template <class T, class U>
619 typename BaseStore<T, U>::UIter
621 {
622 return this->store.end();
623 }
624
626 template <class T, class U>
628 {
629 auto iter = this->ConstIter(_object);
630 return this->IsValidIter(iter);
631 }
632
634 template <class T, class U>
635 bool BaseStore<T, U>::ContainsId(unsigned int _id) const
636 {
637 auto iter = this->ConstIterById(_id);
638 return this->IsValidIter(iter);
639 }
640
642 template <class T, class U>
644 {
645 auto iter = this->ConstIterByName(_name);
646 return this->IsValidIter(iter);
647 }
648
650 template <class T, class U>
651 typename BaseStore<T, U>::TPtr
652 BaseStore<T, U>::GetById(unsigned int _id) const
653 {
654 return this->DerivedById(_id);
655 }
656
658 template <class T, class U>
659 typename BaseStore<T, U>::TPtr
661 {
662 return this->DerivedByName(_name);
663 }
664
666 template <class T, class U>
667 typename BaseStore<T, U>::TPtr
668 BaseStore<T, U>::GetByIndex(unsigned int _index) const
669 {
670 return this->DerivedByIndex(_index);
671 }
672
674 template <class T, class U>
676 {
677 if (!_object)
678 {
679 gzerr << "Cannot add null pointer" << std::endl;
680 return false;
681 }
682
683 UPtr derived = std::dynamic_pointer_cast<U>(_object);
684
685 if (!derived)
686 {
687 gzerr << "Cannot add item created by another render-engine"
688 << std::endl;
689
690 return false;
691 }
692
693 return this->AddImpl(derived);
694 }
695
697 template <class T, class U>
698 typename BaseStore<T, U>::TPtr
700 {
701 auto iter = this->Iter(_object);
702 return this->RemoveImpl(iter);
703 }
704
706 template <class T, class U>
707 typename BaseStore<T, U>::TPtr
709 {
710 return this->RemoveDerivedById(_id);
711 }
712
714 template <class T, class U>
715 typename BaseStore<T, U>::TPtr
717 {
718 return this->RemoveDerivedByName(_name);
719 }
720
722 template <class T, class U>
723 typename BaseStore<T, U>::TPtr
725 {
726 return this->RemoveDerivedByIndex(_index);
727 }
728
730 template <class T, class U>
732 {
733 this->store.clear();
734 this->storeMap.clear();
735 }
736
738 template <class T, class U>
740 {
741 auto iter = this->Iter(_object);
742 this->DestroyImpl(iter);
743 }
744
746 template <class T, class U>
747 void BaseStore<T, U>::DestroyById(unsigned int _id)
748 {
749 auto iter = this->IterById(_id);
750 this->DestroyImpl(iter);
751 }
752
754 template <class T, class U>
756 {
757 auto iter = this->IterByName(_name);
758 this->DestroyImpl(iter);
759 }
760
762 template <class T, class U>
763 void BaseStore<T, U>::DestroyByIndex(unsigned int _index)
764 {
765 auto iter = this->IterByIndex(_index);
766 this->DestroyImpl(iter);
767 }
768
770 template <class T, class U>
772 {
773 unsigned int i = this->Size();
774
775 while (i > 0)
776 {
777 this->DestroyByIndex(--i);
778 }
779 }
780
782 template <class T, class U>
783 typename BaseStore<T, U>::UPtr
784 BaseStore<T, U>::DerivedById(unsigned int _id) const
785 {
786 auto iter = this->ConstIterById(_id);
787 return (this->IsValidIter(iter)) ? *iter : nullptr;
788 }
789
791 template <class T, class U>
792 typename BaseStore<T, U>::UPtr
794 {
795 auto iter = this->ConstIterByName(_name);
796 return (this->IsValidIter(iter)) ? *iter : nullptr;
797 }
798
800 template <class T, class U>
801 typename BaseStore<T, U>::UPtr
802 BaseStore<T, U>::DerivedByIndex(unsigned int _index) const
803 {
804 auto iter = this->ConstIterByIndex(_index);
805 return (this->IsValidIter(iter)) ? *iter : nullptr;
806 }
807
809 template <class T, class U>
811 {
812 if (!_object)
813 {
814 gzerr << "Cannot add null pointer" << std::endl;
815 return false;
816 }
817
818 return this->AddImpl(_object);
819 }
820
822 template <class T, class U>
823 typename BaseStore<T, U>::UPtr
825 {
826 auto iter = this->Iter(_object);
827 return this->RemoveImpl(iter);
828 }
829
831 template <class T, class U>
832 typename BaseStore<T, U>::UPtr
834 {
835 auto iter = this->IterById(_id);
836 return this->RemoveImpl(iter);
837 }
838
840 template <class T, class U>
841 typename BaseStore<T, U>::UPtr
843 {
844 auto iter = this->IterByName(_name);
845 return this->RemoveImpl(iter);
846 }
847
849 template <class T, class U>
850 typename BaseStore<T, U>::UPtr
852 {
853 auto iter = this->IterByIndex(_index);
854 return this->RemoveImpl(iter);
855 }
856
858 template <class T, class U>
859 typename BaseStore<T, U>::ConstUIter
861 {
862 auto begin = this->store.begin();
863 auto end = this->store.end();
864
865 for (auto iter = begin; iter != end; ++iter)
866 {
867 if (*iter == _object)
868 {
869 return iter;
870 }
871 }
872
873 return end;
874 }
875
877 template <class T, class U>
878 typename BaseStore<T, U>::ConstUIter
879 BaseStore<T, U>::ConstIterById(unsigned int _id) const
880 {
881 auto begin = this->store.begin();
882 auto end = this->store.end();
883
884 for (auto iter = begin; iter != end; ++iter)
885 {
886 if ((*iter)->Id() == _id)
887 {
888 return iter;
889 }
890 }
891
892 return end;
893 }
894
896 template <class T, class U>
897 typename BaseStore<T, U>::ConstUIter
899 {
900 auto idx = this->storeMap.find(_name);
901 if (idx == this->storeMap.end())
902 {
903 return this->store.end();
904 }
905 return ConstIterByIndex(idx->second);
906 }
907
909 template <class T, class U>
910 typename BaseStore<T, U>::ConstUIter
911 BaseStore<T, U>::ConstIterByIndex(unsigned int _index) const
912 {
913 if (_index >= this->Size())
914 {
915 gzerr << "Invalid index: " << _index << std::endl;
916 return this->store.end();
917 }
918
919 auto iter = this->store.begin();
920 std::advance(iter, _index);
921 return iter;
922 }
923
925 template <class T, class U>
926 typename BaseStore<T, U>::UIter
928 {
929 auto iter = this->ConstIter(_object);
930 return this->RemoveConstness(iter);
931 }
932
934 template <class T, class U>
935 typename BaseStore<T, U>::UIter
937 {
938 auto iter = this->ConstIterById(_id);
939 return this->RemoveConstness(iter);
940 }
941
943 template <class T, class U>
944 typename BaseStore<T, U>::UIter
946 {
947 auto iter = this->ConstIterByName(_name);
948 return this->RemoveConstness(iter);
949 }
950
952 template <class T, class U>
953 typename BaseStore<T, U>::UIter
954 BaseStore<T, U>::IterByIndex(unsigned int _index)
955 {
956 auto iter = this->ConstIterByIndex(_index);
957 return this->RemoveConstness(iter);
958 }
959
961 template <class T, class U>
963 {
964 unsigned int id = _object->Id();
965 std::string name = _object->Name();
966
967 if (this->ContainsId(id))
968 {
969 gzerr << "Another item already exists with id: " << id << std::endl;
970 return false;
971 }
972
973 if (this->ContainsName(name))
974 {
975 gzerr << "Another item already exists with name: " << name
976 << std::endl;
977 return false;
978 }
979
980 this->storeMap[name] = this->store.size();
981 this->store.emplace_back(_object);
982 return true;
983 }
984
986 template <class T, class U>
987 typename BaseStore<T, U>::UPtr
989 {
990 if (!this->IsValidIter(_iter))
991 {
992 return nullptr;
993 }
994
995
996 auto idx = std::distance(this->store.begin(), _iter);
997 std::string nameToErase;
998 for (auto &[name, objIdx] : this->storeMap)
999 {
1000 if (objIdx == idx)
1001 nameToErase = name;
1002
1003 if (objIdx >= idx)
1004 objIdx--;
1005 }
1006 this->storeMap.erase(nameToErase);
1007
1008 UPtr result = *_iter;
1009 this->store.erase(_iter);
1010 return result;
1011 }
1012
1014 template <class T, class U>
1016 {
1017 UPtr result = this->RemoveImpl(_iter);
1018 if (result) result->Destroy();
1019 }
1020
1022 template <class T, class U>
1023 bool BaseStore<T, U>::IsValidIter(ConstUIter _iter) const
1024 {
1025 return _iter != this->store.end();
1026 }
1027
1029 template <class T, class U>
1030 typename BaseStore<T, U>::UIter
1032 {
1033 return (this->IsValidIter(_iter)) ?
1034 this->store.erase(_iter, _iter) : this->store.end();
1035 }
1036
1038 template <class T>
1042
1044 template <class T>
1048
1050 template <class T>
1051 unsigned int BaseCompositeStore<T>::Size() const
1052 {
1053 unsigned int size = 0;
1054
1055 for (auto store : this->stores)
1056 {
1057 size += store->Size();
1058 }
1059
1060 return size;
1061 }
1062
1064 template <class T>
1066 {
1067 for (auto store : this->stores)
1068 {
1069 if (store->Contains(_object)) return true;
1070 }
1071
1072 return false;
1073 }
1074
1076 template <class T>
1077 bool BaseCompositeStore<T>::ContainsId(unsigned int _id) const
1078 {
1079 for (auto store : this->stores)
1080 {
1081 if (store->ContainsId(_id)) return true;
1082 }
1083
1084 return false;
1085 }
1086
1088 template <class T>
1090 {
1091 for (auto store : this->stores)
1092 {
1093 if (store->ContainsName(_name)) return true;
1094 }
1095
1096 return false;
1097 }
1098
1100 template <class T>
1102 BaseCompositeStore<T>::GetById(unsigned int _id) const
1103 {
1104 for (auto store : this->stores)
1105 {
1106 TPtr object = store->GetById(_id);
1107 if (object) return object;
1108 }
1109
1110 return nullptr;
1111 }
1112
1114 template <class T>
1117 {
1118 for (auto store : this->stores)
1119 {
1120 TPtr object = store->GetByName(_name);
1121 if (object) return object;
1122 }
1123
1124 return nullptr;
1125 }
1126
1128 template <class T>
1130 BaseCompositeStore<T>::GetByIndex(unsigned int _index) const
1131 {
1132 unsigned int origIndex = _index;
1133
1134 for (auto store : this->stores)
1135 {
1136 unsigned int size = store->Size();
1137 if (_index < size)
1138 return store->GetByIndex(_index);
1139 _index -= size;
1140 }
1141
1142 gzerr << "Invalid index: " << origIndex << std::endl;
1143 return nullptr;
1144 }
1145
1147 template <class T>
1149 {
1150 gzerr << "Adding to BaseCompositeStore not supported" << std::endl;
1151 return false;
1152 }
1153
1155 template <class T>
1158 {
1159 TPtr result = nullptr;
1160
1161 for (auto store : this->stores)
1162 {
1163 TPtr temp = store->Remove(_object);
1164 if (!result) result = temp;
1165 }
1166
1167 return result;
1168 }
1169
1171 template <class T>
1174 {
1175 TPtr result = nullptr;
1176
1177 for (auto store : this->stores)
1178 {
1179 TPtr temp = store->RemoveById(_id);
1180 if (!result) result = temp;
1181 }
1182
1183 return result;
1184 }
1185
1187 template <class T>
1190 {
1191 TPtr result = nullptr;
1192
1193 for (auto store : this->stores)
1194 {
1195 TPtr temp = store->RemoveByName(_name);
1196 if (!result) result = temp;
1197 }
1198
1199 return result;
1200 }
1201
1203 template <class T>
1206 {
1207 TPtr result = nullptr;
1208
1209 for (auto store : this->stores)
1210 {
1211 TPtr temp = store->RemoveByIndex(_index);
1212 if (!result) result = temp;
1213 }
1214
1215 return result;
1216 }
1217
1219 template <class T>
1221 {
1222 for (auto store : this->stores)
1223 {
1224 store->RemoveAll();
1225 }
1226 }
1227
1229 template <class T>
1231 {
1232 for (auto store : this->stores)
1233 {
1234 if (store->Contains(_object))
1235 {
1236 store->Destroy(_object);
1237 return;
1238 }
1239 }
1240 }
1241
1243 template <class T>
1245 {
1246 for (auto store : this->stores)
1247 {
1248 store->DestroyById(_id);
1249 }
1250 }
1251
1253 template <class T>
1255 {
1256 for (auto store : this->stores)
1257 {
1258 store->DestroyByName(_name);
1259 }
1260 }
1261
1263 template <class T>
1265 {
1266 for (auto store : this->stores)
1267 {
1268 store->DestroyByIndex(_index);
1269 }
1270 }
1271
1273 template <class T>
1275 {
1276 for (auto store : this->stores)
1277 {
1278 store->DestroyAll();
1279 }
1280 }
1281
1283 template <class T>
1285 {
1286 return this->stores.size();
1287 }
1288
1290 template <class T>
1292 {
1293 auto begin = this->stores.begin();
1294 auto end = this->stores.end();
1295 auto iter = std::find(begin, end, _store);
1296 return iter != end;
1297 }
1298
1300 template <class T>
1302 BaseCompositeStore<T>::GetStore(unsigned int _index) const
1303 {
1304 if (_index >= this->GetStoreCount())
1305 {
1306 gzerr << "Invalid store index: " << _index << std::endl;
1307 return nullptr;
1308 }
1309
1310 return this->stores[_index];
1311 }
1312
1314 template <class T>
1316 {
1317 if (!_store)
1318 {
1319 gzerr << "Cannot all null store pointer" << std::endl;
1320 return false;
1321 }
1322
1323 if (this->ContainsStore(_store))
1324 {
1325 gzerr << "Store has already been added" << std::endl;
1326 return false;
1327 }
1328
1329 this->stores.push_back(_store);
1330 return true;
1331 }
1332
1334 template <class T>
1337 {
1338 auto begin = this->stores.begin();
1339 auto end = this->stores.end();
1340 auto iter = std::find(begin, end, _store);
1341 return this->RemoveStoreImpl(iter);
1342 }
1343
1345 template <class T>
1348 {
1349 if (_index >= this->GetStoreCount())
1350 {
1351 gzerr << "Invalid store index: " << _index << std::endl;
1352 return nullptr;
1353 }
1354
1355 auto iter = this->stores.begin();
1356 std::advance(iter, _index);
1357 return this->RemoveStoreImpl(iter);
1358 }
1359
1361 template <class T>
1364 {
1365 if (_iter == this->stores.end())
1366 {
1367 return nullptr;
1368 }
1369
1370 TStorePtr result = *_iter;
1371 this->stores.erase(_iter);
1372 return result;
1373 }
1374
1376 template <class T, class U>
1378 store(_store)
1379 {
1380 }
1381
1383 template <class T, class U>
1387
1389 template <class T, class U>
1390 unsigned int BaseStoreWrapper<T, U>::Size() const
1391 {
1392 return this->store->Size();
1393 }
1394
1396 template <class T, class U>
1398 {
1400 return this->store->Contains(derived);
1401 }
1402
1404 template <class T, class U>
1405 bool BaseStoreWrapper<T, U>::ContainsId(unsigned int _id) const
1406 {
1407 return this->store->ContainsId(_id);
1408 }
1409
1411 template <class T, class U>
1413 {
1414 return this->store->ContainsName(_name);
1415 }
1416
1418 template <class T, class U>
1420 BaseStoreWrapper<T, U>::GetById(unsigned int _id) const
1421 {
1422 return this->store->GetById(_id);
1423 }
1424
1426 template <class T, class U>
1429 {
1430 return this->store->GetByName(_name);
1431 }
1432
1434 template <class T, class U>
1436 BaseStoreWrapper<T, U>::GetByIndex(unsigned int _index) const
1437 {
1438 return this->store->GetByIndex(_index);
1439 }
1440
1442 template <class T, class U>
1444 {
1445 UPtr derived = std::dynamic_pointer_cast<U>(_object);
1446 return this->store->Add(derived);
1447 }
1448
1450 template <class T, class U>
1453 {
1454 UPtr derived = std::dynamic_pointer_cast<U>(_object);
1455 return this->store->Remove(derived);
1456 }
1457
1459 template <class T, class U>
1462 {
1463 return this->store->RemoveById(_id);
1464 }
1465
1467 template <class T, class U>
1470 {
1471 return this->store->RemoveByName(_name);
1472 }
1473
1475 template <class T, class U>
1478 {
1479 return this->store->RemoveByIndex(_index);
1480 }
1481
1483 template <class T, class U>
1485 {
1486 this->store->RemoveAll();
1487 }
1488
1490 template <class T, class U>
1492 {
1493 UPtr derived = std::dynamic_pointer_cast<U>(_object);
1494 this->store->Destroy(derived);
1495 }
1496
1498 template <class T, class U>
1500 {
1501 this->store->DestroyById(_id);
1502 }
1503
1505 template <class T, class U>
1507 {
1508 this->store->DestroyByName(_name);
1509 }
1510
1512 template <class T, class U>
1514 {
1515 this->store->DestroyByIndex(_index);
1516 }
1517
1519 template <class T, class U>
1521 {
1522 this->store->DestroyAll();
1523 }
1524 }
1525 }
1526}
1527#endif