8 #ifndef INCL_evo_cortex_h 9 #define INCL_evo_cortex_h 12 #if defined(EVO_CORTEX_DEFAULT_HASHMAP) 14 #define EVO_CORTEX_IMPL_DEFAULT =MapHash<String,SharedPtr<PureBase> > 15 #elif !defined(EVO_CORTEX_NO_DEFAULT) 17 #define EVO_CORTEX_IMPL_DEFAULT =MapList<String,SharedPtr<PureBase> > 19 #define EVO_CORTEX_IMPL_DEFAULT 31 #define EVO_CORTEX_MAPLIST(KEY, BASE) evo::Cortex< evo::MapList<KEY, evo::SharedPtr<BASE> > > 42 #define EVO_CORTEX_MAPHASH(KEY, BASE) evo::Cortex< evo::MapHash<KEY, evo::SharedPtr<BASE> > > 48 #if !defined(EVO_CORTEX_DYNAMIC_CAST) 54 #define EVO_CORTEX_DYNAMIC_CAST 1 58 #if EVO_CORTEX_DYNAMIC_CAST 59 #define EVO_CORTEX_IMPL_CAST dynamic_cast 61 #define EVO_CORTEX_IMPL_CAST static_cast 171 template<
class T EVO_CORTEX_IMPL_DEFAULT>
178 #if defined(EVO_OLDCC) 179 typedef typename T::Key Key;
180 typedef typename T::Value Value;
182 using typename T::Key;
183 using typename T::Value;
188 #if defined(EVO_CPP11) 189 static_assert(
IsSmartPtr<Value>::value,
"Cortex Map Value must be a SharedPtr to a type derived from evo::PureBase");
202 template<
class ItemT>
204 bool created =
false;
205 Value& item = MapType::get(key, &created);
222 template<
class ItemT>
224 bool created =
false;
225 Value& item = MapType::get(key, &created);
228 return *(EVO_CORTEX_IMPL_CAST <ItemT*>(item.ptr()));
241 template<
class ItemT>
243 Value* item = MapType::findM(key);
246 return EVO_CORTEX_IMPL_CAST <ItemT*>(item->ptr());
259 template<
class ItemT>
261 const Value* item = MapType::find(key);
264 return EVO_CORTEX_IMPL_CAST <const ItemT*>(item->ptr());
381 return * EVO_CORTEX_IMPL_CAST <T*>(
this);
419 static T&
get(U& ptr) {
422 return *EVO_CORTEX_IMPL_CAST <T*>(ptr.ptr());
438 return EVO_CORTEX_IMPL_CAST <T*>(ptr.ptr());
445 #undef EVO_CORTEX_IMPL_CAST Check if type is a SmartPtr or SharedPtr.
Definition: ptr.h:1093
ItemT * getptr(const Key &key)
Get stored item pointer using key (mutable).
Definition: cortex.h:242
Helper for getting a concrete module from a CortexModulePtr (or similar pointer). ...
Definition: cortex.h:407
Cortex< T > This
This type.
Definition: cortex.h:174
Cortex()
Constructor.
Definition: cortex.h:187
A Map with a collection of independent abstract context items.
Definition: cortex.h:172
#define EVO_ONCPP11(EXPR)
Compile EXPR only if C++11 support is detected, otherwise this is a no-op.
Definition: sys.h:259
static T * getptr(U &ptr)
Get module pointer from stored pointer.
Definition: cortex.h:436
A simple base class for defining a module using a similar pattern to Cortex, but without the dynamic ...
Definition: cortex.h:365
const ItemT * getptr_const(const Key &key) const
Get stored item pointer using key (const).
Definition: cortex.h:260
T MapType
Map type (from T)
Definition: cortex.h:175
virtual ~CortexModuleBase()
Destructor.
Definition: cortex.h:367
T & as()
Get this module as a concrete type.
Definition: cortex.h:380
Evo C++ Library namespace.
Definition: alg.h:11
T::Value::Item ValueBase
Value base type, normally PureBase.
Definition: cortex.h:176
This & create(const Key &key)
Create item for key, if needed.
Definition: cortex.h:203
Shared smart pointer to single object.
Definition: ptr.h:399
ItemT & get_create(const Key &key)
Get stored item using key, create if needed.
Definition: cortex.h:223