Specialization of abstract interface class ConfigurationPlugin, which holds configuration variables in memory. Instances of this class are used to create two plug-ins within standard configurations:
This class in addition acts as the parent of class IniFile and may be used likewise as a base of custom plug-ins.
To serve the IniFile requirements, this plug-ing divides the set of variables into sections (according to the category of a variable), allows comment strings for variables and sections, and virtualizes some key methods to allow descendants to take specific actions.
This type uses monotonic allocation for all internal data, except long name and comment strings. Nevertheless, due to the recycling facilities of the container types of module ALib Monomem , it is 100% safe against memory exhaustion, independent from the number of repeated insert and delete operations.
Definition at line 47 of file inmemoryplugin.hpp.
#include <inmemoryplugin.hpp>
Inner Type Index: | |
class | Entry |
struct | EntryKey |
class | Section |
Public Method Index: | |
ALIB_API | InMemoryPlugin (String pName, MonoAllocator *externalMA=nullptr) |
virtual ALIB_API | ~InMemoryPlugin () override |
virtual ALIB_API void | Clear () |
virtual ALIB_API void | FromVariable (Entry &entry, Variable &variable) const |
virtual ALIB_API Iterator * | GetIterator (const String §ionName) override |
virtual ALIB_API bool | Load (Variable &variable, bool searchOnly=false) override |
virtual String | Name () const override |
Entry * | SearchEntry (const String §ion, const String &name) |
Entry * | SearchEntry (Section *section, const String &name) |
ALIB_API std::pair< Section *, bool > | SearchOrCreateSection (const String §ionName) |
ALIB_API const Section * | SearchSection (const String §ionName) |
const List< Section > & | Sections () const |
virtual ALIB_API bool | Store (Variable &variable) override |
virtual bool | Store (Variable &variable, const String &externalizedValue) |
virtual ALIB_API void | ToVariable (Entry &entry, Variable &variable) const |
Public Method Index: inherited from ConfigurationPlugin | |
virtual | ~ConfigurationPlugin () |
Additional Inherited Members | |
Public Field Index: inherited from ConfigurationPlugin | |
XTernalizer * | StringConverter |
|
protected |
The list type used by struct Section to store entries.
Definition at line 63 of file inmemoryplugin.hpp.
|
protected |
The list type used by struct Entry to store additional values of multi-value entries.
Definition at line 67 of file inmemoryplugin.hpp.
|
protected |
A monotonic allocator used for allocating sections and entries.
Definition at line 281 of file inmemoryplugin.hpp.
|
protected |
The shared recycler for Entry list nodes. This object is passed to the entry list of each section.
Definition at line 288 of file inmemoryplugin.hpp.
|
protected |
The entry hash set. This is used to find entries by section name and entry name. The set contains all entries of all sections.
Definition at line 301 of file inmemoryplugin.hpp.
|
protected |
If a monotonic allocator instance was provided from outside, this flag is false
. otherwise true
.
Definition at line 311 of file inmemoryplugin.hpp.
|
protected |
The name of the plug-in. Provided in constructor, returned with Name.
Definition at line 284 of file inmemoryplugin.hpp.
The list of sections.
Definition at line 305 of file inmemoryplugin.hpp.
|
protected |
The shared recycler for value list nodes of struct Entry. This object is passed to the value list of each entry.
Definition at line 292 of file inmemoryplugin.hpp.
InMemoryPlugin | ( | String | pName, |
MonoAllocator * | externalMA = nullptr ) |
Constructor.
pName | The name of the plug-in as returned with Name. |
externalMA | External monotonic allocator. If not given, an internal one is created. Optional and defaults to nullptr . |
Definition at line 23 of file inmemoryplugin.cpp.
|
overridevirtual |
Virtual Destructor.
Definition at line 37 of file inmemoryplugin.cpp.
|
virtual |
Clears all configuration data.
Reimplemented in IniFile.
Definition at line 45 of file inmemoryplugin.cpp.
Creates a new entry. Must be invoked only if the entry does not exist, yet.
section | The section. |
name | The name of the entry to be created. |
Definition at line 510 of file inmemoryplugin.hpp.
Appends a new section to the end of the list. Must be invoked only if the section does not exist, yet.
sectionName | The name of the section. |
nullptr
. Definition at line 483 of file inmemoryplugin.hpp.
Virtual method that copies the values of the given variable to an entry.
entry | The entry to convert. |
variable | The variable to fill with our values. |
Reimplemented in IniFile.
Definition at line 137 of file inmemoryplugin.cpp.
Creates an iterator object to return all variables within a section.
The iterator object returned, needs to be deleted by the caller.
sectionName | The name of the section to iterate. |
Reimplemented from ConfigurationPlugin.
|
overridevirtual |
Searches the variable in our storage.
variable | The variable to retrieve. |
searchOnly | If true , the variable is not read. Defaults to false . |
true
if variable was found, false
if not. Implements ConfigurationPlugin.
Reimplemented in IniFile.
Definition at line 80 of file inmemoryplugin.cpp.
|
inlineoverridevirtual |
Abstract method to return a plug-in name. The name may be used in human readable output, e.g. log-files or exception messages to tell a user for example, which plug-in loaded a variable containing a syntax error.
Implements ConfigurationPlugin.
Reimplemented in IniFile.
Definition at line 432 of file inmemoryplugin.hpp.
Searches an entry with the given name.
section | The name of the section. |
name | The name of the entry to be searched. |
nullptr
. Definition at line 396 of file inmemoryplugin.hpp.
Searches an entry with the given name. The search is performed case insensitive.
section | The name of the section |
name | The name of the entry to be searched. |
nullptr
. Definition at line 494 of file inmemoryplugin.hpp.
Searches an entry with the given name.
section | The section. |
name | The name of the entry to be searched. |
nullptr
. Definition at line 407 of file inmemoryplugin.hpp.
std::pair< InMemoryPlugin::Section *, bool > SearchOrCreateSection | ( | const String & | sectionName | ) |
Searches the Section with the given name. If the section was not found, it is created.
sectionName | The name of the section to be retrieved. |
std::pair
with the first element being a pointer to the section and the second a boolean that is true
if the section was created and false
otherwise. Definition at line 67 of file inmemoryplugin.cpp.
const InMemoryPlugin::Section * SearchSection | ( | const String & | sectionName | ) |
Searches the Section with the given name.
sectionName | The name of the section to be retrieved. |
Definition at line 51 of file inmemoryplugin.cpp.
Returns a constant reference to the sections of this plug-in.
Definition at line 416 of file inmemoryplugin.hpp.
|
overridevirtual |
Creates or replaces existing variable in our storage. If the variable has no value, an existing entry is deleted.
variable | The variable to retrieve. |
true
if the variable was written, false
if not. The latter might only happen if the variable given was illegal, e.g. empty name. Reimplemented from ConfigurationPlugin.
Reimplemented in IniFile.
Definition at line 90 of file inmemoryplugin.cpp.
Convenience method that parses the values from the given string using field StringConverter and then invokes Store.
variable | The variable to store. |
externalizedValue | The value to parse into the variable before storing |
true
if the variable was written, false
if not which typically indicates that this plug-in is not able to write values. Reimplemented from ConfigurationPlugin.
Definition at line 212 of file config/plugins.hpp.
Virtual method that copies the values of an entry to the given variable .
entry | The entry to convert. |
variable | The variable to fill with our values. |
Reimplemented in IniFile.
Definition at line 121 of file inmemoryplugin.cpp.