1 #ifndef ARRAY_REF_OPENGL_UTILITY_H
2 #define ARRAY_REF_OPENGL_UTILITY_H
13 #include <boost/array.hpp>
59 typedef const T * pointer;
60 typedef const T & reference;
61 typedef const T & const_reference;
62 typedef const T * const_iterator;
63 typedef const_iterator iterator;
64 typedef std::reverse_iterator< const_iterator > const_reverse_iterator;
65 typedef const_reverse_iterator reverse_iterator;
66 typedef size_t size_type;
67 typedef ptrdiff_t difference_type;
72 array_ref(
const T *arr,
size_t length) : m_data(arr), m_size(length) {}
73 array_ref(
const std::vector<T> & v) : m_data(&v[0]), m_size(v.size()) {}
75 array_ref(
const T(&a)[N]) : m_data(a), m_size(N) {}
77 array_ref(
const boost::array< T, N > & a) : m_data(a.data()), m_size(N) {}
79 const_iterator begin()
const {
return m_data;}
80 const_iterator end()
const {
return m_data + m_size;}
81 const_iterator cbegin()
const {
return m_data;}
82 const_iterator cend()
const {
return m_data + m_size;}
83 const_reverse_iterator rbegin()
const {
return const_reverse_iterator(end());}
84 const_reverse_iterator rend()
const {
return const_reverse_iterator(begin());}
85 const_reverse_iterator crbegin()
const {
return const_reverse_iterator(cend());}
86 const_reverse_iterator crend()
const {
return const_reverse_iterator(cbegin());}
88 size_type size()
const {
return m_size;}
89 size_type max_size()
const {
return std::numeric_limits<size_type>::max();}
90 bool empty()
const {
return m_size == 0;}
92 const T & operator[](
size_t i)
const {
return m_data[i];}
93 const T & at(
size_t i)
const
96 throw std::out_of_range();
99 const T & front()
const {
return m_data[0];}
100 const T & back()
const {
return m_data[m_size - 1];}
101 const T * data()
const {
return m_data;}
103 std::vector<T> vec()
const {
return std::vector<T>(m_data, m_data + m_size);}
104 std::basic_string<T> str()
const {
return std::basic_string<T>(m_data, m_data + m_size);}
106 void clear() {m_size = 0; m_data = NULL;}
107 void remove_prefix(size_type n)
115 void remove_suffix(size_type n)
122 void pop_front() {remove_prefix(1);}
123 void pop_back() {remove_suffix(1);}
131 #endif //ARRAY_REF_OPENGL_UTILITY_H