ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::camp::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 of 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 Programmer's Manual of module ALib Bootstrap explains how 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 80 of file camp.inl.

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

Public Type Index:

using SPResourcePool = SharedPtr<resources::ResourcePool, MonoAllocator>
 

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.
 
virtual void Bootstrap ()=0
 
void BootstrapResource (const NString &name, const String &data)
 
void BootstrapSetConfig (const SharedConfiguration &pConfig)
 
void BootstrapSetPhase (BootstrapPhases phase)
 
void BootstrapSetResourcePool (const SPResourcePool &pResourcePool)
 
BootstrapPhases GetBootstrapState ()
 
SharedConfigurationGetConfig ()
 
const StringGetResource (const NString &name)
 
SPResourcePoolGetResourcePool ()
 
bool IsBootstrapped ()
 
void operator= (Camp &&)=delete
 Deleted move assignment.
 
void operator= (const Camp &)=delete
 Deleted copy assignment.
 
virtual void Shutdown (ShutdownPhases phase)=0
 
const StringTryResource (const NString &name)
 

Protected Field Index:

int bootstrapState = 0
 
SharedConfiguration config
 
SPResourcePool resourcePool
 

Type Definition Details:

◆ SPResourcePool

Type definition used for sharing resource-pool instances. With default-bootstrapping, an instance of type LocalResourcePool is used here, which is created with allocator instance GLOBAL_ALLOCATOR.

Definition at line 86 of file camp.inl.

Field Details:

◆ bootstrapState

int alib::camp::Camp::bootstrapState = 0
protected

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

Definition at line 91 of file camp.inl.

◆ config

SharedConfiguration alib::camp::Camp::config
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.

Definition at line 104 of file camp.inl.

◆ ResourceCategory

NCString alib::camp::Camp::ResourceCategory

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

Definition at line 113 of file camp.inl.

◆ resourcePool

SPResourcePool alib::camp::Camp::resourcePool
protected

Shared pointer to the resource pool.

See also
Function BootstrapSetResourcePool.

Definition at line 95 of file camp.inl.

Constructor(s) / Destructor Details:

◆ Camp()

alib::camp::Camp::Camp ( const NCString & resourceCategory)
inline

Constructor.

Parameters
resourceCategoryValue for field ResourceCategory.

Definition at line 120 of file camp.inl.

◆ ~Camp()

virtual alib::camp::Camp::~Camp ( )
inlinevirtual

Virtual destructor to satisfy C++ abstract type rules.

Definition at line 138 of file camp.inl.

Method Details:

◆ Bootstrap()

virtual void alib::camp::Camp::Bootstrap ( )
pure virtual

Abstract method which is invoked during bootstrapping by function
alib::Bootstrap(BootstrapPhases targetPhase, camp::Camp* targetCamp, int,int,TCompilationFlags) for each phase, and each camp found in list CAMPS. Implementations of this function receive the phase to perform with GetBootstrapState.

This method is not to be called from outside, but is internally invoked by function alib::Bootstrap.

For details on bootstrappingALib Camps, see the detailed explanations in the Programmer's Manual of module ALib Bootstrap.

Implemented in alib::camp::Basecamp, alib::cli::CliCamp, alib::expressions::ExpressionsCamp, alib::files::FilesCamp, and alib::lox::ALoxCamp.

◆ BootstrapResource()

void alib::camp::Camp::BootstrapResource ( const NString & name,
const String & data )
inline

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

Parameters
nameThe resource name.
dataThe resource data string.

Definition at line 250 of file camp.inl.

◆ BootstrapSetConfig()

void alib::camp::Camp::BootstrapSetConfig ( const SharedConfiguration & pConfig)
inline

Sets the configuration instance of this camp.

Attention
Note the documentation of sibling method BootstrapSetResourcePool. Here, the very same rules apply in respect to the distribution of configuration instances between different camps and in respect to the customization of bootstrapping.
See also
Chapter 7. Customizing The Bootstrap Process of the Programmer's Manual of module ALib Bootstrap.
Parameters
pConfigThe configuration to use.

Definition at line 205 of file camp.inl.

◆ BootstrapSetPhase()

void alib::camp::Camp::BootstrapSetPhase ( BootstrapPhases phase)
inline

Sets the (next) bootstrap phase to perform.

Parameters
phaseThe upcomming phase.

Definition at line 180 of file camp.inl.

◆ BootstrapSetResourcePool()

void alib::camp::Camp::BootstrapSetResourcePool ( const SPResourcePool & pResourcePool)
inline

Sets the resource pool of this camp. By default, this function is called with pResourcePool holding an instance of type LocalResourcePool when ALib is bootstrapped.

In case a custom resource pool type (and/or instance) should be used with this camp, a custom shared pointer has to be created and the custom pool has to be inserted (potentially using method SharedPtr::InsertDerived). Then this method has to be called on the camp prior to the invocation of alib::Bootstrap.

Note that the Function alib::Bootstrap will distribute the given instance to each lower-level camp that has not received a different object. If this should be avoided (to separate the resources of this camp from lower level camps), a further customized bootstrap strategy has to be implemented.

Parameters
pResourcePoolThe resource pool to use.

Definition at line 232 of file camp.inl.

◆ GetBootstrapState()

BootstrapPhases alib::camp::Camp::GetBootstrapState ( )
inline

Returns the bootstrap state of this camp.

Returns
The internal state flag.

Definition at line 176 of file camp.inl.

◆ GetConfig()

SharedConfiguration & alib::camp::Camp::GetConfig ( )
inline

Returns a reference (!) to the configuration object.

Returns
The configuration object set with bootstrapping.

Definition at line 215 of file camp.inl.

◆ GetResource()

const String & alib::camp::Camp::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.Camp.H.
Parameters
nameThe resource name.
Returns
The resource string, respectively a nulled string on failure.

Definition at line 265 of file camp.inl.

◆ GetResourcePool()

SPResourcePool & alib::camp::Camp::GetResourcePool ( )
inline

Returns a reference (!) to the SharedPtr holding the resource pool.

Returns
The resource pool set with bootstrapping.

Definition at line 243 of file camp.inl.

◆ IsBootstrapped()

bool alib::camp::Camp::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 186 of file camp.inl.

◆ Shutdown()

virtual void alib::camp::Camp::Shutdown ( ShutdownPhases phase)
pure virtual

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

This method is not to be called from outside, but is internally invoked by function alib::Bootstrap.

For details on bootstrapping ALib Camps, see the detailed explanations in the Programmer's Manual of module ALib Bootstrap.

Parameters
phaseThe termination level to perform.

Implemented in alib::camp::Basecamp, alib::cli::CliCamp, alib::expressions::ExpressionsCamp, alib::files::FilesCamp, and alib::lox::ALoxCamp.

◆ TryResource()

const String & alib::camp::Camp::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.Camp.H.
Parameters
nameThe resource name.
Returns
The resource string, respectively a nulled string on failure.

Definition at line 281 of file camp.inl.


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