ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
InMemoryPlugin Class Reference

Description:


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:

  • One with priority Priorities::DefaultValues (low priority) to store default values not found in other configuration plug-ins and
  • a second with priority Priorities::ProtectedValues (maximum priority), which can be used protect configuration values from external changes.

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.

Monotonic Allocation

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>

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

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 IteratorGetIterator (const String &sectionName) override
 
virtual ALIB_API bool Load (Variable &variable, bool searchOnly=false) override
 
virtual String Name () const override
 
EntrySearchEntry (const String &section, const String &name)
 
EntrySearchEntry (Section *section, const String &name)
 
ALIB_API std::pair< Section *, bool > SearchOrCreateSection (const String &sectionName)
 
ALIB_API const SectionSearchSection (const String &sectionName)
 
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
XTernalizerStringConverter
 

Type Definition Details:

◆ TEntryList

using TEntryList = List<Entry , Recycling::Shared>
protected

The list type used by struct Section to store entries.

Definition at line 63 of file inmemoryplugin.hpp.

◆ TValueList

The list type used by struct Entry to store additional values of multi-value entries.

Definition at line 67 of file inmemoryplugin.hpp.

Field Details:

◆ allocator

MonoAllocator* allocator
protected

A monotonic allocator used for allocating sections and entries.

Definition at line 281 of file inmemoryplugin.hpp.

◆ entryRecycler

TEntryList::TSharedRecycler entryRecycler
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.

◆ entryTable

monomem::HashMap<EntryKey, std::pair<Section*, TEntryList::Iterator>, EntryKey::Hash, EntryKey::EqualTo> entryTable
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.

◆ isMAOwner

bool isMAOwner
protected

If a monotonic allocator instance was provided from outside, this flag is false. otherwise true.

Definition at line 311 of file inmemoryplugin.hpp.

◆ plugInName

String plugInName
protected

The name of the plug-in. Provided in constructor, returned with Name.

Definition at line 284 of file inmemoryplugin.hpp.

◆ sections

List<Section> sections
protected

The list of sections.

Definition at line 305 of file inmemoryplugin.hpp.

◆ valueRecycler

TValueList::TSharedRecycler valueRecycler
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.

Constructor(s) / Destructor Details::

◆ InMemoryPlugin()

InMemoryPlugin ( String pName,
MonoAllocator * externalMA = nullptr )

Constructor.

Parameters
pNameThe name of the plug-in as returned with Name.
externalMAExternal monotonic allocator. If not given, an internal one is created. Optional and defaults to nullptr.

Definition at line 23 of file inmemoryplugin.cpp.

◆ ~InMemoryPlugin()

~InMemoryPlugin ( )
overridevirtual

Virtual Destructor.

Definition at line 37 of file inmemoryplugin.cpp.

Here is the call graph for this function:

Method Details:

◆ Clear()

void Clear ( )
virtual

Clears all configuration data.

Reimplemented in IniFile.

Definition at line 45 of file inmemoryplugin.cpp.

◆ createEntry()

ALIB_API Entry * createEntry ( Section * section,
const String & name )
inlineprotected

Creates a new entry. Must be invoked only if the entry does not exist, yet.

Parameters
sectionThe section.
nameThe name of the entry to be created.
Returns
The entry found or created.

Definition at line 510 of file inmemoryplugin.hpp.

Here is the call graph for this function:

◆ createSection()

virtual Section * createSection ( const String & sectionName)
inlineprotectedvirtual

Appends a new section to the end of the list. Must be invoked only if the section does not exist, yet.

Parameters
sectionNameThe name of the section.
Returns
The entry if found, else nullptr.

Definition at line 483 of file inmemoryplugin.hpp.

◆ FromVariable()

void FromVariable ( Entry & entry,
Variable & variable ) const
virtual

Virtual method that copies the values of the given variable to an entry.

Parameters
entryThe entry to convert.
variableThe variable to fill with our values.

