17#include "ksComponent.h"
20typedef std::function<void(std::string&)> AppLogProviderFunc_t;
21typedef std::function<void(std::string&&)> AppLogCallbackFunc_t;
49 AppLogCallbackFunc_t appLogCallback;
68 template <
class TComponentType,
class... TParams>
72 "You're calling addComponent, but provided type lacks RTTI implementation. Did you miss KSF_RTTI_DECLARATIONS?"
75 auto componentSp{std::make_shared<TComponentType>(arg...)};
76 auto componentWp{std::weak_ptr<TComponentType>(componentSp)};
86 template <
class TComponentType>
87 void findComponents(std::vector<std::weak_ptr<TComponentType>>& outComponents)
90 "You're calling findComponents, but provided type lacks RTTI implementation. Did you miss KSF_RTTI_DECLARATIONS?"
93 outComponents.clear();
97 if (comp->isA(TComponentType::getClassType()))
99 std::weak_ptr<TComponentType> castedCompWp{std::static_pointer_cast<TComponentType>(comp)};
100 if (!castedCompWp.expired())
101 outComponents.push_back(std::move(castedCompWp));
111 template <
class TComponentType>
115 "You're calling findComponent, but provided type lacks RTTI implementation. Did you miss KSF_RTTI_DECLARATIONS?"
119 if (comp->isA(TComponentType::getClassType()))
120 return std::static_pointer_cast<TComponentType>(comp);
122 return std::weak_ptr<TComponentType>();
142 void log(AppLogProviderFunc_t provideLogFn)
const;
148 void setLogCallback(AppLogCallbackFunc_t logCallback);
A class that serves as the base for user-defined applications.
Definition ksApplication.h:44
std::list< std::shared_ptr< ksComponent > > components
An array with shared_ptr of components (holding main reference).
Definition ksApplication.h:46
virtual bool loop()
Executes application logic loop.
Definition ksApplication.cpp:18
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:112
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:87
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:69
virtual bool init()=0
Initializes application.
virtual const std::size_t getInstanceType() const
Retrieves type ID of the object.
Definition ksComponent.h:37