Skip to content
Snippets Groups Projects
Commit 12aa7727 authored by Joan Solà Ortega's avatar Joan Solà Ortega
Browse files

Add method Factory::isCreatorRegistered()

parent 16908981
No related branches found
No related tags found
1 merge request!466devel->main
......@@ -305,6 +305,7 @@ class Factory
public:
static bool registerCreator(const std::string& _type, CreatorCallback createFn);
static bool unregisterCreator(const std::string& _type);
static bool isCreatorRegistered(const std::string& _type);
static TypeBasePtr create(const std::string& _type, TypeInput... _input);
std::string getClass() const;
static void printAddress();
......@@ -356,6 +357,12 @@ inline bool Factory<TypeBase, TypeInput...>::unregisterCreator(const std::string
return get().callbacks_.erase(_type) == 1;
}
template<class TypeBase, typename... TypeInput>
inline bool Factory<TypeBase, TypeInput...>::isCreatorRegistered(const std::string& _type)
{
return get().callbacks_.count(_type) == 1;
}
template<class TypeBase, typename... TypeInput>
inline typename Factory<TypeBase, TypeInput...>::TypeBasePtr Factory<TypeBase, TypeInput...>::create(const std::string& _type, TypeInput... _input)
{
......
......@@ -44,6 +44,19 @@ TEST(TestFactory, DummyObjectFactory)
DummyObjectDerived obj_derived = DummyObjectDerived("AnotherCoolDummyObject", server);
}
TEST(TestFactory, isCreatorRegistered)
{
ParserYaml parser = ParserYaml("test/yaml/params_basic.yaml", wolf_root);
ParamsServer server = ParamsServer(parser.getParams());
bool object_creator_registered = FactoryDummyObject::isCreatorRegistered("DummyObjectDerived");
ASSERT_TRUE(object_creator_registered);
// FORCE LOADING
DummyObjectDerived obj_derived = DummyObjectDerived("AnotherCoolDummyObject", server);
}
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment