#pragma once #include "container.hpp" #include "function_wrapper.hpp" #include "object_wrapper.hpp" #include template BindingBuilder::BindingBuilder(Container *container) : _container(container) { } template template void BindingBuilder::to() { _container->bindings.emplace( ObjectType(), std::dynamic_pointer_cast( std::make_shared>(*_container))); } template void BindingBuilder::to_factory(Interface func) { _container->bindings.emplace(ObjectType(), std::dynamic_pointer_cast( std::make_shared>(func))); } template BindingBuilder Container::bind() { return BindingBuilder(this); } template std::shared_ptr Container::get() const { ObjectType interface_type; if (bindings.count(interface_type) == 0) { std::cerr << "Error: Tried to get a item from the container using unbound interface '" << interface_type.name() << "'" << std::endl; exit(EXIT_FAILURE); } auto wrapper = std::dynamic_pointer_cast>>( bindings.at(interface_type)); return wrapper->get(); } template Interface Container::get() const { auto wrapper = std::dynamic_pointer_cast>( bindings.at(ObjectType())); return wrapper->get(); }