Ignition Rendering

API Reference

0.1.0
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 IGNITION_RENDERING_BASE_BASESTORAGE_HH_
18 #define IGNITION_RENDERING_BASE_BASESTORAGE_HH_
19 
20 #include <map>
21 #include <string>
22 #include <vector>
23 
24 #include <ignition/common/Console.hh>
25 
27 
28 namespace ignition
29 {
30  namespace rendering
31  {
33  template <class T, class U>
34  class BaseMap :
35  public Map<T>
36  {
37  typedef std::shared_ptr<T> TPtr;
38 
40 
41  typedef std::shared_ptr<U> UPtr;
42 
44 
45  typedef typename UMap::iterator UIter;
46 
47  typedef typename UMap::const_iterator ConstUIter;
48 
49  public: BaseMap();
50 
51  public: virtual ~BaseMap();
52 
53  public: virtual unsigned int Size() const;
54 
55  public: virtual bool ContainsKey(const std::string &_key) const;
56 
57  public: virtual bool ContainsValue(ConstTPtr _value) const;
58 
59  public: virtual TPtr Get(const std::string &_key) const;
60 
61  public: virtual TPtr GetByIndex(unsigned int _index) const;
62 
63  public: virtual bool Put(const std::string &_key, TPtr _value);
64 
65  public: virtual void Remove(const std::string &_key);
66 
67  public: virtual void Remove(TPtr _value);
68 
69  public: virtual void RemoveAll();
70 
71  public: virtual UPtr Derived(const std::string &_key) const;
72 
73  public: virtual UPtr DerivedByIndex(unsigned int _index) const;
74 
75  protected: virtual bool IsValidIter(ConstUIter _iter) const;
76 
77  protected: UMap map;
78  };
79 
81  template <class T, class U>
82  class IGNITION_RENDERING_VISIBLE BaseStore :
83  public Store<T>
84  {
85  typedef std::shared_ptr<T> TPtr;
86 
88 
89  typedef std::shared_ptr<U> UPtr;
90 
92 
93  typedef typename UStore::iterator UIter;
94 
95  typedef typename UStore::const_iterator ConstUIter;
96 
97  public: BaseStore();
98 
99  public: virtual ~BaseStore();
100 
101  public: virtual unsigned int Size() const;
102 
103  public: virtual bool Contains(ConstTPtr _object) const;
104 
105  public: virtual bool ContainsId(unsigned int _id) const;
106 
107  public: virtual bool ContainsName(const std::string &_name) const;
108 
109  public: virtual TPtr GetById(unsigned int _id) const;
110 
111  public: virtual TPtr GetByName(const std::string &_name) const;
112 
113  public: virtual TPtr GetByIndex(unsigned int _index) const;
114 
115  public: virtual bool Add(TPtr _object);
116 
117  public: virtual TPtr Remove(TPtr _object);
118 
119  public: virtual TPtr RemoveById(unsigned int _id);
120 
121  public: virtual TPtr RemoveByName(const std::string &_name);
122 
123  public: virtual TPtr RemoveByIndex(unsigned int _index);
124 
125  public: virtual void RemoveAll();
126 
127  public: virtual void Destroy(TPtr _object);
128 
129  public: virtual void DestroyById(unsigned int _id);
130 
131  public: virtual void DestroyByName(const std::string &_name);
132 
133  public: virtual void DestroyByIndex(unsigned int _index);
134 
135  public: virtual void DestroyAll();
136 
137  public: virtual UPtr DerivedById(unsigned int _id) const;
138 
139  public: virtual UPtr DerivedByName(const std::string &_name) const;
140 
141  public: virtual UPtr DerivedByIndex(unsigned int _index) const;
142 
143  public: virtual bool AddDerived(UPtr _object);
144 
145  public: virtual UPtr RemoveDerived(UPtr _object);
146 
147  public: virtual UPtr RemoveDerivedById(unsigned int _id);
148 
149  public: virtual UPtr RemoveDerivedByName(const std::string &_name);
150 
151  public: virtual UPtr RemoveDerivedByIndex(unsigned int _index);
152 
153  protected: virtual ConstUIter ConstIter(ConstTPtr _object) const;
154 
155  protected: virtual ConstUIter ConstIterById(unsigned int _id) const;
156 
157  protected: virtual ConstUIter ConstIterByName(
158  const std::string &_name) const;
159 
160  protected: virtual ConstUIter ConstIterByIndex(unsigned int _index) const;
161 
162  protected: virtual UIter Iter(ConstTPtr _object);
163 
164  protected: virtual UIter IterById(unsigned int _id);
165 
166  protected: virtual UIter IterByName(const std::string &_name);
167 
168  protected: virtual UIter IterByIndex(unsigned int _index);
169 
170  protected: virtual bool AddImpl(UPtr _object);
171 
172  protected: virtual UPtr RemoveImpl(UIter _iter);
173 
174  protected: virtual void DestroyImpl(UIter _iter);
175 
176  protected: virtual bool IsValidIter(ConstUIter _iter) const;
177 
178  protected: virtual UIter RemoveConstness(ConstUIter _iter);
179 
180  protected: UStore store;
181  };
182 
184  template <class T>
185  class IGNITION_RENDERING_VISIBLE BaseCompositeStore :
186  public CompositeStore<T>
187  {
188  typedef std::shared_ptr<T> TPtr;
189 
191 
192  typedef Store<T> TStore;
193 
195 
197 
199 
200  typedef typename TStoreList::iterator TStoreIter;
201 
202  public: BaseCompositeStore();
203 
204  public: virtual ~BaseCompositeStore();
205 
206  public: virtual unsigned int Size() const;
207 
208  public: virtual bool Contains(ConstTPtr _object) const;
209 
210  public: virtual bool ContainsId(unsigned int _id) const;
211 
212  public: virtual bool ContainsName(const std::string &_name) const;
213 
214  public: virtual TPtr GetById(unsigned int _id) const;
215 
216  public: virtual TPtr GetByName(const std::string &_name) const;
217 
218  public: virtual TPtr GetByIndex(unsigned int _index) const;
219 
220  public: virtual bool Add(TPtr _object);
221 
222  public: virtual TPtr Remove(TPtr _object);
223 
224  public: virtual TPtr RemoveById(unsigned int _id);
225 
226  public: virtual TPtr RemoveByName(const std::string &_name);
227 
228  public: virtual TPtr RemoveByIndex(unsigned int _index);
229 
230  public: virtual void RemoveAll();
231 
232  public: virtual void Destroy(TPtr _object);
233 
234  public: virtual void DestroyById(unsigned int _id);
235 
236  public: virtual void DestroyByName(const std::string &_name);
237 
238  public: virtual void DestroyByIndex(unsigned int _index);
239 
240  public: virtual void DestroyAll();
241 
242  public: virtual unsigned int GetStoreCount() const;
243 
244  public: virtual bool ContainsStore(ConstTStorePtr _store) const;
245 
246  public: virtual TStorePtr GetStore(unsigned int _index) const;
247 
248  public: virtual bool AddStore(TStorePtr _store);
249 
250  public: virtual TStorePtr RemoveStore(TStorePtr _store);
251 
252  public: virtual TStorePtr RemoveStore(unsigned int _index);
253 
254  public: virtual TStorePtr RemoveStoreImpl(TStoreIter _iter);
255 
256  protected: TStoreList stores;
257  };
258 
260  template <class T, class U>
261  class IGNITION_RENDERING_VISIBLE BaseStoreWrapper :
262  public StoreWrapper<T, U>
263  {
264  typedef std::shared_ptr<T> TPtr;
265 
267 
268  typedef std::shared_ptr<U> UPtr;
269 
271 
272  typedef Store<U> UStore;
273 
275 
276  public: BaseStoreWrapper(UStorePtr _store);
277 
278  public: virtual ~BaseStoreWrapper();
279 
280  public: virtual unsigned int Size() const;
281 
282  public: virtual bool Contains(ConstTPtr _object) const;
283 
284  public: virtual bool ContainsId(unsigned int _id) const;
285 
286  public: virtual bool ContainsName(const std::string &_name) const;
287 
288  public: virtual TPtr GetById(unsigned int _id) const;
289 
290  public: virtual TPtr GetByName(const std::string &_name) const;
291 
292  public: virtual TPtr GetByIndex(unsigned int _index) const;
293 
294  public: virtual bool Add(TPtr _object);
295 
296  public: virtual TPtr Remove(TPtr _object);
297 
298  public: virtual TPtr RemoveById(unsigned int _id);
299 
300  public: virtual TPtr RemoveByName(const std::string &_name);
301 
302  public: virtual TPtr RemoveByIndex(unsigned int _index);
303 
304  public: virtual void RemoveAll();
305 
306  public: virtual void Destroy(TPtr _object);
307 
308  public: virtual void DestroyById(unsigned int _id);
309 
310  public: virtual void DestroyByName(const std::string &_name);
311 
312  public: virtual void DestroyByIndex(unsigned int _index);
313 
314  public: virtual void DestroyAll();
315 
316  protected: UStorePtr store;
317  };
318 
320  class IGNITION_RENDERING_VISIBLE BaseNodeCompositeStore :
321  public BaseCompositeStore<Node>
322  {
323  };
324 
325  template <class T>
326  class IGNITION_RENDERING_VISIBLE BaseSceneStore :
327  public BaseStore<Scene, T>
328  {
329  };
330 
331  template <class T>
332  class IGNITION_RENDERING_VISIBLE BaseNodeStore :
333  public BaseStore<Node, T>
334  {
335  };
336 
337  template <class T>
338  class IGNITION_RENDERING_VISIBLE BaseLightStore :
339  public BaseStore<Light, T>
340  {
341  };
342 
343  template <class T>
344  class IGNITION_RENDERING_VISIBLE BaseSensorStore :
345  public BaseStore<Sensor, T>
346  {
347  };
348 
349  template <class T>
350  class IGNITION_RENDERING_VISIBLE BaseVisualStore :
351  public BaseStore<Visual, T>
352  {
353  };
354 
355  template <class T>
356  class IGNITION_RENDERING_VISIBLE BaseGeometryStore :
357  public BaseStore<Geometry, T>
358  {
359  };
360 
361  template <class T>
362  class IGNITION_RENDERING_VISIBLE BaseSubMeshStore :
363  public BaseStore<SubMesh, T>
364  {
365  };
366 
367  template <class T>
368  class IGNITION_RENDERING_VISIBLE BaseMaterialMap :
369  public BaseMap<Material, T>
370  {
371  };
372 
374  template <class T, class U>
376  {
377  }
378 
380  template <class T, class U>
382  {
383  }
384 
386  template <class T, class U>
387  unsigned int BaseMap<T, U>::Size() const
388  {
389  return this->map.size();
390  }
391 
393  template <class T, class U>
394  bool BaseMap<T, U>::ContainsKey(const std::string &_key) const
395  {
396  return this->map.count(_key) > 0;
397  }
398 
400  template <class T, class U>
402  {
403  for (auto pair : this->map)
404  {
405  if (pair.second == _value) return true;
406  }
407 
408  return false;
409  }
410 
412  template <class T, class U>
413  typename BaseMap<T, U>::TPtr
414  BaseMap<T, U>::Get(const std::string &_key) const
415  {
416  return this->Derived(_key);
417  }
418 
420  template <class T, class U>
421  typename BaseMap<T, U>::TPtr
422  BaseMap<T, U>::GetByIndex(unsigned int _index) const
423  {
424  return this->DerivedByIndex(_index);
425  }
426 
428  template <class T, class U>
429  bool BaseMap<T, U>::Put(const std::string &_key, TPtr _value)
430  {
431  if (_key.empty())
432  {
433  ignerr << "Cannot store item with empty key" << std::endl;
434  return false;
435  }
436 
437  if (!_value)
438  {
439  ignerr << "Cannot store null pointer value" << std::endl;
440  return false;
441  }
442 
443  if (this->ContainsKey(_key))
444  {
445  ignerr << "Item already registered with key: " << _key << std::endl;
446  return false;
447  }
448 
449  UPtr derived = std::dynamic_pointer_cast<U>(_value);
450 
451  if (!derived)
452  {
453  ignerr << "Cannot add item created by another render-engine"
454  << std::endl;
455 
456  return false;
457  }
458 
459  this->map[_key] = derived;
460  return true;
461  }
462 
464  template <class T, class U>
466  {
467  auto iter = this->map.find(_key);
468 
469  if (this->IsValidIter(iter))
470  {
471  this->map.erase(iter);
472  }
473  }
474 
476  template <class T, class U>
478  {
479  auto iter = this->map.begin();
480 
481  while (this->IsValidIter(iter))
482  {
483  if (iter->second == _value)
484  {
485  this->map.erase(iter);
486  continue;
487  }
488 
489  ++iter;
490  }
491  }
492 
494  template <class T, class U>
496  {
497  this->map.clear();
498  }
499 
501  template <class T, class U>
502  typename BaseMap<T, U>::UPtr
504  {
505  auto iter = this->map.find(_key);
506  return (this->IsValidIter(iter)) ? iter->second : nullptr;
507  }
508 
510  template <class T, class U>
511  typename BaseMap<T, U>::UPtr
512  BaseMap<T, U>::DerivedByIndex(unsigned int _index) const
513  {
514  if (_index >= this->Size())
515  {
516  ignerr << "Invalid index: " << _index << std::endl;
517  return nullptr;
518  }
519 
520  auto iter = this->map.begin();
521  std::advance(iter, _index);
522  return iter->second;
523  }
524 
526  template <class T, class U>
527  bool BaseMap<T, U>::IsValidIter(ConstUIter _iter) const
528  {
529  return _iter != this->map.end();
530  }
531 
533  template <class T, class U>
535  {
536  }
537 
539  template <class T, class U>
541  {
542  }
543 
545  template <class T, class U>
546  unsigned int BaseStore<T, U>::Size() const
547  {
548  return this->store.size();
549  }
550 
552  template <class T, class U>
554  {
555  auto iter = this->ConstIter(_object);
556  return this->IsValidIter(iter);
557  }
558 
560  template <class T, class U>
561  bool BaseStore<T, U>::ContainsId(unsigned int _id) const
562  {
563  auto iter = this->ConstIterById(_id);
564  return this->IsValidIter(iter);
565  }
566 
568  template <class T, class U>
570  {
571  auto iter = this->ConstIterByName(_name);
572  return this->IsValidIter(iter);
573  }
574 
576  template <class T, class U>
577  typename BaseStore<T, U>::TPtr
578  BaseStore<T, U>::GetById(unsigned int _id) const
579  {
580  return this->DerivedById(_id);
581  }
582 
584  template <class T, class U>
585  typename BaseStore<T, U>::TPtr
587  {
588  return this->DerivedByName(_name);
589  }
590 
592  template <class T, class U>
593  typename BaseStore<T, U>::TPtr
594  BaseStore<T, U>::GetByIndex(unsigned int _index) const
595  {
596  return this->DerivedByIndex(_index);
597  }
598 
600  template <class T, class U>
602  {
603  if (!_object)
604  {
605  ignerr << "Cannot add null pointer" << std::endl;
606  return false;
607  }
608 
609  UPtr derived = std::dynamic_pointer_cast<U>(_object);
610 
611  if (!derived)
612  {
613  ignerr << "Cannot add item created by another render-engine"
614  << std::endl;
615 
616  return false;
617  }
618 
619  return this->AddImpl(derived);
620  }
621 
623  template <class T, class U>
624  typename BaseStore<T, U>::TPtr
626  {
627  auto iter = this->Iter(_object);
628  return this->RemoveImpl(iter);
629  }
630 
632  template <class T, class U>
633  typename BaseStore<T, U>::TPtr
634  BaseStore<T, U>::RemoveById(unsigned int _id)
635  {
636  return this->RemoveDerivedById(_id);
637  }
638 
640  template <class T, class U>
641  typename BaseStore<T, U>::TPtr
643  {
644  return this->RemoveDerivedByName(_name);
645  }
646 
648  template <class T, class U>
649  typename BaseStore<T, U>::TPtr
650  BaseStore<T, U>::RemoveByIndex(unsigned int _index)
651  {
652  return this->RemoveDerivedByIndex(_index);
653  }
654 
656  template <class T, class U>
658  {
659  this->store.clear();
660  }
661 
663  template <class T, class U>
665  {
666  auto iter = this->Iter(_object);
667  this->DestroyImpl(iter);
668  }
669 
671  template <class T, class U>
672  void BaseStore<T, U>::DestroyById(unsigned int _id)
673  {
674  auto iter = this->IterById(_id);
675  this->DestroyImpl(iter);
676  }
677 
679  template <class T, class U>
681  {
682  auto iter = this->IterByName(_name);
683  this->DestroyImpl(iter);
684  }
685 
687  template <class T, class U>
688  void BaseStore<T, U>::DestroyByIndex(unsigned int _index)
689  {
690  auto iter = this->IterByIndex(_index);
691  this->DestroyImpl(iter);
692  }
693 
695  template <class T, class U>
697  {
698  unsigned int i = this->Size();
699 
700  while (i > 0)
701  {
702  this->DestroyByIndex(--i);
703  }
704  }
705 
707  template <class T, class U>
708  typename BaseStore<T, U>::UPtr
709  BaseStore<T, U>::DerivedById(unsigned int _id) const
710  {
711  auto iter = this->ConstIterById(_id);
712  return (this->IsValidIter(iter)) ? iter->second : nullptr;
713  }
714 
716  template <class T, class U>
717  typename BaseStore<T, U>::UPtr
719  {
720  auto iter = this->ConstIterByName(_name);
721  return (this->IsValidIter(iter)) ? iter->second : nullptr;
722  }
723 
725  template <class T, class U>
726  typename BaseStore<T, U>::UPtr
727  BaseStore<T, U>::DerivedByIndex(unsigned int _index) const
728  {
729  auto iter = this->ConstIterByIndex(_index);
730  return (this->IsValidIter(iter)) ? iter->second : nullptr;
731  }
732 
734  template <class T, class U>
736  {
737  if (!_object)
738  {
739  ignerr << "Cannot add null pointer" << std::endl;
740  return false;
741  }
742 
743  return this->AddImpl(_object);
744  }
745 
747  template <class T, class U>
748  typename BaseStore<T, U>::UPtr
750  {
751  auto iter = this->Iter(_object);
752  return this->RemoveImpl(iter);
753  }
754 
756  template <class T, class U>
757  typename BaseStore<T, U>::UPtr
759  {
760  auto iter = this->IterById(_id);
761  return this->RemoveImpl(iter);
762  }
763 
765  template <class T, class U>
766  typename BaseStore<T, U>::UPtr
768  {
769  auto iter = this->IterByName(_name);
770  return this->RemoveImpl(iter);
771  }
772 
774  template <class T, class U>
775  typename BaseStore<T, U>::UPtr
777  {
778  auto iter = this->IterByIndex(_index);
779  return this->RemoveImpl(iter);
780  }
781 
783  template <class T, class U>
784  typename BaseStore<T, U>::ConstUIter
786  {
787  auto begin = this->store.begin();
788  auto end = this->store.end();
789 
790  for (auto iter = begin; iter != end; ++iter)
791  {
792  if (iter->second == _object)
793  {
794  return iter;
795  }
796  }
797 
798  return end;
799  }
800 
802  template <class T, class U>
803  typename BaseStore<T, U>::ConstUIter
804  BaseStore<T, U>::ConstIterById(unsigned int _id) const
805  {
806  auto begin = this->store.begin();
807  auto end = this->store.end();
808 
809  for (auto iter = begin; iter != end; ++iter)
810  {
811  if (iter->second->Id() == _id)
812  {
813  return iter;
814  }
815  }
816 
817  return end;
818  }
819 
821  template <class T, class U>
822  typename BaseStore<T, U>::ConstUIter
824  {
825  return this->store.find(_name);
826  }
827 
829  template <class T, class U>
830  typename BaseStore<T, U>::ConstUIter
831  BaseStore<T, U>::ConstIterByIndex(unsigned int _index) const
832  {
833  if (_index >= this->Size())
834  {
835  ignerr << "Invalid index: " << _index << std::endl;
836  return this->store.end();
837  }
838 
839  auto iter = this->store.begin();
840  std::advance(iter, _index);
841  return iter;
842  }
843 
845  template <class T, class U>
846  typename BaseStore<T, U>::UIter
848  {
849  auto iter = this->ConstIter(_object);
850  return this->RemoveConstness(iter);
851  }
852 
854  template <class T, class U>
855  typename BaseStore<T, U>::UIter
856  BaseStore<T, U>::IterById(unsigned int _id)
857  {
858  auto iter = this->ConstIterById(_id);
859  return this->RemoveConstness(iter);
860  }
861 
863  template <class T, class U>
864  typename BaseStore<T, U>::UIter
866  {
867  auto iter = this->ConstIterByName(_name);
868  return this->RemoveConstness(iter);
869  }
870 
872  template <class T, class U>
873  typename BaseStore<T, U>::UIter
874  BaseStore<T, U>::IterByIndex(unsigned int _index)
875  {
876  auto iter = this->ConstIterByIndex(_index);
877  return this->RemoveConstness(iter);
878  }
879 
881  template <class T, class U>
883  {
884  unsigned int id = _object->Id();
885  std::string name = _object->Name();
886 
887  if (this->ContainsId(id))
888  {
889  ignerr << "Another item already exists with id: " << id << std::endl;
890  return false;
891  }
892 
893  if (this->ContainsName(name))
894  {
895  ignerr << "Another item already exists with name: " << name
896  << std::endl;
897  return false;
898  }
899 
900  this->store[name] = _object;
901  return true;
902  }
903 
905  template <class T, class U>
906  typename BaseStore<T, U>::UPtr
908  {
909  if (!this->IsValidIter(_iter))
910  {
911  return nullptr;
912  }
913 
914  UPtr result = _iter->second;
915  this->store.erase(_iter);
916  return result;
917  }
918 
920  template <class T, class U>
922  {
923  UPtr result = this->RemoveImpl(_iter);
924  if (result) result->Destroy();
925  }
926 
928  template <class T, class U>
929  bool BaseStore<T, U>::IsValidIter(ConstUIter _iter) const
930  {
931  return _iter != this->store.end();
932  }
933 
935  template <class T, class U>
936  typename BaseStore<T, U>::UIter
938  {
939  return (this->IsValidIter(_iter)) ?
940  this->store.erase(_iter, _iter) : this->store.end();
941  }
942 
944  template <class T>
946  {
947  }
948 
950  template <class T>
952  {
953  }
954 
956  template <class T>
957  unsigned int BaseCompositeStore<T>::Size() const
958  {
959  unsigned int size = 0;
960 
961  for (auto store : this->stores)
962  {
963  size += store->Size();
964  }
965 
966  return size;
967  }
968 
970  template <class T>
972  {
973  for (auto store : this->stores)
974  {
975  if (store->Contains(_object)) return true;
976  }
977 
978  return false;
979  }
980 
982  template <class T>
983  bool BaseCompositeStore<T>::ContainsId(unsigned int _id) const
984  {
985  for (auto store : this->stores)
986  {
987  if (store->ContainsId(_id)) return true;
988  }
989 
990  return false;
991  }
992 
994  template <class T>
996  {
997  for (auto store : this->stores)
998  {
999  if (store->ContainsName(_name)) return true;
1000  }
1001 
1002  return false;
1003  }
1004 
1006  template <class T>
1008  BaseCompositeStore<T>::GetById(unsigned int _id) const
1009  {
1010  for (auto store : this->stores)
1011  {
1012  TPtr object = store->GetById(_id);
1013  if (object) return object;
1014  }
1015 
1016  return nullptr;
1017  }
1018 
1020  template <class T>
1023  {
1024  for (auto store : this->stores)
1025  {
1026  TPtr object = store->GetByName(_name);
1027  if (object) return object;
1028  }
1029 
1030  return nullptr;
1031  }
1032 
1034  template <class T>
1036  BaseCompositeStore<T>::GetByIndex(unsigned int _index) const
1037  {
1038  unsigned int origIndex = _index;
1039 
1040  for (auto store : this->stores)
1041  {
1042  unsigned int size = store->Size();
1043  if (_index < size)
1044  return store->GetByIndex(_index);
1045  _index -= size;
1046  }
1047 
1048  ignerr << "Invalid index: " << origIndex << std::endl;
1049  return nullptr;
1050  }
1051 
1053  template <class T>
1055  {
1056  ignerr << "Adding to BaseCompositeStore not supported" << std::endl;
1057  return false;
1058  }
1059 
1061  template <class T>
1064  {
1065  TPtr result = nullptr;
1066 
1067  for (auto store : this->stores)
1068  {
1069  TPtr temp = store->Remove(_object);
1070  if (!result) result = temp;
1071  }
1072 
1073  return result;
1074  }
1075 
1077  template <class T>
1080  {
1081  TPtr result = nullptr;
1082 
1083  for (auto store : this->stores)
1084  {
1085  TPtr temp = store->RemoveById(_id);
1086  if (!result) result = temp;
1087  }
1088 
1089  return result;
1090  }
1091 
1093  template <class T>
1096  {
1097  TPtr result = nullptr;
1098 
1099  for (auto store : this->stores)
1100  {
1101  TPtr temp = store->RemoveByName(_name);
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->RemoveByIndex(_index);
1118  if (!result) result = temp;
1119  }
1120 
1121  return result;
1122  }
1123 
1125  template <class T>
1127  {
1128  for (auto store : this->stores)
1129  {
1130  store->RemoveAll();
1131  }
1132  }
1133 
1135  template <class T>
1137  {
1138  for (auto store : this->stores)
1139  {
1140  store->Destroy(_object);
1141  }
1142  }
1143 
1145  template <class T>
1146  void BaseCompositeStore<T>::DestroyById(unsigned int _id)
1147  {
1148  for (auto store : this->stores)
1149  {
1150  store->DestroyById(_id);
1151  }
1152  }
1153 
1155  template <class T>
1157  {
1158  for (auto store : this->stores)
1159  {
1160  store->DestroyByName(_name);
1161  }
1162  }
1163 
1165  template <class T>
1166  void BaseCompositeStore<T>::DestroyByIndex(unsigned int _index)
1167  {
1168  for (auto store : this->stores)
1169  {
1170  store->DestroyByIndex(_index);
1171  }
1172  }
1173 
1175  template <class T>
1177  {
1178  for (auto store : this->stores)
1179  {
1180  store->DestroyAll();
1181  }
1182  }
1183 
1185  template <class T>
1187  {
1188  return this->stores.size();
1189  }
1190 
1192  template <class T>
1194  {
1195  auto begin = this->stores.begin();
1196  auto end = this->stores.end();
1197  auto iter = std::find(begin, end, _store);
1198  return iter != end;
1199  }
1200 
1202  template <class T>
1204  BaseCompositeStore<T>::GetStore(unsigned int _index) const
1205  {
1206  if (_index >= this->GetStoreCount())
1207  {
1208  ignerr << "Invalid store index: " << _index << std::endl;
1209  return nullptr;
1210  }
1211 
1212  return this->stores[_index];
1213  }
1214 
1216  template <class T>
1218  {
1219  if (!_store)
1220  {
1221  ignerr << "Cannot all null store pointer" << std::endl;
1222  return false;
1223  }
1224 
1225  if (this->ContainsStore(_store))
1226  {
1227  ignerr << "Store has already been added" << std::endl;
1228  return false;
1229  }
1230 
1231  this->stores.push_back(_store);
1232  return true;
1233  }
1234 
1236  template <class T>
1239  {
1240  auto begin = this->stores.begin();
1241  auto end = this->stores.end();
1242  auto iter = std::find(begin, end, _store);
1243  return this->RemoveStoreImpl(iter);
1244  }
1245 
1247  template <class T>
1250  {
1251  if (_index >= this->GetStoreCount())
1252  {
1253  ignerr << "Invalid store index: " << _index << std::endl;
1254  return nullptr;
1255  }
1256 
1257  auto iter = this->stores.begin();
1258  std::advance(iter, _index);
1259  return this->RemoveStoreImpl(iter);
1260  }
1261 
1263  template <class T>
1266  {
1267  if (_iter == this->stores.end())
1268  {
1269  return nullptr;
1270  }
1271 
1272  TStorePtr result = *_iter;
1273  this->stores.erase(_iter);
1274  return result;
1275  }
1276 
1278  template <class T, class U>
1280  store(_store)
1281  {
1282  }
1283 
1285  template <class T, class U>
1287  {
1288  }
1289 
1291  template <class T, class U>
1292  unsigned int BaseStoreWrapper<T, U>::Size() const
1293  {
1294  return this->store->Size();
1295  }
1296 
1298  template <class T, class U>
1300  {
1301  ConstUPtr derived = std::dynamic_pointer_cast<const U>(_object);
1302  return this->store->Contains(derived);
1303  }
1304 
1306  template <class T, class U>
1307  bool BaseStoreWrapper<T, U>::ContainsId(unsigned int _id) const
1308  {
1309  return this->store->ContainsId(_id);
1310  }
1311 
1313  template <class T, class U>
1315  {
1316  return this->store->ContainsName(_name);
1317  }
1318 
1320  template <class T, class U>
1322  BaseStoreWrapper<T, U>::GetById(unsigned int _id) const
1323  {
1324  return this->store->GetById(_id);
1325  }
1326 
1328  template <class T, class U>
1331  {
1332  return this->store->GetByName(_name);
1333  }
1334 
1336  template <class T, class U>
1338  BaseStoreWrapper<T, U>::GetByIndex(unsigned int _index) const
1339  {
1340  return this->store->GetByIndex(_index);
1341  }
1342 
1344  template <class T, class U>
1346  {
1347  UPtr derived = std::dynamic_pointer_cast<U>(_object);
1348  return this->store->Add(derived);
1349  }
1350 
1352  template <class T, class U>
1355  {
1356  UPtr derived = std::dynamic_pointer_cast<U>(_object);
1357  return this->store->Remove(derived);
1358  }
1359 
1361  template <class T, class U>
1364  {
1365  return this->store->RemoveById(_id);
1366  }
1367 
1369  template <class T, class U>
1372  {
1373  return this->store->RemoveByName(_name);
1374  }
1375 
1377  template <class T, class U>
1380  {
1381  return this->store->RemoveByIndex(_index);
1382  }
1383 
1385  template <class T, class U>
1387  {
1388  this->store->RemoveAll();
1389  }
1390 
1392  template <class T, class U>
1394  {
1395  UPtr derived = std::dynamic_pointer_cast<U>(_object);
1396  this->store->Destroy(derived);
1397  }
1398 
1400  template <class T, class U>
1402  {
1403  this->store->DestroyById(_id);
1404  }
1405 
1407  template <class T, class U>
1409  {
1410  this->store->DestroyByName(_name);
1411  }
1412 
1414  template <class T, class U>
1415  void BaseStoreWrapper<T, U>::DestroyByIndex(unsigned int _index)
1416  {
1417  this->store->DestroyByIndex(_index);
1418  }
1419 
1421  template <class T, class U>
1423  {
1424  this->store->DestroyAll();
1425  }
1426  }
1427 }
1428 #endif
Represents a collection of Store objects, collectively working as a single composite store...
Definition: Storage.hh:224
virtual ~BaseMap()
Definition: BaseStorage.hh:381
T empty(T... args)
UStorePtr store
Definition: BaseStorage.hh:316
virtual UPtr Derived(const std::string &_key) const
Definition: BaseStorage.hh:503
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: BaseStorage.hh:601
Definition: BaseStorage.hh:185
virtual TStorePtr GetStore(unsigned int _index) const
Get store at the given index. If no such store exists NULL will be returned.
Definition: BaseStorage.hh:1204
virtual UIter RemoveConstness(ConstUIter _iter)
Definition: BaseStorage.hh:937
virtual bool ContainsId(unsigned int _id) const
Determine if store contains the element with the given ID.
Definition: BaseStorage.hh:1307
virtual unsigned int Size() const
Get number of elements in this store.
Definition: BaseStorage.hh:546
virtual UIter IterByIndex(unsigned int _index)
Definition: BaseStorage.hh:874
virtual bool Contains(ConstTPtr _object) const
Determine if store contains the given element.
Definition: BaseStorage.hh:971
virtual bool ContainsName(const std::string &_name) const
Determine if store contains the element with the given name.
Definition: BaseStorage.hh:1314
BaseStoreWrapper(UStorePtr _store)
Definition: BaseStorage.hh:1279
virtual UPtr RemoveImpl(UIter _iter)
Definition: BaseStorage.hh:907
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: BaseStorage.hh:625
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: BaseStorage.hh:1166
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: BaseStorage.hh:1401
virtual TPtr GetByIndex(unsigned int _index) const
Get the element at the given index.
Definition: BaseStorage.hh:422
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: BaseStorage.hh:672
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: BaseStorage.hh:1063
T advance(T... args)
virtual UPtr DerivedByName(const std::string &_name) const
Definition: BaseStorage.hh:718
virtual UIter IterById(unsigned int _id)
Definition: BaseStorage.hh:856
T endl(T... args)
Definition: BaseStorage.hh:34
virtual bool ContainsValue(ConstTPtr _value) const
Determine if the given element exists in this map.
Definition: BaseStorage.hh:401
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: BaseStorage.hh:1354
virtual TPtr RemoveById(unsigned int _id)
Remove element with the given ID. If the specified element does not exists in this store...
Definition: BaseStorage.hh:1363
virtual ConstUIter ConstIterById(unsigned int _id) const
Definition: BaseStorage.hh:804
virtual bool ContainsName(const std::string &_name) const
Determine if store contains the element with the given name.
Definition: BaseStorage.hh:995
virtual TPtr GetByIndex(unsigned int _index) const
Get element at the given index.
Definition: BaseStorage.hh:1036
virtual ConstUIter ConstIterByName(const std::string &_name) const
Definition: BaseStorage.hh:823
T end(T... args)
BaseMap()
Definition: BaseStorage.hh:375
Definition: BaseStorage.hh:82
virtual void RemoveAll()
Remove all elements from store.
Definition: BaseStorage.hh:1386
virtual bool IsValidIter(ConstUIter _iter) const
Definition: BaseStorage.hh:929
virtual TPtr GetByIndex(unsigned int _index) const
Get element at the given index.
Definition: BaseStorage.hh:594
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: BaseStorage.hh:1415
virtual TPtr GetByIndex(unsigned int _index) const
Get element at the given index.
Definition: BaseStorage.hh:1338
Definition: BaseStorage.hh:261
virtual bool ContainsKey(const std::string &_key) const
Determine if an elements is mapped to the given key.
Definition: BaseStorage.hh:394
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: BaseStorage.hh:1146
virtual void Remove(const std::string &_key)
Remove the element mapped to the given key. If the specified element does not exists, no work will be done.
Definition: BaseStorage.hh:465
virtual void Destroy(TPtr _object)
Remove and destroy given element. If the given element does not exists, in this store, then no work will be done.
Definition: BaseStorage.hh:1136
virtual bool Contains(ConstTPtr _object) const
Determine if store contains the given element.
Definition: BaseStorage.hh:1299
virtual UPtr DerivedById(unsigned int _id) const
Definition: BaseStorage.hh:709
virtual TStorePtr RemoveStoreImpl(TStoreIter _iter)
Definition: BaseStorage.hh:1265
STL class.
Definition: BaseStorage.hh:320
virtual TStorePtr RemoveStore(TStorePtr _store)
Remove given store. If no such store exists no work will be done and NULL will be returned...
Definition: BaseStorage.hh:1238
virtual bool Contains(ConstTPtr _object) const
Determine if store contains the given element.
Definition: BaseStorage.hh:553
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: BaseStorage.hh:1156
virtual void DestroyImpl(UIter _iter)
Definition: BaseStorage.hh:921
virtual TPtr RemoveByIndex(unsigned int _index)
Remove element at the given index. If the specified element does not exists in this store...
Definition: BaseStorage.hh:650
String name
virtual TPtr Get(const std::string &_key) const
Get the element mapped to the given key.
Definition: BaseStorage.hh:414
virtual TPtr GetByName(const std::string &_name) const
Get element with the given name.
Definition: BaseStorage.hh:1330
Storage map from std::string to template class T.
Definition: Storage.hh:46
virtual void Destroy(TPtr _object)
Remove and destroy given element. If the given element does not exists, in this store, then no work will be done.
Definition: BaseStorage.hh:1393
UStore store
Definition: BaseStorage.hh:180
UMap map
Definition: BaseStorage.hh:77
T erase(T... args)
virtual TPtr RemoveByName(const std::string &_name)
Remove element with the given name. If the specified element does not exists in this store...
Definition: BaseStorage.hh:642
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: BaseStorage.hh:429
virtual unsigned int Size() const
Get number of elements in this store.
Definition: BaseStorage.hh:1292
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: BaseStorage.hh:1408
virtual bool AddDerived(UPtr _object)
Definition: BaseStorage.hh:735
Multi-access storage structure of template class T. Template class T is expected to have functions Ge...
Definition: Storage.hh:111
T dynamic_pointer_cast(T... args)
virtual void RemoveAll()
Remove all elements from this map.
Definition: BaseStorage.hh:495
virtual UPtr RemoveDerivedByIndex(unsigned int _index)
Definition: BaseStorage.hh:776
virtual UPtr DerivedByIndex(unsigned int _index) const
Definition: BaseStorage.hh:512
virtual UIter Iter(ConstTPtr _object)
Definition: BaseStorage.hh:847
T clear(T... args)
virtual TPtr RemoveByName(const std::string &_name)
Remove element with the given name. If the specified element does not exists in this store...
Definition: BaseStorage.hh:1095
virtual bool ContainsStore(ConstTStorePtr _store) const
Determine if given store exists.
Definition: BaseStorage.hh:1193
T count(T... args)
BaseStore()
Definition: BaseStorage.hh:534
virtual TPtr GetById(unsigned int _id) const
Get element with the given ID.
Definition: BaseStorage.hh:1322
T find(T... args)
T size(T... args)
virtual UPtr RemoveDerived(UPtr _object)
Definition: BaseStorage.hh:749
virtual bool ContainsId(unsigned int _id) const
Determine if store contains the element with the given ID.
Definition: BaseStorage.hh:561
virtual void RemoveAll()
Remove all elements from store.
Definition: BaseStorage.hh:657
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: BaseStorage.hh:680
virtual void DestroyAll()
Remove and destroy all elements in store.
Definition: BaseStorage.hh:1422
T begin(T... args)
virtual TPtr GetByName(const std::string &_name) const
Get element with the given name.
Definition: BaseStorage.hh:1022
bool result
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: BaseStorage.hh:1345
BaseCompositeStore()
Definition: BaseStorage.hh:945
Simple wrapper class that allows a Store of type Derived to be treated as a Store of type Base...
Definition: Storage.hh:288
virtual bool ContainsName(const std::string &_name) const
Determine if store contains the element with the given name.
Definition: BaseStorage.hh:569
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: BaseStorage.hh:1054
virtual UPtr DerivedByIndex(unsigned int _index) const
Definition: BaseStorage.hh:727
virtual TPtr RemoveByIndex(unsigned int _index)
Remove element at the given index. If the specified element does not exists in this store...
Definition: BaseStorage.hh:1111
virtual UIter IterByName(const std::string &_name)
Definition: BaseStorage.hh:865
virtual unsigned int Size() const
Get number of elements in this store.
Definition: BaseStorage.hh:957
virtual ~BaseCompositeStore()
Definition: BaseStorage.hh:951
virtual void DestroyAll()
Remove and destroy all elements in store.
Definition: BaseStorage.hh:1176
virtual TPtr RemoveById(unsigned int _id)
Remove element with the given ID. If the specified element does not exists in this store...
Definition: BaseStorage.hh:634
virtual unsigned int Size() const
Get the number of elements in this map.
Definition: BaseStorage.hh:387
virtual unsigned int GetStoreCount() const
Get number of Stores.
Definition: BaseStorage.hh:1186
virtual TPtr GetById(unsigned int _id) const
Get element with the given ID.
Definition: BaseStorage.hh:578
virtual bool AddStore(TStorePtr _store)
Add the given store. If the given store already exists, then no work will be done.
Definition: BaseStorage.hh:1217
virtual void Destroy(TPtr _object)
Remove and destroy given element. If the given element does not exists, in this store, then no work will be done.
Definition: BaseStorage.hh:664
Definition: ArrowVisual.hh:22
virtual ConstUIter ConstIterByIndex(unsigned int _index) const
Definition: BaseStorage.hh:831
virtual void DestroyAll()
Remove and destroy all elements in store.
Definition: BaseStorage.hh:696
virtual bool IsValidIter(ConstUIter _iter) const
Definition: BaseStorage.hh:527
TStoreList stores
Definition: BaseStorage.hh:256
virtual bool AddImpl(UPtr _object)
Definition: BaseStorage.hh:882
virtual ~BaseStore()
Definition: BaseStorage.hh:540
virtual TPtr RemoveByIndex(unsigned int _index)
Remove element at the given index. If the specified element does not exists in this store...
Definition: BaseStorage.hh:1379
virtual UPtr RemoveDerivedByName(const std::string &_name)
Definition: BaseStorage.hh:767
virtual TPtr RemoveById(unsigned int _id)
Remove element with the given ID. If the specified element does not exists in this store...
Definition: BaseStorage.hh:1079
virtual ConstUIter ConstIter(ConstTPtr _object) const
Definition: BaseStorage.hh:785
virtual TPtr GetByName(const std::string &_name) const
Get element with the given name.
Definition: BaseStorage.hh:586
virtual UPtr RemoveDerivedById(unsigned int _id)
Definition: BaseStorage.hh:758
virtual ~BaseStoreWrapper()
Definition: BaseStorage.hh:1286
virtual TPtr GetById(unsigned int _id) const
Get element with the given ID.
Definition: BaseStorage.hh:1008
virtual void RemoveAll()
Remove all elements from store.
Definition: BaseStorage.hh:1126
virtual bool ContainsId(unsigned int _id) const
Determine if store contains the element with the given ID.
Definition: BaseStorage.hh:983
virtual TPtr RemoveByName(const std::string &_name)
Remove element with the given name. If the specified element does not exists in this store...
Definition: BaseStorage.hh:1371
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: BaseStorage.hh:688