-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffer.hpp
More file actions
100 lines (79 loc) · 2.56 KB
/
Copy pathbuffer.hpp
File metadata and controls
100 lines (79 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* File: /lib/data/buffer.hpp
*
* This file is a part of cpplib project which is distributed under MIT License.
* See file LICENSE for full license details.
*
* Copyright (c) 2020-present Nikita Zuev (V.Slavski!) <[email protected]>
*/
#ifndef CPPLIB__lib__data__buffer__hpp
#define CPPLIB__lib__data__buffer__hpp
#include <algorithm>
#include <span>
#include "../../lib/types.hpp"
namespace lib::data {
namespace detail {
template< class Buffer >
concept CBufferLike = requires( const Buffer & b ) {
(void*) b.data();
(usize) b.size();
sizeof(typename Buffer::value_type);
};
template< class Buffer >
concept BufferLike = requires( Buffer & b ) {
*b.data() = {};
(usize) b.size();
sizeof(typename Buffer::value_type);
};
template< class...Args >
concept SpanConstU8Constructable = requires( Args...args ) {
::std::span<const u8>{ args... };
};
template< class...Args >
concept SpanU8Constructable = requires( Args...args ) {
::std::span<u8>{ args... };
};
} // namespace detail
// DECLARATION lib::data::cbuffer_t
struct cbuffer_t
: ::std::span<const u8>
{
constexpr cbuffer_t( const void * data, usize size ) noexcept
: ::std::span<const u8>{ (const u8*) data, size }
{}
template< class B > requires detail::CBufferLike<B>
constexpr cbuffer_t( const B & buffer ) noexcept
: cbuffer_t{ buffer.data(), buffer.size() * sizeof(typename B::value_type) }
{}
template< class...Args > requires detail::SpanU8Constructable<Args...>
constexpr cbuffer_t( Args...args ) noexcept
: ::std::span<const u8>{ args... }
{}
template< class B > requires detail::CBufferLike<B>
constexpr bool operator == ( const B & buffer ) const noexcept {
const cbuffer_t cmp_buff{ buffer };
return ::std::equal( begin(), end(), cmp_buff.begin(), cmp_buff.end() );
}
};
// DECLARATION lib::data::buffer_t
struct buffer_t
: ::std::span<u8>
{
constexpr buffer_t( void * data, usize size ) noexcept
: ::std::span<u8>{ (u8*) data, size }
{}
template< class B > requires detail::BufferLike<B>
constexpr buffer_t( B & buffer ) noexcept
: buffer_t{ buffer.data(), buffer.size() * sizeof(typename B::value_type) }
{}
template< class...Args > requires detail::SpanU8Constructable<Args...>
constexpr buffer_t( Args...args ) noexcept
: ::std::span<u8>{ args... }
{}
template< class B > requires detail::CBufferLike<B>
constexpr bool operator == ( const B & buffer ) const noexcept {
const cbuffer_t cmp_buff{ buffer };
return ::std::equal( begin(), end(), cmp_buff.begin(), cmp_buff.end() );
}
};
} // namespace lib::data
#endif // CPPLIB__lib__data__buffer__hpp