34 #include <cugar/basic/types.h> 35 #include <cugar/basic/iterator.h> 86 template <
typename Iterator,
typename IndexType = u
int32>
89 typedef Iterator iterator;
90 typedef Iterator const_iterator;
93 typedef typename iterator_traits<Iterator>::value_type value_type;
94 typedef typename iterator_traits<Iterator>::reference reference;
95 typedef typename to_const<reference>::type const_reference;
96 typedef typename iterator_traits<Iterator>::pointer pointer;
97 typedef IndexType size_type;
98 typedef IndexType index_type;
99 typedef typename iterator_traits<Iterator>::difference_type difference_type;
100 typedef std::random_access_iterator_tag iterator_category;
107 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
112 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
117 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
118 void resize(
const uint32 sz) { m_size = sz; }
122 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
127 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
128 IndexType
size()
const {
return m_size; }
132 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
133 IndexType
length()
const {
return m_size; }
137 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
138 bool empty()
const {
return m_size == 0; }
142 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
143 const_reference
operator*()
const { CUGAR_CUDA_DEBUG_ASSERT( 0 < m_size,
"vector_view: access out of bounds, dereferenced zero sized vector\n" );
return *m_vec; }
147 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
148 reference
operator*() { CUGAR_CUDA_DEBUG_ASSERT( 0 < m_size,
"vector_view: access out of bounds, dereferenced zero sized vector\n" );
return *m_vec; }
152 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
153 const_reference
operator[](
const IndexType i)
const { CUGAR_CUDA_DEBUG_ASSERT( i < m_size, "vector_view: access out of bounds, %llu >= %llu\n
", uint64(i), uint64(m_size) ); return m_vec[i]; } 157 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE 158 reference operator[](const IndexType i) { CUGAR_CUDA_DEBUG_ASSERT( i < m_size, "vector_view: access out of bounds, %llu >= %llu\n
", uint64(i), uint64(m_size) ); return m_vec[i]; } 162 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE 163 const_reference front(void) const { return m_vec[0]; } 167 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE 168 reference front(void) { return m_vec[0]; } 172 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE 173 const_reference back(void) const { return m_vec[m_size-1]; } 177 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE 178 reference back(void) { return m_vec[m_size-1]; } 182 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE 183 Iterator base() const { return m_vec; } 187 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE 188 const_iterator begin() const { return m_vec; } 192 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE 193 const_iterator end() const { return m_vec + m_size; } 197 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE 198 iterator begin() { return m_vec; } 202 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE 203 iterator end() { return m_vec + m_size; } 207 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE 208 operator Iterator() const { return m_vec; } 212 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE 213 void push_back(const_reference val) { m_vec[ m_size ] = val; m_size++; } 217 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE 218 void pop_back() { --m_size; } 226 template <typename Iterator> 227 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE 228 uint32 length(const vector_view<Iterator>& vec) { return vec.length(); } 232 template <typename T> 233 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE 234 T raw_pointer(const vector_view<T>& vec) { return vec.base(); } 238 template <typename T, typename I> 239 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE 240 T begin(vector_view<T,I>& vec) { return vec.begin(); } 244 template <typename T, typename I> 245 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE 246 T begin(const vector_view<T,I>& vec) { return vec.begin(); } 249 // --- std::vector views ---------------------------------------------------------------------------- 254 template <typename T> struct plain_view_subtype< std::vector<T> > { typedef vector_view<T*,uint64> type; }; 258 template <typename T> struct plain_view_subtype< const std::vector<T> > { typedef vector_view<const T*,uint64> type; }; 263 template <typename T> 264 vector_view<T*,uint64> plain_view(std::vector<T>& vec) { return vector_view<T*,uint64>( vec.size(), vec.size() ? &vec[0] : NULL ); } 268 template <typename T> 269 vector_view<const T*,uint64> plain_view(const std::vector<T>& vec) { return vector_view<const T*,uint64>( vec.size(), vec.size() ? &vec[0] : NULL ); } 273 template <typename T> 274 T* raw_pointer(std::vector<T>& vec) { return vec.size() ? &vec[0] : NULL; } 278 template <typename T> 279 const T* raw_pointer(const std::vector<T>& vec) { return vec.size() ? &vec[0] : NULL; } 283 template <typename T> T* begin(T* vec) { return vec; } 287 template <typename T> const T* begin(const T* vec) { return vec; } CUGAR_FORCEINLINE CUGAR_HOST_DEVICE reference operator*()
Definition: vector_view.h:148
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE void clear()
Definition: vector_view.h:123
Definition: vector_view.h:87
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE IndexType length() const
Definition: vector_view.h:133
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE IndexType size() const
Definition: vector_view.h:128
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE vector_view()
Definition: vector_view.h:108
T forward_iterator
add forward iterator conversion
Definition: iterator.h:118
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE bool empty() const
Definition: vector_view.h:138
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE const_reference operator*() const
Definition: vector_view.h:143
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE void resize(const uint32 sz)
Definition: vector_view.h:118
Define a vector_view POD type and plain_view() for std::vector.
Definition: diff.h:38
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE vector_view(const IndexType size, Iterator vec)
Definition: vector_view.h:113
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE const_reference operator[](const IndexType i) const
Definition: vector_view.h:153