ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
Camp Class Referenceabstract

Description:

This class is used by ALib to

  • manage library bootstrap and termination,
  • provide resources and to
  • provide Configuration data (e.g., configuration files, command line parameters, etc.).

Typically, every "bigger" and "higher level" ALib Module disposes about a type derived from this class. The singleton instances of these types are collected in namespace alib and are named in capital letters, for example alib::ALOX, alib::EXPRESSIONS, etc.

Types found in an ALib Module, will use methods GetResourcePool and GetConfig of that singleton to access resources and to read and write configuration data. With that, it has to be kept in mind that these objects most probably are shared with other camps. As a consequence, clear and understandable resource and variable categories and names are to be used, to avoid conflicting entries.

The ALib Programmer's Manual provides several chapters that explain how 4. Bootstrapping And Shutting Down ALib is performed with the help of this class.
Furthermore, source code sample is given with the tutorial of ALib Module CLI.

Often, types that comprise a "camp singleton" (as the derived types shown in the inheritance diagram above) incorporate some further functionality specific to the field of application that a "module" respectively "camp" covers.

Reference Documentation

Definition at line 58 of file camp.hpp.

#include <camp.hpp>

Inheritance diagram for Camp:
[legend]
Collaboration diagram for Camp:
[legend]

Public Field Index:

NCString ResourceCategory
 

Public Method Index:

 Camp (Camp &&)=delete
 Deleted move constructor.
 
 Camp (const Camp &)=delete
 Deleted copy constructor.
 
 Camp (const NCString &resourceCategory)
 
virtual ~Camp ()
 Virtual destructor to satisfy C++ abstract type rules.
 
void BootstrapResource (const NString &name, const String &data)
 
void BootstrapSetConfig (config::Configuration *pConfig)
 
void BootstrapSetResourcePool (lang::resources::ResourcePool *pool)
 
config::ConfigurationGetConfig ()
 
threads::SharedLockGetConfigLock ()
 
const StringGetResource (const NString &name)
 
resources::ResourcePoolGetResourcePool ()
 
bool IsBootstrapped ()
 
void operator= (Camp &&)=delete
 Deleted move assignment.
 
void operator= (const Camp &)=delete
 Deleted copy assignment.
 
const StringTryResource (const NString &name)
 

Protected Field Index:

int bootstrapState = 0
 
config::Configurationconfig = nullptr
 
SharedLockconfigLock
 A shared lock associated to member config.
 
bool isConfigOwner = false
 
bool isResourceOwner = false
 
lang::resources::ResourcePoolresourcePool = nullptr
 

Protected Method Index:

virtual void bootstrap (BootstrapPhases phase)=0
 
virtual void shutdown (ShutdownPhases phase)=0
 

Field Details:

◆ bootstrapState

int bootstrapState = 0
protected

State of initialization, used to avoid double initialization as well as initialization "gaps".

Definition at line 68 of file camp.hpp.

◆ config

config::Configuration* config = nullptr
protected

Pointer to the configuration instance used to load variable configuration data. An instance is created and assigned with the invocation of one of the Bootstrap methods. This instance is then passed to all dependent libraries (recursively) and this way shared. Dependent libraries that are to an own dedicated instance, have to be initialized explicitly before initializing this ALib Camp.

Access to the field is provided with method GetConfig.

Note
This field is available only when ALib Configuration is included in the ALib Distribution.
The rationale for using a pointer and separated field isConfigOwner, instead of type TSharedConfiguration here, is to avoid header dependencies with module ALib Configuration.

Definition at line 96 of file camp.hpp.

◆ configLock

SharedLock* configLock
protected

A shared lock associated to member config.

Definition at line 100 of file camp.hpp.

◆ isConfigOwner

bool isConfigOwner = false
protected

If a configuration instance has been created when this ALib Camp was initialized, this flag evaluates to true and the instance stored in config will be deleted with destruction of this object.

Note
This field is available only when ALib Configuration is included in the ALib Distribution.

Definition at line 108 of file camp.hpp.

◆ isResourceOwner

bool isResourceOwner = false
protected

If a default instance of type LocalResourcePool has been created when this camp was initialized, this flag evaluates to true and the instance stored in resourcePool will be deleted with destruction of this object.

Definition at line 80 of file camp.hpp.

◆ ResourceCategory

NCString ResourceCategory

The name of the resource category of externalized string resources defined and used by this ALib Camp.
Special camp ALib BaseCamp uses "ALIB". Other ALib Camps use a short unique name.

Definition at line 119 of file camp.hpp.

◆ resourcePool

lang::resources::ResourcePool* resourcePool = nullptr
protected

Pointer to the resource pool. An instance is created and assigned with the invocation of one of the Bootstrap methods. This instance is then passed to all dependent camps (recursively) and this way shared. Dependent libraries that are to an own dedicated instance, have to be initialized explicitly before initializing this ALib Camp.

Definition at line 75 of file camp.hpp.

Constructor(s) / Destructor Details:

◆ Camp()

Camp ( const NCString & resourceCategory)
inline

Constructor.

Parameters
resourceCategoryValue for field ResourceCategory.

Definition at line 128 of file camp.hpp.

◆ ~Camp()

virtual ~Camp ( )
inlinevirtual

