diff options
Diffstat (limited to 'serialize/binary-reader.hpp')
-rw-r--r-- | serialize/binary-reader.hpp | 98 |
1 files changed, 49 insertions, 49 deletions
diff --git a/serialize/binary-reader.hpp b/serialize/binary-reader.hpp index 2d09d51b..881ed88f 100644 --- a/serialize/binary-reader.hpp +++ b/serialize/binary-reader.hpp @@ -1,49 +1,49 @@ -#pragma once
-#include "binary-serializer.hpp"
-#include <iterator>
-#include <Corrade/Containers/StringView.h>
-
-namespace floormat::Serialize {
-
-template<typename T>
-concept char_sequence = requires(T& x, const T& cx) {
- requires std::same_as<decltype(std::begin(x)), decltype(std::end(x))>;
- requires std::same_as<decltype(std::cbegin(cx)), decltype(std::cend(cx))>;
- requires std::forward_iterator<decltype(std::begin(x))>;
- requires std::forward_iterator<decltype(std::cbegin(cx))>;
- requires std::same_as<char, std::decay_t<decltype(*std::begin(x))>>;
- requires std::same_as<char, std::decay_t<decltype(*std::cbegin(x))>>;
-};
-
-template<typename It>
-concept string_input_iterator = requires(It it) {
- requires std::forward_iterator<It>;
- requires std::is_same_v<char, std::decay_t<decltype(*it)>>;
-};
-
-template<string_input_iterator It>
-struct binary_reader final {
- template<char_sequence Seq> explicit constexpr binary_reader(const Seq& seq) noexcept;
- constexpr binary_reader(It begin, It end) noexcept;
- constexpr void assert_end() noexcept;
-
- template<serializable T> constexpr T read() noexcept;
- template<std::size_t N> constexpr std::array<char, N> read() noexcept;
- constexpr std::size_t bytes_read() const noexcept { return num_bytes_read; }
- template<std::size_t Max> constexpr auto read_asciiz_string() noexcept;
-
-private:
- std::size_t num_bytes_read = 0;
- It it, end;
-};
-
-template<string_input_iterator It, serializable T>
-binary_reader<It>& operator>>(binary_reader<It>& reader, T& x) noexcept;
-
-template<string_input_iterator It> binary_reader(It&& begin, It&& end) -> binary_reader<std::decay_t<It>>;
-
-template<typename Array>
-binary_reader(Array&& array) -> binary_reader<std::decay_t<decltype(std::begin(array))>>;
-
-} // namespace floormat::Serialize
-
+#pragma once +#include "binary-serializer.hpp" +#include <iterator> +#include <Corrade/Containers/StringView.h> + +namespace floormat::Serialize { + +template<typename T> +concept char_sequence = requires(T& x, const T& cx) { + requires std::same_as<decltype(std::begin(x)), decltype(std::end(x))>; + requires std::same_as<decltype(std::cbegin(cx)), decltype(std::cend(cx))>; + requires std::forward_iterator<decltype(std::begin(x))>; + requires std::forward_iterator<decltype(std::cbegin(cx))>; + requires std::same_as<char, std::decay_t<decltype(*std::begin(x))>>; + requires std::same_as<char, std::decay_t<decltype(*std::cbegin(x))>>; +}; + +template<typename It> +concept string_input_iterator = requires(It it) { + requires std::forward_iterator<It>; + requires std::is_same_v<char, std::decay_t<decltype(*it)>>; +}; + +template<string_input_iterator It> +struct binary_reader final { + template<char_sequence Seq> explicit constexpr binary_reader(const Seq& seq) noexcept; + constexpr binary_reader(It begin, It end) noexcept; + constexpr void assert_end() noexcept; + + template<serializable T> constexpr T read() noexcept; + template<std::size_t N> constexpr std::array<char, N> read() noexcept; + constexpr std::size_t bytes_read() const noexcept { return num_bytes_read; } + template<std::size_t Max> constexpr auto read_asciiz_string() noexcept; + +private: + std::size_t num_bytes_read = 0; + It it, end; +}; + +template<string_input_iterator It, serializable T> +binary_reader<It>& operator>>(binary_reader<It>& reader, T& x) noexcept; + +template<string_input_iterator It> binary_reader(It&& begin, It&& end) -> binary_reader<std::decay_t<It>>; + +template<typename Array> +binary_reader(Array&& array) -> binary_reader<std::decay_t<decltype(std::begin(array))>>; + +} // namespace floormat::Serialize + |