Application - smartel99/NilaiTFO GitHub Wiki

Application

The Application class is the core of any project using this API. It contains the two main function of your entire project, Init and Run, both declared as pure virtual functions.

Init is a function that is only called once at the beginning of the program, before the Run loop. Run is a function that is called after the initialization and that should never return. It contains the main while(true) loop.

To use it in your project, simply create a class that inherits from Application and define Init and Run, that's it!

Example of implementation:

class MyApplication : public cep::Application
{
public:
  MyApplication() = default;
  virtual ~MyApplication() override = default;

  virtual void Init() override
  {
    // Adds an instance of MyModule to the application.
    AddModule(new MyModule());
  }

  virtual void Run() override
  {
    while(true)
    {
      for(cep::Module* module : m_modules)
      {
        module->Run();
      }
    }
  }

  void AddModule(cep::Module* newModule)
  {
    m_modules.push_back(newModule);
  }

private:
  std::vector<cep::Module*> m_modules;
};

int main()
{
  // Initialize low level hardware.
  HAL_Init();

  // Create an instance of our application.
  MyApplication myApp;

  // Call the initialization method of the application.
  myApp.Init();

  // Call the run loop, aka where everything happens.
  myApp.Run();
}