Gazebo Rendering

API Reference

6.6.3
gz/rendering/base/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/common/SuppressWarning.hh>
27 
28 #include "gz/rendering/Storage.hh"
29 
30 namespace ignition
31 {
32  namespace rendering
33  {
34  inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
35  //
37  template <class T, class U>
38  class BaseMap :
39  public Map<T>
40  {
41  typedef std::shared_ptr<T> TPtr;
42 
44 
45  typedef std::shared_ptr<U> UPtr;
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 
64  public: virtual TPtr Get(const std::string &_key) const;
65 
66  public: virtual TPtr GetByIndex(unsigned int _index) const;
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  {
91  typedef std::shared_ptr<T> TPtr;
92 
94 
95  typedef std::shared_ptr<U> UPtr;
96 
98 
99  typedef typename UStore::iterator UIter;
100 
101  typedef typename UStore::const_iterator ConstUIter;
102 
103  public: BaseStore();
104 
105  public: virtual ~BaseStore();
106 
107  public: virtual unsigned int Size() const;
108 
109  public: virtual bool Contains(ConstTPtr _object) const;
110 
111  public: virtual bool ContainsId(unsigned int _id) const;
112 
113  public: virtual bool ContainsName(const std::string &_name) const;
114 
115  public: virtual TPtr GetById(unsigned int _id) const;
116 
117  public: virtual TPtr GetByName(const std::string &_name) const;
118 
119  public: virtual TPtr GetByIndex(unsigned int _index) const;
120 
121  public: virtual bool Add(TPtr _object);
122 
123  public: virtual TPtr Remove(TPtr _object);
124 
125  public: virtual TPtr RemoveById(unsigned int _id);
126 
127  public: virtual TPtr RemoveByName(const std::string &_name);
128 
129  public: virtual TPtr RemoveByIndex(unsigned int _index);
130 
131  public: virtual void RemoveAll();
132 
133  public: virtual void Destroy(TPtr _object);
134 
135  public: virtual void DestroyById(unsigned int _id);
136 
137  public: virtual void DestroyByName(const std::string &_name);
138 
139  public: virtual void DestroyByIndex(unsigned int _index);
140 
141  public: virtual void DestroyAll();
142 
143  public: virtual UPtr DerivedById(unsigned int _id) const;
144 
145  public: virtual UPtr DerivedByName(const std::string &_name) const;
146 
147  public: virtual UPtr DerivedByIndex(unsigned int _index) const;
148 
149  public: virtual bool AddDerived(UPtr _object);
150 
151  public: virtual UPtr RemoveDerived(UPtr _object);
152 
153  public: virtual UPtr RemoveDerivedById(unsigned int _id);
154 
155  public: virtual UPtr RemoveDerivedByName(const std::string &_name);
156 
157  public: virtual UPtr RemoveDerivedByIndex(unsigned int _index);
158 
161  public: virtual UIter Begin();
162 
165  public: virtual UIter End();
166 
167  protected: virtual ConstUIter ConstIter(ConstTPtr _object) const;
168 
169  protected: virtual ConstUIter ConstIterById(unsigned int _id) const;
170 
171  protected: virtual ConstUIter ConstIterByName(
172  const std::string &_name) const;
173 
174  protected: virtual ConstUIter ConstIterByIndex(unsigned int _index) const;
175 
176  protected: virtual UIter Iter(ConstTPtr _object);
177 
178  protected: virtual UIter IterById(unsigned int _id);
179 
180  protected: virtual UIter IterByName(const std::string &_name);
181 
182  protected: virtual UIter IterByIndex(unsigned int _index);
183 
184  protected: virtual bool AddImpl(UPtr _object);
185 
186  protected: virtual UPtr RemoveImpl(UIter _iter);
187 
188  protected: virtual void DestroyImpl(UIter _iter);
189 
190  protected: virtual bool IsValidIter(ConstUIter _iter) const;
191 
192  protected: virtual UIter RemoveConstness(ConstUIter _iter);
193 
194  protected: UStore store;
195  };
196 
198  template <class T>
200  public CompositeStore<T>
201  {
202  typedef std::shared_ptr<T> TPtr;
203 
205 
206  typedef Store<T> TStore;
207 
209 
211 
213 
214  typedef typename TStoreList::iterator TStoreIter;
215 
216  public: BaseCompositeStore();
217 
218  public: virtual ~BaseCompositeStore();
219 
220  public: virtual unsigned int Size() const;
221 
222  public: virtual bool Contains(ConstTPtr _object) const;
223 
224  public: virtual bool ContainsId(unsigned int _id) const;
225 
226  public: virtual bool ContainsName(const std::string &_name) const;
227 
228  public: virtual TPtr GetById(unsigned int _id) const;
229 
230  public: virtual TPtr GetByName(const std::string &_name) const;
231 
232  public: virtual TPtr GetByIndex(unsigned int _index) const;
233 
234  public: virtual bool Add(TPtr _object);
235 
236  public: virtual TPtr Remove(TPtr _object);
237 
238  public: virtual TPtr RemoveById(unsigned int _id);
239 
240  public: virtual TPtr RemoveByName(const std::string &_name);
241 
242  public: virtual TPtr RemoveByIndex(unsigned int _index);
243 
244  public: virtual void RemoveAll();
245 
246  public: virtual void Destroy(TPtr _object);
247 
248  public: virtual void DestroyById(unsigned int _id);
249 
250  public: virtual void DestroyByName(const std::string &_name);
251 
252  public: virtual void DestroyByIndex(unsigned int _index);
253 
254  public: virtual void DestroyAll();
255 
256  public: virtual unsigned int GetStoreCount() const;
257 
258  public: virtual bool ContainsStore(ConstTStorePtr _store) const;
259 
260  public: virtual TStorePtr GetStore(unsigned int _index) const;
261 
262  public: virtual bool AddStore(TStorePtr _store);
263 
264  public: virtual TStorePtr RemoveStore(TStorePtr _store);
265 
266  public: virtual TStorePtr RemoveStore(unsigned int _index);
267 
268  public: virtual TStorePtr RemoveStoreImpl(TStoreIter _iter);
269 
271  protected: TStoreList stores;
273  };
274 
276  template <class T, class U>
278  public StoreWrapper<T, U>
279  {
280  typedef std::shared_ptr<T> TPtr;
281 
283 
284  typedef std::shared_ptr<U> UPtr;
285 
287 
288  typedef Store<U> UStore;
289 
291 
292  public: explicit BaseStoreWrapper(UStorePtr _store);
293 
294  public: virtual ~BaseStoreWrapper();
295 
296  public: virtual unsigned int Size() const;
297 
298  public: virtual bool Contains(ConstTPtr _object) const;
299 
300  public: virtual bool ContainsId(unsigned int _id) const;
301 
302  public: virtual bool ContainsName(const std::string &_name) const;
303 
304  public: virtual TPtr GetById(unsigned int _id) const;
305 
306  public: virtual TPtr GetByName(const std::string &_name) const;
307 
308  public: virtual TPtr GetByIndex(unsigned int _index) const;
309 
310  public: virtual bool Add(TPtr _object);
311 
312  public: virtual TPtr Remove(TPtr _object);
313 
314  public: virtual TPtr RemoveById(unsigned int _id);
315 
316  public: virtual TPtr RemoveByName(const std::string &_name);
317 
318  public: virtual TPtr RemoveByIndex(unsigned int _index);
319 
320  public: virtual void RemoveAll();
321 
322  public: virtual void Destroy(TPtr _object);
323 
324  public: virtual void DestroyById(unsigned int _id);
325 
326  public: virtual void DestroyByName(const std::string &_name);
327 
328  public: virtual void DestroyByIndex(unsigned int _index);
329 
330  public: virtual void DestroyAll();
331 
332  protected: UStorePtr store;
333  };
334 
337  public BaseCompositeStore<Node>
338  {
339  };
340 
341  template <class T>
342  class BaseSceneStore :
343  public BaseStore<Scene, T>
344  {
345  };
346 
347  template <class T>
348  class BaseNodeStore :
349  public BaseStore<Node, T>
350  {
351  };
352 
353  template <class T>
354  class BaseLightStore :
355  public BaseStore<Light, T>
356  {
357  };
358 
359  template <class T>
360  class BaseSensorStore :
361  public BaseStore<Sensor, T>
362  {
363  };
364 
365  template <class T>
366  class BaseVisualStore :
367  public BaseStore<Visual, T>
368  {
369  };
370 
371  template <class T>
372  class BaseGeometryStore :
373  public BaseStore<Geometry, T>
374  {
375  };
376 
377  template <class T>
378  class BaseSubMeshStore :
379  public BaseStore<SubMesh, T>
380  {
381  };
382 
383  template <class T>
384  class BaseMaterialMap :
385  public BaseMap<Material, T>
386  {
387  };
388 
390  template <class T, class U>
392  {
393  }
394 
396  template <class T, class U>
398  {
399  }
400 
402  template <class T, class U>
403  unsigned int BaseMap<T, U>::Size() const
404  {
405  return this->map.size();
406  }
407 
409  template <class T, class U>
410  bool BaseMap<T, U>::ContainsKey(const std::string &_key) const
411  {
412  return this->map.count(_key) > 0;
413  }
414 
416  template <class T, class U>
418  {
419  for (auto pair : this->map)
420  {
421  if (pair.second == _value) return true;
422  }
423 
424  return false;
425  }
426 
428  template <class T, class U>
429  typename BaseMap<T, U>::TPtr
430  BaseMap<T, U>::Get(const std::string &_key) const
431  {
432  return this->Derived(_key);
433  }
434 
436  template <class T, class U>
437  typename BaseMap<T, U>::TPtr
438  BaseMap<T, U>::GetByIndex(unsigned int _index) const
439  {
440  return this->DerivedByIndex(_index);
441  }
442 
444  template <class T, class U>
445  bool BaseMap<T, U>::Put(const std::string &_key, TPtr _value)
446  {
447  if (_key.empty())
448  {
449  ignerr << "Cannot store item with empty key" << std::endl;
450  return false;
451  }
452 
453  if (!_value)
454  {
455  ignerr << "Cannot store null pointer value" << std::endl;
456  return false;
457  }
458 
459  if (this->ContainsKey(_key))
460  {
461  ignerr << "Item already registered with key: " << _key << std::endl;
462  return false;
463  }
464 
465  UPtr derived = std::dynamic_pointer_cast<U>(_value);
466 
467  if (!derived)
468  {
469  ignerr << "Cannot add item created by another render-engine"
470  << std::endl;
471 
472  return false;
473  }
474 
475  this->map[_key] = derived;
476  return true;
477  }
478 
480  template <class T, class U>
482  {
483  auto iter = this->map.find(_key);
484 
485  if (this->IsValidIter(iter))
486  {
487  this->map.erase(iter);
488  }
489  }
490 
492  template <class T, class U>
494  {
495  auto iter = this->map.begin();
496 
497  while (this->IsValidIter(iter))
498  {
499  if (iter->second == _value)
500  {
501  this->map.erase(iter);
502  continue;
503  }
504 
505  ++iter;
506  }
507  }
508 
510  template <class T, class U>
512  {
513  this->map.clear();
514  }
515 
517  template <class T, class U>
518  typename BaseMap<T, U>::UPtr
520  {
521  auto iter = this->map.find(_key);
522  return (this->IsValidIter(iter)) ? iter->second : nullptr;
523  }
524 
526  template <class T, class U>
527  typename BaseMap<T, U>::UPtr
528  BaseMap<T, U>::DerivedByIndex(unsigned int _index) const
529  {
530  if (_index >= this->Size())
531  {
532  ignerr << "Invalid index: " << _index << std::endl;
533  return nullptr;
534  }
535 
536  auto iter = this->map.begin();
537  std::advance(iter, _index);
538  return iter->second;
539  }
540 
542  template <class T, class U>
543  bool BaseMap<T, U>::IsValidIter(ConstUIter _iter) const
544  {
545  return _iter != this->map.end();
546  }
547 
549  template <class T, class U>
551  {
552  }
553 
555  template <class T, class U>
557  {
558  }
559 
561  template <class T, class U>
562  unsigned int BaseStore<T, U>::Size() const
563  {
564  return this->store.size();
565  }
566 
568  template <class T, class U>
569  typename BaseStore<T, U>::UIter
571  {
572  return this->store.begin();
573  }
574 
576  template <class T, class U>
577  typename BaseStore<T, U>::UIter
579  {
580  return this->store.end();
581  }
582 
584  template <class T, class U>
586  {
587  auto iter = this->ConstIter(_object);
588  return this->IsValidIter(iter);
589  }
590 
592  template <class T, class U>
593  bool BaseStore<T, U>::ContainsId(unsigned int _id) const
594  {
595  auto iter = this->ConstIterById(_id);
596  return this->IsValidIter(iter);
597  }
598 
600  template <class T, class U>
602  {
603  auto iter = this->ConstIterByName(_name);
604  return this->IsValidIter(iter);
605  }
606 
608  template <class T, class U>
609  typename BaseStore<T, U>::TPtr
610  BaseStore<T, U>::GetById(unsigned int _id) const
611  {
612  return this->DerivedById(_id);
613  }
614 
616  template <class T, class U>
617  typename BaseStore<T, U>::TPtr
619  {
620  return this->DerivedByName(_name);
621  }
622 
624  template <class T, class U>
625  typename BaseStore<T, U>::TPtr
626  BaseStore<T, U>::GetByIndex(unsigned int _index) const
627  {
628  return this->DerivedByIndex(_index);
629  }
630 
632  template <class T, class U>
634  {
635  if (!_object)
636  {
637  ignerr << "Cannot add null pointer" << std::endl;
638  return false;
639  }
640 
641  UPtr derived = std::dynamic_pointer_cast<U>(_object);
642 
643  if (!derived)
644  {
645  ignerr << "Cannot add item created by another render-engine"
646  << std::endl;
647 
648  return false;
649  }
650 
651  return this->AddImpl(derived);
652  }
653 
655  template <class T, class U>
656  typename BaseStore<T, U>::TPtr
658  {
659  auto iter = this->Iter(_object);
660  return this->RemoveImpl(iter);
661  }
662 
664  template <class T, class U>
665  typename BaseStore<T, U>::TPtr
666  BaseStore<T, U>::RemoveById(unsigned int _id)
667  {
668  return this->RemoveDerivedById(_id);
669  }
670 
672  template <class T, class U>
673  typename BaseStore<T, U>::TPtr
675  {
676  return this->RemoveDerivedByName(_name);
677  }
678 
680  template <class T, class U>
681  typename BaseStore<T, U>::TPtr
682  BaseStore<T, U>::RemoveByIndex(unsigned int _index)
683  {
684  return this->RemoveDerivedByIndex(_index);
685  }
686 
688  template <class T, class U>
690  {
691  this->store.clear();
692  }
693 
695  template <class T, class U>
697  {
698  auto iter = this->Iter(_object);
699  this->DestroyImpl(iter);
700  }
701 
703  template <class T, class U>
704  void BaseStore<T, U>::DestroyById(unsigned int _id)
705  {
706  auto iter = this->IterById(_id);
707  this->DestroyImpl(iter);
708  }
709 
711  template <class T, class U>
713  {
714  auto iter = this->IterByName(_name);
715  this->DestroyImpl(iter);
716  }
717 
719  template <class T, class U>
720  void BaseStore<T, U>::DestroyByIndex(unsigned int _index)
721  {
722  auto iter = this->IterByIndex(_index);
723  this->DestroyImpl(iter);
724  }
725 
727  template <class T, class U>
729  {
730  unsigned int i = this->Size();
731 
732  while (i > 0)
733  {
734  this->DestroyByIndex(--i);
735  }
736  }
737 
739  template <class T, class U>
740  typename BaseStore<T, U>::UPtr
741  BaseStore<T, U>::DerivedById(unsigned int _id) const
742  {
743  auto iter = this->ConstIterById(_id);
744  return (this->IsValidIter(iter)) ? iter->second : nullptr;
745  }
746 
748  template <class T, class U>
749  typename BaseStore<T, U>::UPtr
751  {
752  auto iter = this->ConstIterByName(_name);
753  return (this->IsValidIter(iter)) ? iter->second : nullptr;
754  }
755 
757  template <class T, class U>
758  typename BaseStore<T, U>::UPtr
759  BaseStore<T, U>::DerivedByIndex(unsigned int _index) const
760  {
761  auto iter = this->ConstIterByIndex(_index);
762  return (this->IsValidIter(iter)) ? iter->second : nullptr;
763  }
764 
766  template <class T, class U>
768  {
769  if (!_object)
770  {
771  ignerr << "Cannot add null pointer" << std::endl;
772  return false;
773  }
774 
775  return this->AddImpl(_object);
776  }
777 
779  template <class T, class U>
780  typename BaseStore<T, U>::UPtr
782  {
783  auto iter = this->Iter(_object);
784  return this->RemoveImpl(iter);
785  }
786 
788  template <class T, class U>
789  typename BaseStore<T, U>::UPtr
791  {
792  auto iter = this->IterById(_id);
793  return this->RemoveImpl(iter);
794  }
795 
797  template <class T, class U>
798  typename BaseStore<T, U>::UPtr
800  {
801  auto iter = this->IterByName(_name);
802  return this->RemoveImpl(iter);
803  }
804 
806  template <class T, class U>
807  typename BaseStore<T, U>::UPtr
809  {
810  auto iter = this->IterByIndex(_index);
811  return this->RemoveImpl(iter);
812  }
813 
815  template <class T, class U>
816  typename BaseStore<T, U>::ConstUIter
818  {
819  auto begin = this->store.begin();
820  auto end = this->store.end();
821 
822  for (auto iter = begin; iter != end; ++iter)
823  {
824  if (iter->second == _object)
825  {
826  return iter;
827  }
828  }
829 
830  return end;
831  }
832 
834  template <class T, class U>
835  typename BaseStore<T, U>::ConstUIter
836  BaseStore<T, U>::ConstIterById(unsigned int _id) const
837  {
838  auto begin = this->store.begin();
839  auto end = this->store.end();
840 
841  for (auto iter = begin; iter != end; ++iter)
842  {
843  if (iter->second->Id() == _id)
844  {
845  return iter;
846  }
847  }
848 
849  return end;
850  }
851 
853  template <class T, class U>
854  typename BaseStore<T, U>::ConstUIter
856  {
857  return this->store.find(_name);
858  }
859 
861  template <class T, class U>
862  typename BaseStore<T, U>::ConstUIter
863  BaseStore<T, U>::ConstIterByIndex(unsigned int _index) const
864  {
865  if (_index >= this->Size())
866  {
867  ignerr << "Invalid index: " << _index << std::endl;
868  return this->store.end();
869  }
870 
871  auto iter = this->store.begin();
872  std::advance(iter, _index);
873  return iter;
874  }
875 
877  template <class T, class U>
878  typename BaseStore<T, U>::UIter
880  {
881  auto iter = this->ConstIter(_object);
882  return this->RemoveConstness(iter);
883  }
884 
886  template <class T, class U>
887  typename BaseStore<T, U>::UIter
888  BaseStore<T, U>::IterById(unsigned int _id)
889  {
890  auto iter = this->ConstIterById(_id);
891  return this->RemoveConstness(iter);
892  }
893 
895  template <class T, class U>
896  typename BaseStore<T, U>::UIter
898  {
899  auto iter = this->ConstIterByName(_name);
900  return this->RemoveConstness(iter);
901  }
902 
904  template <class T, class U>
905  typename BaseStore<T, U>::UIter
906  BaseStore<T, U>::IterByIndex(unsigned int _index)
907  {
908  auto iter = this->ConstIterByIndex(_index);
909  return this->RemoveConstness(iter);
910  }
911 
913  template <class T, class U>
915  {
916  unsigned int id = _object->Id();
917  std::string name = _object->Name();
918 
919  if (this->ContainsId(id))
920  {
921  ignerr << "Another item already exists with id: " << id << std::endl;
922  return false;
923  }
924 
925  if (this->ContainsName(name))
926  {
927  ignerr << "Another item already exists with name: " << name
928  << std::endl;
929  return false;
930  }
931 
932  this->store[name] = _object;
933  return true;
934  }
935 
937  template <class T, class U>
938  typename BaseStore<T, U>::UPtr
940  {
941  if (!this->IsValidIter(_iter))
942  {
943  return nullptr;
944  }
945 
946  UPtr result = _iter->second;
947  this->store.erase(_iter);
948  return result;
949  }
950 
952  template <class T, class U>
954  {
955  UPtr result = this->RemoveImpl(_iter);
956  if (result) result->Destroy();
957  }
958 
960  template <class T, class U>
961  bool BaseStore<T, U>::IsValidIter(ConstUIter _iter) const
962  {
963  return _iter != this->store.end();
964  }
965 
967  template <class T, class U>
968  typename BaseStore<T, U>::UIter
970  {
971  return (this->IsValidIter(_iter)) ?
972  this->store.erase(_iter, _iter) : this->store.end();
973  }
974 
976  template <class T>
978  {
979  }
980 
982  template <class T>
984  {
985  }
986 
988  template <class T>
989  unsigned int BaseCompositeStore<T>::Size() const
990  {
991  unsigned int size = 0;
992 
993  for (auto store : this->stores)
994  {
995  size += store->Size();
996  }
997 
998  return size;
999  }
1000 
1002  template <class T>
1004  {
1005  for (auto store : this->stores)
1006  {
1007  if (store->Contains(_object)) return true;
1008  }
1009 
1010  return false;
1011  }
1012 
1014  template <class T>
1015  bool BaseCompositeStore<T>::ContainsId(unsigned int _id) const
1016  {
1017  for (auto store : this->stores)
1018  {
1019  if (store->ContainsId(_id)) return true;
1020  }
1021 
1022  return false;
1023  }
1024 
1026  template <class T>
1028  {
1029  for (auto store : this->stores)
1030  {
1031  if (store->ContainsName(_name)) return true;
1032  }
1033 
1034  return false;
1035  }
1036 
1038  template <class T>
1040  BaseCompositeStore<T>::GetById(unsigned int _id) const
1041  {
1042  for (auto store : this->stores)
1043  {
1044  TPtr object = store->GetById(_id);
1045  if (object) return object;
1046  }
1047 
1048  return nullptr;
1049  }
1050 
1052  template <class T>
1055  {
1056  for (auto store : this->stores)
1057  {
1058  TPtr object = store->GetByName(_name);
1059  if (object) return object;
1060  }
1061 
1062  return nullptr;
1063  }
1064 
1066  template <class T>
1068  BaseCompositeStore<T>::GetByIndex(unsigned int _index) const
1069  {
1070  unsigned int origIndex = _index;
1071 
1072  for (auto store : this->stores)
1073  {
1074  unsigned int size = store->Size();
1075  if (_index < size)
1076  return store->GetByIndex(_index);
1077  _index -= size;
1078  }
1079 
1080  ignerr << "Invalid index: " << origIndex << std::endl;
1081  return nullptr;
1082  }
1083 
1085  template <class T>
1087  {
1088  ignerr << "Adding to BaseCompositeStore not supported" << std::endl;
1089  return false;
1090  }
1091 
1093  template <class T>
1096  {
1097  TPtr result = nullptr;
1098 
1099  for (auto store : this->stores)
1100  {
1101  TPtr temp = store->Remove(_object);
1102  if (!result) result = temp;
1103  }
1104 
1105  return result;
1106  }
1107 
1109  template <class T>
1112  {
1113  TPtr result = nullptr;
1114 
1115  for (auto store : this->stores)
1116  {
1117  TPtr temp = store->RemoveById(_id);
1118  if (!result) result = temp;
1119  }
1120 
1121  return result;
1122  }
1123 
1125  template <class T>
1128  {
1129  TPtr result = nullptr;
1130 
1131  for (auto store : this->stores)
1132  {
1133  TPtr temp = store->RemoveByName(_name);
1134  if (!result) result = temp;
1135  }
1136 
1137  return result;
1138  }
1139 
1141  template <class T>
1144  {
1145  TPtr result = nullptr;
1146 
1147  for (auto store : this->stores)
1148  {
1149  TPtr temp = store->RemoveByIndex(_index);
1150  if (!result) result = temp;
1151  }
1152 
1153  return result;
1154  }
1155 
1157  template <class T>
1159  {
1160  for (auto store : this->stores)
1161  {
1162  store->RemoveAll();
1163  }
1164  }
1165 
1167  template <class T>
1169  {
1170  for (auto store : this->stores)
1171  {
1172  if (store->Contains(_object))
1173  {
1174  store->Destroy(_object);
1175  return;
1176  }
1177  }
1178  }
1179 
1181  template <class T>
1182  void BaseCompositeStore<T>::DestroyById(unsigned int _id)
1183  {
1184  for (auto store : this->stores)
1185  {
1186  store->DestroyById(_id);
1187  }
1188  }
1189 
1191  template <class T>
1193  {
1194  for (auto store : this->stores)
1195  {
1196  store->DestroyByName(_name);
1197  }
1198  }
1199 
1201  template <class T>
1202  void BaseCompositeStore<T>::DestroyByIndex(unsigned int _index)
1203  {
1204  for (auto store : this->stores)
1205  {
1206  store->DestroyByIndex(_index);
1207  }
1208  }
1209 
1211  template <class T>
1213  {
1214  for (auto store : this->stores)
1215  {
1216  store->DestroyAll();
1217  }
1218  }
1219 
1221  template <class T>
1223  {
1224  return this->stores.size();
1225  }
1226 
1228  template <class T>
1230  {
1231  auto begin = this->stores.begin();
1232  auto end = this->stores.end();
1233  auto iter = std::find(begin, end, _store);
1234  return iter != end;
1235  }
1236 
1238  template <class T>
1240  BaseCompositeStore<T>::GetStore(unsigned int _index) const
1241  {
1242  if (_index >= this->GetStoreCount())
1243  {
1244  ignerr << "Invalid store index: " << _index << std::endl;
1245  return nullptr;
1246  }
1247 
1248  return this->stores[_index];
1249  }
1250 
1252  template <class T>
1254  {
1255  if (!_store)
1256  {
1257  ignerr << "Cannot all null store pointer" << std::endl;
1258  return false;
1259  }
1260 
1261  if (this->ContainsStore(_store))
1262  {
1263  ignerr << "Store has already been added" << std::endl;
1264  return false;
1265  }
1266 
1267  this->stores.push_back(_store);
1268  return true;
1269  }
1270 
1272  template <class T>
1275  {
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);
1280  }
1281 
1283  template <class T>
1286  {
1287  if (_index >= this->GetStoreCount())
1288  {
1289  ignerr << "Invalid store index: " << _index << std::endl;
1290  return nullptr;
1291  }
1292 
1293  auto iter = this->stores.begin();
1294  std::advance(iter, _index);
1295  return this->RemoveStoreImpl(iter);
1296  }
1297 
1299  template <class T>
1302  {
1303  if (_iter == this->stores.end())
1304  {
1305  return nullptr;
1306  }
1307 
1308  TStorePtr result = *_iter;
1309  this->stores.erase(_iter);
1310  return result;
1311  }
1312 
1314  template <class T, class U>
1316  store(_store)
1317  {
1318  }
1319 
1321  template <class T, class U>
1323  {
1324  }
1325 
1327  template <class T, class U>
1328  unsigned int BaseStoreWrapper<T, U>::Size() const
1329  {
1330  return this->store->Size();
1331  }
1332 
1334  template <class T, class U>
1336  {
1337  ConstUPtr derived = std::dynamic_pointer_cast<const U>(_object);
1338  return this->store->Contains(derived);
1339  }
1340 
1342  template <class T, class U>
1343  bool BaseStoreWrapper<T, U>::ContainsId(unsigned int _id) const
1344  {
1345  return this->store->ContainsId(_id);
1346  }
1347 
1349  template <class T, class U>
1351  {
1352  return this->store->ContainsName(_name);
1353  }
1354 
1356  template <class T, class U>
1358  BaseStoreWrapper<T, U>::GetById(unsigned int _id) const
1359  {
1360  return this->store->GetById(_id);
1361  }
1362 
1364  template <class T, class U>
1367  {
1368  return this->store->GetByName(_name);
1369  }
1370 
1372  template <class T, class U>
1374  BaseStoreWrapper<T, U>::GetByIndex(unsigned int _index) const
1375  {
1376  return this->store->GetByIndex(_index);
1377  }
1378 
1380  template <class T, class U>
1382  {
1383  UPtr derived = std::dynamic_pointer_cast<U>(_object);
1384  return this->store->Add(derived);
1385  }
1386 
1388  template <class T, class U>
1391  {
1392  UPtr derived = std::dynamic_pointer_cast<U>(_object);
1393  return this->store->Remove(derived);
1394  }
1395 
1397  template <class T, class U>
1400  {
1401  return this->store->RemoveById(_id);
1402  }
1403 
1405  template <class T, class U>
1408  {
1409  return this->store->RemoveByName(_name);
1410  }
1411 
1413  template <class T, class U>
1416  {
1417  return this->store->RemoveByIndex(_index);
1418  }
1419 
1421  template <class T, class U>
1423  {
1424  this->store->RemoveAll();
1425  }
1426 
1428  template <class T, class U>
1430  {
1431  UPtr derived = std::dynamic_pointer_cast<U>(_object);
1432  this->store->Destroy(derived);
1433  }
1434 
1436  template <class T, class U>
1438  {
1439  this->store->DestroyById(_id);
1440  }
1441 
1443  template <class T, class U>
1445  {
1446  this->store->DestroyByName(_name);
1447  }
1448 
1450  template <class T, class U>
1451  void BaseStoreWrapper<T, U>::DestroyByIndex(unsigned int _index)
1452  {
1453  this->store->DestroyByIndex(_index);
1454  }
1455 
1457  template <class T, class U>
1459  {
1460  this->store->DestroyAll();
1461  }
1462  }
1463  }
1464 }
1465 #endif
virtual bool Put(const std::string &_key, TPtr _value)
Map to given element to the given key. If the given key is already in use, no work will be done.
Definition: gz/rendering/base/BaseStorage.hh:445
virtual unsigned int Size() const
Get number of elements in this store.
Definition: gz/rendering/base/BaseStorage.hh:562
virtual ConstUIter ConstIterByIndex(unsigned int _index) const
Definition: gz/rendering/base/BaseStorage.hh:863
TStoreList stores
Definition: gz/rendering/base/BaseStorage.hh:271
virtual bool AddImpl(UPtr _object)
Definition: gz/rendering/base/BaseStorage.hh:914
UStorePtr store
Definition: gz/rendering/base/BaseStorage.hh:332
Storage map from std::string to template class T.
Definition: gz/rendering/Storage.hh:49
Definition: gz/rendering/base/BaseStorage.hh:277
virtual bool ContainsKey(const std::string &_key) const
Determine if an elements is mapped to the given key.
Definition: gz/rendering/base/BaseStorage.hh:410
virtual void DestroyById(unsigned int _id)
Remove and destroy element with the given ID. If the specified element does not exists in this store,...
Definition: gz/rendering/base/BaseStorage.hh:1182
virtual TPtr GetByName(const std::string &_name) const
Get element with the given name.
Definition: gz/rendering/base/BaseStorage.hh:618
virtual bool Add(TPtr _object)
Add given element. If the element has already been added or its name or ID conflict with other existi...
Definition: gz/rendering/base/BaseStorage.hh:633
BaseCompositeStore()
Definition: gz/rendering/base/BaseStorage.hh:977
STL class.
STL class.
virtual TStorePtr RemoveStoreImpl(TStoreIter _iter)
Definition: gz/rendering/base/BaseStorage.hh:1301
virtual UIter IterById(unsigned int _id)
Definition: gz/rendering/base/BaseStorage.hh:888
virtual TPtr Remove(TPtr _object)
Remove given element. If the given element does not exists in this store, then no work will be done.
Definition: gz/rendering/base/BaseStorage.hh:1390
#define IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
virtual unsigned int Size() const
Get number of elements in this store.
Definition: gz/rendering/base/BaseStorage.hh:989
virtual TPtr RemoveById(unsigned int _id)
Remove element with the given ID. If the specified element does not exists in this store,...
Definition: gz/rendering/base/BaseStorage.hh:1399
virtual unsigned int GetStoreCount() const
Get number of Stores.
Definition: gz/rendering/base/BaseStorage.hh:1222
virtual TPtr Get(const std::string &_key) const
Get the element mapped to the given key.
Definition: gz/rendering/base/BaseStorage.hh:430
T find(T... args)
virtual bool AddStore(TStorePtr _store)
Add the given store. If the given store already exists, then no work will be done.
Definition: gz/rendering/base/BaseStorage.hh:1253
virtual UPtr DerivedByIndex(unsigned int _index) const
Definition: gz/rendering/base/BaseStorage.hh:528
Definition: gz/rendering/base/BaseStorage.hh:199
virtual TPtr GetByIndex(unsigned int _index) const
Get element at the given index.
Definition: gz/rendering/base/BaseStorage.hh:626
virtual ConstUIter ConstIterById(unsigned int _id) const
Definition: gz/rendering/base/BaseStorage.hh:836
virtual TPtr GetByName(const std::string &_name) const
Get element with the given name.
Definition: gz/rendering/base/BaseStorage.hh:1054
virtual TPtr RemoveById(unsigned int _id)
Remove element with the given ID. If the specified element does not exists in this store,...
Definition: gz/rendering/base/BaseStorage.hh:1111
virtual ConstUIter ConstIterByName(const std::string &_name) const
Definition: gz/rendering/base/BaseStorage.hh:855
virtual UIter Begin()
Return an iterator to the beginning.
Definition: gz/rendering/base/BaseStorage.hh:570
virtual void RemoveAll()
Remove all elements from store.
Definition: gz/rendering/base/BaseStorage.hh:1422
virtual void DestroyByIndex(unsigned int _index)
Remove and destroy element at the given index. If the specified element does not exists in this store...
Definition: gz/rendering/base/BaseStorage.hh:1202
virtual TPtr Remove(TPtr _object)
Remove given element. If the given element does not exists in this store, then no work will be done.
Definition: gz/rendering/base/BaseStorage.hh:657
BaseStoreWrapper(UStorePtr _store)
Definition: gz/rendering/base/BaseStorage.hh:1315
virtual bool ContainsName(const std::string &_name) const
Determine if store contains the element with the given name.
Definition: gz/rendering/base/BaseStorage.hh:1350
BaseStore()
Definition: gz/rendering/base/BaseStorage.hh:550
virtual TPtr GetByIndex(unsigned int _index) const
Get element at the given index.
Definition: gz/rendering/base/BaseStorage.hh:1374
virtual UPtr RemoveDerivedById(unsigned int _id)
Definition: gz/rendering/base/BaseStorage.hh:790
virtual bool ContainsStore(ConstTStorePtr _store) const
Determine if given store exists.
Definition: gz/rendering/base/BaseStorage.hh:1229
virtual TPtr GetByName(const std::string &_name) const
Get element with the given name.
Definition: gz/rendering/base/BaseStorage.hh:1366
UMap map
Definition: gz/rendering/base/BaseStorage.hh:83
virtual UPtr RemoveDerivedByIndex(unsigned int _index)
Definition: gz/rendering/base/BaseStorage.hh:808
virtual void DestroyById(unsigned int _id)
Remove and destroy element with the given ID. If the specified element does not exists in this store,...
Definition: gz/rendering/base/BaseStorage.hh:1437
virtual bool IsValidIter(ConstUIter _iter) const
Definition: gz/rendering/base/BaseStorage.hh:961
#define ignerr
virtual UIter End()
Return an iterator to the end.
Definition: gz/rendering/base/BaseStorage.hh:578
virtual bool ContainsName(const std::string &_name) const
Determine if store contains the element with the given name.
Definition: gz/rendering/base/BaseStorage.hh:1027
virtual UIter IterByIndex(unsigned int _index)
Definition: gz/rendering/base/BaseStorage.hh:906
virtual bool Contains(ConstTPtr _object) const
Determine if store contains the given element.
Definition: gz/rendering/base/BaseStorage.hh:585
virtual void DestroyByIndex(unsigned int _index)
Remove and destroy element at the given index. If the specified element does not exists in this store...
Definition: gz/rendering/base/BaseStorage.hh:1451
virtual TStorePtr GetStore(unsigned int _index) const
Get store at the given index. If no such store exists NULL will be returned.
Definition: gz/rendering/base/BaseStorage.hh:1240
virtual bool Contains(ConstTPtr _object) const
Determine if store contains the given element.
Definition: gz/rendering/base/BaseStorage.hh:1335
Multi-access storage structure of template class T. Template class T is expected to have functions Ge...
Definition: gz/rendering/Storage.hh:114
virtual UPtr RemoveDerived(UPtr _object)
Definition: gz/rendering/base/BaseStorage.hh:781
virtual bool Contains(ConstTPtr _object) const
Determine if store contains the given element.
Definition: gz/rendering/base/BaseStorage.hh:1003
virtual void RemoveAll()
Remove all elements from store.
Definition: gz/rendering/base/BaseStorage.hh:689
virtual void Destroy(TPtr _object)
Remove and destroy given element. If the given element does not exists, in this store,...
Definition: gz/rendering/base/BaseStorage.hh:1429
virtual bool ContainsId(unsigned int _id) const
Determine if store contains the element with the given ID.
Definition: gz/rendering/base/BaseStorage.hh:1015
virtual void DestroyImpl(UIter _iter)
Definition: gz/rendering/base/BaseStorage.hh:953
virtual ~BaseCompositeStore()
Definition: gz/rendering/base/BaseStorage.hh:983
virtual TPtr RemoveByIndex(unsigned int _index)
Remove element at the given index. If the specified element does not exists in this store,...
Definition: gz/rendering/base/BaseStorage.hh:1143
virtual UPtr RemoveImpl(UIter _iter)
Definition: gz/rendering/base/BaseStorage.hh:939
virtual unsigned int Size() const
Get the number of elements in this map.
Definition: gz/rendering/base/BaseStorage.hh:403
virtual void DestroyAll()
Remove and destroy all elements in store.
Definition: gz/rendering/base/BaseStorage.hh:1212
virtual void DestroyAll()
Remove and destroy all elements in store.
Definition: gz/rendering/base/BaseStorage.hh:728
virtual void DestroyById(unsigned int _id)
Remove and destroy element with the given ID. If the specified element does not exists in this store,...
Definition: gz/rendering/base/BaseStorage.hh:704
virtual void DestroyAll()
Remove and destroy all elements in store.
Definition: gz/rendering/base/BaseStorage.hh:1458
virtual UIter Iter(ConstTPtr _object)
Definition: gz/rendering/base/BaseStorage.hh:879
virtual TPtr GetByIndex(unsigned int _index) const
Get element at the given index.
Definition: gz/rendering/base/BaseStorage.hh:1068
virtual ConstUIter ConstIter(ConstTPtr _object) const
Definition: gz/rendering/base/BaseStorage.hh:817
virtual bool Add(TPtr _object)
Add given element. If the element has already been added or its name or ID conflict with other existi...
Definition: gz/rendering/base/BaseStorage.hh:1381
virtual TPtr RemoveByName(const std::string &_name)
Remove element with the given name. If the specified element does not exists in this store,...
Definition: gz/rendering/base/BaseStorage.hh:674
virtual bool IsValidIter(ConstUIter _iter) const
Definition: gz/rendering/base/BaseStorage.hh:543
virtual TPtr GetByIndex(unsigned int _index) const
Get the element at the given index.
Definition: gz/rendering/base/BaseStorage.hh:438
virtual TPtr GetById(unsigned int _id) const
Get element with the given ID.
Definition: gz/rendering/base/BaseStorage.hh:1358
virtual unsigned int Size() const
Get number of elements in this store.
Definition: gz/rendering/base/BaseStorage.hh:1328
virtual bool ContainsName(const std::string &_name) const
Determine if store contains the element with the given name.
Definition: gz/rendering/base/BaseStorage.hh:601
Simple wrapper class that allows a Store of type Derived to be treated as a Store of type Base,...
Definition: gz/rendering/Storage.hh:291
T advance(T... args)
virtual bool Add(TPtr _object)
Add given element. If the element has already been added or its name or ID conflict with other existi...
Definition: gz/rendering/base/BaseStorage.hh:1086
virtual void Destroy(TPtr _object)
Remove and destroy given element. If the given element does not exists, in this store,...
Definition: gz/rendering/base/BaseStorage.hh:1168
Definition: gz/rendering/base/BaseStorage.hh:88
virtual UIter IterByName(const std::string &_name)
Definition: gz/rendering/base/BaseStorage.hh:897
virtual void Remove(const std::string &_key)
Remove the element mapped to the given key. If the specified element does not exists,...
Definition: gz/rendering/base/BaseStorage.hh:481
virtual bool AddDerived(UPtr _object)
Definition: gz/rendering/base/BaseStorage.hh:767
T endl(T... args)
virtual TPtr RemoveByIndex(unsigned int _index)
Remove element at the given index. If the specified element does not exists in this store,...
Definition: gz/rendering/base/BaseStorage.hh:682
virtual UPtr DerivedById(unsigned int _id) const
Definition: gz/rendering/base/BaseStorage.hh:741
virtual void DestroyByName(const std::string &_name)
Remove and destroy element with the given name. If the specified element does not exists in this stor...
Definition: gz/rendering/base/BaseStorage.hh:1192
virtual void DestroyByIndex(unsigned int _index)
Remove and destroy element at the given index. If the specified element does not exists in this store...
Definition: gz/rendering/base/BaseStorage.hh:720
virtual void DestroyByName(const std::string &_name)
Remove and destroy element with the given name. If the specified element does not exists in this stor...
Definition: gz/rendering/base/BaseStorage.hh:712
virtual TStorePtr RemoveStore(TStorePtr _store)
Remove given store. If no such store exists no work will be done and NULL will be returned.
Definition: gz/rendering/base/BaseStorage.hh:1274
virtual bool ContainsId(unsigned int _id) const
Determine if store contains the element with the given ID.
Definition: gz/rendering/base/BaseStorage.hh:593
virtual void DestroyByName(const std::string &_name)
Remove and destroy element with the given name. If the specified element does not exists in this stor...
Definition: gz/rendering/base/BaseStorage.hh:1444
Definition: gz/rendering/base/BaseRenderTypes.hh:36
virtual void RemoveAll()
Remove all elements from this map.
Definition: gz/rendering/base/BaseStorage.hh:511
virtual ~BaseStore()
Definition: gz/rendering/base/BaseStorage.hh:556
UStore store
Definition: gz/rendering/base/BaseStorage.hh:194
Definition: gz/rendering/base/BaseStorage.hh:38
virtual TPtr RemoveById(unsigned int _id)
Remove element with the given ID. If the specified element does not exists in this store,...
Definition: gz/rendering/base/BaseStorage.hh:666
T empty(T... args)
BaseMap()
Definition: gz/rendering/base/BaseStorage.hh:391
virtual TPtr RemoveByName(const std::string &_name)
Remove element with the given name. If the specified element does not exists in this store,...
Definition: gz/rendering/base/BaseStorage.hh:1407
virtual UPtr DerivedByIndex(unsigned int _index) const
Definition: gz/rendering/base/BaseStorage.hh:759
Represents a collection of Store objects, collectively working as a single composite store.
Definition: gz/rendering/Storage.hh:227
virtual TPtr GetById(unsigned int _id) const
Get element with the given ID.
Definition: gz/rendering/base/BaseStorage.hh:1040
virtual void RemoveAll()
Remove all elements from store.
Definition: gz/rendering/base/BaseStorage.hh:1158
virtual UIter RemoveConstness(ConstUIter _iter)
Definition: gz/rendering/base/BaseStorage.hh:969
virtual TPtr RemoveByIndex(unsigned int _index)
Remove element at the given index. If the specified element does not exists in this store,...
Definition: gz/rendering/base/BaseStorage.hh:1415
virtual TPtr GetById(unsigned int _id) const
Get element with the given ID.
Definition: gz/rendering/base/BaseStorage.hh:610
Definition: gz/rendering/base/BaseStorage.hh:336
virtual TPtr RemoveByName(const std::string &_name)
Remove element with the given name. If the specified element does not exists in this store,...
Definition: gz/rendering/base/BaseStorage.hh:1127
virtual ~BaseStoreWrapper()
Definition: gz/rendering/base/BaseStorage.hh:1322
virtual bool ContainsValue(ConstTPtr _value) const
Determine if the given element exists in this map.
Definition: gz/rendering/base/BaseStorage.hh:417
virtual TPtr Remove(TPtr _object)
Remove given element. If the given element does not exists in this store, then no work will be done.
Definition: gz/rendering/base/BaseStorage.hh:1095
virtual UPtr RemoveDerivedByName(const std::string &_name)
Definition: gz/rendering/base/BaseStorage.hh:799
virtual UPtr DerivedByName(const std::string &_name) const
Definition: gz/rendering/base/BaseStorage.hh:750
virtual bool ContainsId(unsigned int _id) const
Determine if store contains the element with the given ID.
Definition: gz/rendering/base/BaseStorage.hh:1343
virtual UPtr Derived(const std::string &_key) const
Definition: gz/rendering/base/BaseStorage.hh:519
virtual ~BaseMap()
Definition: gz/rendering/base/BaseStorage.hh:397
#define IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
virtual void Destroy(TPtr _object)
Remove and destroy given element. If the given element does not exists, in this store,...
Definition: gz/rendering/base/BaseStorage.hh:696