19#include "ksComponent.h"
22typedef std::function<void(std::string&)> AppLogProviderFunc_t;
23typedef std::function<void(std::string&&)> AppLogCallbackFunc_t;
51 AppLogCallbackFunc_t appLogCallback;
70 template <
class TComponentType,
class... TParams>
74 "You're calling addComponent, but provided type lacks RTTI implementation. Did you miss KSF_RTTI_DECLARATIONS?"
77 auto componentSp{std::make_shared<TComponentType>(arg...)};
78 auto componentWp{std::weak_ptr<TComponentType>(componentSp)};
88 template <
class TComponentType>
89 void findComponents(std::vector<std::weak_ptr<TComponentType>>& outComponents)
92 "You're calling findComponents, but provided type lacks RTTI implementation. Did you miss KSF_RTTI_DECLARATIONS?"
95 outComponents.clear();
99 if (comp->isA(TComponentType::getClassType()))
101 auto castedCompSp{std::static_pointer_cast<TComponentType>(comp)};
102 outComponents.emplace_back(castedCompSp);
112 template <
class TComponentType>
116 "You're calling findComponent, but provided type lacks RTTI implementation. Did you miss KSF_RTTI_DECLARATIONS?"
121 if (comp->isA(TComponentType::getClassType()))
123 auto castedCompSp{std::static_pointer_cast<TComponentType>(comp)};
124 return std::weak_ptr<TComponentType>(castedCompSp);
128 return std::weak_ptr<TComponentType>();
148 void log(AppLogProviderFunc_t provideLogFn)
const;
154 void setLogCallback(AppLogCallbackFunc_t logCallback);
A class that serves as the base for user-defined applications.
Definition ksApplication.h:46
std::list< std::shared_ptr< ksComponent > > components
An array with shared_ptr of components (holding main reference).
Definition ksApplication.h:48
virtual bool loop()
Executes application logic loop.
Definition ksApplication.cpp:19
virtual ~ksApplication()
Destructor.
std::weak_ptr< TComponentType > findComponent()
Iterates through all components and returns a weak pointer to the first component that matches the ty...
Definition ksApplication.h:113
void findComponents(std::vector< std::weak_ptr< TComponentType > > &outComponents)
Iterates through all components and returns a vector of weak pointers with components that matches th...
Definition ksApplication.h:89
std::weak_ptr< TComponentType > addComponent(TParams... arg)
Instantiates a component of the type defined by the template instance. This function will pass all te...
Definition ksApplication.h:71
virtual bool init()=0
Initializes application.
virtual std::size_t getInstanceType() const
Retrieves type ID of the object.
Definition ksComponent.h:37