OGLplus (0.52.0) a C++ wrapper for OpenGL

wrap_tpl.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_OBJECT_WRAP_TPL_1107121519_HPP
14 #define OGLPLUS_OBJECT_WRAP_TPL_1107121519_HPP
15 
16 #include <oglplus/object/desc.hpp>
18 #include <oglplus/object/seq_tpl.hpp>
19 #include <oglplus/utils/nothing.hpp>
20 #include <type_traits>
21 #include <cassert>
22 
23 namespace oglplus {
24 namespace tag {
25 
26 struct Generate { };
27 struct Create { };
28 
29 } // namespace tag
30 
31 template <typename ObjTag>
32 struct ObjectSubtype : Nothing
33 { };
34 
35 template <typename OpsTag, typename ObjTag>
36 struct ObjGenTag
37 {
38  typedef tag::Generate Type;
39 };
40 
41 template <typename ObjTag>
42 class ObjGenDelOps;
43 
44 template <typename OpsTag, typename ObjTag>
45 class ObjectOps;
46 
47 template <typename OpsTg, typename ObjTg>
48 struct Classify<ObjectOps<OpsTg, ObjTg>>
49 {
50  typedef ObjectOps<OpsTg, ObjTg> Base;
51  typedef tag::ObjectOps Tag;
52  typedef OpsTg OpsTag;
53  typedef ObjTg ObjTag;
54 };
55 
57 template <class ObjTag>
58 class ObjCommonOps
59  : public ObjectName<ObjTag>
60 {
61 protected:
62  ObjCommonOps(void) { }
63 };
64 
66 template <class OpsTag, class ObjTag>
67 class ObjZeroOps
68  : public ObjCommonOps<ObjTag>
69 {
70 protected:
71  ObjZeroOps(void) { }
72 };
73 
75 
79 template <class OpsTag, class ObjTag>
80 class ObjectZero<ObjZeroOps<OpsTag, ObjTag>>
81  : public ObjZeroOps<OpsTag, ObjTag>
82 {
83 public:
85  ObjectZero(void) { }
86 };
87 
89 template <class OpsTag, class ObjTag>
90 class ObjectOps
91  : public ObjZeroOps<OpsTag, ObjTag>
92 {
93 protected:
94  ObjectOps(void) { }
95 };
96 
97 template <typename ObjTag, typename NameHolder>
98 class ObjectTpl
99  : public NameHolder
100  , public ObjGenDelOps<ObjTag>
101 {
102 private:
103  typedef typename ObjTag::NameType NameT;
104 
105  // Object is not copy-constructible
106  ObjectTpl(const ObjectTpl&);
107 
108  void _describe(ObjectDesc&& description)
109  {
110  aux::ObjectDescRegistry::_register_desc(
111  ObjTag::value,
112  this->_name,
113  std::move(description)
114  );
115  }
116 
117  void _undescribe(void)
118  {
119  aux::ObjectDescRegistry::_unregister_desc(
120  ObjTag::value,
121  this->_name
122  );
123  }
124 
125  template <typename GenTag>
126  void _init(GenTag gen_tag, Nothing)
127  {
128  ObjGenDelOps<ObjTag>::Gen(gen_tag, 1, &this->_name);
129  }
130 
131  template <typename GenTag, typename ObjectSubtype>
132  void _init(GenTag gen_tag, ObjectSubtype type)
133  {
134  this->_type = GLenum(type);
135  _init(gen_tag, Nothing());
136  }
137 
138  void _move_in(ObjectTpl&& temp)
139  OGLPLUS_NOEXCEPT(true)
140  {
141  this->_name = temp._name;
142  temp._name = 0;
143  }
144 
145  void _cleanup(void)
146  {
147  if(this->_name != 0u)
148  {
149  _undescribe();
150  ObjGenDelOps<ObjTag>::Delete(1, &this->_name);
151  }
152  }
153 protected:
154  struct Uninitialized_ { };
155 
156  ObjectTpl(Uninitialized_) { }
157 
158  ObjectTpl(ObjectName<ObjTag> name)
159  {
160  this->_name = GetName(name);
161  }
162 
163  ObjectTpl(ObjectName<ObjTag> name, ObjectDesc&& description)
164  {
165  this->_name = GetName(name);
166  _describe(std::move(description));
167  }
168 public:
169  template <typename GenTag>
170  ObjectTpl(GenTag gen_tag)
171  {
172  _init(gen_tag, Nothing());
173  }
174 
175  template <typename GenTag>
176  ObjectTpl(GenTag gen_tag, ObjectDesc&& description)
177  {
178  _init(gen_tag, Nothing());
179  _describe(std::move(description));
180  }
181 
182  typedef typename ObjectSubtype<ObjTag>::Type Subtype;
183 
184  template <typename GenTag>
185  ObjectTpl(GenTag gen_tag, Subtype subtype)
186  {
187  _init(gen_tag, subtype);
188  }
189 
190  template <typename GenTag>
191  ObjectTpl(GenTag gen_tag, Subtype subtype, ObjectDesc&& description)
192  {
193  _init(gen_tag, subtype);
194  _describe(std::move(description));
195  }
196 
198  ObjectTpl(ObjectTpl&& temp)
199  OGLPLUS_NOEXCEPT(true)
200  {
201  _move_in(std::move(temp));
202  }
203 
204  ~ObjectTpl(void)
205  OGLPLUS_NOEXCEPT(true)
206  {
207  try { _cleanup(); }
208  catch(...) { }
209  }
210 
212  ObjectTpl& operator = (ObjectTpl&& temp)
213  {
214  _cleanup();
215  _move_in(std::move(temp));
216  return *this;
217  }
218 
220  const std::string& Description(void) const
221  {
222  return aux::ObjectDescRegistry::_get_desc(
223  ObjTag::value,
224  this->_name
225  );
226  }
227 
228  Sequence<ObjectName<ObjTag>> seq(void) const
229  {
230  return Sequence<ObjectName<ObjTag>>(&this->_name, 1);
231  }
232 
234 
237  operator Sequence<ObjectName<ObjTag>> (void) const
238  {
239  return seq();
240  }
241 };
242 
244 template <typename ObjTag>
246  : public ObjectTpl<ObjTag, ObjectName<ObjTag>>
247 {
248 private:
249  typedef ObjectTpl<ObjTag, ObjectName<ObjTag>> Base_;
250  ObjHandle(const ObjHandle&);
251 public:
253  ObjHandle(tag::Generate generate)
254  : Base_(generate)
255  { }
256 
258  ObjHandle(tag::Create create)
259  : Base_(create)
260  { }
261 
263  ObjHandle(ObjectDesc&& description)
264  : Base_(std::move(description))
265  { }
266 
267  ObjHandle(tag::Generate generate, ObjectDesc&& description)
268  : Base_(generate, std::move(description))
269  { }
270 
271  ObjHandle(tag::Create create, ObjectDesc&& description)
272  : Base_(create, std::move(description))
273  { }
274 
276  typedef typename ObjectSubtype<ObjTag>::Type Subtype;
277 
278  ObjHandle(tag::Generate generate, Subtype subtype)
279  : Base_(generate, subtype)
280  { }
281 
282  ObjHandle(tag::Create create, Subtype subtype)
283  : Base_(create, subtype)
284  { }
285 
288  : Base_(static_cast<Base_&&>(temp))
289  { }
290 
293  {
294  Base_::operator = (static_cast<Base_&&>(temp));
295  return *this;
296  }
297 };
298 
300 
306 template <typename OpsTag, typename ObjTag>
307 class Object<ObjectOps<OpsTag, ObjTag>>
308  : public ObjectTpl<ObjTag, ObjectOps<OpsTag, ObjTag>>
309 {
310 private:
311  typedef typename ObjGenTag<OpsTag, ObjTag>::Type DefGenTag;
312  typedef ObjectTpl<ObjTag, ObjectOps<OpsTag, ObjTag>> Base_;
313 
314  Object(const Object&);
315 protected:
316  Object(typename Base_::Uninitialized_ uninit)
317  : Base_(uninit)
318  { }
319 
320  Object(ObjectName<ObjTag> name)
321  : Base_(name)
322  { }
323 
324  Object(ObjectName<ObjTag> name, ObjectDesc&& description)
325  : Base_(name, std::move(description))
326  { }
327 public:
328  static Object FromRawName(ObjectName<ObjTag> name)
329  {
330  return Object(name);
331  }
332 
334  Object(void)
335  : Base_(DefGenTag())
336  { }
337 
339  Object(tag::Generate generate)
340  : Base_(generate)
341  { }
342 
344  Object(tag::Create create)
345  : Base_(create)
346  { }
347 
349  Object(ObjectDesc&& description)
350  : Base_(DefGenTag(), std::move(description))
351  { }
352 
353  Object(tag::Generate generate, ObjectDesc&& description)
354  : Base_(generate, std::move(description))
355  { }
356 
357  Object(tag::Create create, ObjectDesc&& description)
358  : Base_(create, std::move(description))
359  { }
360 
362  typedef typename ObjectSubtype<ObjTag>::Type Subtype;
363 
365  Object(Subtype subtype)
366  : Base_(DefGenTag(), subtype)
367  { }
368 
369  Object(tag::Generate generate, Subtype subtype)
370  : Base_(generate, subtype)
371  { }
372 
373  Object(tag::Create create, Subtype subtype)
374  : Base_(create, subtype)
375  { }
376 
378  Object(Subtype subtype, ObjectDesc&& description)
379  : Base_(DefGenTag(), subtype, std::move(description))
380  { }
381 
382  Object(tag::Generate generate, Subtype subtype, ObjectDesc&& description)
383  : Base_(generate, subtype, std::move(description))
384  { }
385 
386  Object(tag::Create create, Subtype subtype, ObjectDesc&& description)
387  : Base_(create, subtype, std::move(description))
388  { }
389 
391  Object(Object&& temp)
392  : Base_(static_cast<Base_&&>(temp))
393  { }
394 
396  Object& operator = (Object&& temp)
397  {
398  Base_::operator = (static_cast<Base_&&>(temp));
399  return *this;
400  }
401 };
402 
403 template <typename OpsTg, typename ObjTg>
404 struct Classify<Object<ObjectOps<OpsTg, ObjTg>>>
405  : Classify<ObjectOps<OpsTg, ObjTg>>
406 {
407  typedef Object<ObjectOps<OpsTg, ObjTg>> Base;
408  typedef tag::Object Tag;
409 };
410 
411 } // namespace oglplus
412 
413 #endif // include guard
ObjectSubtype< ObjTag >::Type Subtype
Object subtype.
Definition: wrap_tpl.hpp:276
ObjHandle(tag::Create create)
Construction with a specific method of object creation.
Definition: wrap_tpl.hpp:258
ObjHandle & operator=(ObjHandle &&temp)
Object handles are move assignable.
Definition: wrap_tpl.hpp:292
Declaration of Object description.
ObjHandle(tag::Generate generate)
Construction with a specific method of object creation.
Definition: wrap_tpl.hpp:253
Object(Object &&temp)
Objects are move constructible.
Definition: wrap_tpl.hpp:391
Implements operations applicable to named (non-zero) objects.
Definition: wrap_tpl.hpp:45
Object(ObjectDesc &&description)
A textual description can be attached to objects.
Definition: wrap_tpl.hpp:349
Template.
Definition: wrap_tpl.hpp:245
Object(tag::Create create)
Construction with a specific method of object creation.
Definition: wrap_tpl.hpp:344
Implements operations applicable to any object including object 0 (zero)
Definition: fwd.hpp:157
ObjTag::NameType GetName(ObjectName< ObjTag >)
Returns the base name assigned to named object.
Definition: name_tpl.hpp:128
ObjectZero(void)
ObjectZero is default constructible.
Definition: wrap_tpl.hpp:85
Object(tag::Generate generate)
Construction with a specific method of object creation.
Definition: wrap_tpl.hpp:339
Object(void)
Most objects are default constructible.
Definition: wrap_tpl.hpp:334
Object(Subtype subtype, ObjectDesc &&description)
A textual description can be attached to objects.
Definition: wrap_tpl.hpp:378
ObjHandle(ObjHandle &&temp)
Object handles are move constructible.
Definition: wrap_tpl.hpp:287
ObjectSubtype< ObjTag >::Type Subtype
Object subtype.
Definition: wrap_tpl.hpp:362
Implements operations applicable to any object and any operation kind.
Definition: fwd.hpp:151
Base template for all "named" objects.
ObjHandle(ObjectDesc &&description)
A textual description can be attached to object handles.
Definition: wrap_tpl.hpp:263
Object(Subtype subtype)
Construction with subtype specification.
Definition: wrap_tpl.hpp:365
A common template for "named" objects like textures, buffers, etc.
Definition: fwd.hpp:136

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