ae2f::Core
Loading...
Searching...
No Matches
Own.hpp
Go to the documentation of this file.
1
5
6namespace ae2f { namespace Ds { namespace Arr {
7 #pragma region Own
8
19 template<typename T>
20 struct __Owner<T, 1>
21 : public Alloc::xrOwner,
22 public __def<T>
23 {
24 using _f = __def<T>;
25
43 inline const typename _f::El_t Read(size_t index, ae2f_errint_t* perr = 0) const noexcept {
44 if(!perr) perr = &ae2f_errGlob_LastErr;
45
46 T b[1];
47
48 perr[0] = Alloc::xrOwner::Read(
49 index * sizeof(T),
50 ae2f_reinterpret_cast(void*, b),
51 sizeof(T)
52 );
53
54 return b[0];
55 }
56
72 inline ae2f_errint_t Write(size_t idx, const typename _f::El_t& el) noexcept {
74 idx * sizeof(T),
75 ae2f_reinterpret_cast(const void*, &el),
76 sizeof(T)
77 );
78 }
79
95 inline ae2f_errint_t Write(size_t idx, const typename _f::El_t&& el) noexcept {
97 idx * sizeof(T),
98 ae2f_reinterpret_cast(const void*, &el),
99 sizeof(T)
100 );
101 }
102
104 constexpr ae2f_errint_t ReConfig(size_t elcount, size_t elsize) {
106 }
107
109 constexpr ae2f_errint_t Copy(const Alloc::rRefer& src) noexcept {
111 }
112
114 constexpr ae2f_errint_t Copy(const Alloc::rRefer&& src) noexcept {
116 }
117
118 inline ae2f_errint_t Resize(size_t elcount) {
119 return xrOwner::ReConfig(elcount, _f::ElSize);
120 }
121
122 inline __Owner(
123 ae2f_errint_t* perr,
124 const ae2f_ds_vAlloc* imp
125 ) : Alloc::xrOwner(perr, imp) {}
126 };
127
139 template<typename T>
140 struct __Owner<T, 0>
141 : public Alloc::xrOwner,
142 public __def<Pack<T>>
143 {
145
164 inline const typename _f::El_t Read(size_t index, ae2f_errint_t* perr = 0) const noexcept {
165 if(!perr) perr = &ae2f_errGlob_LastErr;
166
167 typename _f::El_t b[1];
168
169 perr[0] |= Alloc::xrOwner::Read(
170 index * _f::ElSize,
171 ae2f_reinterpret_cast(void*, b),
172 _f::ElSize
173 );
174
175 if(!b->isvalid())
176 perr[0] |= eRef::EL_NON_VALID;
177
178 return b[0];
179 }
180
181#pragma region non_trivial writing
182
200 template<typename... Args>
201 inline ae2f_errint_t Write(size_t idx, Args&& ...args) noexcept {
204 }
205
206 ae2f_errint_t code[1] = { ae2f_errGlob_OK };
207 typename _f::El_t el[1] = { Read(idx, code) };
208
209 if(code[0] & eRef::EL_NON_VALID) {
210 if(!(code[0] & ae2f_errGlob_DONE_HOWEV))
211 return code[0];
212 }
213
214 if(el->isvalid()) {
215 el->Obj.~T();
216 }
217 new(el->c) T(args...);
218 el->_isvalid() = 1;
219
221 idx * _f::ElSize,
222 ae2f_reinterpret_cast(void*, el->c),
223 _f::ElSize
224 );
225 }
226
241 inline ae2f_errint_t Write(size_t idx) noexcept {
244 }
245
246 ae2f_errint_t code[1] = { ae2f_errGlob_OK };
247 typename _f::El_t el[1] = { Read(idx, code) };
248
249 if(code[0] & eRef::EL_NON_VALID) {
250 if(!(code[0] & ae2f_errGlob_DONE_HOWEV))
251 return code[0];
252 }
253
254 if(el->isvalid()) el->Obj.~T();
255 new(el->c) T();
256 el->_isvalid() = 1;
257
259 idx * _f::ElSize,
260 ae2f_reinterpret_cast(void*, el->c),
261 _f::ElSize
262 );
263 }
264
265#pragma endregion
266
267 inline ~__Owner() {
268 size_t a[2] = {0, 0};
269 ae2f_errGlob_LastErr |= this->Length(a, a+1);
270
271 a[0] = (a[1] * a[0]) / this->ElSize;
272
273 for(size_t i = 0; i < a[0]; i++) {
274 Pack<T> t = this->Read(i, &ae2f_errGlob_LastErr);
275 if(t.isvalid()) t.Obj.~T();
276 }
277 }
278
279
280 inline ae2f_errint_t Resize(size_t nCount) noexcept {
281 size_t a, b; ae2f_errint_t err = ae2f_errGlob_OK;
282 err |= xrOwner::Length(&a, &b);
283 if(err) {
284 return err;
285 }
286
287 a = (b * a) / _f::ElSize;
288
289 for(size_t i = nCount; i < a; i++) {
290 typename _f::El_t read = Read(i, &err);
291 if(err) return err;
292 if(read._isvalid()) {
293 read.Obj.~T();
294 }
295 }
296
297 return xrOwner::ReConfig(nCount, _f::ElSize);
298 }
299
300 constexpr ae2f_errint_t ReConfig(size_t elcount, size_t elsize) {
302 }
303
304 constexpr ae2f_errint_t Copy(const Alloc::rRefer& src) noexcept {
306 }
307
308 constexpr ae2f_errint_t Copy(const Alloc::rRefer&& src) noexcept {
310 }
311
312 inline __Owner(
313 ae2f_errint_t* perr,
314 const ae2f_ds_vAlloc* imp
315 ) : Alloc::xrOwner(perr, imp) {}
316 };
317
318 template<typename T>
320
321 #pragma endregion
322}}}
#define _ae2f_ds_Alloc_FndFun(This, Name)
Definition Alloc.h:53
#define ae2f_static_cast(t, v)
Definition Cast.h:49
#define ae2f_reinterpret_cast(t, v)
Definition Cast.h:57
ae2f_extern ae2f_errint_t ae2f_errGlob_LastErr
Definition errGlob.h:52
#define ae2f_errGlob_OK
The Operation you've wanted went successful.
Definition errGlob.h:14
#define ae2f_errGlob_DONE_HOWEV
The operation went done. Note that operation may not be valid.
Definition errGlob.h:46
uint8_t ae2f_errint_t
Informs that this number represents the error.
Definition errGlob.h:10
#define ae2f_errGlob_IMP_NOT_FOUND
Failed to find the function on preprocessor which is callable for some reason No operation has beed d...
Definition errGlob.h:19
ae2f_ds_Alloc_cRef rRefer
Definition Defs.hpp:19
constexpr ae2f_errint_t EL_NON_VALID
The element has not been yet constructed.
Definition Defs.hpp:47
Definition Alloc.hpp:6
Definition Own.hpp:15
ae2f_errint_t Write(size_t i, const void *src, size_t srclen) noexcept
Sets data to a class.
Definition Own.hpp:50
ae2f_errint_t Read(size_t i, void *dest, size_t destlen) const noexcept
Gets data from a class.
Definition Own.hpp:31
~__Owner()
Definition Own.hpp:267
constexpr ae2f_errint_t ReConfig(size_t elcount, size_t elsize)
Definition Own.hpp:300
constexpr ae2f_errint_t Copy(const Alloc::rRefer &src) noexcept
Definition Own.hpp:304
ae2f_errint_t Resize(size_t nCount) noexcept
Definition Own.hpp:280
__Owner(ae2f_errint_t *perr, const ae2f_ds_vAlloc *imp)
Definition Own.hpp:312
constexpr ae2f_errint_t Copy(const Alloc::rRefer &&src) noexcept
Definition Own.hpp:308
ae2f_errint_t Write(size_t idx, Args &&...args) noexcept
Sets data to a class.
Definition Own.hpp:201
const _f::El_t Read(size_t index, ae2f_errint_t *perr=0) const noexcept
Gets data from a class.
Definition Own.hpp:164
ae2f_errint_t Write(size_t idx) noexcept
Sets data to a class.
Definition Own.hpp:241
ae2f_errint_t Write(size_t idx, const typename _f::El_t &&el) noexcept
Sets data to a class.
Definition Own.hpp:95
constexpr ae2f_errint_t Copy(const Alloc::rRefer &src) noexcept
Definition Own.hpp:109
constexpr ae2f_errint_t ReConfig(size_t elcount, size_t elsize)
Definition Own.hpp:104
ae2f_errint_t Write(size_t idx, const typename _f::El_t &el) noexcept
Sets data to a class.
Definition Own.hpp:72
ae2f_errint_t Resize(size_t elcount)
Definition Own.hpp:118
const _f::El_t Read(size_t index, ae2f_errint_t *perr=0) const noexcept
Gets data from a class.
Definition Own.hpp:43
__Owner(ae2f_errint_t *perr, const ae2f_ds_vAlloc *imp)
Definition Own.hpp:122
constexpr ae2f_errint_t Copy(const Alloc::rRefer &&src) noexcept
Definition Own.hpp:114
Definition Defs.hpp:39
A helper class for getting element type and element size.
Definition Pack.hpp:13
T El_t
Definition Pack.hpp:19
Structure for virtual function pointer.
Definition Alloc.h:20
A value package for non-trivial classes. Which will not call the destructor of [T].
Definition Pack.hpp:32
T Obj
Definition Pack.hpp:63
constexpr bool isvalid() const noexcept
Check if ae2f::Ds::Arr::Pack<T>::Obj is valid.
Definition Pack.hpp:67