#include <evo/cortex.h>
template<class T>
struct evo::CortexModuleAsBase< T >
Helper for getting a concrete module from a CortexModulePtr (or similar pointer).
- This is a helper for calling CortexModuleBase::as() in a cleaner way (without a template argument)
- Use this to create a helper type for each module inheriting CortexModuleBase like this, where
ModuleFoo is the concrete module type: typedef CortexModuleAsBase<ModuleFoo> ModuleAsFoo;
- Call get() to get an instance (create if needed), or getptr() to get instance pointer
- Template Parameters
-
|
| template<class U > |
| static T & | get (U &ptr) |
| | Get module reference from stored pointer, create if needed. More...
|
| |
| template<class U > |
| static T * | getptr (U &ptr) |
| | Get module pointer from stored pointer. More...
|
| |
◆ get()
Get module reference from stored pointer, create if needed.
- This uses
dynamic_cast to cast the base type to the requested type
- This has some runtime overhead, and throws
std::bad_cast if the cast fails
- To use
static_cast instead define EVO_CORTEX_DYNAMIC_CAST 0 (before including this)
- Caution: Results are undefined if the concrete type (
ItemT) doesn't match the current object for key
- Template Parameters
-
| U | Smart pointer type – inferred from argument |
- Parameters
-
| ptr | Smart pointer type holding the object, if null then a new object is created and stored here |
- Returns
- Reference to value from
ptr
◆ getptr()
| static T* getptr |
( |
U & |
ptr | ) |
|
|
inlinestatic |
Get module pointer from stored pointer.
- This uses
dynamic_cast to cast the base type to the requested type
- This has some runtime overhead, and throws
std::bad_cast if the cast fails
- To use
static_cast instead define EVO_CORTEX_DYNAMIC_CAST 0 (before including this)
- Caution: Results are undefined if the concrete type (
ItemT) doesn't match the current object for key
- Template Parameters
-
| U | Smart pointer type – inferred from argument |
- Parameters
-
| ptr | Pointer type holding the object |
- Returns
- Pointer to value from
ptr, NULL if none
The documentation for this struct was generated from the following file: