55class DependencyInjector;
56class DependencyManager;
127 std::vector<int32_t> deps;
141 template <
typename T,
typename = std::enable_if_t<
142 std::is_base_of<Injectable, T>::value>>
146 getDependencyId<T>(),
reinterpret_cast<void*
>(dependency),
147 static_cast<Injectable*
>(dependency),
typeid(T).name());
163 [[nodiscard]]
bool inject();
166 [[nodiscard]]
bool insertImpl(int32_t
id,
void* raw,
Injectable* injectable,
169 void* getImpl(int32_t
id);
174 bool load_success =
true;
176 std::map<int32_t, ModuleInfo> modules;
188 DependencyManager::ModuleInfo& info)
189 : manager(manager), info(info)
200 template <
typename T>
203 return reinterpret_cast<T*
>(getImpl(getDependencyId<T>()));
207 void* getImpl(int32_t
id);
213 DependencyManager::ModuleInfo& info;
216namespace DependencyManagerDetails
220template <
typename... Types>
227 template <
typename T>
234template <
typename Type,
typename... Types>
240 Type* item =
nullptr;
244 item = injector.get<Type>();
246 Super::inject(injector);
249 template <
typename T>
250 typename std::enable_if_t<std::is_same<T, Type>::value, T*>
get()
255 template <
typename T>
256 typename std::enable_if_t<!std::is_same<T, Type>::value, T*>
get()
258 return Super::template get<T>();
263template <
typename T,
typename... Types>
268template <
typename T,
typename Type,
typename... Types>
270 : std::integral_constant<bool, std::is_same<T, Type>::value ||
271 Contains<T, Types...>::value>
285template <
typename... Types>
307 template <
typename T,
308 typename = std::enable_if_t<
312 return storage.template get<T>();
323template <
typename Base,
typename... Types>
331 using Super = InjectableWithDeps<InjectableBase<Base>, Types...>;
337 static_assert(std::is_base_of<Injectable, Base>::value,
338 "Base must be Injectable");
342 Base::inject(injector);
352 template <
typename T,
353 typename = std::enable_if_t<
357 return storage.template get<T>();
Proxy class used to obtain dependencies.
T * get()
Retrieve a specific dependencies, recording it and tracking unsatisfied dependencies.
Main DependencyManager class.
bool inject()
Inject all dependencies into all inserted .
bool insert(T *dependency)
Insert a new dependency.
void graphviz(std::ostream &os)
Generate a gaphviz compatible output showing dependencies. Needs to be called after inject.
Interface for an injectable dependency.
virtual void inject(DependencyInjector &injector)
Invoked by the DependencyManager to inject dependencies. Override this method to retrieve dependencie...
virtual ~Injectable()=default
Base class for an Injectable with dependencies and an Injectable superclass.
T * getModule()
Get one of the modules in Types.
virtual void inject(DependencyInjector &injector) override
< Inherit constructors from Base
Base class for an Injectable with dependencies.
T * getModule()
Get one of the modules in Types.
InjectableWithDeps< Types... > Super
virtual void inject(DependencyInjector &injector) override
Invoked by the DependencyManager to inject dependencies. Override this method to retrieve dependencie...
static PrintLogger getLogger(const string &name)
This file includes all the types the logdecoder script will decode.
int32_t getDependencyId()
Get the ID associated with the given T type.
int32_t getNextDependencyId()
Returns the next available id.
std::enable_if_t< std::is_same< T, Type >::value, T * > get()
void inject(DependencyInjector &injector)
std::enable_if_t<!std::is_same< T, Type >::value, T * > get()
void inject(DependencyInjector &injector)