ptr_vector.h
Go to the documentation of this file.
1 #ifndef PTR_VECTOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
2 #define PTR_VECTOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
3 
4 #if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
5 #pragma once
6 #endif
7 
9 #include <cstddef>
10 #include <cstdlib>
11 #include <memory>
12 #include <vector>
13 
14 namespace YAML_PM {
15 
16  template <typename T>
18  {
19  public:
21  ~ptr_vector() { clear(); }
22 
23  void clear() {
24  for(unsigned i=0;i<m_data.size();i++)
25  delete m_data[i];
26  m_data.clear();
27  }
28 
29  std::size_t size() const { return m_data.size(); }
30  bool empty() const { return m_data.empty(); }
31 
32  void push_back(std::auto_ptr<T> t) {
33  m_data.push_back(NULL);
34  m_data.back() = t.release();
35  }
36  T& operator[](std::size_t i) { return *m_data[i]; }
37  const T& operator[](std::size_t i) const { return *m_data[i]; }
38 
39  T& back() { return *m_data.back(); }
40  const T& back() const { return *m_data.back(); }
41 
42  private:
43  std::vector<T*> m_data;
44  };
45 }
46 
47 #endif // PTR_VECTOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
T & operator[](std::size_t i)
Definition: ptr_vector.h:36
const T & operator[](std::size_t i) const
Definition: ptr_vector.h:37
std::size_t size() const
Definition: ptr_vector.h:29
const T & back() const
Definition: ptr_vector.h:40
std::vector< T * > m_data
Definition: ptr_vector.h:43
bool empty() const
Definition: ptr_vector.h:30
void push_back(std::auto_ptr< T > t)
Definition: ptr_vector.h:32


libpointmatcher
Author(s):
autogenerated on Sat May 27 2023 02:38:03