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.
Definition at line 34 of file localresourcepool.inl.
Public Static Field Index: | |
| static std::ostream * | DbgResourceLoadObserver = nullptr |
Public Method Index: | |
| LocalResourcePool () | |
| Constructor. | |
| virtual | ~LocalResourcePool () override |
| Destructor. | |
| virtual bool | BootstrapAddOrReplace (const NString &category, const NString &name, const String &data) override |
| virtual void | BootstrapBulk (const nchar *category,...) override |
| detail::StaticResourceMap & | BootstrapGetInternalHashMap () |
| virtual std::vector< std::pair< NString, integer > > | DbgGetCategories () override |
| virtual std::vector< std::tuple< NString, NString, String, integer > > | DbgGetList () override |
| virtual const String & | Get (const NString &category, const NString &name, bool dbgAssert) override |
| Public Method Index: inherited from alib::resources::ResourcePool | |
| virtual | ~ResourcePool ()=default |
| Virtual destructor. | |
| void | Bootstrap (const NString &category, const NString &name, const String &data) |
| const String & | Get (const NString &category, const String &name, bool dbgAssert) |
Protected Field Index: | |
| detail::StaticResourceMap | data |
| A hash map used to store static resources. | |
|
protected |
A hash map used to store static resources.
Definition at line 38 of file localresourcepool.inl.
|
static |
If set before 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.
Definition at line 49 of file localresourcepool.inl.
|
inline |
Constructor.
Definition at line 57 of file localresourcepool.inl.
|
inlineoverridevirtual |
Destructor.
Definition at line 63 of file localresourcepool.inl.
|
overridevirtual |
Implements abstract method virtual bool BootstrapAddOrReplace(const NString&, const NString&, const String&) =0.
| 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. Implements alib::resources::ResourcePool.
Definition at line 51 of file localresourcepool.cpp.
|
overridevirtual |
Implements abstract method virtual void BootstrapBulk(const nchar*, ...) =0.
| 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. |
Implements alib::resources::ResourcePool.
Definition at line 69 of file localresourcepool.cpp.
|
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:
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 process. Therefore , the prefix in this method's name.
Definition at line 82 of file localresourcepool.inl.
|
overridevirtual |
Implements abstract method virtual std::vector< std::pair< NString, integer > > DbgGetCategories() .
Reimplemented from alib::resources::ResourcePool.
Definition at line 181 of file localresourcepool.cpp.
|
overridevirtual |
Returns a vector of tuples for each resourced element. Each tuple contains:
While being useful to generally inspect the resources, a high number of requests might indicate a performance penalty. Mitigation can usually be performed in a very simple fashion by "caching" a resource string in a local or global/static string variable.
Reimplemented from alib::resources::ResourcePool.
Definition at line 151 of file localresourcepool.cpp.
|
overridevirtual |
Implements abstract method const String & Get(const NString&, const String&, bool) .
| category | Category string of the resource. |
| name | Name string of the resource |
| dbgAssert | This parameter is available (and to be passed) only in debug mode. If true, an error is raised if the resource was not found. |
Implements alib::resources::ResourcePool.
Definition at line 109 of file localresourcepool.cpp.