ae2f::Core
Loading...
Searching...
No Matches
Ref.hpp
Go to the documentation of this file.
1
5
6namespace ae2f { namespace Ds { namespace Arr {
7
18 template<typename T>
19 struct __Refer<T, 1>
20 : public Alloc::cRefer,
21 public __def<T>
22 {
23 using _f = __def<T>;
24
41 inline const typename _f::El_t Read(size_t index, ae2f_errint_t* perr = &ae2f_errGlob_LastErr) const noexcept {
42 if(!perr) perr = &ae2f_errGlob_LastErr;
43
44 T b[1];
45
46 perr[0] |= Alloc::cRefer::Read(
47 index * sizeof(T),
48 ae2f_reinterpret_cast(void*, b),
49 sizeof(T)
50 );
51
52 return b[0];
53 }
54
69 inline ae2f_errint_t Write(size_t idx, const typename _f::El_t& el) noexcept {
71 idx * sizeof(T),
72 ae2f_reinterpret_cast(const void*, &el),
73 sizeof(T)
74 );
75 }
76
91 inline ae2f_errint_t Write(size_t idx, const typename _f::El_t&& el) noexcept {
93 idx * sizeof(T),
94 ae2f_reinterpret_cast(const void*, &el),
95 sizeof(T)
96 );
97 }
98
99 constexpr __Refer(const Alloc::rRefer& src)
100 : cRefer(src) {}
101
102 constexpr __Refer(const Alloc::rRefer&& src)
103 : cRefer(src) {}
104 };
105
117 template<typename T>
118 struct __Refer<T, 0>
119 : public Alloc::cRefer,
120 public __def<Pack<T>>
121 {
123
140 inline const typename _f::El_t Read(size_t index, ae2f_errint_t* perr = 0) const noexcept {
141 if(!perr) perr = &ae2f_errGlob_LastErr;
142
143 typename _f::El_t b[1];
144
145 perr[0] |= Alloc::cRefer::Read(
146 index * _f::ElSize,
147 ae2f_reinterpret_cast(void*, b),
148 _f::ElSize
149 );
150
151 if(!b->isvalid())
152 perr[0] |= eRef::EL_NON_VALID;
153
154 return b[0];
155 }
156
157#pragma region non_trivial writing
158
176 template<typename... Args>
177 inline ae2f_errint_t Write(size_t idx, Args&& ...args) noexcept {
180 }
181
182 ae2f_errint_t code[1] = { ae2f_errGlob_OK };
183 typename _f::El_t el[1] = { Read(idx, code) };
184
185 if(code[0] & eRef::EL_NON_VALID) {
186 if(!(code[0] & ae2f_errGlob_DONE_HOWEV))
187 return code[0];
188 }
189
190 if(el->isvalid()) {
191 el->Obj.~T();
192 }
193 new(el->c) T(args...);
194 el->_isvalid() = 1;
195
197 idx * _f::ElSize,
198 ae2f_reinterpret_cast(void*, el->c),
199 _f::ElSize
200 );
201 }
202
216 inline ae2f_errint_t Write(size_t idx) noexcept {
219 }
220
221 ae2f_errint_t code[1] = { ae2f_errGlob_OK };
222 typename _f::El_t el[1] = { Read(idx, code) };
223
224 if(code[0] & eRef::EL_NON_VALID) {
225 if(!(code[0] & ae2f_errGlob_DONE_HOWEV))
226 return code[0];
227 }
228
229 if(el->isvalid()) el->Obj.~T();
230 new(el->c) T();
231 el->_isvalid() = 1;
232
234 idx * _f::ElSize,
235 ae2f_reinterpret_cast(void*, el->c),
236 _f::ElSize
237 );
238 }
239
240#pragma endregion
241 constexpr __Refer(const __Refer<T, 0>& src)
242 : cRefer(src) {}
243
244 constexpr __Refer(const __Refer<T, 0>&& src)
245 : cRefer(src) {}
246
247 constexpr __Refer(const __Owner<T, 0>& src)
248 : cRefer(src) {}
249
250 constexpr __Refer(const __Owner<T, 0>&& src)
251 : cRefer(src) {}
252 };
253
254
259 template<typename T>
261
262}}}
#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 Ref.hpp:15
ae2f_errint_t Write(size_t idx, const void *src, size_t srcsize) noexcept
Sets data to a class.
Definition Ref.hpp:49
ae2f_errint_t Read(size_t idx, void *buff, size_t elsize) const noexcept
Gets data from a class.
Definition Ref.hpp:31
ae2f_errint_t Write(size_t i, const void *src, size_t srclen) noexcept
Sets data to a class.
Definition Own.hpp:50
Definition Defs.hpp:39
constexpr __Refer(const __Refer< T, 0 > &&src)
Definition Ref.hpp:244
const _f::El_t Read(size_t index, ae2f_errint_t *perr=0) const noexcept
Gets data from a class.
Definition Ref.hpp:140
constexpr __Refer(const __Owner< T, 0 > &src)
Definition Ref.hpp:247
ae2f_errint_t Write(size_t idx) noexcept
Sets data to a class.
Definition Ref.hpp:216
ae2f_errint_t Write(size_t idx, Args &&...args) noexcept
Sets data to a class.
Definition Ref.hpp:177
constexpr __Refer(const __Refer< T, 0 > &src)
Definition Ref.hpp:241
constexpr __Refer(const __Owner< T, 0 > &&src)
Definition Ref.hpp:250
ae2f_errint_t Write(size_t idx, const typename _f::El_t &&el) noexcept
Sets data to a class.
Definition Ref.hpp:91
ae2f_errint_t Write(size_t idx, const typename _f::El_t &el) noexcept
Sets data to a class.
Definition Ref.hpp:69
const _f::El_t Read(size_t index, ae2f_errint_t *perr=&ae2f_errGlob_LastErr) const noexcept
Gets data from a class.
Definition Ref.hpp:41
constexpr __Refer(const Alloc::rRefer &src)
Definition Ref.hpp:99
constexpr __Refer(const Alloc::rRefer &&src)
Definition Ref.hpp:102
Definition Defs.hpp:22
A helper class for getting element type and element size.
Definition Pack.hpp:13
T El_t
Definition Pack.hpp:19
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