OGLplus (0.52.0) a C++ wrapper for OpenGL

desc.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_OBJECT_DESC_1107121519_HPP
14 #define OGLPLUS_OBJECT_DESC_1107121519_HPP
15 
16 #include <oglplus/config/object.hpp>
17 #include <oglplus/string/empty.hpp>
19 
20 #if !OGLPLUS_NO_OBJECT_DESC
21 #include <cassert>
22 #include <map>
23 #endif
24 
25 namespace oglplus {
26 
27 class ObjectDesc
28 {
29 private:
30 #if !OGLPLUS_NO_OBJECT_DESC
31  std::string _str;
32 #endif
33 public:
34  ObjectDesc(void) { }
35 
36  ObjectDesc(std::string&& str)
37 #if !OGLPLUS_NO_OBJECT_DESC
38  : _str(std::forward<std::string>(str))
39 #endif
40  {
41  OGLPLUS_FAKE_USE(str);
42  }
43 
44  ObjectDesc(ObjectDesc&& tmp)
45 #if !OGLPLUS_NO_OBJECT_DESC
46  : _str(std::move(tmp._str))
47 #endif
48  {
49  OGLPLUS_FAKE_USE(tmp);
50  }
51 
52  const std::string& Str(void)
53  {
54 #if !OGLPLUS_NO_OBJECT_DESC
55  return _str;
56 #else
57  return EmptyStdString();
58 #endif
59  }
60 
61 #if !OGLPLUS_NO_OBJECT_DESC
62  std::string&& Release(void)
63  {
64  return std::move(_str);
65  }
66 #endif
67 };
68 
69 namespace aux {
70 
71 #if !OGLPLUS_NO_OBJECT_DESC
72 ::std::map<unsigned, std::string>& ObjectDescRegistryStorage(int id);
73 #endif
74 
75 #if !OGLPLUS_NO_OBJECT_DESC
76 class ObjectDescRegistryBase
77 {
78 private:
79  typedef ::std::map<unsigned, std::string> _desc_map;
80 protected:
81  static void _do_register_desc(
82  _desc_map& storage,
83  unsigned name,
84  ObjectDesc&& desc
85  );
86 
87  static void _do_unregister_desc(
88  _desc_map& storage,
89  unsigned name
90  );
91 
92  static const std::string& _do_get_desc(
93  _desc_map& storage,
94  unsigned name
95  );
96 };
97 #endif // !OGLPLUS_NO_OBJECT_DESC
98 
99 class ObjectDescRegistry
100 #if !OGLPLUS_NO_OBJECT_DESC
101  : public ObjectDescRegistryBase
102 #endif
103 {
104 private:
105 #if !OGLPLUS_NO_OBJECT_DESC
106  typedef ObjectDescRegistryBase _base;
107  typedef ::std::map<unsigned, std::string> _desc_map;
108 
109  static _desc_map& _storage(int id)
110  {
111  return ObjectDescRegistryStorage(id);
112  }
113 #endif
114 public:
115  // internal implementation detail. do not use directly
116  static void _register_desc(int id, unsigned name, ObjectDesc&& desc)
117 #if OGLPLUS_NO_OBJECT_DESC
118  OGLPLUS_NOEXCEPT(true) { (void)id; (void)name; (void)desc; }
119 #else
120  {
121  _base::_do_register_desc(
122  _storage(id),
123  name,
124  std::move(desc)
125  );
126  }
127 #endif
128 
129  // internal implementation detail. do not use directly
130  static void _unregister_desc(int id, unsigned name)
131 #if OGLPLUS_NO_OBJECT_DESC
132  OGLPLUS_NOEXCEPT(true) { (void)id; (void)name; }
133 #else
134  {
135  _base::_do_unregister_desc(_storage(id), name);
136  }
137 #endif
138 
139  // internal implementation detail. do not use directly
140 #if OGLPLUS_NO_OBJECT_DESC
141  static const std::string& _get_desc(int, unsigned)
142  OGLPLUS_NOEXCEPT(true)
143  {
144  return EmptyStdString();
145  }
146 #else
147  static const std::string& _get_desc(int id, unsigned name)
148  {
149  return _base::_do_get_desc(_storage(id), name);
150  }
151 #endif
152 };
153 
154 } // namespace aux
155 
156 template <typename ObjTag>
157 inline const std::string& DescriptionOf(ObjectName<ObjTag> object)
158 {
159  return aux::ObjectDescRegistry::_get_desc(
160  ObjTag::value,
161  GetName(object)
162  );
163 }
164 
165 } // namespace oglplus
166 
167 #if !OGLPLUS_LINK_LIBRARY || defined(OGLPLUS_IMPLEMENTING_LIBRARY)
168 #include <oglplus/object/desc.ipp>
169 #endif // OGLPLUS_LINK_LIBRARY
170 
171 #endif // include guard
Empty std::string.
ObjTag::NameType GetName(ObjectName< ObjTag >)
Returns the base name assigned to named object.
Definition: name_tpl.hpp:128
Base template for all "named" objects.

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