Helios++
Helios software for LiDAR simulations
PointerVector.h
1 #pragma once
2 
3 #include <memory>
4 #include <vector>
5 
17 template <typename T> class PointerVector {
18 protected:
19  // *** ATTRIBUTES *** //
20  // ******************** //
24  std::vector<T *> v;
25 
26 public:
27  // *** CONSTRUCTION / DESTRUCTION *** //
28  // ************************************ //
32  PointerVector() = default;
39  PointerVector(size_t const numElements) {v.reserve(numElements);}
44  virtual ~PointerVector() {for(T * vi : v) delete vi;}
45 
46  // *** OPERATORS *** //
47  // ******************* //
51  inline std::vector<T *> & operator* () {return v;}
57  inline T * operator[] (size_t const i){return v[i];}
58 };
Wrapper to have a vector of pointers such that when it is destroyed, all the pointers are deleted.
Definition: PointerVector.h:17
PointerVector(size_t const numElements)
Constructor that initializes a shared vector to hold for numElements pointers.
Definition: PointerVector.h:39
PointerVector()=default
Default constructor.
std::vector< T * > & operator*()
Access a reference to the vector.
Definition: PointerVector.h:51
virtual ~PointerVector()
Destructor that deletes what is hold for each pointer in the pointer vector before deleting the Point...
Definition: PointerVector.h:44
std::vector< T * > v
The vector of pointers.
Definition: PointerVector.h:24
T * operator[](size_t const i)
Definition: PointerVector.h:57