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

37 lines
747 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>
#include <boost/shared_ptr.hpp>
#include <cassert>
namespace Core {
2018-03-09 00:06:44 +01:00
class Framework
{
using TypenameToObject = std::map< std::type_index, boost::shared_ptr< void > >;
TypenameToObject ObjectMap;
2018-03-09 00:06:44 +01:00
public:
template< typename T >
boost::shared_ptr< T > get()
{
auto iType = ObjectMap.find( typeid( T ) );
assert( !( iType == ObjectMap.end() ) );
return boost::static_pointer_cast< T >( iType->second );
}
2018-03-09 00:06:44 +01:00
template< typename T >
void set( boost::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