OGLplus (0.52.0) a C++ wrapper for OpenGL

name_tpl.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_OBJECT_NAME_TPL_1107121519_HPP
14 #define OGLPLUS_OBJECT_NAME_TPL_1107121519_HPP
15 
16 #include <oglplus/config/compiler.hpp>
17 
18 #include <type_traits>
19 #include <utility>
20 #include <cassert>
21 
22 namespace oglplus {
23 namespace tag {
24 
25 struct ObjectName;
26 
27 } // namespace tag
28 
29 template <typename ObjTag>
30 class ObjectName;
31 
32 template <typename ObjTag>
33 typename ObjTag::NameType
34 GetName(ObjectName<ObjTag>);
35 
37 
46 template <typename ObjTag>
47 class ObjectName
48 {
49 protected:
50  typedef typename ObjTag::NameType NameT;
51 
52  friend NameT GetName<ObjTag>(ObjectName);
53  NameT _name;
54 
55  void _copy(const ObjectName& that)
56  OGLPLUS_NOEXCEPT(true)
57  {
58  _name = that._name;
59  }
60 
61  void _adopt(ObjectName&& temp)
62  OGLPLUS_NOEXCEPT(true)
63  {
64  _name = temp._name;
65  temp._name = 0;
66  }
67 public:
69  ObjectName(void)
70  OGLPLUS_NOEXCEPT(true)
71  : _name(NameT(0))
72  { }
73 
75  explicit ObjectName(NameT name)
76  OGLPLUS_NOEXCEPT(true)
77  : _name(name)
78  { }
79 
80  ObjectName(const ObjectName& that)
81  OGLPLUS_NOEXCEPT(true)
82  : _name(that._name)
83  { }
84 
85  ObjectName(ObjectName&& temp)
86  OGLPLUS_NOEXCEPT(true)
87  : _name(temp._name)
88  {
89  temp._name = 0;
90  }
91 
92  ObjectName& operator = (const ObjectName& that)
93  OGLPLUS_NOEXCEPT(true)
94  {
95  _copy(that);
96  return *this;
97  }
98 
99  ObjectName& operator = (ObjectName&& temp)
100  OGLPLUS_NOEXCEPT(true)
101  {
102  _adopt(std::move(temp));
103  return *this;
104  }
105 
108  {
109  return a._name == b._name;
110  }
111 
114  {
115  return a._name != b._name;
116  }
117 
120  {
121  return a._name < b._name;
122  }
123 };
124 
126 template <typename ObjTag>
127 inline typename ObjTag::NameType
129 {
130  return named._name;
131 }
132 
133 template <typename X>
134 struct Classify;
135 
136 template <typename ObjTg>
137 struct Classify<ObjectName<ObjTg>>
138 {
139  typedef ObjectName<ObjTg> Base;
140  typedef tag::ObjectName Tag;
141  typedef ObjTg ObjTag;
142 };
143 
144 } // namespace oglplus
145 
146 #endif // include guard
ObjectName(NameT name)
Constructs wrapper for the specified name.
Definition: name_tpl.hpp:75
friend bool operator!=(ObjectName a, ObjectName b)
Inequality comparison.
Definition: name_tpl.hpp:113
friend bool operator<(ObjectName a, ObjectName b)
Ordering.
Definition: name_tpl.hpp:119
ObjTag::NameType GetName(ObjectName< ObjTag >)
Returns the base name assigned to named object.
Definition: name_tpl.hpp:128
friend bool operator==(ObjectName a, ObjectName b)
Equality comparison.
Definition: name_tpl.hpp:107
ObjectName(void)
Constructs wrapper for name 0 (zero).
Definition: name_tpl.hpp:69
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).