16#include "ksComponent.h"
19typedef std::function<void(std::string&)> AppLogProviderFunc_t;
20typedef std::function<void(std::string&&)> AppLogCallbackFunc_t;
48 AppLogCallbackFunc_t appLogCallback;
62 template <
class TComponentType,
class... TParams>
66 "You're calling addComponent, but provided type lacks RTTI implementation. Did you miss KSF_RTTI_DECLARATIONS?"
69 auto componentSp{std::make_shared<TComponentType>(arg...)};
70 auto componentWp{std::weak_ptr<TComponentType>(componentSp)};
80 template <
class TComponentType>
81 void findComponents(std::vector<std::weak_ptr<TComponentType>>& outComponents)
84 "You're calling findComponents, but provided type lacks RTTI implementation. Did you miss KSF_RTTI_DECLARATIONS?"
87 outComponents.clear();
91 if (comp->isA(TComponentType::getClassType()))
93 std::weak_ptr<TComponentType> castedCompWp{std::static_pointer_cast<TComponentType>(comp)};
94 if (!castedCompWp.expired())
95 outComponents.push_back(std::move(castedCompWp));
105 template <
class TComponentType>
109 "You're calling findComponent, but provided type lacks RTTI implementation. Did you miss KSF_RTTI_DECLARATIONS?"
113 if (comp->isA(TComponentType::getClassType()))
114 return std::static_pointer_cast<TComponentType>(comp);
116 return std::weak_ptr<TComponentType>();
136 void log(AppLogProviderFunc_t provideLogFn)
const;
142 void setLogCallback(AppLogCallbackFunc_t logCallback);
A class that is a base for user-defined application.
Definition ksApplication.h:43
std::list< std::shared_ptr< ksComponent > > components
An array with shared_ptr of components (holding main reference).
Definition ksApplication.h:45
virtual bool loop()
Executes application logic loop.
Definition ksApplication.cpp:15
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:106
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:81
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:63
virtual bool init()=0
Initializes application.
Base component class.
Definition ksComponent.h:51
virtual const size_t getInstanceType() const
Retrieves type ID of the object.
Definition ksComponent.h:52