ALib C++ Library
Library Version: 2312 R0
Documentation generated by doxygen
Public Static Fields | Public Methods | Protected Fields | List of all members
LocalResourcePool Class Reference

#include <localresourcepool.hpp>

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

Class Description


This class provides a very simple implementation of abstract interface class ResourcePool, which does not externalize resources.

A shared instance of this class is attached to each ALib Module, if the bootstrapping of ALib is not customized.

With the use of type HashTable for its internal data management, this class uses monotonically growing memory taken from the global allocator.

Only pointers to the given resources (as well as their associated category and name strings) are stored, hence all string argument's of this class's methods have to be static data.

For debug or optimization purposes, method BootstrapGetInternalHashMap is given that allows fine-tune the performance parameters or to inspect the data. For the latter, in debug-compilations, consider also methods DbgGetList and DbgGetCategories.

See also
Please consult the Programmer's Manual of module ALib Resources for details on the concept of resources. Some details on this specific type are given in chapter 4.1 Class LocalResourcePool.

Definition at line 47 of file localresourcepool.hpp.

Public Static Fields

static std::ostream * DbgResourceLoadObserver = nullptr
 

Public Methods

 LocalResourcePool ()
 
virtual ALIB_API ~LocalResourcePool () override
 
virtual ALIB_API bool BootstrapAddOrReplace (const NString &category, const NString &name, const String &data) override
 
virtual ALIB_API void BootstrapBulk (const nchar *category,...) override
 
detail::StaticResourceMapBootstrapGetInternalHashMap ()
 
virtual ALIB_API std::vector< std::pair< NString, integer > > DbgGetCategories () override
 
virtual ALIB_API std::vector< std::tuple< NString, NString, String, integer > > DbgGetList () override
 
virtual const NALIB_API StringGet (const NString &category, const NString &name, bool dbgAssert) override
 
- Public Methods inherited from ResourcePool
virtual ~ResourcePool ()
 
void Bootstrap (const NString &category, const NString &name, const String &data)
 
const StringGet (const NString &category, const String &name, bool dbgAssert)
 

Protected Fields

detail::StaticResourceMap data
 

Additional Inherited Members

- Public Static Methods inherited from ResourcePool
static ALIB_API AString DbgDump (std::vector< std::tuple< NString, NString, String, integer >> &list, const NString &catFilter=nullptr, const String &format=A_CHAR("({3:}) {1}={2!TAB20!ESC<!Q}\n"))
 

Constructor & Destructor Documentation

◆ LocalResourcePool()

LocalResourcePool ( )
inline

Constructor.

Definition at line 70 of file localresourcepool.hpp.

◆ ~LocalResourcePool()

virtual ALIB_API ~LocalResourcePool ( )
inlineoverridevirtual

Destructor.

Definition at line 77 of file localresourcepool.hpp.

Member Function Documentation

◆ BootstrapAddOrReplace()

bool BootstrapAddOrReplace ( const NString category,
const NString name,
const String data 
)
overridevirtual

Implements abstract method ResourcePool::BootstrapAddOrReplace.

Note
If compiler symbol ALIB_DEBUG_RESOURCES is set on compilation and static field LocalResourcePool::DbgResourceLoadObserver is set prior to bootstrapping, this method will write information about whether the given data is added or replaced to the debug output stream.
Parameters
categoryCategory string of the resource to add.
nameName string of the resource.
dataThe resource data.
Returns
true if the resource did exist and was replaced, false if it was an insertion.

Implements ResourcePool.

Definition at line 50 of file localresourcepool.cpp.

Here is the call graph for this function:

◆ BootstrapBulk()

void BootstrapBulk ( const nchar category,
  ... 
)
overridevirtual

Implements abstract method ResourcePool::BootstrapBulk.

Parameters
categoryThe category of the resources given.
...A list of pairs of const nchar* and const character* keys and data, including a terminating nullptr value.

Implements ResourcePool.

Definition at line 70 of file localresourcepool.cpp.

Here is the call graph for this function:

◆ BootstrapGetInternalHashMap()

detail::StaticResourceMap& BootstrapGetInternalHashMap ( )
inline

Returns the internal table that maps a pair of category and name strings to the resource string.

Access to this map may be useful for two purposes:

  1. Debug inspection.
  2. Modification of the parameters of the hash table. (For example, the use of methods Reserve, BaseLoadFactor or MaxLoadFactor).

Modifications on the returned object are allowed only while no threads have been started by the software process (respectively no threads that use ALib ), which usually is true during bootstrapping a software. Therefore the prefix in this method's name.

Returns
The internal hash map.

Definition at line 96 of file localresourcepool.hpp.

◆ DbgGetCategories()

std::vector< std::pair< NString, integer > > DbgGetCategories ( )
overridevirtual

Implements abstract method ResourcePool::DbgGetCategories.

Availability

Available only if compiler symbol ALIB_DEBUG_RESOURCES is set.

Returns
The externalized resource string.

Reimplemented from ResourcePool.

Definition at line 183 of file localresourcepool.cpp.

Here is the call graph for this function:

◆ DbgGetList()

std::vector< std::tuple< NString, NString, String, integer > > DbgGetList ( )
overridevirtual

Implements abstract method ResourcePool::DbgGetList.

Availability

Available only if compiler symbol ALIB_DEBUG_RESOURCES is set.

Returns
The externalized resource string.

Reimplemented from ResourcePool.

Definition at line 153 of file localresourcepool.cpp.

Here is the call graph for this function:

◆ Get()

const String & Get ( const NString category,
const NString name,
bool  dbgAssert 
)
overridevirtual

Implements abstract method ResourcePool::Get.

Parameters
categoryCategory string of the resource.
nameName string of the resource
dbgAssertThis parameter is available only in debug mode. If true, an assertion is raised if the resource was not found.
Returns
The resource string, respectively a nulled string on failure.

Implements ResourcePool.

Definition at line 108 of file localresourcepool.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ data

detail::StaticResourceMap data
protected

A hash map used to store static resources.

Definition at line 51 of file localresourcepool.hpp.

◆ DbgResourceLoadObserver

std::ostream * DbgResourceLoadObserver = nullptr
static

If set prior to bootstrapping (e.g. to &std::cout), then each found resource string is written here. This is very useful to find errors in bulk resource strings, for example a simple missing comma.

Availability

Available only if compiler symbol ALIB_DEBUG_RESOURCES is set.

See also
Manual section 6.3 Debug- And Usage Statistics.

Definition at line 62 of file localresourcepool.hpp.


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