IceShard
1
A personal game engine project, with development focused on 2D/2.5D games.
Toggle main menu visibility
Loading...
Searching...
No Matches
utils
public
ice
data_storage.hxx
Go to the documentation of this file.
1
3
4
#pragma once
5
#include <
ice/stringid.hxx
>
6
#include <
ice/mem_allocator.hxx
>
7
#include <
ice/hashmap.hxx
>
8
#include <
ice/span.hxx
>
9
10
namespace
ice
11
{
12
//class DataStorage
13
14
//{
15
//public:
16
// virtual ~DataStorage() noexcept = default;
17
18
// template<typename T>
19
// auto named_object(ice::StringID_Arg name) noexcept -> T*;
20
21
// template<typename T>
22
// auto named_object(ice::StringID_Arg name) const noexcept -> T const*;
23
24
// template<typename T>
25
// requires ice::TrivialContainerLogicAllowed<T>
26
// auto named_span(ice::StringID_Arg name) noexcept -> ice::Span<T>;
27
28
// template<typename T>
29
// requires ice::TrivialContainerLogicAllowed<T>
30
// auto named_span(ice::StringID_Arg name) const noexcept -> ice::Span<T const>;
31
32
// template<typename T, typename... Args>
33
// auto create_named_object(ice::StringID_Arg name, Args&&... args) noexcept -> T*;
34
35
// template<typename T>
36
// requires ice::TrivialContainerLogicAllowed<T>
37
// auto create_named_span(ice::StringID_Arg name, ice::ucount count) noexcept -> ice::Span<T>;
38
39
// template<typename T>
40
// void destroy_named_object(ice::StringID_Arg name) noexcept;
41
42
//protected:
43
// virtual auto allocate_named_data(
44
// ice::StringID_Arg name,
45
// ice::meminfo type_meminfo
46
// ) noexcept -> void* = 0;
47
48
// virtual auto allocate_named_array(
49
// ice::StringID_Arg name,
50
// ice::meminfo type_meminfo,
51
// ice::ucount count
52
// ) noexcept -> void* = 0;
53
54
// virtual auto named_data(ice::StringID_Arg name) noexcept -> void* = 0;
55
56
// virtual auto named_data(ice::StringID_Arg name) const noexcept -> void const* = 0;
57
58
// virtual void release_named_data(ice::StringID_Arg name) noexcept = 0;
59
//};
60
61
//template<typename T>
62
//inline auto DataStorage::named_object(ice::StringID_Arg name) noexcept -> T*
63
//{
64
// return reinterpret_cast<T*>(named_data(name));
65
//}
66
67
//template<typename T>
68
//inline auto DataStorage::named_object(ice::StringID_Arg name) const noexcept -> T const*
69
//{
70
// return reinterpret_cast<T const*>(named_data(name));
71
//}
72
73
//template<typename T>
74
// requires ice::TrivialContainerLogicAllowed<T>
75
//inline auto DataStorage::named_span(ice::StringID_Arg name) noexcept -> ice::Span<T>
76
//{
77
// // We assume we used 'created_named_span' this the span size is at head of the data.
78
// ice::ucount* span_info = reinterpret_cast<ice::ucount*>(named_data(name));
79
80
// return ice::Span<T>{
81
// reinterpret_cast<T*>(ice::ptr_add(span_info, { span_info[1] })),
82
// span_info[0]
83
// };
84
//}
85
86
//template<typename T>
87
// requires ice::TrivialContainerLogicAllowed<T>
88
//inline auto DataStorage::named_span(ice::StringID_Arg name) const noexcept -> ice::Span<T const>
89
//{
90
// // We assume we used 'created_named_span' this the span size is at head of the data.
91
// ice::ucount const* span_info = reinterpret_cast<ice::ucount const*>(named_data(name));
92
93
// return ice::Span<T const>{
94
// reinterpret_cast<T const*>(ice::ptr_add(span_info, { span_info[1] })),
95
// span_info[0]
96
// };
97
//}
98
99
//template<typename T, typename... Args>
100
//inline auto DataStorage::create_named_object(ice::StringID_Arg name, Args&&... args) noexcept -> T*
101
//{
102
// void* const allocated_data = allocate_named_data(name, ice::meminfo_of<T>);
103
// return new (allocated_data) T{ ice::forward<Args>(args)... };
104
//}
105
106
//template<typename T>
107
//inline void DataStorage::destroy_named_object(ice::StringID_Arg name) noexcept
108
//{
109
// T* const obj = named_object<T>(name);
110
// if (obj != nullptr)
111
// {
112
// obj->~T();
113
// release_named_data(name);
114
// }
115
//}
116
117
//template<typename T>
118
// requires ice::TrivialContainerLogicAllowed<T>
119
//inline auto DataStorage::create_named_span(ice::StringID_Arg name, ice::ucount count) noexcept -> ice::Span<T>
120
//{
121
// ice::ucount* span_info = reinterpret_cast<ice::ucount*>(
122
// allocate_named_array(name, ice::meminfo_of<T>, count)
123
// );
124
125
// ice::Span<T> result{
126
// reinterpret_cast<T*>(ice::ptr_add(span_info, { span_info[1] })),
127
// span_info[0]
128
// };
129
130
// // We initialize the objects if needed
131
// if constexpr (std::is_trivially_constructible_v<T> == false)
132
// {
133
// ice::mem_construct_n_at<T>(
134
// ice::Memory{ .location = result._data, .size = ice::span::size_bytes(result), .alignment = ice::align_of<T> },
135
// ice::span::count(result)
136
// );
137
// }
138
139
// return result;
140
//}
141
142
//class HashedDataStorage final : public ice::DataStorage
143
//{
144
//public:
145
// HashedDataStorage(ice::Allocator& alloc) noexcept;
146
// ~HashedDataStorage() noexcept override;
147
148
//protected:
149
// auto named_data(
150
// ice::StringID_Arg name
151
// ) noexcept -> void* override;
152
153
// auto named_data(
154
// ice::StringID_Arg name
155
// ) const noexcept -> void const* override;
156
157
// auto allocate_named_data(
158
// ice::StringID_Arg name,
159
// ice::meminfo type_meminfo
160
// ) noexcept -> void* override;
161
162
// auto allocate_named_array(
163
// ice::StringID_Arg name,
164
// ice::meminfo type_meminfo,
165
// ice::ucount count
166
// ) noexcept -> void* override;
167
168
// void release_named_data(
169
// ice::StringID_Arg name
170
// ) noexcept override;
171
172
//private:
173
// ice::Allocator& _allocator;
174
// ice::HashMap<ice::AllocResult> _named_data;
175
//};
176
177
}
// namespace ice
hashmap.hxx
mem_allocator.hxx
ice
SPDX-License-Identifier: MIT.
Definition
array.hxx:12
span.hxx
stringid.hxx
Generated by
1.18.0