Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef CLASP_POD_VECTOR_H_INCLUDED
00022 #define CLASP_POD_VECTOR_H_INCLUDED
00023 #include <clasp/util/pod_vector.h>
00024 #include <vector>
00025
00026 namespace Clasp {
00027
00028 #ifdef _DEBUG
00029 template <class Type>
00030 struct PodVector {
00031 typedef std::vector<Type> type;
00032 static void destruct(type& t) {t.clear();}
00033 };
00034 #else
00035 template <class Type>
00036 struct PodVector {
00037 typedef bk_lib::pod_vector<Type> type;
00038 static void destruct(type& t) {
00039 for (typename type::size_type i = 0, end = t.size(); i != end; ++i) {
00040 t[i].~Type();
00041 }
00042 t.clear();
00043 }
00044 };
00045 #endif
00046
00047 template <class T>
00048 inline void releaseVec(T& t) {
00049 T().swap(t);
00050 }
00051
00052 template <class T>
00053 inline void shrinkVecTo(T& t, typename T::size_type j) {
00054 t.erase(t.begin()+j, t.end());
00055 }
00056
00057 template <class T>
00058 inline void growVecTo(T& vec, typename T::size_type j, const typename T::value_type& val = typename T::value_type()) {
00059 if (vec.size() < j) {
00060 if (vec.capacity() < j) { vec.reserve(j + j / 2); }
00061 vec.resize(j, val);
00062 }
00063 }
00064
00065 template <class T>
00066 void moveDown(T& t, typename T::size_type from, typename T::size_type to) {
00067 for (typename T::size_type end = t.size(); from != end;) {
00068 t[to++] = t[from++];
00069 }
00070 shrinkVecTo(t, to);
00071 }
00072
00073 template <class T>
00074 struct PodQueue {
00075 typedef typename PodVector<T>::type vec_type;
00076 typedef typename vec_type::size_type size_type;
00077 PodQueue() : qFront(0) {}
00078 bool empty() const { return qFront == vec.size(); }
00079 size_type size() const { return vec.size() - qFront; }
00080 const T& front() const { return vec[qFront]; }
00081 const T& back() const { return vec.back(); }
00082 T& front() { return vec[qFront]; }
00083 T& back() { return vec.back(); }
00084 void push(const T& x){ vec.push_back(x); }
00085 void pop() { ++qFront; }
00086 T pop_ret() { return vec[qFront++]; }
00087 void clear() { vec.clear(); qFront = 0; }
00088 void rewind() { qFront = 0; }
00089 vec_type vec;
00090 size_type qFront;
00091 };
00092
00093 }
00094
00095 #endif