ptr_stack.h
Go to the documentation of this file.
00001 #ifndef PTR_STACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
00002 #define PTR_STACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
00003 
00004 #if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
00005 #pragma once
00006 #endif
00007 
00008 #include "yaml-cpp-pm/noncopyable.h"
00009 #include <cstddef>
00010 #include <cstdlib>
00011 #include <memory>
00012 #include <vector>
00013 
00014 template <typename T>
00015 class ptr_stack: private YAML_PM::noncopyable
00016 {
00017 public:
00018         ptr_stack() {}
00019         ~ptr_stack() { clear(); }
00020         
00021         void clear() {
00022                 for(unsigned i=0;i<m_data.size();i++)
00023                         delete m_data[i];
00024                 m_data.clear();
00025         }
00026         
00027         std::size_t size() const { return m_data.size(); }
00028         bool empty() const { return m_data.empty(); }
00029         
00030         void push(std::auto_ptr<T> t) {
00031                 m_data.push_back(NULL);
00032                 m_data.back() = t.release();
00033         }
00034         std::auto_ptr<T> pop() {
00035                 std::auto_ptr<T> t(m_data.back());
00036                 m_data.pop_back();
00037                 return t;
00038         }
00039         T& top() { return *m_data.back(); }
00040         const T& top() const { return *m_data.back(); }
00041         
00042 private:
00043         std::vector<T*> m_data;
00044 };
00045 
00046 #endif // PTR_STACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM


libpointmatcher
Author(s):
autogenerated on Mon Sep 14 2015 02:59:06