Skyward boardcore
Loading...
Searching...
No Matches
Boardcore::DependencyManager Class Reference

Main DependencyManager class. More...

#include <DependencyManager.h>

Public Member Functions

 DependencyManager ()
 
template<typename T , typename = std::enable_if_t< std::is_base_of<Injectable, T>::value>>
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.
 
bool inject ()
 Inject all dependencies into all inserted .
 

Friends

class DependencyInjector
 

Detailed Description

Main DependencyManager class.

This utility is meant to be used as a dependency injector for Skyward OBSW.

Dependencies and dependents should inherit from Injectable. Normally though you should extend from InjectableWithDeps in case of dependencies.

Here's a quick example (for more examples look at src/tests/catch/test-dependencymanager.cpp):

// A simple direct dependency
class MyDependency1 : public Injectable {};
// Abstracting direct dependencies with a common interface
class MyDependency2Iface : public Injectable {};
class MyDependency2 : public
InjectableWithDeps<InjectableBase<MyDependency2Iface>> {};
// A simple dependant (which can become a dependency itself)
class MyDependant : public InjectableWithDeps<MyDependency1,
MyDependency2Iface> {};
DependencyManager dependency_mgr;
// Initialize the dependencies
dependency_mgr.insert<MyDependency1>(new MyDependency1());
dependency_mgr.insert<MyDependency2Iface>(new MyDependency2());
dependency_mgr.insert<MyDependant>(new MyDependant());
// Inject and resolve all dependencies!
dependency_mgr.inject();
// Optionally, print the resulting graph
dependency_mgr.graphviz(std::cout);
Interface for an injectable dependency.
virtual void inject(DependencyInjector &injector)
Invoked by the DependencyManager to inject dependencies. Override this method to retrieve dependencie...

Definition at line 114 of file DependencyManager.h.

Constructor & Destructor Documentation

◆ DependencyManager()

Boardcore::DependencyManager::DependencyManager ( )
inline

Definition at line 131 of file DependencyManager.h.

Member Function Documentation

◆ graphviz()

void DependencyManager::graphviz ( std::ostream & os)

Generate a gaphviz compatible output showing dependencies. Needs to be called after inject.

Parameters
osOutput stream to write to.

Definition at line 53 of file DependencyManager.cpp.

◆ inject()

bool DependencyManager::inject ( )

Inject all dependencies into all inserted .

Returns
True if successful, false otherwise.

Definition at line 75 of file DependencyManager.cpp.

◆ insert()

template<typename T , typename = std::enable_if_t< std::is_base_of<Injectable, T>::value>>
bool Boardcore::DependencyManager::insert ( T * dependency)
inline

Insert a new dependency.

Note
If T is not Injectable the compiler will fail to find this method!
Parameters
dependencyInjectable to insert in the DependencyManager.
Returns
True if successful, false otherwise.

Definition at line 143 of file DependencyManager.h.

Friends And Related Symbol Documentation

◆ DependencyInjector

friend class DependencyInjector
friend

Definition at line 116 of file DependencyManager.h.


The documentation for this class was generated from the following files: