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

decl_name.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_REFLECT_DECL_NAME_HPP
10 #define EAGINE_REFLECT_DECL_NAME_HPP
11 
12 #include "../memory/span_algo.hpp"
13 #include "../string_span.hpp"
14 
15 namespace eagine {
16 //------------------------------------------------------------------------------
17 struct decl_name : string_view {
18  static constexpr const span_size_t max_length = 80;
19 
20  constexpr decl_name() noexcept = default;
21 
22  template <
23  std::size_t N,
24  typename = std::enable_if_t<(N <= span_size_t(max_length))>>
25  constexpr decl_name(const char (&array)[N]) noexcept
26  : string_view{array} {}
27 };
28 //------------------------------------------------------------------------------
29 class decl_name_storage {
30 public:
31  static constexpr const span_size_t max_length = decl_name::max_length;
32 
33  auto assign(string_view str) -> bool {
34  if(str.size() <= max_length) {
35  memory::copy(str, cover(_storage));
36  _length = str.size();
37  return true;
38  }
39  return false;
40  }
41 
42  auto get() noexcept {
43  return head(cover(_storage), _length);
44  }
45 
46  auto get() const noexcept {
47  return head(view(_storage), _length);
48  }
49 
50 private:
51  std::array<char, max_length> _storage{};
52  span_size_t _length{0};
53 };
54 //------------------------------------------------------------------------------
55 } // namespace eagine
56 
57 #endif // EAGINE_REFLECT_DECL_NAME_HPP
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
basic_string_span< const char > string_view
Alias for const string views.
Definition: string_span.hpp:116
Common code is placed in this namespace.
Definition: eagine.hpp:21
static constexpr auto cover(T *addr, S size) noexcept -> span_if_mutable< T >
Creates a span starting at the specified pointer and specified length.
Definition: span.hpp:465
static constexpr auto view(T *addr, S size) noexcept -> const_span< T >
Creates a view starting at the specified pointer and specified length.
Definition: span.hpp:458
static constexpr auto head(basic_span< T, P, S > s, L l) noexcept -> basic_span< T, P, S >
Returns the first l elements from the front of a span.
Definition: span_algo.hpp:99
static auto copy(const_block source, block dest) -> block
Copies the content of source block to destination block.
Definition: copy.hpp:23

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