This purely abstract class provides an interface to store and retrieve "resourced" string data which are organized in a two-level key hierarchy named "resource category" and "resource name". The latter are of narrow string type.
Definition at line 49 of file resources.hpp.
#include <resources.hpp>
Public Static Method Index: | |
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")) |
Public Method Index: | |
virtual | ~ResourcePool () |
void | Bootstrap (const NString &category, const NString &name, const String &data) |
virtual bool | BootstrapAddOrReplace (const NString &category, const NString &name, const String &data)=0 |
virtual void | BootstrapBulk (const nchar *category,...)=0 |
virtual ALIB_API std::vector< std::pair< NString, integer > > | DbgGetCategories () |
virtual ALIB_API std::vector< std::tuple< NString, NString, String, integer > > | DbgGetList () |
virtual const String & | Get (const NString &category, const NString &name, bool dbgAssert)=0 |
const String & | Get (const NString &category, const String &name, bool dbgAssert) |
|
inlinevirtual |
Virtual destructor.
Definition at line 54 of file resources.hpp.
Simple inline method that invokes virtual method BootstrapAddOrReplace. In debug-compilations, it is asserted that a resource with the given key did not exist already.
The use of this method is preferred over a direct invocation of BootstrapAddOrReplace.
category | Category string of the resource to add. |
name | Name string of the resource. |
data | The resource data. |
Definition at line 95 of file resources.hpp.
|
pure virtual |
Used to store a resource string.
In the context of ALib Modules , which usually are the only areas where instances of this type are available (used), this method must only invoked during the process of bootstrapping ALib (and corresponding custom modules).
category | Category string of the resource to add. |
name | Name string of the resource. |
data | The resource data. |
true
if the resource did exist and was replaced, false
if it was an insertion. Implemented in ConfigResourcePool, and LocalResourcePool.
|
pure virtual |
Same as Bootstrap but accepts an array of name/value pairs to be filled into the given parameter category .
nullptr
argument for the next name!In the context of ALib Modules , which usually are the only areas where instances of this type are available (used), this method must only invoked during the process of bootstrapping ALib (and corresponding custom modules).
"..."
in general is not recommended to be used. We still do it here, because this method is usually used with implementations of Camp::bootstrap to load static default values. This approach saves a lot of otherwise needed single invocations (reduces code size) and allows a clean code for the init methods.const nchar*
.category | The category of the resources given. |
... | A list of pairs of const nchar* and const character* keys and data, including a terminating nullptr value. |
Implemented in ConfigResourcePool, and LocalResourcePool.
|
static |
Writes the list of resources obtainable with DbgGetList to an AString.
list | The list of resources, obtained with DbgGetList. |
catFilter | Comma-separated list of names of categories to print. Defaults to nulled string, which includes all caegories. |
format | The format of a line. Defaults to "({3:}) {1}={2!TAB20!ESC<!Q}\\n". |
Definition at line 206 of file localresourcepool.cpp.
Implements abstract method ResourcePool::DbgGetCategories .
Reimplemented in LocalResourcePool.
Definition at line 143 of file localresourcepool.cpp.
Returns a vector of tuples for each resourced element. Each tuple contains: 0. The category name
While being useful to generaly inspect the resources, a high number of requests might indicate a performance penality for a using software. Such can usually be mitigated in a very simple fashion by "caching" a resource string in a local or global/static string variable.
Reimplemented in LocalResourcePool.
Definition at line 132 of file localresourcepool.cpp.
|
pure virtual |
Returns a resource. On failure (resource not found), a nulled string is returned.
category | Category string of the resource. |
name | Name string of the resource |
dbgAssert | This parameter is available only in debug mode. If true , an assertion is raised if the resource was not found. |
Implemented in ConfigResourcePool, and LocalResourcePool.
Convenience inlined method that accepts parameter name as character instead of nchar based string type. The rationale for this is that often, resource name keys are read from other resourced strings and need conversion if used. This avoids external conversion prior to invoking this method.
This method is available only when ALib is compiled with type character not being equivalent to nchar .
After string conversion simply returns result of virtual method Get(const NString&, const NString&, bool).
category | Category string of the resource. |
name | Name string of the resource |
dbgAssert | This parameter is available only in debug mode. If true , an assertion is raised if the resource was not found. |