Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

ogdf::RegisteredArray< Registry, Value, WithDefault, Base > Class Template Reference

Dynamic arrays indexed with arbitrary keys. More...

#include <ogdf/basic/RegisteredArray.h>

+ Inheritance diagram for ogdf::RegisteredArray< Registry, Value, WithDefault, Base >:

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)
 

Detailed Description

template<class Registry, class Value, bool WithDefault = true, class Base = Registry>
class ogdf::RegisteredArray< Registry, Value, WithDefault, 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.

Warning
When the array grows or shrinks, all pointers to its entries become invalid.
Template Parameters
RegistryThe class which manages the registered keys. Must provide the functions defined in class RegistryBase.
ValueThe type of the stored data.
WithDefaultDetermines 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.
BaseThe 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)

Class Interaction

  • 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.

  • RegistryBase

    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.

  • RegisteredArray

    Used in user code. Inherits from RegisteredArrayWithoutDefault or RegisteredArrayWithDefault, depending on the template parameter WithDefault.

Example Setup

A simple registry that only allows addition of keys:

class ExampleKey {
int m_index;
public:
explicit ExampleKey(int index) : m_index(index) {}
int index() const { return m_index; }
};
class ExampleRegistry : public RegistryBase<ExampleKey *, ExampleRegistry> {
std::list<std::unique_ptr<ExampleKey>> m_keys;
public:
ExampleKey *newKey() {
m_keys.push_back(std::unique_ptr<ExampleKey>(new ExampleKey(m_keys.size())));
keyAdded(m_keys.back().get());
return m_keys.back().get();
}
bool isKeyAssociated(ExampleKey *key) const override { return true; }
int maxKeyIndex() const override { return m_keys.size() - 1; }
int calculateArraySize() const override { return calculateTableSize(m_keys.size()); }
void begin() const override {}
void end() const override {}
};

With this setup, registering an array and modifying its values works as follows:

ExampleRegistry G;
RegisteredArray<ExampleRegistry, int> R(G);
ExampleKey *key = G.newKey();
R[key] = 42;
See also
RegisteredArrayWithoutDefaultOrIndexAccess, RegisteredArrayWithoutDefault, RegisteredArrayWithDefault, RegistryBase, NodeArray

Definition at line 817 of file RegisteredArray.h.

Member Typedef Documentation

◆ RA

template<class Registry , class Value , bool WithDefault = true, class Base = Registry>
using ogdf::RegisteredArray< Registry, Value, WithDefault, Base >::RA = typename std::conditional<WithDefault, internal::RegisteredArrayWithDefault<Registry, Value>, internal::RegisteredArrayWithoutDefault<Registry, Value> >::type
private

Definition at line 822 of file RegisteredArray.h.

Constructor & Destructor Documentation

◆ RegisteredArray() [1/5]

template<class Registry , class Value , bool WithDefault = true, class Base = Registry>
ogdf::RegisteredArray< Registry, Value, WithDefault, Base >::RegisteredArray ( )
inline

Creates a new registered array associated with no registry.

Definition at line 835 of file RegisteredArray.h.

◆ RegisteredArray() [2/5]

template<class Registry , class Value , bool WithDefault = true, class Base = Registry>
ogdf::RegisteredArray< Registry, Value, WithDefault, Base >::RegisteredArray ( const Base &  base)
inlineexplicit

Creates a new registered array associated with the matching registry of base.

Definition at line 838 of file RegisteredArray.h.

◆ RegisteredArray() [3/5]

template<class Registry , class Value , bool WithDefault = true, class Base = Registry>
ogdf::RegisteredArray< Registry, Value, WithDefault, Base >::RegisteredArray ( const Base &  base,
const Value &  def 
)
inline

Creates a new registered array associated with the matching registry of base and initializes all values with def.

Remarks
This constructor is only available with WithDefault = true.

Definition at line 845 of file RegisteredArray.h.

◆ RegisteredArray() [4/5]

template<class Registry , class Value , bool WithDefault = true, class Base = Registry>
ogdf::RegisteredArray< Registry, Value, WithDefault, Base >::RegisteredArray ( const Base *  base)
inlineexplicit

Creates a new registered array associated with the matching registry of base.

Definition at line 848 of file RegisteredArray.h.

◆ RegisteredArray() [5/5]

template<class Registry , class Value , bool WithDefault = true, class Base = Registry>
ogdf::RegisteredArray< Registry, Value, WithDefault, Base >::RegisteredArray ( const Base *  base,
const Value &  def 
)
inline

Creates a new registered array associated with the matching registry of base and initializes all values with def.

Remarks
This constructor is only available with WithDefault = true.

Definition at line 855 of file RegisteredArray.h.

Member Function Documentation

◆ cast()

template<class Registry , class Value , bool WithDefault = true, class Base = Registry>
static const Registry* ogdf::RegisteredArray< Registry, Value, WithDefault, Base >::cast ( const Base *  base)
inlinestaticprivate

Definition at line 824 of file RegisteredArray.h.

◆ init() [1/4]

template<class Registry , class Value , bool WithDefault = true, class Base = Registry>
void ogdf::RegisteredArray< Registry, Value, WithDefault, Base >::init ( const Base &  base)
inline

Reinitializes the array. Associates the array with the matching registry of base.

Definition at line 861 of file RegisteredArray.h.

◆ init() [2/4]

template<class Registry , class Value , bool WithDefault = true, class Base = Registry>
void ogdf::RegisteredArray< Registry, Value, WithDefault, Base >::init ( const Base &  base,
const Value &  new_default 
)
inline

Reinitializes the array with default value new_default.

Associates the array with the matching registry of base.

Remarks
This method is only available with WithDefault = true.

Definition at line 868 of file RegisteredArray.h.

◆ init() [3/4]

template<class Registry , class Value , bool WithDefault = true, class Base = Registry>
void ogdf::RegisteredArray< Registry, Value, WithDefault, Base >::init ( const Base *  base,
const Value &  new_default 
)
inline

Definition at line 873 of file RegisteredArray.h.

◆ init() [4/4]

template<class Registry , class Value , bool WithDefault = true, class Base = Registry>
void ogdf::RegisteredArray< Registry, Value, WithDefault, Base >::init ( const Base *  base = nullptr)
inline

Reinitializes the array. Associates the array with the matching registry of base.

Definition at line 858 of file RegisteredArray.h.


The documentation for this class was generated from the following file:
ogdf::begin
HypergraphRegistry< HypernodeElement >::iterator begin(const HypergraphRegistry< HypernodeElement > &self)
ogdf::calculateTableSize
int calculateTableSize(int actualCount)
The default growth function for registered arrays.
Definition: RegisteredArray.h:67
ogdf::graphml::Attribute::G
@ G
ogdf::end
HypergraphRegistry< HypernodeElement >::iterator end(const HypergraphRegistry< HypernodeElement > &self)
ogdf::graphml::Attribute::R
@ R