ALib C++ Library
Library Version: 2402 R1
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 79 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
 
 Camp (const Camp &)=delete
 
 Camp (const NCString &resourceCategory)
 
virtual ~Camp ()
 
void BootstrapResource (const NString &name, const String &data)
 
void BootstrapSetConfig (config::Configuration *pConfig)
 
void BootstrapSetResourcePool (lang::resources::ResourcePool *pool)
 
config::ConfigurationGetConfig ()
 
const StringGetResource (const NString &name)
 
resources::ResourcePoolGetResourcePool ()
 
bool IsBootstrapped ()
 
void operator= (Camp &&)=delete
 
void operator= (const Camp &)=delete
 
const StringTryResource (const NString &name)
 

Field Details:

◆ bootstrapState

int bootstrapState = 0
protected

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

Definition at line 89 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 prior to 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 .

Definition at line 121 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 130 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 105 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 142 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 prior to initializing this ALib Camp .

Definition at line 98 of file camp.hpp.

Constructor(s) / Destructor Details::

◆ Camp() [1/3]

Camp ( const NCString & resourceCategory)
inline

Constructor.

Parameters
resourceCategoryValue for field ResourceCategory.

Definition at line 151 of file camp.hpp.

◆ Camp() [2/3]

Camp ( const Camp & )
delete

Deleted copy constructor.

◆ Camp() [3/3]

Camp ( Camp && )
delete

Deleted move constructor.

◆ ~Camp()

virtual ~Camp ( )
inlinevirtual

Virtual destructor to satisfy C++ abstract type rules.

Definition at line 171 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 ALox, Cli, Config, Expressions, Files, and BaseCamp.

◆ 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 20 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 219 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 254 of file camp.hpp.

◆ GetConfig()

config::Configuration & GetConfig ( )
inline

Returns a reference to the configuration object.

Returns
The configuration object set with bootstrapping.

Definition at line 231 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 21 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 266 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 190 of file camp.hpp.

◆ operator=() [1/2]

void operator= ( Camp && )
delete

Deleted move assignment.

◆ operator=() [2/2]

void operator= ( const Camp & )
delete

Deleted copy assignment.

◆ 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 ALox, Cli, Config, Expressions, BaseCamp, and Files.

◆ 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 22 of file camp_inlines.hpp.

Here is the call graph for this function:

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