ptr_vector.h
Go to the documentation of this file.
00001 #ifndef PTR_VECTOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
00002 #define PTR_VECTOR_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 namespace YAML_PM {
00015         
00016         template <typename T>
00017         class ptr_vector: private YAML_PM::noncopyable
00018         {
00019         public:
00020                 ptr_vector() {}
00021                 ~ptr_vector() { clear(); }
00022                 
00023                 void clear() {
00024                         for(unsigned i=0;i<m_data.size();i++)
00025                                 delete m_data[i];
00026                         m_data.clear();
00027                 }
00028                 
00029                 std::size_t size() const { return m_data.size(); }
00030                 bool empty() const { return m_data.empty(); }
00031                 
00032                 void push_back(std::auto_ptr<T> t) {
00033                         m_data.push_back(NULL);
00034                         m_data.back() = t.release();
00035                 }
00036                 T& operator[](std::size_t i) { return *m_data[i]; }
00037                 const T& operator[](std::size_t i) const { return *m_data[i]; }
00038                 
00039                 T& back() { return *m_data.back(); }
00040                 const T& back() const { return *m_data.back(); }
00041 
00042         private:
00043                 std::vector<T*> m_data;
00044         };
00045 }
00046 
00047 #endif // PTR_VECTOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM


libpointmatcher
Author(s):
autogenerated on Thu Jun 20 2019 19:51:32