60 template <
typename Key,
typename BaseClass,
typename... Args >
63 static_assert( std::has_virtual_destructor< BaseClass >::value,
64 "BaseClass must have a virtual destructor" );
67 template <
typename DerivedClass >
70 static_assert( std::is_base_of< BaseClass, DerivedClass >::value,
71 "DerivedClass must be a subclass of BaseClass" );
73 std::is_constructible< DerivedClass, Args... >::value,
74 "DerivedClass must be constructible with Args..." );
77 key,
Creator( create_function_impl< DerivedClass > ) )
81 "Factory",
"Trying to register twice the same key" );
85 static std::unique_ptr< BaseClass >
create(
86 const Key& key,
const Args&... args )
88 auto creator =
store_.find( key );
89 if( creator !=
store_.end() )
91 return creator->second(
92 std::forward< const Args& >( args )... );
99 std::vector< Key > creators;
100 creators.reserve(
store_.size() );
101 for(
const auto& creator :
store_ )
103 creators.emplace_back( creator.first );
113 using Creator =
typename std::add_pointer< std::unique_ptr< BaseClass >(
114 const Args&... ) >::type;
118 template <
typename DerivedClass >
122 return std::unique_ptr< BaseClass >{
new DerivedClass{
123 std::forward< Args >( args )... } };
129 template <
typename Key,
typename BaseClass,
typename... Args >
static std::vector< Key > list_creators()
std::map< Key, Creator > FactoryStore
static std::unique_ptr< BaseClass > create(const Key &key, const Args &... args)
static void warn(const std::string &feature, const Args &... args)
static bool has_creator(const Key &key)
static std::unique_ptr< BaseClass > create_function_impl(Args &&... args)
typename std::add_pointer< std::unique_ptr< BaseClass >(const Args &...) >::type Creator
Classes to build GeoModel from various inputs.
static FactoryStore store_
static void register_creator(const Key &key)