RavEngine
Loading...
Searching...
No Matches
Span.hpp
1#pragma once
2#include <cstdint>
3#include <cstddef>
4
5namespace RGL {
6 struct MutableSpan {
7 void* data = nullptr;
8 size_t size = 0;
9 };
10
12 const void* ptr = nullptr;
13 const size_t size_bytes = 0;
14 public:
15 untyped_span(decltype(ptr) ptr, decltype(size_bytes) size_bytes) : ptr(ptr), size_bytes(size_bytes) {}
16
17 template<typename T>
18 untyped_span(const T& ptr) : ptr(&ptr), size_bytes(sizeof(T)) {}
19
20 constexpr auto data() const { return ptr; }
21 constexpr auto size() const { return size_bytes; }
22 };
23
24 // a bit of an odd concept. Its purpose is to have data Moved into it, which it will then free.
25 // it assumes ownership of that data.
26 template<typename freer>
28 void* ptr = nullptr;
29 size_t size_bytes = 0;
30 constexpr static freer free_fn{};
31
33 untyped_owning_span(decltype(ptr) ptr, decltype(size_bytes) size_bytes) : ptr(ptr), size_bytes(size_bytes) {}
34
35 // move constructor
36 untyped_owning_span(untyped_owning_span&& other) : ptr(other.ptr), size_bytes(other.size_bytes){
37 other.ptr = nullptr;
38 other.size_bytes = 0;
39 }
40
41 // remove copy ctor
43 untyped_owning_span& operator=(const untyped_owning_span&) = delete;
44
46 if (ptr){
47 free_fn(ptr);
48 ptr = nullptr;
49 size_bytes = 0;
50 }
51 }
52
53 operator untyped_span() const{
54 return untyped_span{ptr, size_bytes};
55 }
56 };
57}
Definition Span.hpp:11
Definition Span.hpp:6
Definition Span.hpp:27