external libraries: yaml-cpp version bump
[supercollider.git] / external_libraries / yaml-cpp-0.3.0 / src / ptr_vector.h
blob7b936cb5fedb7dc06c7815490b182e8953a51343
1 #ifndef PTR_VECTOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
2 #define PTR_VECTOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
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
8 #include "yaml-cpp/noncopyable.h"
9 #include <cstddef>
10 #include <cstdlib>
11 #include <memory>
12 #include <vector>
14 namespace YAML {
16 template <typename T>
17 class ptr_vector: private YAML::noncopyable
19 public:
20 ptr_vector() {}
21 ~ptr_vector() { clear(); }
23 void clear() {
24 for(unsigned i=0;i<m_data.size();i++)
25 delete m_data[i];
26 m_data.clear();
29 std::size_t size() const { return m_data.size(); }
30 bool empty() const { return m_data.empty(); }
32 void push_back(std::auto_ptr<T> t) {
33 m_data.push_back(NULL);
34 m_data.back() = t.release();
36 T& operator[](std::size_t i) { return *m_data[i]; }
37 const T& operator[](std::size_t i) const { return *m_data[i]; }
39 T& back() { return *m_data.back(); }
40 const T& back() const { return *m_data.back(); }
42 private:
43 std::vector<T*> m_data;
47 #endif // PTR_VECTOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66