Browse Source

adding put methods for callbacks

Now, you can also use
mrmc::settings::Callbacks::instance()->put()
to add a new callback from some other code.
tempestpy_adaptions
gereon 12 years ago
parent
commit
89d93d87d4
  1. 7
      src/utility/settings.cpp
  2. 42
      src/utility/settings.h

7
src/utility/settings.cpp

@ -77,6 +77,7 @@ Settings::Settings(const int argc, const char* argv[], const char* filename)
//! Finalize parsed options, check for specified requirements
bpo::notify(this->vm);
mrmc::settings::Callbacks::instance()->disabled = true;
LOG4CPLUS_DEBUG(logger, "Finished loading config.");
}
catch (bpo::reading_file e)
@ -134,7 +135,7 @@ void Settings::initDescriptions()
/*
* Get Callbacks object, then iterate over and call all register callbacks.
*/
Callbacks* cb = mrmc::settings::Callbacks::getInstance();
Callbacks* cb = mrmc::settings::Callbacks::instance();
while (cb->registerList.size() > 0)
{
CallbackType type = cb->registerList.front().first;
@ -184,7 +185,7 @@ void Settings::firstRun(const int argc, const char* argv[], const char* filename
/*
* Call intermediate callbacks.
*/
Callbacks* cb = mrmc::settings::Callbacks::getInstance();
Callbacks* cb = mrmc::settings::Callbacks::instance();
while (cb->intermediateList.size() > 0)
{
CallbackType type = cb->intermediateList.front().first;
@ -242,7 +243,7 @@ void Settings::secondRun(const int argc, const char* argv[], const char* filenam
/*
* Call checker callbacks.
*/
Callbacks* cb = mrmc::settings::Callbacks::getInstance();
Callbacks* cb = mrmc::settings::Callbacks::instance();
while (cb->checkerList.size() > 0)
{
CheckerCallback fptr = cb->checkerList.front();

42
src/utility/settings.h

@ -240,26 +240,48 @@ namespace settings {
*/
class Callbacks
{
public:
inline void put(const CallbackType type, const RegisterCallback ptr)
{
if (this->disabled) throw mrmc::exceptions::InvalidSettings();
this->registerList.push_back(std::pair<CallbackType, RegisterCallback>(type, ptr));
}
inline void put(const CallbackType type, const IntermediateCallback ptr)
{
if (this->disabled) throw mrmc::exceptions::InvalidSettings();
this->intermediateList.push_back(std::pair<CallbackType, IntermediateCallback>(type, ptr));
}
inline void put(const CheckerCallback ptr)
{
if (this->disabled) throw mrmc::exceptions::InvalidSettings();
this->checkerList.push_back(ptr);
}
private:
/*!
* @brief Stores register callbacks.
* @brief Stores register callbacks.
*/
std::list<std::pair<CallbackType, RegisterCallback>> registerList;
/*!
* @brief Stores intermediate callbacks.
* @brief Stores intermediate callbacks.
*/
std::list<std::pair<CallbackType, IntermediateCallback>> intermediateList;
/*!
* @brief Stores check callbacks.
* @brief Stores check callbacks.
*/
std::list<CheckerCallback> checkerList;
/*!
* @brief Stores if we already loaded the settings.
*/
bool disabled;
/*!
* @brief Private constructor.
*/
Callbacks() {}
Callbacks() : disabled(false) {}
/*!
* @brief Private copy constructor.
*/
@ -273,10 +295,10 @@ namespace settings {
* @brief Returns current instance to create singleton.
* @return current instance
*/
inline static Callbacks* getInstance()
inline static Callbacks* instance()
{
static Callbacks instance;
return &instance;
static Callbacks inst;
return &inst;
}
/*!
@ -321,7 +343,7 @@ namespace settings {
*/
Register(const CallbackType type, const RegisterCallback ptr)
{
mrmc::settings::Callbacks::getInstance()->registerList.push_back(std::pair<CallbackType, RegisterCallback>(type, ptr));
mrmc::settings::Callbacks::instance()->put(type, ptr);
}
/*!
@ -342,7 +364,7 @@ namespace settings {
*/
Register(const CallbackType type, const IntermediateCallback ptr)
{
mrmc::settings::Callbacks::getInstance()->intermediateList.push_back(std::pair<CallbackType, IntermediateCallback>(type, ptr));
mrmc::settings::Callbacks::instance()->put(type, ptr);
}
/*!
@ -362,7 +384,7 @@ namespace settings {
*/
Register(const CheckerCallback ptr)
{
mrmc::settings::Callbacks::getInstance()->checkerList.push_back(ptr);
mrmc::settings::Callbacks::instance()->put(ptr);
}
};

Loading…
Cancel
Save