Virtual destructor to satisfy C++ abstract type rules.

Definition at line 148 of file camp.hpp.

Method Details:

◆ bootstrap()

virtual void bootstrap ( BootstrapPhases phase)
protectedpure virtual

Abstract method which is invoked during bootstrapping by function
alib::Bootstrap(BootstrapPhases targetPhase. for each phase, and each camp found in list CAMPS.

For details on bootstrapping ALib Camps, see the detailed explanations in chapter 4.Bootstrapping And Shutting Down ALib of the ALib Programmer's Manual.

Parameters
phaseThe initialization phase to perform.

Implemented in CliCamp, ConfigCamp, ExpressionsCamp, FilesCamp, BaseCamp, and ALoxCamp.

◆ BootstrapResource()

void BootstrapResource ( const NString & name,
const String & data )
inline

Shortcut method that invokes ResourcePool::Bootstrap on field resourcePool providing field ResourceCategory as parameter.

Note
This method is defined only after inclusion of header file alib/lang/basecamp/camp_inlines.hpp.
Parameters
nameThe resource name.
dataThe resource data string.

Definition at line 15 of file camp_inlines.hpp.

Here is the call graph for this function:

◆ BootstrapSetConfig()

void BootstrapSetConfig ( config::Configuration * pConfig)
inline

Sets the configuration object of this ALib Camp.

Attention
This method must be invoked before function Bootstrap is invoked with parameter targetPhase set equal or higher than BootstrapPhases::PrepareConfig, because in this phase, internally a configuration is created if none is set.
Function Bootstrap will distribute the given instance to each lower level ALib Camp that has not received a different object.
See also
Chapter 4. Bootstrapping And Shutting Down ALib of the Programmer's Manual of ALib.
Parameters
pConfigThe external configuration object to use.

Definition at line 197 of file camp.hpp.

◆ BootstrapSetResourcePool()

void BootstrapSetResourcePool ( lang::resources::ResourcePool * pool)
inline

Sets the resource pool of this camp.

Attention
This method must be invoked before method Bootstrap, because in the first phase BootstrapPhases::PrepareConfig, internally a pool of type LocalResourcePool is created if none is set.
Method Bootstrap will distribute the given instance to each lower level camp that has not received a different object.
See also
Chapter 4. Bootstrapping And Shutting Down ALib of the Programmer's Manual of ALib.
Parameters
poolThe external resource pool to use.

Definition at line 242 of file camp.hpp.

◆ GetConfig()

config::Configuration & GetConfig ( )
inline

Returns a reference to the configuration object.

Attention
The shared lock receivable with GetConfigLock() has to be acquired when this field is accessed.
Returns
The configuration object set with bootstrapping.

Definition at line 211 of file camp.hpp.

◆ GetConfigLock()

threads::SharedLock & GetConfigLock ( )
inline

Returns a reference to the shared lock that is associated with the configuration object receivable with GetConfig.

See also
Macros ALIB_LOCK_WITH and ALIB_LOCK_SHARED_WITH.
Returns
The shared lock which is needed to be acquired when writing or reading configuration variables.

Definition at line 219 of file camp.hpp.

◆ GetResource()

const String & GetResource ( const NString & name)
inline

Shortcut method that invokes ResourcePool::Get on field resourcePool providing field ResourceCategory as parameter.

With debug-builds, this method asserts that a resource was found. If this is not wanted, use TryResource.

Note
This method is defined only after inclusion of header file alib/lang/basecamp/camp_inlines.hpp.
Parameters
nameThe resource name.
Returns
The resource string, respectively a nulled string on failure.

Definition at line 16 of file camp_inlines.hpp.

Here is the call graph for this function:

◆ GetResourcePool()

resources::ResourcePool & GetResourcePool ( )
inline

Returns a reference to the resource pool.

Returns
The resource pool set with bootstrapping.

Definition at line 254 of file camp.hpp.

◆ IsBootstrapped()

bool IsBootstrapped ( )
inline

Tests if this ALib Camp was completely initialized.

Returns
true if the initialization state is either BootstrapPhases::Final or ShutdownPhases::Announce, false otherwise.

Definition at line 168 of file camp.hpp.

◆ shutdown()

virtual void shutdown ( ShutdownPhases phase)
protectedpure virtual

Abstract method which is invoked during bootstrapping by function
alib::Shutdown(ShutdownPhases targetPhase for each phase, and each camp found in list CAMPS.

For details on bootstrapping ALib Camps, see the detailed explanations in chapter 4. Bootstrapping And Shutting Down ALib of the ALib Programmer's Manual.

Parameters
phaseThe termination level to perform.

Implemented in CliCamp, ConfigCamp, ExpressionsCamp, FilesCamp, BaseCamp, and ALoxCamp.

◆ TryResource()

const String & TryResource ( const NString & name)
inline

Shortcut method that invokes ResourcePool::Get on field resourcePool providing field ResourceCategory as parameter.

Note
Usually, it is recommended to use GetResource, which asserts with debug-builds if a resource was not found.
This method is defined only after inclusion of header file alib/lang/basecamp/camp_inlines.hpp.
Parameters
nameThe resource name.
Returns
The resource string, respectively a nulled string on failure.

Definition at line 17 of file camp_inlines.hpp.

Here is the call graph for this function:

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