OGLplus  (0.59.0) a C++ wrapper for rendering APIs

string_ref.hpp
Go to the documentation of this file.
1 #ifndef OGLPLUS_GLSL_STRING_REF_HPP
9 #define OGLPLUS_GLSL_STRING_REF_HPP
10 
11 #include "source_ref.hpp"
12 #include <eagine/memory/block.hpp>
13 
14 namespace eagine::oglp {
15 //------------------------------------------------------------------------------
19 public:
22 
25 
27  glsl_string_ref(const char* src_str, span_size_t n) noexcept
28  : _src_str(static_cast<const char_type*>(src_str))
29  , _length(int_type(n == 0 ? 0 : (src_str[n - 1] == '\0' ? n - 1 : n))) {}
30 
32  explicit glsl_string_ref(string_view str) noexcept
33  : glsl_string_ref(str.data(), str.size()) {}
34 
36  explicit glsl_string_ref(memory::const_block blk) noexcept
37  : glsl_string_ref(as_chars(blk)) {}
38 
40  operator glsl_source_ref() const noexcept {
41  return glsl_source_ref(1, &_src_str, &_length);
42  }
43 
44 private:
45  mutable const char_type* _src_str{nullptr};
46  int_type _length{0};
47 };
48 //------------------------------------------------------------------------------
52 class glsl_literal : public glsl_string_ref {
53 public:
55  template <span_size_t N>
56  glsl_literal(const char (&src_str)[N]) noexcept
57  : glsl_string_ref(static_cast<const char*>(src_str), N) {}
58 };
59 //------------------------------------------------------------------------------
62 static inline auto operator"" _glsl(const char* src_str, std::size_t n) noexcept
63  -> glsl_string_ref {
64  return {src_str, span_size(n)};
65 }
66 //------------------------------------------------------------------------------
67 } // namespace eagine::oglp
68 
69 #endif // OGLPLUS_GLSL_STRING_REF_HPP
GLchar char_type
String character type.
Definition: config.hpp:46
Class referencing a set of GLSL source code strings.
Definition: source_ref.hpp:20
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
static constexpr auto span_size(T v) noexcept
Converts argument to span size type.
Definition: types.hpp:59
GLint int_type
Signed integer type.
Definition: config.hpp:70
glsl_string_ref(memory::const_block blk) noexcept
Explicit construction from a memory const_block.
Definition: string_ref.hpp:36
gl_types::char_type char_type
Alias for string character type.
Definition: string_ref.hpp:21
glsl_string_ref(const char *src_str, span_size_t n) noexcept
Construction from a C-string and a length value.
Definition: string_ref.hpp:27
Non-owning view of a contiguous range of memory with ValueType elements.
Definition: flatten_fwd.hpp:16
Reference to a GLSL source code string.
Definition: string_ref.hpp:18
Wrapper class for a GLSL string literal, convertible to glsl_source_ref.
Definition: string_ref.hpp:52
glsl_literal(const char(&src_str)[N]) noexcept
Construction from a zero-terminated string literal.
Definition: string_ref.hpp:56
glsl_string_ref(string_view str) noexcept
Explicit construction from a string_view.
Definition: string_ref.hpp:32
gl_types::int_type int_type
Alias for signed intever type.
Definition: string_ref.hpp:24
static constexpr auto as_chars(block blk) noexcept
Converts a block into a span of characters.
Definition: block.hpp:48

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).