Template Class Configured

Inheritance Relationships

Base Type

Class Documentation

template<typename C>
class Configured : public Nextsim::ConfiguredBase

A base class to provide configuration infrastructure to classes that can be configured.

Public Types

typedef ConfigurationHelp::HelpMap HelpMap
using ConfigType = ConfigurationHelp::ConfigType

Public Functions

Configured() = default
virtual ~Configured() = default
virtual void configure() = 0

The configuration function.

inline virtual ConfigMap getConfiguration() const

Returns the current configuration of the object.

Public Static Functions

template<typename T>
static void tryConfigure(T &ref)

Template function for conditionally configuring references.

Pass any class to this function (or its pointer equivalent). If it is a derived class of Configured, the overridden configure() function will be called. If it is not, the function will do nothing, gracefully.

Parameters:

ref – A reference to the class on which to attempt configuration.

template<typename T>
static void tryConfigure(T *ptr)

Template function for conditionally configuring classes via a pointer.

Pass any class to this function (or its reference equivalent). If it is a derived class of Configured, the overridden configure() function will be called. If it is not, the function will do nothing, gracefully.

Parameters:

ptr – A pointer to the class on which to attempt configuration.

template<typename T>
static ConfigMap tryGetConfiguration(T &ref)

Template function for conditionally retrieving class configuration via a reference.

Pass any class to this function (or its pointer equivalent). If it is a derived class of Configured, the overridden getConfiguration() function will be called. If it is not, the function will do nothing, gracefully, and return an empty ConfigMap.

Parameters:

ref – A reference to the class for which to attempt to retrieve the configuration.

template<typename T>
static ConfigMap tryGetConfiguration(T *ptr)

Template function for conditionally retrieving class configuration via a pointer.

Pass any class pointer to this function (or its reference equivalent). If it is a derived class of Configured, the overridden getConfiguration() function will be called. If it is not, the function will do nothing, gracefully and return an empty ConfigMap.

Parameters:

ptr – A pointer to the class for which to attempt to retrieve the configuration.

template<typename T>
static inline T getConfiguration(const std::string &name, const T &defaultValue)

Gets the value of the configuration with a given name from the default Configurator.

Parameters:
  • name – Name of the configuration option to fetch.

  • defaultValue – Default value to apply if the configuration is not found.

static HelpMap &getHelpText(HelpMap &map, bool getAll)

Gets the text to be printed as the help text for this configuration.

Parameters:
  • map – The map to fill with the new text.

  • getAll – Get all options, or just the ones for configured modules?

static HelpMap &getHelpRecursive(HelpMap &map, bool getAll)

Gets the configuration help text for the current class as well as any classes used herein.

Parameters:
  • map – The map to fill with the new text.

  • getAll – Get all options, or just the ones for configured modules?

static inline void clearConfigurationMap()

Clear the configuration map. Usually used only in test suites.

Protected Functions

template<typename T>
inline void addOption(const std::string &name, const T &defaultValue)

Adds an option to the per-class option map.

Parameters:
  • name – Name of the option to add.

  • defaultValue – Default value to apply if the configuration is not found.

template<typename T>
inline T retrieveValue(const std::string &name)

Retrieves a configured value of a single option.

Parameters:

name – Name of the configuration option to fetch.