Dynamic arrays indexed with arbitrary keys. More...
#include <ogdf/basic/RegisteredArray.h>
Public Member Functions | |
RegisteredArray () | |
Creates a new registered array associated with no registry. More... | |
RegisteredArray (const Base &base) | |
Creates a new registered array associated with the matching registry of base . More... | |
RegisteredArray (const Base &base, const Value &def) | |
Creates a new registered array associated with the matching registry of base and initializes all values with def . More... | |
RegisteredArray (const Base *base) | |
Creates a new registered array associated with the matching registry of base . More... | |
RegisteredArray (const Base *base, const Value &def) | |
Creates a new registered array associated with the matching registry of base and initializes all values with def . More... | |
void | init (const Base &base) |
Reinitializes the array. Associates the array with the matching registry of base . More... | |
void | init (const Base &base, const Value &new_default) |
Reinitializes the array with default value new_default . More... | |
void | init (const Base *base, const Value &new_default) |
void | init (const Base *base=nullptr) |
Reinitializes the array. Associates the array with the matching registry of base . More... | |
Private Types | |
using | RA = typename std::conditional< WithDefault, internal::RegisteredArrayWithDefault< Registry, Value >, internal::RegisteredArrayWithoutDefault< Registry, Value > >::type |
Static Private Member Functions | |
static const Registry * | cast (const Base *base) |
Dynamic arrays indexed with arbitrary keys.
Registered arrays provide an efficient, constant-time mapping from indexed keys of a Registry to elements of type Value. The storage automatically grows and shrinks when keys are added to or removed from the registry.
Registry | The class which manages the registered keys. Must provide the functions defined in class RegistryBase. |
Value | The type of the stored data. |
WithDefault | Determines whether the registered array inherits from RegisteredArrayWithDefault or RegisteredArrayWithoutDefault. With WithDefault = true , the array can be initialized with specific default values, but this requires Value to be a copy-constructible type. With WithDefault = false , the array uses the default constructor of Value to initialize new storage. |
Base | The class that manages multiple related registries. Base must be convertible to Registry. If only one such registry exists, Base and Registry can be the same class (i.e. Base directly inherits from class RegistryBase) |
Key
Used to index the registered array. Every key must have a unique non-negative index. Must either provide a public method called index()
or the template function keyToIndex() must offer a specialization for Key to give access to its index.
Value
The type of the elements stored in the array.
Defines the interface for the Registry.
Registry
Implements the abstract functionality defined in RegistryBase. Manages the objects of type Key and stores a list of associated registered arrays for Key. Determines the growth rate of the arrays. When keys are added or removed, the functions RegistryBase::keyAdded(), RegistryBase::keyRemoved(), and RegistryBase::keysCleared() should be called so that the size of all arrays will be adjusted accordingly.
RegisteredArrayBase
Abstract base class for all registered arrays. The Registry communicates with its registered arrays using this interface.
RegisteredArrayWithoutDefault
Provides the core functionality for accessing the values stored in the array. New entries are initialized using the default constructor of type Value. Additionally, there are variants providing by-index access if the Keys are not already ints.
RegisteredArrayWithDefault
Extends the functionality of RegisteredArrayWithoutDefault by adding the possibility to set a specific default value for new keys added to the registry. This requires type Value to be copy-constructible.
Used in user code. Inherits from RegisteredArrayWithoutDefault or RegisteredArrayWithDefault, depending on the template parameter WithDefault.
A simple registry that only allows addition of keys:
With this setup, registering an array and modifying its values works as follows:
Definition at line 817 of file RegisteredArray.h.
|
private |
Definition at line 822 of file RegisteredArray.h.
|
inline |
Creates a new registered array associated with no registry.
Definition at line 835 of file RegisteredArray.h.
|
inlineexplicit |
Creates a new registered array associated with the matching registry of base
.
Definition at line 838 of file RegisteredArray.h.
|
inline |
Creates a new registered array associated with the matching registry of base
and initializes all values with def
.
true
. Definition at line 845 of file RegisteredArray.h.
|
inlineexplicit |
Creates a new registered array associated with the matching registry of base
.
Definition at line 848 of file RegisteredArray.h.
|
inline |
Creates a new registered array associated with the matching registry of base
and initializes all values with def
.
true
. Definition at line 855 of file RegisteredArray.h.
|
inlinestaticprivate |
Definition at line 824 of file RegisteredArray.h.
|
inline |
Reinitializes the array. Associates the array with the matching registry of base
.
Definition at line 861 of file RegisteredArray.h.
|
inline |
Reinitializes the array with default value new_default
.
Associates the array with the matching registry of base
.
true
. Definition at line 868 of file RegisteredArray.h.
|
inline |
Definition at line 873 of file RegisteredArray.h.
|
inline |
Reinitializes the array. Associates the array with the matching registry of base
.
Definition at line 858 of file RegisteredArray.h.