VISR  0.12.0
Versatile Interactive Scene Renderer
object_vector.hpp
Go to the documentation of this file.
1 /* Copyright Institute of Sound and Vibration Research - All rights reserved */
2 
3 #ifndef VISR_OBJECTMODEL_OBJECT_VECTOR_HPP_INCLUDED
4 #define VISR_OBJECTMODEL_OBJECT_VECTOR_HPP_INCLUDED
5 
6 #include "object.hpp"
7 
8 #include "export_symbols.hpp"
9 #include "diffuse_source.hpp"
10 
11 #include <set>
12 #include <memory>
13 
14 namespace visr
15 {
16 namespace objectmodel
17 {
18 
22 class VISR_OBJECTMODEL_LIBRARY_SYMBOL ObjectVector
23 {
24 private:
30  struct Containee
31  {
32  public:
33  Containee( ObjectId id )
34  : mId( id )
35  {
36  }
37 
38  Containee( Containee const & rhs )
39  : mVal( rhs.mVal->clone() )
40  , mId( mVal->id() )
41  {
42  }
43 
44  Containee( Containee && rhs )
45  : mVal( std::move( rhs.mVal ) )
46  , mId( mVal->id() )
47  {
48  }
49 
50  Containee( std::unique_ptr<Object> && obj )
51  : mVal( std::move( obj ) )
52  , mId( mVal->id() )
53  {
54  }
55 
56  Containee& operator=(Containee const & rhs )
57  {
58  mVal = rhs.mVal->clone();
59  mId = mVal->id();
60  return *this;
61  }
62 
63  bool operator<( Containee const & rhs ) const
64  {
65  return mId < rhs.mId;
66  }
67 
68  std::unique_ptr<Object> mVal;
69 
70  ObjectId mId;
71  };
72 
76  using ObjectContainer = std::set< Containee >;
77 
78 public:
79 
83  ObjectVector();
84 
89  explicit ObjectVector( ObjectVector const & rhs );
90 
94  ObjectVector( ObjectVector && rhs );
95 
99  ObjectVector& operator=( ObjectVector const & rhs );
100 
104  ObjectVector& operator=( ObjectVector && rhs );
105 
109  ~ObjectVector();
110 
114  void assign( ObjectVector const & rhs );
115 
120  void swap( ObjectVector & rhs );
121 
125  std::size_t size() const { return mObjects.size(); }
126 
130  bool empty() const { return mObjects.empty(); }
131 
137  Object & at( ObjectId id );
138 
144  Object const & at( ObjectId id ) const;
145 
150  class iterator
151  {
152  public:
153  friend class ObjectVector;
154  using value_type = Object&;
155  using pointer = Object*;
156  value_type operator*() const { return *(mImpl->mVal); }
157 
158  iterator() = default;
159  iterator( iterator const & rhs ) = default;
160  iterator( iterator && rhs ) = default;
161 
162  pointer operator->() const { return mImpl->mVal.get(); };
163  bool operator==( const iterator& rhs ) const { return mImpl == rhs.mImpl; }
164  bool operator!=( const iterator& rhs ) const { return mImpl != rhs.mImpl; }
165 
169  iterator& operator++() { ++mImpl; return *this; }
170 
175  {
176  iterator ret( *this );
177  mImpl++;
178  return ret;
179  }
180 
184  iterator & operator--() { --mImpl; return *this; }
185 
190  {
191  iterator ret( *this );
192  mImpl--;
193  return ret;
194  }
195  private:
196  explicit iterator( ObjectContainer::iterator const & internal )
197  : mImpl( internal )
198  {
199  }
200  explicit iterator( ObjectContainer::iterator && internal )
201  : mImpl( internal )
202  {
203  }
204 
205  ObjectContainer::iterator mImpl;
206  };
207 
213  {
214  public:
215  friend class ObjectVector;
216  using value_type = Object&;
217  using pointer = Object*;
218 
219  const_iterator() = default;
220  const_iterator( const_iterator const & rhs ) = default;
221  value_type operator*() const { return *(mImpl->mVal); }
222  pointer operator->() const { return mImpl->mVal.get(); };
223  bool operator==( const const_iterator& rhs ) const { return mImpl == rhs.mImpl; }
224  bool operator!=( const const_iterator& rhs ) const { return mImpl != rhs.mImpl; }
225 
229  const_iterator& operator++() { ++mImpl; return *this; }
230 
235  {
236  const_iterator ret( *this );
237  mImpl++;
238  return ret;
239  }
240 
244  const_iterator & operator--() { --mImpl; return *this; }
245 
250  {
251  const_iterator ret( *this );
252  mImpl--;
253  return ret;
254  }
255 
256  private:
257  const_iterator( ObjectContainer::const_iterator const & internal )
258  : mImpl( internal )
259  {
260  }
261 
262  const_iterator( ObjectContainer::const_iterator && internal )
263  : mImpl( internal )
264  {
265  }
266 
267  ObjectContainer::const_iterator mImpl;
268  };
269 
270  iterator begin() { return iterator( mObjects.begin() ); }
271 
272  iterator end() { return iterator( mObjects.end() ); }
273 
279  const_iterator begin() const { return mObjects.cbegin(); }
280 
281  const_iterator end() const { return mObjects.cend(); }
283 
284  const_iterator cbegin() const { return mObjects.cbegin(); }
285 
286  const_iterator cend() const { return mObjects.cend(); }
287 
288  const_iterator find( ObjectId id ) const { return mObjects.find( id ); }
289 
295  iterator find( ObjectId id ) { return iterator( mObjects.find( id ) ); }
297 
298 
304  void insert( Object const & obj );
305 
311  void insert( std::unique_ptr<Object> && obj );
312 
318  void remove( ObjectId id );
319 
323  void clear();
324 
325 private:
326  ObjectContainer mObjects;
327 };
328 
329 } // namespace objectmodel
330 } // namespace visr
331 
332 #endif // #ifndef VISR_OBJECTMODEL_OBJECT_VECTOR_HPP_INCLUDED
iterator operator++(int)
Definition: object_vector.hpp:174
pointer operator->() const
Definition: object_vector.hpp:162
iterator end()
Definition: object_vector.hpp:272
bool operator!=(const iterator &rhs) const
Definition: object_vector.hpp:164
value_type operator*() const
Definition: object_vector.hpp:156
iterator find(ObjectId id)
Definition: object_vector.hpp:295
const_iterator end() const
Definition: object_vector.hpp:281
unsigned int ObjectId
Definition: object.hpp:23
bool empty() const
Definition: object_vector.hpp:130
const_iterator begin() const
Definition: object_vector.hpp:279
Definition: object_vector.hpp:212
pointer operator->() const
Definition: object_vector.hpp:222
iterator & operator--()
Definition: object_vector.hpp:184
std::size_t size() const
Definition: object_vector.hpp:125
bool operator==(const iterator &rhs) const
Definition: object_vector.hpp:163
bool operator==(const const_iterator &rhs) const
Definition: object_vector.hpp:223
iterator operator--(int)
Definition: object_vector.hpp:189
const_iterator find(ObjectId id) const
Definition: object_vector.hpp:288
Definition: options.cpp:10
bool operator<(InterpolationParameter const &lhs, InterpolationParameter const &rhs)
Definition: interpolation_parameter.hpp:80
const_iterator operator++(int)
Definition: object_vector.hpp:234
const_iterator & operator++()
Definition: object_vector.hpp:229
Definition: object.hpp:36
const_iterator cbegin() const
Definition: object_vector.hpp:284
Definition: object_vector.hpp:150
iterator begin()
Definition: object_vector.hpp:270
iterator & operator++()
Definition: object_vector.hpp:169
Definition: object_vector.hpp:22
value_type operator*() const
Definition: object_vector.hpp:221
const_iterator operator--(int)
Definition: object_vector.hpp:249
bool operator!=(const const_iterator &rhs) const
Definition: object_vector.hpp:224
const_iterator & operator--()
Definition: object_vector.hpp:244
const_iterator cend() const
Definition: object_vector.hpp:286