AusweisApp2/src/global/Initializer.h

49 lines
963 B
C
Raw Normal View History

2017-12-20 14:54:05 +01:00
/*
* \brief Initializer to register a lambda that will be executed if QCoreApplication is ready.
*
2018-03-28 15:10:51 +02:00
* \copyright Copyright (c) 2017-2018 Governikus GmbH & Co. KG, Germany
2017-12-20 14:54:05 +01:00
*/
#pragma once
#include <functional>
#include <list>
class test_Initializer;
namespace governikus
{
class Initializer
{
private:
friend class ::test_Initializer;
std::list<std::function<void()> > mRegisteredFunctions;
protected:
Initializer() = default;
~Initializer() = default;
public:
static Initializer& getInstance();
struct Entry final
{
Entry(const std::function<void()>& pRegister)
{
Initializer::getInstance().add(pRegister);
}
Entry(const Entry& pCopy) = delete;
Entry(const Entry&& pCopy) = delete;
Entry& operator=(const Entry& pCopy) = delete;
Entry& operator=(const Entry&& pCopy) = delete;
};
void init(); // No need to call this!
void add(const std::function<void()>& pRegister);
};
} /* namespace governikus */