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

file_magic_number.hpp
Go to the documentation of this file.
1 #ifndef EAGINE_FILE_MAGIC_NUMBER_HPP
9 #define EAGINE_FILE_MAGIC_NUMBER_HPP
10 
11 #include "types.hpp"
12 #include <array>
13 #include <cstring>
14 
15 namespace eagine {
16 
17 template <char... C>
18 class file_magic_number {
19 private:
20  static_assert(
21  sizeof...(C) <= 16,
22  "File magic number cannot be more than 16 bytes long");
23 
24  const std::array<const char, 16> _magic_number;
25 
26  static constexpr auto _make_magic_number() -> std::array<const char, 16> {
27  return {{C...}};
28  }
29 
30 public:
31  using value_type = const char;
32  using size_type = span_size_t;
33 
34  constexpr file_magic_number() noexcept
35  : _magic_number(_make_magic_number()) {}
36 
37  auto is_valid() const noexcept -> bool {
38  return std::strncmp(
39  _magic_number.data(),
40  _make_magic_number().data(),
41  sizeof...(C)) == 0;
42  }
43 
44  auto data() const noexcept -> const char* {
45  return _magic_number.data();
46  }
47 
48  static constexpr auto size() noexcept -> span_size_t {
49  return 16;
50  }
51 };
52 
53 } // namespace eagine
54 
55 #endif // EAGINE_FILE_MAGIC_NUMBER_HPP
value_type
Value tree value element data type enumeration.
Definition: interface.hpp:27
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
Common code is placed in this namespace.
Definition: eagine.hpp:21

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