Choreonoid  1.8
PolymorphicPointerArray.h
Go to the documentation of this file.
1 
5 #ifndef CNOID_UTIL_POLYMORPHIC_POINTER_ARRAY_H
6 #define CNOID_UTIL_POLYMORPHIC_POINTER_ARRAY_H
7 
8 #include "Referenced.h"
9 #include <vector>
10 
11 namespace cnoid {
12 
14 {
15 public:
17 };
18 
19 
20 template<class ObjectType, class PointerType>
22 {
23  typedef std::vector<PointerType> Container;
24  Container elements;
25 
26 public:
28  typedef typename Container::iterator iterator;
29  typedef typename Container::const_iterator const_iterator;
30  typedef typename Container::reference reference;
31  typedef typename Container::const_reference const_reference;
32 
34 
35  template <class RhsObjectType, class RhsPointerType>
37  (*this) << rhs;
38  }
39 
41 
42  template <class RhsObjectType, class RhsPointerType>
44  for(std::size_t i=0; i < rhs.size(); ++i){
45  PointerType p = cnoid::dynamic_pointer_cast<ObjectType>(rhs[i]);
46  if(p){
47  push_back(p);
48  }
49  }
50  return *this;
51  }
52 
53  bool operator==(const PolymorphicPointerArray& rhs) const {
54  return elements == rhs.elements;
55  }
56 
57  bool operator!=(const PolymorphicPointerArray& rhs) const {
58  return elements != rhs.elements;
59  }
60 
61  bool empty() const {
62  return elements.empty();
63  }
64 
65  void reserve(size_t size) {
66  elements.reserve(size);
67  }
68 
69  void resize(size_t size) {
70  elements.resize(size);
71  }
72 
73  std::size_t size() const {
74  return elements.size();
75  }
76 
78  return elements.begin();
79  }
80 
82  return elements.begin();
83  }
84 
86  return elements.end();
87  }
88 
89  const_iterator end() const {
90  return elements.end();
91  }
92 
93  PointerType& back() {
94  return elements.back();
95  }
96 
97  const PointerType& back() const {
98  return elements.back();
99  }
100 
101  PointerType& front() {
102  return elements.front();
103  }
104 
105  const PointerType& front() const {
106  return elements.front();
107  }
108 
109  PointerType& operator[](std::size_t i) {
110  return elements[i];
111  }
112 
113  const PointerType& operator[](std::size_t i) const {
114  return elements[i];
115  }
116 
117  void clear(){
118  elements.clear();
119  }
120 
121  void push_back(const PointerType& pointer){
122  elements.push_back(pointer);
123  }
124 
125  void pop_back(){
126  elements.pop_back();
127  }
128 
130  return elements.erase(pos);
131  }
132 
134  elements.swap(x.elements);
135  }
136 };
137 
138 }
139 
140 #endif
cnoid::PolymorphicPointerArray::operator==
bool operator==(const PolymorphicPointerArray &rhs) const
Definition: PolymorphicPointerArray.h:53
cnoid::PolymorphicPointerArray::size
std::size_t size() const
Definition: PolymorphicPointerArray.h:73
cnoid::PolymorphicPointerArray::front
const PointerType & front() const
Definition: PolymorphicPointerArray.h:105
cnoid::PolymorphicPointerArray::erase
iterator erase(iterator pos)
Definition: PolymorphicPointerArray.h:129
cnoid::PolymorphicPointerArray::push_back
void push_back(const PointerType &pointer)
Definition: PolymorphicPointerArray.h:121
cnoid::PolymorphicPointerArrayBase::~PolymorphicPointerArrayBase
virtual ~PolymorphicPointerArrayBase()
Definition: PolymorphicPointerArray.h:16
Referenced.h
cnoid::PolymorphicPointerArray::~PolymorphicPointerArray
virtual ~PolymorphicPointerArray()
Definition: PolymorphicPointerArray.h:40
cnoid::PolymorphicPointerArray::const_reference
Container::const_reference const_reference
Definition: PolymorphicPointerArray.h:31
cnoid::PolymorphicPointerArray::clear
void clear()
Definition: PolymorphicPointerArray.h:117
cnoid::PolymorphicPointerArray::operator<<
PolymorphicPointerArray & operator<<(const PolymorphicPointerArray< RhsObjectType, RhsPointerType > &rhs)
Definition: PolymorphicPointerArray.h:43
cnoid::PolymorphicPointerArray::operator[]
PointerType & operator[](std::size_t i)
Definition: PolymorphicPointerArray.h:109
cnoid::PolymorphicPointerArray::back
const PointerType & back() const
Definition: PolymorphicPointerArray.h:97
cnoid::PolymorphicPointerArray::begin
iterator begin()
Definition: PolymorphicPointerArray.h:77
cnoid::PolymorphicPointerArray::back
PointerType & back()
Definition: PolymorphicPointerArray.h:93
cnoid::PolymorphicPointerArray::operator!=
bool operator!=(const PolymorphicPointerArray &rhs) const
Definition: PolymorphicPointerArray.h:57
cnoid::PolymorphicPointerArray::end
iterator end()
Definition: PolymorphicPointerArray.h:85
cnoid::PolymorphicPointerArray::Base
PolymorphicPointerArrayBase Base
Definition: PolymorphicPointerArray.h:27
cnoid::PolymorphicPointerArray
Definition: PolymorphicPointerArray.h:21
cnoid::PolymorphicPointerArray::resize
void resize(size_t size)
Definition: PolymorphicPointerArray.h:69
cnoid::PolymorphicPointerArray::PolymorphicPointerArray
PolymorphicPointerArray()
Definition: PolymorphicPointerArray.h:33
cnoid::PolymorphicPointerArrayBase
Definition: PolymorphicPointerArray.h:13
cnoid::PolymorphicPointerArray::empty
bool empty() const
Definition: PolymorphicPointerArray.h:61
cnoid::PolymorphicPointerArray::pop_back
void pop_back()
Definition: PolymorphicPointerArray.h:125
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::PolymorphicPointerArray::swap
void swap(PolymorphicPointerArray &x)
Definition: PolymorphicPointerArray.h:133
cnoid::PolymorphicPointerArray::reserve
void reserve(size_t size)
Definition: PolymorphicPointerArray.h:65
cnoid::PolymorphicPointerArray::begin
const_iterator begin() const
Definition: PolymorphicPointerArray.h:81
cnoid::PolymorphicPointerArray::end
const_iterator end() const
Definition: PolymorphicPointerArray.h:89
cnoid::PolymorphicPointerArray::front
PointerType & front()
Definition: PolymorphicPointerArray.h:101
cnoid::PolymorphicPointerArray::const_iterator
Container::const_iterator const_iterator
Definition: PolymorphicPointerArray.h:29
cnoid::PolymorphicPointerArray::iterator
Container::iterator iterator
Definition: PolymorphicPointerArray.h:28
cnoid::PolymorphicPointerArray::operator[]
const PointerType & operator[](std::size_t i) const
Definition: PolymorphicPointerArray.h:113
cnoid::PolymorphicPointerArray::reference
Container::reference reference
Definition: PolymorphicPointerArray.h:30
cnoid::PolymorphicPointerArray::PolymorphicPointerArray
PolymorphicPointerArray(const PolymorphicPointerArray< RhsObjectType, RhsPointerType > &rhs)
Definition: PolymorphicPointerArray.h:36