From 2ff00441cb29951d842b03b0211547c43f28666a Mon Sep 17 00:00:00 2001 From: gereon Date: Sun, 9 Dec 2012 19:23:14 +0100 Subject: [PATCH] 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) --- src/utility/settings.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/utility/settings.h b/src/utility/settings.h index cfafad475..42c848190 100644 --- a/src/utility/settings.h +++ b/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> registerList; + + /*! + * @brief Stores intermediate callbacks. + */ + std::list> intermediateList; + /*! * @brief Stores check callbacks. */ @@ -233,6 +245,27 @@ namespace settings { mrmc::settings::Callbacks::getInstance()->registerList.push_back(std::pair(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(type, ptr)); + } + /*! * @brief Registers given function as check callback. *