Flow 1.0.1
Flow project: Full implementation reference.
Public Types | Public Member Functions | Private Attributes | List of all members
flow::cfg::Dynamic_cfg_context< Root, Target, Target_ptr > Class Template Reference

Class which facilitates managing access to a dynamic configuration. More...

#include <dynamic_cfg_context.hpp>

Collaboration diagram for flow::cfg::Dynamic_cfg_context< Root, Target, Target_ptr >:
[legend]

Public Types

using Target_ptr_type = Target_ptr
 Type alias for Target_ptr. More...
 
using Get_root_func = Function< typename Root::Const_ptr()>
 Type for a function object which returns a ref-counted pointer to an immutable root configuration object. More...
 
using Root_to_target_func = Function< const Target &(const Root &)>
 Type for a function object which translates a Root object to a contained Target object. More...
 

Public Member Functions

 Dynamic_cfg_context (Get_root_func &&get_root_func_moved, Root_to_target_func &&root_to_target_func_moved)
 Constructor. More...
 
template<typename... S_d_value_set>
 Dynamic_cfg_context (const Config_manager< S_d_value_set... > &config_manager, Root_to_target_func &&root_to_target_func_moved, size_t d_value_set_idx=0)
 Constructor. More...
 
Root::Const_ptr root_dynamic_cfg () const
 Obtain the root configuration. More...
 
Target_ptr dynamic_cfg () const
 Obtain the target configuration. More...
 

Private Attributes

const Get_root_func m_get_root_func
 Called to obtain the root configuration. More...
 
const Root_to_target_func m_root_to_target_func
 Translates a root configuration object to a contained target configuration object. More...
 

Detailed Description

template<typename Root, typename Target, typename Target_ptr>
class flow::cfg::Dynamic_cfg_context< Root, Target, Target_ptr >

Class which facilitates managing access to a dynamic configuration.

Another class can make use of this one by means of a composition relationship, either through inheritance (probably private or protected) or by containing one or more Dynamic_cfg_context members. If using inheritance, the class will gain methods which can be used to access the dynamic configuration. If using composition by members, more than one dynamic configuration can be used, each of which can be accessed separately by calling the access methods of the associated member.

A "configuration," here, is a data object (probably a struct), which is referred to as the "root", containing an internal data object, which is referred to as the "target". The target is the configuration object which is expected to be normally accessed. The root and the target can be the same.

Template Parameters
RootType for the root configuration. This should meet the requirements of the template argument for Option_set. A Root::Const_ptr type for a ref-counted pointer to an immutable Root must at least be defined (which can be provided by deriving from util::Shared_ptr_alias_holder). See Option_set.
TargetType for the target configuration.
Target_ptrPlease leave this at its default. Background: This would not have been a template parameter in the first place, had the authors known of pointer_traits::rebind at that the time. To preserve backwards compatibility this parameter remains for now (albeit deprecated).
Todo:
flow::cfg::Dynamic_cfg_context Target_ptr is deprecated and shall be always left at its default value in future code; eventually remove it entirely and hard-code the default value internally.

Definition at line 56 of file dynamic_cfg_context.hpp.

Member Typedef Documentation

◆ Get_root_func

template<typename Root , typename Target , typename Target_ptr >
using flow::cfg::Dynamic_cfg_context< Root, Target, Target_ptr >::Get_root_func = Function<typename Root::Const_ptr ()>

Type for a function object which returns a ref-counted pointer to an immutable root configuration object.

Definition at line 68 of file dynamic_cfg_context.hpp.

◆ Root_to_target_func

template<typename Root , typename Target , typename Target_ptr >
using flow::cfg::Dynamic_cfg_context< Root, Target, Target_ptr >::Root_to_target_func = Function<const Target& (const Root&)>

Type for a function object which translates a Root object to a contained Target object.

Definition at line 71 of file dynamic_cfg_context.hpp.

◆ Target_ptr_type

template<typename Root , typename Target , typename Target_ptr >
using flow::cfg::Dynamic_cfg_context< Root, Target, Target_ptr >::Target_ptr_type = Target_ptr

Type alias for Target_ptr.

Definition at line 65 of file dynamic_cfg_context.hpp.

Constructor & Destructor Documentation

◆ Dynamic_cfg_context() [1/2]

template<typename Root , typename Target , typename Target_ptr >
flow::cfg::Dynamic_cfg_context< Root, Target, Target_ptr >::Dynamic_cfg_context ( Get_root_func &&  get_root_func_moved,
Root_to_target_func &&  root_to_target_func_moved 
)

Constructor.

Parameters
get_root_func_movedReturns a ref-counted pointer to the (immutable) root configuration object.
root_to_target_func_movedTranslates a root configuration object to a contained target configuration object.

Definition at line 135 of file dynamic_cfg_context.hpp.

◆ Dynamic_cfg_context() [2/2]

template<typename Root , typename Target , typename Target_ptr >
template<typename... S_d_value_set>
flow::cfg::Dynamic_cfg_context< Root, Target, Target_ptr >::Dynamic_cfg_context ( const Config_manager< S_d_value_set... > &  config_manager,
Root_to_target_func &&  root_to_target_func_moved,
size_t  d_value_set_idx = 0 
)

Constructor.

This produces a Dynamic_cfg_context which will obtain its configuration from a Config_manager.

Parameters
config_managerA Config_manager which is currently managing the desired dynamic configuration.
root_to_target_func_movedTranslates a root configuration object to a contained target configuration object.
d_value_set_idxThe dynamic config slot index of config_manager which corresponds to the desired dynamic configuration.
See also
Config_manager.

Definition at line 144 of file dynamic_cfg_context.hpp.

Member Function Documentation

◆ dynamic_cfg()

template<typename Root , typename Target , typename Target_ptr >
Target_ptr flow::cfg::Dynamic_cfg_context< Root, Target, Target_ptr >::dynamic_cfg

Obtain the target configuration.

This method provides the key mechanism of the class. The returned pointer object can be used to easily access the target object, but will additionally cause the containing root object to be held valid in memory.

Returns
a ref-counted pointer to the (immutable) target configuration object, but which shares ownership of the containing root configuration object.

Definition at line 162 of file dynamic_cfg_context.hpp.

◆ root_dynamic_cfg()

template<typename Root , typename Target , typename Target_ptr >
Root::Const_ptr flow::cfg::Dynamic_cfg_context< Root, Target, Target_ptr >::root_dynamic_cfg

Obtain the root configuration.

Returns
a ref-counted pointer to the (immutable) root configuration object.

Definition at line 156 of file dynamic_cfg_context.hpp.

Member Data Documentation

◆ m_get_root_func

template<typename Root , typename Target , typename Target_ptr >
const Get_root_func flow::cfg::Dynamic_cfg_context< Root, Target, Target_ptr >::m_get_root_func
private

Called to obtain the root configuration.

Definition at line 126 of file dynamic_cfg_context.hpp.

◆ m_root_to_target_func

template<typename Root , typename Target , typename Target_ptr >
const Root_to_target_func flow::cfg::Dynamic_cfg_context< Root, Target, Target_ptr >::m_root_to_target_func
private

Translates a root configuration object to a contained target configuration object.

Definition at line 129 of file dynamic_cfg_context.hpp.


The documentation for this class was generated from the following files: