ptr_stack.h
Go to the documentation of this file.
1 #ifndef PTR_STACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
2 #define PTR_STACK_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 template <typename T>
16 {
17 public:
18  ptr_stack() {}
19  ~ptr_stack() { clear(); }
20 
21  void clear() {
22  for(unsigned i=0;i<m_data.size();i++)
23  delete m_data[i];
24  m_data.clear();
25  }
26 
27  std::size_t size() const { return m_data.size(); }
28  bool empty() const { return m_data.empty(); }
29 
30  void push(std::auto_ptr<T> t) {
31  m_data.push_back(NULL);
32  m_data.back() = t.release();
33  }
34  std::auto_ptr<T> pop() {
35  std::auto_ptr<T> t(m_data.back());
36  m_data.pop_back();
37  return t;
38  }
39  T& top() { return *m_data.back(); }
40  const T& top() const { return *m_data.back(); }
41 
42 private:
43  std::vector<T*> m_data;
44 };
45 
46 #endif // PTR_STACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
std::size_t size() const
Definition: ptr_stack.h:27
void push(std::auto_ptr< T > t)
Definition: ptr_stack.h:30
bool empty() const
Definition: ptr_stack.h:28
const T & top() const
Definition: ptr_stack.h:40
~ptr_stack()
Definition: ptr_stack.h:19
T & top()
Definition: ptr_stack.h:39
std::auto_ptr< T > pop()
Definition: ptr_stack.h:34
ptr_stack()
Definition: ptr_stack.h:18
void clear()
Definition: ptr_stack.h:21
std::vector< T * > m_data
Definition: ptr_stack.h:43


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