26 template <
typename T >
54 template <
typename T >
86 template <
typename T >
112 template<
typename Type>
129 : _key{std::move( key )}, _entry{std::move( entry )} {}
142 auto itoa = [](std::size_t id){
143 return std::to_string(
id);
146 (std::string(
"Try to access instances '") + itoa(idx)
147 +
"', which is outside of [0;" 152 enum struct Need { Void, Index, VoidIndex };
154 template<
typename R,
typename ET, R(ET::*)(std::
size_t)>
156 static constexpr
bool value =
true;};
158 template<
typename R,
typename ET, R(ET::*)(
void)>
160 static constexpr
bool value =
true;};
162 template<
typename T,
typename TF>
164 template<
typename R,
typename ET>
165 static constexpr std::true_type
168 template<
typename,
typename>
172 template<
typename R,
typename ET>
173 static constexpr std::true_type
175 template<
typename,
typename>
176 static constexpr std::false_type
181 n_index<T,TF>(
nullptr).
value 182 || n_void<T,TF>(
nullptr).
value,
"no valid handle");
184 n_index<T,TF>(
nullptr).
value 185 && n_void<T,TF>(
nullptr).
value) {
186 return Need::VoidIndex;
187 }
else if constexpr (
188 n_index<T,TF>(
nullptr).
value) {
196 template<
typename T,
typename ET>
197 static constexpr
Need handle_need_v =
200 template<
typename T, std::
size_t I = 0>
203 std::shared_ptr<EntryBase> entry,
206 using EntryType = std::tuple_element_t<I, EntryTypes<T>>;
208 if (key.
flags == EntryType::Flag) {
209 constexpr
Need need = handle_need_v<T, EntryType>;
210 std::shared_ptr<EntryType> pEntry =
211 std::static_pointer_cast<EntryType>(entry);
212 if constexpr (need == Need::Index) {
213 ThrowIfOutOfBound(key, idx);
214 return pEntry->handle(idx);
215 }
else if constexpr (need == Need::Void){
216 return pEntry->handle();
217 }
else if constexpr (need == Need::VoidIndex) {
219 ThrowIfOutOfBound(key, idx);
220 return pEntry->handle(idx);
222 return pEntry->handle();
225 static_assert(I!=I,
"no callable Handle function");
230 return handle<T, I + 1>(entry, key, idx);
233 "Entry has an invalid Flag combination! Can't create Handle!" ) ;
251 if ( std::type_index(
typeid( T ) ) != _key.type ) {
255 return EntryHelper::handle<T>(_entry, key(), idx);
267 [[nodiscard]]
bool valid()
const {
return _entry !=
nullptr; }
273 std::shared_ptr< EntryBase > _entry{
nullptr} ;
static Handle< T > handle(std::shared_ptr< EntryBase > entry, const EntryKey &key, std::size_t idx)
class which helps to access entry from the different EntryTypes
Data selection to identify and manage an Entry.
Context _context
Context of the Entry. Containing needed references.
std::tuple< EntrySingle< Type >, EntryMultiCopy< Type >, EntryMultiShared< Type > > EntryTypes
static constexpr Flag_t Flag
static constexpr std::false_type n_index(...)
std::size_t mInstances
number of memory instances
Flag_t flags
Status flags from Entry.
static constexpr std::true_type n_index(need_index< R, ET, &ET::handle > *)
static void ThrowIfOutOfBound(const EntryKey &key, std::size_t idx)
entry for object to be used Multithreaded.
Handle< T > handle()
Creates a new Handle for the object.
EntrySingle()=default
default constructor
constexpr unsigned long long value(const Flag_t &flag)
#define MARLIN_BOOK_THROW(message)
EntryMultiShared(Context context)
constructor
EntryMultiCopy(Context context)
constructor
void clear()
reduce Entry to default constructed version.
const EntryKey & key() const
access key data from entry.
Flag type for flags in marlinmt::book.
Handle< T > handle(std::size_t idx=-1) const
creates an handle for the entry.
constexpr Flag_t MultiShared(1U<< 1U)
create one instance witch concurrent access.
Handle< T > handle()
creates a new handle for the object.
Base type for Entries. To avoid void pointer.
EntrySingle(Context context)
constructor
entry for object to be used Multithreaded.
std::shared_ptr< MemLayout > mem
reference to Memory object. For editing and reading data.
minimal entry for Object.
constexpr Flag_t MultiCopy(1U<< 2U)
create multiple instances of booked object (if possible) to avoid sync points
static constexpr Need needs()
bool valid() const
check if entry is valid.
static constexpr std::true_type n_void(need_void< R, ET, &ET::handle > *)
Handle< T > handle(std::size_t idx)
creates a new handle for the object.
Entry(std::shared_ptr< EntryBase > entry, EntryKey key)
constructor
Data selection for the Entry to work properly.
class to store and manage objects in BookStore.
static constexpr std::false_type n_void(...)
constexpr Flag_t Single(1U<< 0U)
vanilla object.