Browse Source

adding intermediate callbacks for settings

we'll soon have two runs of the option parser. The whole process will look like this:

* call register callbacks (may update options_description)
* first run of parser
* call intermediate callbacks (may check variable_map and update options_description)
* second run of parser (with new options_description)
* call checker callbacks (may check variable_map)
tempestpy_adaptions
gereon 12 years ago
parent
commit
2ff00441cb
  1. 33
      src/utility/settings.h

33
src/utility/settings.h

@ -126,6 +126,12 @@ namespace settings {
*/
typedef void(*RegisterCallback)(bpo::options_description&);
/*!
* @brief Function type for functions changing the parser state
* between the first and second run.
*/
typedef void(*IntermediateCallback)(bpo::options_description&, bpo::variables_map&);
/*!
* @brief Function type for function checking constraints on settings.
*/
@ -160,6 +166,12 @@ namespace settings {
* @brief Stores register callbacks.
*/
std::list<std::pair<CallbackType, RegisterCallback>> registerList;
/*!
* @brief Stores intermediate callbacks.
*/
std::list<std::pair<CallbackType, IntermediateCallback>> intermediateList;
/*!
* @brief Stores check callbacks.
*/
@ -233,6 +245,27 @@ namespace settings {
mrmc::settings::Callbacks::getInstance()->registerList.push_back(std::pair<CallbackType, RegisterCallback>(type, ptr));
}
/*!
* @brief Registers given function as intermediate callback.
*
* This constructor registers a callback routine that can check
* the option assignment after the first run and change the
* options description before the second run.
* It should be used like this:
* @code
* void intermediate(bpo::options_description& desc, bpo::variables_map& map) {
* // check contents of map and maybe change desc
* }
* mrmc::settings::Register reg(mrmc::settings::CB_CLI, &intermediate);
* @endcode
* This code should be executed during static initialization, i.e.
* it should be somewhere in the cpp-file.
*/
Register(const CallbackType type, const IntermediateCallback ptr)
{
mrmc::settings::Callbacks::getInstance()->intermediateList.push_back(std::pair<CallbackType, IntermediateCallback>(type, ptr));
}
/*!
* @brief Registers given function as check callback.
*

Loading…
Cancel
Save