Environment configurations specify typed and untyped environment injector bindings. More...
#include <EnvironmentConfiguration.hpp>
Static Public Member Functions | |
template<typename BaseT > | |
static void | registerUniqueType (const std::string &typeString, const UniquePropertyCloner< BaseT > &cloner) |
Add a polymorphic type custom property binding builder factory to the global property binding builder factory map. More... | |
static void | registerUnsignedTypes () |
Register C++ specific unsigned integer value type property binding builder factories in the global property binding builder factory map. More... | |
template<typename ValueT > | |
static void | registerValueType (const std::string &typeString) |
Add a non-polymorphic type custom property binding builder factory to the global property binding builder factory map. More... | |
Public Member Functions | |
EnvironmentConfiguration (const std::vector< std::shared_ptr< Resource::Uri >> &inputs, const std::vector< std::shared_ptr< Resource::Uri >> &specs={}) | |
Create an environment configuration by specifying a vector of URIs pointing to the source properties texts and a vector of URIs pointing to type specification texts. More... | |
EnvironmentConfiguration (const std::vector< Resource::File > &inputs, const std::vector< Resource::File > &specs={}) | |
Create an environment configuration by specifying a vector of files pointing to the source properties texts and a vector of files pointing to type specification texts. More... | |
template<typename ... UriT> | |
EnvironmentConfiguration (const Resource::Uri &input, const Resource::Uri &firstTypeSpecifications, const UriT &... moreTypeSpecifications) | |
Create an environment configuration by specifying the source properties file and the property types via a properties file. More... | |
template<typename ... UriT> | |
EnvironmentConfiguration (const std::shared_ptr< Resource::Uri > &input, const std::shared_ptr< Resource::Uri > &firstTypeSpecifications, const UriT &... moreTypeSpecifications) | |
Create an environment configuration by specifying a URI pointing to the source properties text and the property types via a properties file. More... | |
EnvironmentConfiguration (const std::string &input, const std::string &typeSpecifications_) | |
Create an environment configuration by specifying a string for the source properties text and the property types via a properties file. More... | |
EnvironmentConfiguration (const Resource::Uri &input) | |
Create an environment configuration by specifying the source properties file. More... | |
EnvironmentConfiguration (const std::shared_ptr< Resource::Uri > &input) | |
Create an environment configuration by specifying a URI pointing to the source properties text. More... | |
EnvironmentConfiguration (const std::string &input) | |
Create an environment configuration by specifying a string for the source properties text. More... | |
void | configure () const override |
Configure the injector configuration. More... | |
Protected Member Functions | |
template<typename ... FactoryPtrT> | |
Impl::PropertyBindingBuilderFactoryPtr | group (std::string name, FactoryPtrT ... tokens) const |
Declare a composite property specification in the environment configuration. More... | |
template<typename BaseT > | |
Impl::PropertyBindingBuilderFactoryPtr | unique (std::string name) const |
Declare a polymorphic "unique" value property specification in the environment configuration. More... | |
template<typename BaseT > | |
Impl::PropertyBindingBuilderFactoryPtr | unique (std::string name, std::unique_ptr< BaseT > &&defaultValue) const |
Declare a polymorphic "unique" value property specification in the environment configuration, specifying a default value. More... | |
template<typename BaseT > | |
Impl::PropertyBindingBuilderFactoryPtr | unique (std::string name, const UniquePropertyCloner< BaseT > &cloner) const |
Declare a polymorphic "unique" value property specification in the environment configuration. More... | |
template<typename BaseT > | |
Impl::PropertyBindingBuilderFactoryPtr | unique (std::string name, const UniquePropertyCloner< BaseT > &cloner, std::unique_ptr< BaseT > &&defaultValue) const |
Declare a polymorphic "unique" value property specification in the environment configuration, specifying a default value. More... | |
template<typename ValueT = std::string> | |
Impl::PropertyBindingBuilderFactoryPtr | value (std::string name) const |
Declare a non-polymorphic value property specification in the environment configuration. More... | |
template<typename ValueT = std::string> | |
Impl::PropertyBindingBuilderFactoryPtr | value (std::string name, ValueT defaultValue) const |
Declare a non-polymorphic value property specification in the environment configuration, specifying a default value. More... | |
Environment configurations specify typed and untyped environment injector bindings.
Implementations of this class can be used to load simple or hierarchical properties files into an application's injector, in order to parameterise the configuration of an application according to the specific environment.
There are two ways to use the environment configuration class:
The two approaches can be mixed if required, by deriving from EnvironmentConfiguration and passing one or more type specification properties files to the base class constructor.
The instantiated EnvironmentConfiguration or derived class(es) should then be passed to the injector create function along with the application configuration instance(s).
Each instance of EnvironmentConfiguration or derived classes should be provided with a properties file input. During injector instantiation, a set of named value and shared bindings are created. These bindings represent the simple and composite properties in the properties file.
Typically, environment properties are sourced from one or more properties files on the local disk. Providing paths to the environment's property file(s) can be achieved by various methods, a couple of simple ones being:
Once the environment property file path(s) have been obtained, one or more corresponding EnvironmentConfiguration instance(s) can be created and passed to the injector.
The EnvironmentConfiguration class is designed to fail immediately if the property text is not well formed, preventing the application from starting up with an invalid configuration.
If a property type has been registered for a property name, the subsequent creation of a property binding for that property will result in a named value binding of that type being created if the property is simple. The value will be created via a call to the fromString function and placed within the named value binding. For all simple properties in the properties file that do not have types registered for them, a std::string named value binding is created.
All root composite properties in the properties file will result in injector named bindings being created of type EnvironmentProperties. Any property types registered for these property names will be ignored (a warning is also logged).
All simple and composite properties defined as descendants of root composite properties result in named value and shared bindings being created directly or indirectly within the root composite properties bindings in the injector. Refer to the EnvironmentProperties class for more information on the bindings created for descendant properties.
|
inline |
Create an environment configuration by specifying a vector of URIs pointing to the source properties texts and a vector of URIs pointing to type specification texts.
inputs | a vector of URIs pointing to the source properties texts |
specs | a vector of URIs pointing to the type specification texts |
|
inline |
Create an environment configuration by specifying a vector of files pointing to the source properties texts and a vector of files pointing to type specification texts.
This convenience constructor allows file URIS to be supplied by value instead of via pointer containers.
inputs | a vector of files pointing to the source properties texts |
specs | a vector of files pointing to the type specification texts |
|
inline |
Create an environment configuration by specifying the source properties file and the property types via a properties file.
FileT | the Resource::File type for moreTypeSpecifications |
input | the path to the properties file to parse |
firstTypeSpecifications | the first properties type specifications file |
moreTypeSpecifications | more properties type specifications files |
|
inline |
Create an environment configuration by specifying a URI pointing to the source properties text and the property types via a properties file.
UriT | the std::shared_ptr<Resource::Uri> type for moreTypeSpecifications |
input | the URI pointing to the source properties text |
firstTypeSpecifications | the first properties type specifications source |
moreTypeSpecifications | more properties type specifications sources |
|
inline |
Create an environment configuration by specifying a string for the source properties text and the property types via a properties file.
input | the properties text |
typeSpecification | the properties type specifications |
|
inline |
Create an environment configuration by specifying the source properties file.
input | the path to the properties file to parse |
|
inline |
Create an environment configuration by specifying a URI pointing to the source properties text.
input | the URI pointing to the source properties text |
|
inline |
Create an environment configuration by specifying a string for the source properties text.
input | the properties text |
|
inlineoverridevirtual |
Configure the injector configuration.
Implements InjectorConfiguration.
|
inlineprotected |
Declare a composite property specification in the environment configuration.
This call is used when the declaration needs to state that the composite property is required.
FactoryPtrT | the intermediate binding builder factory pointer type |
name | the name of the composite property |
tokens | the child property specifications |
|
inlinestatic |
Add a polymorphic type custom property binding builder factory to the global property binding builder factory map.
Instances of the polymorphic (unique) type will be created by calling the supplied cloner function.
The type must have a corresponding fromString function, otherwise there will be a compilation error.
This function must be called before the injector is instantiated, in order to define the custom types.
BaseT | the type of the property's value |
typeString | the string identification of the type |
factory | a pointer to the factory to return when typeString is requested |
cloner | a function that is used to clone the value |
|
inlinestatic |
Register C++ specific unsigned integer value type property binding builder factories in the global property binding builder factory map.
These types are not pre-registered as they are not listed in the environment configuration pre-registered type list.
The additional types registered are:
This function must be called before the injector is instantiated, in order to define the custom types.
|
inlinestatic |
Add a non-polymorphic type custom property binding builder factory to the global property binding builder factory map.
Instances of the non-polymorphic (value) type will be created via prototype copying.
The type must have a corresponding fromString function, otherwise there will be a compilation error.
This function must be called before the injector is instantiated, in order to define the custom types.
ValueT | the type of the property's value |
typeString | the string identification of the type |
factory | a pointer to the factory to return when typeString is requested |
|
inlineprotected |
Declare a polymorphic "unique" value property specification in the environment configuration.
A binding builder factory (that supplies the unique pointer cloner for this type) will be required to have been registered for custom types.
If no entry is found in the binding builder factory map for the specified type, an exception will be thrown.
BaseT | the base type of the class that the property value will be converted to |
name | the name of the value property |
EnvironmentConfigurationException | if no binding builder factory map for the specified type has been registered |
|
inlineprotected |
Declare a polymorphic "unique" value property specification in the environment configuration, specifying a default value.
The unique pointer cloner function will be looked up in the registered factory map. If no entry is found in the factory map, an exception will be thrown.
This overload should be used when a default value for the property should be used when no such property is provided in the environment properties file.
BaseT | the base type of the class that the property value will be converted to |
name | the name of the value property |
defaultValue | the value used in the resulting binding if the property is not set |
|
inlineprotected |
Declare a polymorphic "unique" value property specification in the environment configuration.
The supplied unique pointer cloner function will be used for cloning the unique pointer prototype value.
BaseT | the base type of the class that the property value will be converted to |
name | the name of the value property |
|
inlineprotected |
Declare a polymorphic "unique" value property specification in the environment configuration, specifying a default value.
The supplied unique pointer cloner function will be used for cloning the unique pointer prototype value.
This overload should be used when a default value for the property should be used when no such property is provided in the environment properties file.
BaseT | the base type of the class that the property value will be converted to |
name | the name of the value property |
defaultValue | the value used in the resulting binding if the property is not set |
|
inlineprotected |
Declare a non-polymorphic value property specification in the environment configuration.
ValueT | the value type that the property value will be converted to |
name | the name of the value property |
|
inlineprotected |
Declare a non-polymorphic value property specification in the environment configuration, specifying a default value.
This overload should be used when a default value for the property should be used when no such property is provided in the environment properties file.
ValueT | the value type that the property value will be converted to |
name | the name of the value property |
defaultValue | the value used in the resulting binding if the property is not set |