17 #ifndef GZ_RENDERING_BASE_BASESTORAGE_HH_
18 #define GZ_RENDERING_BASE_BASESTORAGE_HH_
25 #include <gz/common/Console.hh>
26 #include <gz/utils/SuppressWarning.hh>
34 inline namespace GZ_RENDERING_VERSION_NAMESPACE {
37 template <
class T,
class U>
49 typedef typename UMap::iterator UIter;
51 typedef typename UMap::const_iterator ConstUIter;
57 public:
virtual unsigned int Size()
const;
59 public:
virtual bool ContainsKey(
const std::string &_key)
const;
61 public:
virtual bool ContainsValue(
ConstTPtr _value)
const;
63 GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
66 public:
virtual TPtr GetByIndex(
unsigned int _index)
const;
67 GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
71 public:
virtual void Remove(
const std::string &_key);
73 public:
virtual void Remove(
TPtr _value);
75 public:
virtual void RemoveAll();
79 public:
virtual UPtr DerivedByIndex(
unsigned int _index)
const;
81 protected:
virtual bool IsValidIter(ConstUIter _iter)
const;
87 template <
class T,
class U>
99 typedef typename UStore::iterator UIter;
101 typedef typename UStore::const_iterator ConstUIter;
107 public:
virtual unsigned int Size()
const;
109 public:
virtual bool Contains(
ConstTPtr _object)
const;
111 public:
virtual bool ContainsId(
unsigned int _id)
const;
113 public:
virtual bool ContainsName(
const std::string &_name)
const;
115 public:
virtual TPtr GetById(
unsigned int _id)
const;
119 public:
virtual TPtr GetByIndex(
unsigned int _index)
const;
121 public:
virtual bool Add(
TPtr _object);
123 public:
virtual TPtr Remove(
TPtr _object);
125 public:
virtual TPtr RemoveById(
unsigned int _id);
129 public:
virtual TPtr RemoveByIndex(
unsigned int _index);
131 public:
virtual void RemoveAll();
133 public:
virtual void Destroy(
TPtr _object);
135 public:
virtual void DestroyById(
unsigned int _id);
137 public:
virtual void DestroyByName(
const std::string &_name);
139 public:
virtual void DestroyByIndex(
unsigned int _index);
141 public:
virtual void DestroyAll();
143 public:
virtual UPtr DerivedById(
unsigned int _id)
const;
147 public:
virtual UPtr DerivedByIndex(
unsigned int _index)
const;
149 public:
virtual bool AddDerived(
UPtr _object);
151 public:
virtual UPtr RemoveDerived(
UPtr _object);
153 public:
virtual UPtr RemoveDerivedById(
unsigned int _id);
157 public:
virtual UPtr RemoveDerivedByIndex(
unsigned int _index);
161 public:
virtual UIter Begin();
165 public:
virtual UIter End();
167 protected:
virtual ConstUIter ConstIter(
ConstTPtr _object)
const;
169 protected:
virtual ConstUIter ConstIterById(
unsigned int _id)
const;
171 protected:
virtual ConstUIter ConstIterByName(
174 protected:
virtual ConstUIter ConstIterByIndex(
unsigned int _index)
const;
176 protected:
virtual UIter Iter(
ConstTPtr _object);
178 protected:
virtual UIter IterById(
unsigned int _id);
180 protected:
virtual UIter IterByName(
const std::string &_name);
182 protected:
virtual UIter IterByIndex(
unsigned int _index);
184 protected:
virtual bool AddImpl(
UPtr _object);
186 protected:
virtual UPtr RemoveImpl(UIter _iter);
188 protected:
virtual void DestroyImpl(UIter _iter);
190 protected:
virtual bool IsValidIter(ConstUIter _iter)
const;
192 protected:
virtual UIter RemoveConstness(ConstUIter _iter);
214 typedef typename TStoreList::iterator TStoreIter;
220 public:
virtual unsigned int Size()
const;
222 public:
virtual bool Contains(
ConstTPtr _object)
const;
224 public:
virtual bool ContainsId(
unsigned int _id)
const;
226 public:
virtual bool ContainsName(
const std::string &_name)
const;
228 public:
virtual TPtr GetById(
unsigned int _id)
const;
232 public:
virtual TPtr GetByIndex(
unsigned int _index)
const;
234 public:
virtual bool Add(
TPtr _object);
236 public:
virtual TPtr Remove(
TPtr _object);
238 public:
virtual TPtr RemoveById(
unsigned int _id);
242 public:
virtual TPtr RemoveByIndex(
unsigned int _index);
244 public:
virtual void RemoveAll();
246 public:
virtual void Destroy(
TPtr _object);
248 public:
virtual void DestroyById(
unsigned int _id);
250 public:
virtual void DestroyByName(
const std::string &_name);
252 public:
virtual void DestroyByIndex(
unsigned int _index);
254 public:
virtual void DestroyAll();
256 public:
virtual unsigned int GetStoreCount()
const;
260 public:
virtual TStorePtr GetStore(
unsigned int _index)
const;
262 public:
virtual bool AddStore(
TStorePtr _store);
266 public:
virtual TStorePtr RemoveStore(
unsigned int _index);
268 public:
virtual TStorePtr RemoveStoreImpl(TStoreIter _iter);
270 GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
272 GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
276 template <
class T,
class U>
296 public:
virtual unsigned int Size()
const;
298 public:
virtual bool Contains(
ConstTPtr _object)
const;
300 public:
virtual bool ContainsId(
unsigned int _id)
const;
302 public:
virtual bool ContainsName(
const std::string &_name)
const;
304 public:
virtual TPtr GetById(
unsigned int _id)
const;
308 public:
virtual TPtr GetByIndex(
unsigned int _index)
const;
310 public:
virtual bool Add(
TPtr _object);
312 public:
virtual TPtr Remove(
TPtr _object);
314 public:
virtual TPtr RemoveById(
unsigned int _id);
318 public:
virtual TPtr RemoveByIndex(
unsigned int _index);
320 public:
virtual void RemoveAll();
322 public:
virtual void Destroy(
TPtr _object);
324 public:
virtual void DestroyById(
unsigned int _id);
326 public:
virtual void DestroyByName(
const std::string &_name);
328 public:
virtual void DestroyByIndex(
unsigned int _index);
330 public:
virtual void DestroyAll();
348 class BaseNodeStore :
349 public BaseStore<Node, T>
354 class BaseLightStore :
355 public BaseStore<Light, T>
360 class BaseSensorStore :
361 public BaseStore<Sensor, T>
366 class BaseVisualStore :
367 public BaseStore<Visual, T>
372 class BaseGeometryStore :
373 public BaseStore<Geometry, T>
378 class BaseSubMeshStore :
379 public BaseStore<SubMesh, T>
384 class BaseMaterialMap :
385 public BaseMap<Material, T>
390 template <
class T,
class U>
396 template <
class T,
class U>
402 template <
class T,
class U>
405 return this->map.size();
409 template <
class T,
class U>
412 return this->map.count(_key) > 0;
416 template <
class T,
class U>
419 for (
auto pair : this->map)
421 if (pair.second == _value)
return true;
428 template <
class T,
class U>
432 return this->Derived(_key);
436 template <
class T,
class U>
440 return this->DerivedByIndex(_index);
444 template <
class T,
class U>
459 if (this->ContainsKey(_key))
461 gzerr <<
"Item already registered with key: " << _key <<
std::endl;
465 UPtr derived = std::dynamic_pointer_cast<U>(_value);
469 gzerr <<
"Cannot add item created by another render-engine"
475 this->map[_key] = derived;
480 template <
class T,
class U>
483 auto iter = this->map.find(_key);
485 if (this->IsValidIter(iter))
487 this->map.erase(iter);
492 template <
class T,
class U>
495 auto iter = this->map.begin();
497 while (this->IsValidIter(iter))
499 if (iter->second == _value)
501 this->map.erase(iter);
510 template <
class T,
class U>
517 template <
class T,
class U>
521 auto iter = this->map.find(_key);
522 return (this->IsValidIter(iter)) ? iter->second :
nullptr;
526 template <
class T,
class U>
530 if (_index >= this->Size())
536 auto iter = this->map.begin();
542 template <
class T,
class U>
545 return _iter != this->map.end();
549 template <
class T,
class U>
555 template <
class T,
class U>
561 template <
class T,
class U>
564 return this->store.size();
568 template <
class T,
class U>
569 typename BaseStore<T, U>::UIter
572 return this->store.begin();
576 template <
class T,
class U>
577 typename BaseStore<T, U>::UIter
580 return this->store.end();
584 template <
class T,
class U>
587 auto iter = this->ConstIter(_object);
588 return this->IsValidIter(iter);
592 template <
class T,
class U>
595 auto iter = this->ConstIterById(_id);
596 return this->IsValidIter(iter);
600 template <
class T,
class U>
603 auto iter = this->ConstIterByName(_name);
604 return this->IsValidIter(iter);
608 template <
class T,
class U>
612 return this->DerivedById(_id);
616 template <
class T,
class U>
620 return this->DerivedByName(_name);
624 template <
class T,
class U>
628 return this->DerivedByIndex(_index);
632 template <
class T,
class U>
641 UPtr derived = std::dynamic_pointer_cast<U>(_object);
645 gzerr <<
"Cannot add item created by another render-engine"
651 return this->AddImpl(derived);
655 template <
class T,
class U>
659 auto iter = this->Iter(_object);
660 return this->RemoveImpl(iter);
664 template <
class T,
class U>
668 return this->RemoveDerivedById(_id);
672 template <
class T,
class U>
676 return this->RemoveDerivedByName(_name);
680 template <
class T,
class U>
684 return this->RemoveDerivedByIndex(_index);
688 template <
class T,
class U>
695 template <
class T,
class U>
698 auto iter = this->Iter(_object);
699 this->DestroyImpl(iter);
703 template <
class T,
class U>
706 auto iter = this->IterById(_id);
707 this->DestroyImpl(iter);
711 template <
class T,
class U>
714 auto iter = this->IterByName(_name);
715 this->DestroyImpl(iter);
719 template <
class T,
class U>
722 auto iter = this->IterByIndex(_index);
723 this->DestroyImpl(iter);
727 template <
class T,
class U>
730 unsigned int i = this->Size();
734 this->DestroyByIndex(--i);
739 template <
class T,
class U>
743 auto iter = this->ConstIterById(_id);
744 return (this->IsValidIter(iter)) ? iter->second :
nullptr;
748 template <
class T,
class U>
752 auto iter = this->ConstIterByName(_name);
753 return (this->IsValidIter(iter)) ? iter->second :
nullptr;
757 template <
class T,
class U>
761 auto iter = this->ConstIterByIndex(_index);
762 return (this->IsValidIter(iter)) ? iter->second :
nullptr;
766 template <
class T,
class U>
775 return this->AddImpl(_object);
779 template <
class T,
class U>
783 auto iter = this->Iter(_object);
784 return this->RemoveImpl(iter);
788 template <
class T,
class U>
792 auto iter = this->IterById(_id);
793 return this->RemoveImpl(iter);
797 template <
class T,
class U>
801 auto iter = this->IterByName(_name);
802 return this->RemoveImpl(iter);
806 template <
class T,
class U>
810 auto iter = this->IterByIndex(_index);
811 return this->RemoveImpl(iter);
815 template <
class T,
class U>
816 typename BaseStore<T, U>::ConstUIter
819 auto begin = this->store.begin();
820 auto end = this->store.end();
822 for (
auto iter = begin; iter != end; ++iter)
824 if (iter->second == _object)
834 template <
class T,
class U>
835 typename BaseStore<T, U>::ConstUIter
838 auto begin = this->store.begin();
839 auto end = this->store.end();
841 for (
auto iter = begin; iter != end; ++iter)
843 if (iter->second->Id() == _id)
853 template <
class T,
class U>
854 typename BaseStore<T, U>::ConstUIter
857 return this->store.find(_name);
861 template <
class T,
class U>
862 typename BaseStore<T, U>::ConstUIter
865 if (_index >= this->Size())
868 return this->store.end();
871 auto iter = this->store.begin();
877 template <
class T,
class U>
878 typename BaseStore<T, U>::UIter
881 auto iter = this->ConstIter(_object);
882 return this->RemoveConstness(iter);
886 template <
class T,
class U>
887 typename BaseStore<T, U>::UIter
890 auto iter = this->ConstIterById(_id);
891 return this->RemoveConstness(iter);
895 template <
class T,
class U>
896 typename BaseStore<T, U>::UIter
899 auto iter = this->ConstIterByName(_name);
900 return this->RemoveConstness(iter);
904 template <
class T,
class U>
905 typename BaseStore<T, U>::UIter
908 auto iter = this->ConstIterByIndex(_index);
909 return this->RemoveConstness(iter);
913 template <
class T,
class U>
916 unsigned int id = _object->Id();
919 if (this->ContainsId(
id))
921 gzerr <<
"Another item already exists with id: " <<
id <<
std::endl;
925 if (this->ContainsName(name))
927 gzerr <<
"Another item already exists with name: " << name
932 this->store[name] = _object;
937 template <
class T,
class U>
941 if (!this->IsValidIter(_iter))
946 UPtr result = _iter->second;
947 this->store.erase(_iter);
952 template <
class T,
class U>
955 UPtr result = this->RemoveImpl(_iter);
956 if (result) result->Destroy();
960 template <
class T,
class U>
963 return _iter != this->store.end();
967 template <
class T,
class U>
968 typename BaseStore<T, U>::UIter
971 return (this->IsValidIter(_iter)) ?
972 this->store.erase(_iter, _iter) : this->store.end();
991 unsigned int size = 0;
993 for (
auto store : this->stores)
995 size += store->Size();
1005 for (
auto store : this->stores)
1007 if (store->Contains(_object))
return true;
1017 for (
auto store : this->stores)
1019 if (store->ContainsId(_id))
return true;
1029 for (
auto store : this->stores)
1031 if (store->ContainsName(_name))
return true;
1042 for (
auto store : this->stores)
1044 TPtr object = store->GetById(_id);
1045 if (
object)
return object;
1056 for (
auto store : this->stores)
1058 TPtr object = store->GetByName(_name);
1059 if (
object)
return object;
1070 unsigned int origIndex = _index;
1072 for (
auto store : this->stores)
1074 unsigned int size = store->Size();
1076 return store->GetByIndex(_index);
1088 gzerr <<
"Adding to BaseCompositeStore not supported" <<
std::endl;
1097 TPtr result =
nullptr;
1099 for (
auto store : this->stores)
1101 TPtr temp = store->Remove(_object);
1102 if (!result) result = temp;
1113 TPtr result =
nullptr;
1115 for (
auto store : this->stores)
1117 TPtr temp = store->RemoveById(_id);
1118 if (!result) result = temp;
1129 TPtr result =
nullptr;
1131 for (
auto store : this->stores)
1133 TPtr temp = store->RemoveByName(_name);
1134 if (!result) result = temp;
1145 TPtr result =
nullptr;
1147 for (
auto store : this->stores)
1149 TPtr temp = store->RemoveByIndex(_index);
1150 if (!result) result = temp;
1160 for (
auto store : this->stores)
1170 for (
auto store : this->stores)
1172 if (store->Contains(_object))
1174 store->Destroy(_object);
1184 for (
auto store : this->stores)
1186 store->DestroyById(_id);
1194 for (
auto store : this->stores)
1196 store->DestroyByName(_name);
1204 for (
auto store : this->stores)
1206 store->DestroyByIndex(_index);
1214 for (
auto store : this->stores)
1216 store->DestroyAll();
1224 return this->stores.size();
1231 auto begin = this->stores.begin();
1232 auto end = this->stores.end();
1233 auto iter =
std::find(begin, end, _store);
1242 if (_index >= this->GetStoreCount())
1248 return this->stores[_index];
1261 if (this->ContainsStore(_store))
1267 this->stores.push_back(_store);
1276 auto begin = this->stores.begin();
1277 auto end = this->stores.end();
1278 auto iter =
std::find(begin, end, _store);
1279 return this->RemoveStoreImpl(iter);
1287 if (_index >= this->GetStoreCount())
1293 auto iter = this->stores.begin();
1295 return this->RemoveStoreImpl(iter);
1303 if (_iter == this->stores.end())
1309 this->stores.erase(_iter);
1314 template <
class T,
class U>
1321 template <
class T,
class U>
1327 template <
class T,
class U>
1330 return this->store->Size();
1334 template <
class T,
class U>
1337 ConstUPtr derived = std::dynamic_pointer_cast<const U>(_object);
1338 return this->store->Contains(derived);
1342 template <
class T,
class U>
1345 return this->store->ContainsId(_id);
1349 template <
class T,
class U>
1352 return this->store->ContainsName(_name);
1356 template <
class T,
class U>
1360 return this->store->GetById(_id);
1364 template <
class T,
class U>
1368 return this->store->GetByName(_name);
1372 template <
class T,
class U>
1376 return this->store->GetByIndex(_index);
1380 template <
class T,
class U>
1383 UPtr derived = std::dynamic_pointer_cast<U>(_object);
1384 return this->store->Add(derived);
1388 template <
class T,
class U>
1392 UPtr derived = std::dynamic_pointer_cast<U>(_object);
1393 return this->store->Remove(derived);
1397 template <
class T,
class U>
1401 return this->store->RemoveById(_id);
1405 template <
class T,
class U>
1409 return this->store->RemoveByName(_name);
1413 template <
class T,
class U>
1417 return this->store->RemoveByIndex(_index);
1421 template <
class T,
class U>
1424 this->store->RemoveAll();
1428 template <
class T,
class U>
1431 UPtr derived = std::dynamic_pointer_cast<U>(_object);
1432 this->store->Destroy(derived);
1436 template <
class T,
class U>
1439 this->store->DestroyById(_id);
1443 template <
class T,
class U>
1446 this->store->DestroyByName(_name);
1450 template <
class T,
class U>
1453 this->store->DestroyByIndex(_index);
1457 template <
class T,
class U>
1460 this->store->DestroyAll();