OGLplus (0.52.0) a C++ wrapper for OpenGL

seq_tpl.hpp
1 
12 #pragma once
13 #ifndef OGLPLUS_OBJECT_SEQ_TPL_1405011014_HPP
14 #define OGLPLUS_OBJECT_SEQ_TPL_1405011014_HPP
15 
17 #include <cstddef>
18 #include <cassert>
19 
20 namespace oglplus {
21 
23 template <typename ObjectT>
25 {
26 private:
27  typedef typename Classify<ObjectT>::ObjTag ObjTag;
28  typedef typename ObjTag::NameType NameT;
29  const NameT* _pos;
30 public:
31  SeqIterator(const NameT* pos)
32  : _pos(pos)
33  { }
34 
37  {
38  return a._pos == b._pos;
39  }
40 
43  {
44  return a._pos != b._pos;
45  }
46 
49  {
50  return a._pos < b._pos;
51  }
52 
54  typedef ObjectT value_type;
55 
57  typedef std::ptrdiff_t difference_type;
58 
61  {
62  return a._pos - b._pos;
63  }
64 
66  value_type operator * (void) const
67  {
68  assert(_pos != nullptr);
69  return ObjectT(ObjectName<ObjTag>(*_pos));
70  }
71 
73  value_type operator [](std::size_t index) const
74  {
75  assert(_pos != nullptr);
76  return ObjectT(ObjectName<ObjTag>(_pos[index]));
77  }
78 
81  {
82  ++_pos;
83  return *this;
84  }
85 
88  {
89  return SeqIterator(_pos++);
90  }
91 
94  {
95  --_pos;
96  return *this;
97  }
98 
101  {
102  return SeqIterator(_pos--);
103  }
104 
107  {
108  return SeqIterator(a._pos+d);
109  }
110 
113  {
114  _pos += d;
115  return *this;
116  }
117 
120  {
121  return SeqIterator(a._pos-d);
122  }
123 
126  {
127  _pos -= d;
128  return *this;
129  }
130 };
131 
132 template <typename ObjectT>
133 const typename Classify<ObjectT>::ObjTag::NameType*
134 GetNames(const Sequence<ObjectT>&);
135 
137 template <typename ObjectT>
138 class Sequence
139 {
140 private:
141  typedef typename Classify<ObjectT>::ObjTag ObjTag;
142  typedef typename ObjTag::NameType NameT;
143 
144  friend const NameT* GetNames<ObjectT>(const Sequence&);
145 
146  const NameT* _names;
147  std::size_t _size;
148 public:
149  Sequence(void)
150  : _names(nullptr)
151  , _size(0)
152  { }
153 
154  Sequence(const NameT* names, std::size_t count)
155  : _names(names)
156  , _size(count)
157  { }
158 
160  bool empty(void) const
161  {
162  return _size == 0;
163  }
164 
166  std::size_t size(void) const
167  {
168  return _size;
169  }
170 
172  ObjectT at(std::size_t index) const
173  {
174  assert(index < _size);
175  return ObjectT(_names[index]);
176  }
177 
179  ObjectT operator[](std::size_t index) const
180  {
181  return at(index);
182  }
183 
185  Sequence slice(std::size_t start) const
186  {
187  assert(start <= _size);
188  return Sequence(_names+start, _size-start);
189  }
190 
192  Sequence slice(std::size_t start, std::size_t count) const
193  {
194  assert(start + count <= _size);
195  return Sequence(_names+start, count);
196  }
197 
202 
204  const_iterator begin(void) const
205  {
206  return const_iterator(_names);
207  }
208 
210  const_iterator end(void) const
211  {
212  return const_iterator(_names+_size);
213  }
214 };
215 
217 template <typename ObjectT>
218 inline const typename Classify<ObjectT>::ObjTag::NameType*
219 GetNames(const Sequence<ObjectT>& sequence)
220 {
221  return sequence._names;
222 }
223 
224 } // namespace oglplus
225 
226 #endif // include guard
Common base class for Object name sequences.
Definition: fwd.hpp:139
friend SeqIterator operator+(SeqIterator a, difference_type d)
Positive offset.
Definition: seq_tpl.hpp:106
Object sequence iterator template.
Definition: seq_tpl.hpp:24
SeqIterator< ObjectT > const_iterator
Const iterator type.
Definition: seq_tpl.hpp:201
bool empty(void) const
Returns true if the sequence is empty.
Definition: seq_tpl.hpp:160
value_type operator[](std::size_t index) const
Array access.
Definition: seq_tpl.hpp:73
SeqIterator & operator++(void)
Preincrement.
Definition: seq_tpl.hpp:80
std::size_t size(void) const
Returns the size of the sequence.
Definition: seq_tpl.hpp:166
SeqIterator & operator+=(difference_type d)
Positive offset.
Definition: seq_tpl.hpp:112
const_iterator end(void) const
Position past the end of the sequence.
Definition: seq_tpl.hpp:210
friend bool operator!=(SeqIterator a, SeqIterator b)
Inequality comparison.
Definition: seq_tpl.hpp:42
SeqIterator & operator--(void)
Predecrement.
Definition: seq_tpl.hpp:93
SeqIterator & operator-=(difference_type d)
Negative offset.
Definition: seq_tpl.hpp:125
const_iterator begin(void) const
Position at the beginning of the sequence.
Definition: seq_tpl.hpp:204
ObjectT operator[](std::size_t index) const
Returns the object name at the specified index.
Definition: seq_tpl.hpp:179
ObjectT value_type
Value type.
Definition: seq_tpl.hpp:54
const Classify< ObjectT >::ObjTag::NameType * GetNames(const Sequence< ObjectT > &)
Returns a pointer to array of names stored in a sequence.
Definition: seq_tpl.hpp:219
value_type operator*(void) const
Dereference.
Definition: seq_tpl.hpp:66
ObjectT at(std::size_t index) const
Returns the object name at the specified index.
Definition: seq_tpl.hpp:172
friend bool operator==(SeqIterator a, SeqIterator b)
Equality comparison.
Definition: seq_tpl.hpp:36
friend bool operator<(SeqIterator a, SeqIterator b)
Ordering.
Definition: seq_tpl.hpp:48
friend difference_type operator-(SeqIterator a, SeqIterator b)
Distance.
Definition: seq_tpl.hpp:60
Sequence slice(std::size_t start) const
Returns a subsequence starting at start.
Definition: seq_tpl.hpp:185
Base template for all "named" objects.
std::ptrdiff_t difference_type
Difference type.
Definition: seq_tpl.hpp:57
SeqIterator< ObjectT > iterator
Iterator type.
Definition: seq_tpl.hpp:199
A common template for "named" objects like textures, buffers, etc.
Definition: fwd.hpp:136
Sequence slice(std::size_t start, std::size_t count) const
Returns a subsequence with the specified count starting at start.
Definition: seq_tpl.hpp:192

Copyright © 2010-2014 Matúš Chochlík, University of Žilina, Žilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Mon Sep 22 2014 by Doxygen (version 1.8.6).