OGLplus (0.52.0) a C++ wrapper for OpenGL

named_string.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_NAMED_STRING_1202231207_HPP
14 #define OGLPLUS_NAMED_STRING_1202231207_HPP
15 
16 #if OGLPLUS_DOCUMENTATION_ONLY || GL_ARB_shading_language_include
17 
18 #include <oglplus/glfunc.hpp>
20 #include <oglplus/string/ref.hpp>
21 #include <oglplus/string/def.hpp>
22 
23 namespace oglplus {
24 
27 {
28 private:
29  String _name;
30 
31  NamedString(const NamedString&);
32 public:
34  static void Set(
35  NamedStringType type,
36  const StrCRef& name,
37  const StrCRef& value
38  )
39  {
40  OGLPLUS_GLFUNC(NamedStringARB)(
41  GLenum(type),
42  GLint(name.size()),
43  name.c_str(),
44  GLint(value.size()),
45  value.c_str()
46  );
47  OGLPLUS_CHECK_SIMPLE(NamedStringARB);
48  }
49 
51  static String Get(const StrCRef& name)
52  {
53  GLint len = 0;
54  OGLPLUS_GLFUNC(GetNamedStringivARB)(
55  GLint(name.size()),
56  name.c_str(),
57  GL_NAMED_STRING_LENGTH_ARB,
58  &len
59  );
60  OGLPLUS_CHECK_SIMPLE(GetNamedStringivARB);
61 
62  String result(len, '\0');
63  OGLPLUS_GLFUNC(GetNamedStringARB)(
64  GLint(name.size()),
65  name.c_str(),
66  len,
67  &len,
68  &result.front()
69  );
70  OGLPLUS_CHECK_SIMPLE(GetNamedStringARB);
71  return std::move(result);
72 
73  }
74 
76  static void Delete(const StrCRef& name)
77  {
78  OGLPLUS_GLFUNC(DeleteNamedStringARB)(
79  GLint(name.size()),
80  name.c_str()
81  );
82  OGLPLUS_CHECK_SIMPLE(DeleteNamedStringARB);
83  }
84 
86  static NamedStringType Type(const StrCRef& name)
87  {
88  GLint result = 0;
89  OGLPLUS_GLFUNC(GetNamedStringivARB)(
90  GLint(name.size()),
91  name.c_str(),
92  GL_NAMED_STRING_TYPE_ARB,
93  &result
94  );
95  OGLPLUS_CHECK_SIMPLE(GetNamedStringivARB);
96  return NamedStringType(GLenum(result));
97  }
98 
100  static bool IsA(const StrCRef& name)
101  {
102  GLboolean result = OGLPLUS_GLFUNC(IsNamedStringARB)(
103  GLint(name.size()),
104  name.c_str()
105  );
106  OGLPLUS_CHECK_SIMPLE(IsNamedStringARB);
107  return result == GL_TRUE;
108  }
109 
111  void Set(NamedStringType type, const StrCRef& value)
112  {
113  Set(type, _name, value);
114  }
115 
117  String Get(void) const
118  {
119  return Get(_name);
120  }
121 
124  : _name(std::move(tmp._name))
125  { }
126 
129  NamedStringType type,
130  String&& name,
131  const StrCRef& value
132  ): _name(std::move(name))
133  {
134  Set(type, value);
135  }
136 
139  {
140  if(!_name.empty())
141  {
142  Delete(_name);
143  }
144  }
145 };
146 
149  : public NamedString
150 {
151 public:
153  ShaderInclude(String&& name, const StrCRef& value)
154  : NamedString(
156  std::move(name),
157  value
158  ){ }
159 
161  : NamedString(static_cast<NamedString&&>(tmp))
162  { }
163 
165  void Set(const StrCRef& value)
166  {
168  }
169 };
170 
171 } // namespace oglplus
172 
173 #endif // GL_ARB_shading_language_include
174 
175 #endif // include guard
const Char * c_str(void) const
Returns the null-terminated c-string.
Definition: ref_tpl.hpp:200
void Set(NamedStringType type, const StrCRef &value)
Sets the value of the specified type in this NamedString.
Definition: named_string.hpp:111
NamedString(NamedString &&tmp)
Move-construction.
Definition: named_string.hpp:123
Specialization of NamedString for ShaderInclude type.
Definition: named_string.hpp:148
static void Delete(const StrCRef &name)
Deletes the value stored under name.
Definition: named_string.hpp:76
String type definition and related functions.
static NamedStringType Type(const StrCRef &name)
Gets the type of the named string stored under name.
Definition: named_string.hpp:86
ShaderInclude(String &&name, const StrCRef &value)
Create a shader include with the specified name and value.
Definition: named_string.hpp:153
~NamedString(void)
Delete this named string.
Definition: named_string.hpp:138
String reference.
std::size_t size(void) const
Return the size (length) string.
Definition: ref_tpl.hpp:149
String const reference wrapper template.
Definition: ref_tpl.hpp:72
Helper macro for optional checking of availability of GL function.
static String Get(const StrCRef &name)
Gets the value stored under name.
Definition: named_string.hpp:51
void Set(const StrCRef &value)
Set a new value for this shader include.
Definition: named_string.hpp:165
::std::basic_string< GLchar > String
String class.
Definition: def.hpp:36
static bool IsA(const StrCRef &name)
Checks if name is a stored string.
Definition: named_string.hpp:100
String Get(void) const
Sets the value of this NamedString.
Definition: named_string.hpp:117
NamedString type specifier enumeration.
NamedStringType
Enumeration of named string type specifiers.
Definition: named_string_type.hpp:25
Wrapper for GL NamedStrings.
Definition: named_string.hpp:26
static void Set(NamedStringType type, const StrCRef &name, const StrCRef &value)
Store the value, of the specified type under name.
Definition: named_string.hpp:34
NamedString(NamedStringType type, String &&name, const StrCRef &value)
Store a string value of the specified type under name.
Definition: named_string.hpp:128

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