|
|
@ -27,6 +27,8 @@ namespace settings { |
|
|
|
|
|
|
|
namespace bpo = boost::program_options; |
|
|
|
|
|
|
|
class Destroyer; |
|
|
|
|
|
|
|
/*! |
|
|
|
* @brief Wrapper around boost::program_options to handle configuration options. |
|
|
|
* |
|
|
@ -43,8 +45,7 @@ namespace settings { |
|
|
|
* option modules. An option module can be anything that implements the |
|
|
|
* interface specified by registerModule(). |
|
|
|
*/ |
|
|
|
class Settings |
|
|
|
{ |
|
|
|
class Settings { |
|
|
|
public: |
|
|
|
|
|
|
|
/*! |
|
|
@ -123,13 +124,26 @@ namespace settings { |
|
|
|
friend std::ostream& helpConfigfile(std::ostream& os); |
|
|
|
friend Settings* instance(); |
|
|
|
friend Settings* newInstance(int const argc, char const * const argv[], char const * const filename, bool const sloppy = false); |
|
|
|
friend Destroyer; |
|
|
|
|
|
|
|
private: |
|
|
|
/*! |
|
|
|
* @brief Constructor. |
|
|
|
* @brief Private constructor. |
|
|
|
* |
|
|
|
* This constructor is private, as noone should be able to create |
|
|
|
* an instance manually, one should always use the |
|
|
|
* newInstance() method. |
|
|
|
*/ |
|
|
|
Settings(int const argc, char const * const argv[], char const * const filename, bool const sloppy); |
|
|
|
|
|
|
|
/*! |
|
|
|
* @brief Private destructor. |
|
|
|
* |
|
|
|
* This destructor should be private, as noone should be able to destroy a singleton. |
|
|
|
* The object is automatically destroyed when the program terminates by the destroyer. |
|
|
|
*/ |
|
|
|
~Settings() {} |
|
|
|
|
|
|
|
/*! |
|
|
|
* @brief Initialize options_description object. |
|
|
|
*/ |
|
|
@ -174,6 +188,33 @@ namespace settings { |
|
|
|
* @brief actual instance of this class. |
|
|
|
*/ |
|
|
|
static Settings* inst; |
|
|
|
|
|
|
|
/*! |
|
|
|
* @brief Destroyer object. |
|
|
|
*/ |
|
|
|
static Destroyer destroyer; |
|
|
|
}; |
|
|
|
|
|
|
|
/*! |
|
|
|
* @brief Destroyer class for singleton object of Settings. |
|
|
|
* |
|
|
|
* The sole purpose of this class is to clean up the singleton object |
|
|
|
* instance of Settings. The Settings class has a static member of this |
|
|
|
* Destroyer type that gets cleaned up when the program terminates. In |
|
|
|
* it's destructor, this object will remove the Settings instance. |
|
|
|
*/ |
|
|
|
class Destroyer { |
|
|
|
public: |
|
|
|
/*! |
|
|
|
* @brief Destructor. |
|
|
|
* |
|
|
|
* Free Settings::inst. |
|
|
|
*/ |
|
|
|
~Destroyer() { |
|
|
|
if (Settings::inst != nullptr) { |
|
|
|
delete Settings::inst; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
/*! |
|
|
|