OGLplus (0.52.0) a C++ wrapper for OpenGL

array.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_OBJECT_ARRAY_1107121519_HPP
14 #define OGLPLUS_OBJECT_ARRAY_1107121519_HPP
15 
17 #include <oglplus/object/seq_tpl.hpp>
18 #include <oglplus/utils/nothing.hpp>
19 
20 #include <vector>
21 #include <cassert>
22 
23 namespace oglplus {
24 
25 template <typename ObjTag>
26 struct ObjectSubtype;
27 
28 template <typename ObjTag>
29 class ObjGenDelOps;
30 
32 
37 template <typename Object>
38 class Array
39  : public ObjGenDelOps<typename Classify<Object>::ObjTag>
40 {
41 private:
42  typedef typename Classify<Object>::OpsTag OpsTag;
43  typedef typename Classify<Object>::ObjTag ObjTag;
44  typedef typename ObjGenTag<OpsTag, ObjTag>::Type GenTag;
45  typedef ObjGenDelOps<ObjTag> GenDelOps;
46 
48  Array(const Array&);
49 protected:
50  typedef typename ObjTag::NameType NameT;
51  std::vector<NameT> _names;
52 
53  void _init(Nothing)
54  {
55  GenDelOps::Gen(GenTag(), GLsizei(_names.size()), _names.data());
56  }
57 
58  template <typename ObjectSubtype>
59  void _init(ObjectSubtype type)
60  {
61  this->_type = decltype(this->_type)(type);
62  _init(Nothing());
63  }
64 public:
66  Array(Array&& temp)
67  : _names(std::move(temp._names))
68  { }
69 
71  Array(std::size_t count)
72  : _names(count, 0u)
73  {
74  _init(Nothing());
75  }
76 
78  Array(std::size_t n, typename ObjectSubtype<ObjTag>::Type type)
79  : _names(n, 0u)
80  {
81  _init(type);
82  }
83 
84  ~Array(void)
85  {
86  if(!_names.empty())
87  {
88  GenDelOps::Delete(
89  GLsizei(_names.size()),
90  _names.data()
91  );
92  }
93  }
94 
96  bool empty(void) const
97  {
98  return _names.empty();
99  }
100 
102  std::size_t size(void) const
103  {
104  return _names.size();
105  }
106 
109 
111  typedef const reference const_reference;
112 
114  reference at(std::size_t index)
115  {
116  return reference(ObjectName<ObjTag>(_names.at(index)));
117  }
118 
120  const_reference at(NameT index) const
121  {
122  return const_reference(ObjectName<ObjTag>(_names.at(index)));
123  }
124 
126  reference operator[](std::size_t index)
127  {
128  return at(index);
129  }
130 
132  const_reference operator[](std::size_t index) const
133  {
134  return at(index);
135  }
136 
139 
142 
144  const_iterator begin(void) const
145  {
146  return const_iterator(_names.data());
147  }
148 
150  const_iterator end(void) const
151  {
152  return const_iterator(_names.data()+_names.size());
153  }
154 
155 /*
157  Range<Object> all(void) const;
158 */
159  Sequence<ObjectName<ObjTag>> seq(void) const
160  {
162  _names.data(),
163  _names.size()
164  );
165  }
166 
167  operator Sequence<ObjectName<ObjTag>> (void) const
168  {
169  return seq();
170  }
171 };
172 
173 } // namespace oglplus
174 
175 #endif // include guard
Array(std::size_t count)
Constructs an an array of count instances of Object.
Definition: array.hpp:71
Common base class for Object name sequences.
Definition: fwd.hpp:139
Reference< Object > reference
Reference to elements.
Definition: array.hpp:108
const_iterator end(void) const
Returns an iterator pointing past the last element.
Definition: array.hpp:150
iterator const_iterator
Const-iterator type.
Definition: array.hpp:141
Object sequence iterator template.
Definition: seq_tpl.hpp:24
Reference to an existing Object.
const_iterator begin(void) const
Returns an iterator pointing to the first element.
Definition: array.hpp:144
std::size_t size(void) const
Returns the number of instances in the array.
Definition: array.hpp:102
reference operator[](std::size_t index)
Returns a reference to the i-th instance in the array.
Definition: array.hpp:126
SeqIterator< Object > iterator
Iterator type.
Definition: array.hpp:138
Array(Array &&temp)
Array is moveable.
Definition: array.hpp:66
bool empty(void) const
Returns true if the array is empty.
Definition: array.hpp:96
Array(std::size_t n, typename ObjectSubtype< ObjTag >::Type type)
Constructs an an array of n instances of Object with type.
Definition: array.hpp:78
reference at(std::size_t index)
Returns a reference to the i-th instance in the array.
Definition: array.hpp:114
const_reference at(NameT index) const
Returns a const reference to the i-th instance in the array.
Definition: array.hpp:120
Allows to allocate and manage several instances of Object at the same time.
Definition: fwd.hpp:183
A common template for "named" objects like textures, buffers, etc.
Definition: fwd.hpp:136
Allows to make managed copies of instances of Object.
Definition: fwd.hpp:172
const reference const_reference
Reference to const elements.
Definition: array.hpp:111
const_reference operator[](std::size_t index) const
Returns a const reference to the i-th instance in the array.
Definition: array.hpp:132

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).