1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-26 14:37:44 +00:00
sapphire/src/common/Framework.h

38 lines
763 B
C
Raw Normal View History

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-10-28 21:53:21 +01:00
namespace Core
{
2018-03-09 00:06:44 +01:00
2018-10-28 21:53:21 +01:00
class Framework
{
2018-10-28 21:53:21 +01:00
using TypenameToObject = std::map< std::type_index, std::shared_ptr< void > >;
TypenameToObject ObjectMap;
2018-03-09 00:06:44 +01:00
2018-10-28 21:53:21 +01:00
public:
template< typename T >
std::shared_ptr< T > get()
{
auto iType = ObjectMap.find( typeid( T ) );
assert( !( iType == ObjectMap.end() ) );
return std::static_pointer_cast< T >( iType->second );
}
template< typename T >
void set( std::shared_ptr< T > value )
{
assert( value ); // why would anyone store nullptrs....
ObjectMap[ typeid( T ) ] = value;
}
};
2018-03-09 00:06:44 +01:00
}
#endif // _CORE_FRAMEWORK_H