query/include/matador/object/collection_resolver_factory...

28 lines
1.1 KiB
C++

#ifndef MATADOR_CONTAINER_RESOLVER_FACTORY_HPP
#define MATADOR_CONTAINER_RESOLVER_FACTORY_HPP
#include "matador/object/collection_resolver.hpp"
namespace matador::object {
class abstract_collection_resolver_factory {
public:
virtual ~abstract_collection_resolver_factory() = default;
virtual std::shared_ptr<abstract_collection_resolver> acquire_collection_resolver(const std::type_index &root_type, const std::type_index &element_type, const std::string &collection_name) = 0;
virtual void register_collection_resolver(std::shared_ptr<abstract_collection_resolver> &&resolver) = 0;
};
class collection_resolver_factory : public abstract_collection_resolver_factory {
public:
template<class Type>
std::shared_ptr<collection_resolver<Type>> resolver(const std::type_index &root_type, const std::string &collection_name) {
const auto res = acquire_collection_resolver(typeid(Type), root_type, collection_name);
if (!res) {
return std::dynamic_pointer_cast<collection_resolver<Type>>(res);
}
return std::dynamic_pointer_cast<collection_resolver<Type>>(res);
}
};
}
#endif //MATADOR_CONTAINER_RESOLVER_FACTORY_HPP