2018-03-09 00:06:44 +01:00
|
|
|
#ifndef _CORE_FRAMEWORK_H
|
|
|
|
#define _CORE_FRAMEWORK_H
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <typeindex>
|
|
|
|
#include <typeinfo>
|
2018-10-24 12:53:26 +02:00
|
|
|
#include <memory>
|
2018-03-09 00:06:44 +01:00
|
|
|
#include <cassert>
|
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
namespace Core {
|
2018-03-09 00:06:44 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
class Framework
|
|
|
|
{
|
2018-10-24 12:53:26 +02:00
|
|
|
using TypenameToObject = std::map< std::type_index, std::shared_ptr< void > >;
|
2018-08-29 21:40:59 +02:00
|
|
|
TypenameToObject ObjectMap;
|
2018-03-09 00:06:44 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
public:
|
|
|
|
template< typename T >
|
2018-10-24 12:53:26 +02:00
|
|
|
std::shared_ptr< T > get()
|
2018-08-29 21:40:59 +02:00
|
|
|
{
|
|
|
|
auto iType = ObjectMap.find( typeid( T ) );
|
|
|
|
assert( !( iType == ObjectMap.end() ) );
|
2018-10-24 12:53:26 +02:00
|
|
|
return std::static_pointer_cast< T >( iType->second );
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
2018-03-09 00:06:44 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
template< typename T >
|
2018-10-24 12:53:26 +02:00
|
|
|
void set( std::shared_ptr< T > value )
|
2018-08-29 21:40:59 +02:00
|
|
|
{
|
|
|
|
assert( value ); // why would anyone store nullptrs....
|
|
|
|
ObjectMap[ typeid( T ) ] = value;
|
|
|
|
}
|
|
|
|
};
|
2018-03-09 00:06:44 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // _CORE_FRAMEWORK_H
|