Reimplemented in IniFile.

Definition at line 137 of file inmemoryplugin.cpp.

Here is the call graph for this function:

◆ GetIterator()

virtual ALIB_API Iterator * GetIterator ( const String & sectionName)
overridevirtual

Creates an iterator object to return all variables within a section.

The iterator object returned, needs to be deleted by the caller.

Note
Method Configuration::GetIterator returns an iterator that allows to iterate across all variables of a section found in all plug-ins
Parameters
sectionNameThe name of the section to iterate.
Returns
The iterator requested.

Reimplemented from ConfigurationPlugin.

◆ Load()

bool Load ( Variable & variable,
bool searchOnly = false )
overridevirtual

Searches the variable in our storage.

Parameters
variableThe variable to retrieve.
searchOnlyIf true, the variable is not read. Defaults to false.
Returns
true if variable was found, false if not.

Implements ConfigurationPlugin.

Reimplemented in IniFile.

Definition at line 80 of file inmemoryplugin.cpp.

Here is the call graph for this function:

◆ Name()

virtual String Name ( ) const
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.

Returns
The name of the plug-in.

Implements ConfigurationPlugin.

Reimplemented in IniFile.

Definition at line 432 of file inmemoryplugin.hpp.

◆ SearchEntry() [1/2]

Entry * SearchEntry ( const String & section,
const String & name )
inline

Searches an entry with the given name.

Parameters
sectionThe name of the section.
nameThe name of the entry to be searched.
Returns
The entry if found, else nullptr.

Definition at line 396 of file inmemoryplugin.hpp.

Here is the call graph for this function:

◆ searchEntry()

Entry * searchEntry ( const String & section,
const String & name )
inlineprotected

Searches an entry with the given name. The search is performed case insensitive.

Parameters
sectionThe name of the section
nameThe name of the entry to be searched.
Returns
The entry if found, else nullptr.

Definition at line 494 of file inmemoryplugin.hpp.

◆ SearchEntry() [2/2]

Entry * SearchEntry ( Section * section,
const String & name )
inline

Searches an entry with the given name.

Parameters
sectionThe section.
nameThe name of the entry to be searched.
Returns
The entry if found, else nullptr.

Definition at line 407 of file inmemoryplugin.hpp.

Here is the call graph for this function:

◆ SearchOrCreateSection()

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.

Parameters
sectionNameThe name of the section to be retrieved.
Returns
Returns a 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.

Here is the call graph for this function:

◆ SearchSection()

const InMemoryPlugin::Section * SearchSection ( const String & sectionName)

Searches the Section with the given name.

Parameters
sectionNameThe name of the section to be retrieved.
Returns
Returns the section if it was found, nullptr otherwise.

Definition at line 51 of file inmemoryplugin.cpp.

Here is the call graph for this function:

◆ Sections()

const List< Section > & Sections ( ) const
inline

Returns a constant reference to the sections of this plug-in.

Returns
The list of sections.

Definition at line 416 of file inmemoryplugin.hpp.

◆ Store() [1/2]

bool Store ( Variable & variable)
overridevirtual

Creates or replaces existing variable in our storage. If the variable has no value, an existing entry is deleted.

Parameters
variableThe variable to retrieve.
Returns
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.

Here is the call graph for this function:

◆ Store() [2/2]

virtual bool Store ( Variable & variable,
const String & externalizedValue )
inlinevirtual

Convenience method that parses the values from the given string using field StringConverter and then invokes Store.

Parameters
variableThe variable to store.
externalizedValueThe value to parse into the variable before storing
Returns
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.

◆ ToVariable()

void ToVariable ( Entry & entry,
Variable & variable ) const
virtual

Virtual method that copies the values of an entry to the given variable .

Parameters
entryThe entry to convert.
variableThe variable to fill with our values.

Reimplemented in IniFile.

Definition at line 121 of file inmemoryplugin.cpp.

Here is the call graph for this function:

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