Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

ogdf::RegistryBase< Key, Registry, Iterator > Class Template Reference

Abstract base class for registries. More...

#include <ogdf/basic/RegisteredArray.h>

+ Inheritance diagram for ogdf::RegistryBase< Key, Registry, Iterator >:

Public Types

using iterator_type = Iterator
 
using key_type = Key
 
using registered_array_type = internal::RegisteredArrayBase< Registry >
 
using registration_iterator_type = typename registration_list_type::iterator
 
using registration_list_type = std::list< registered_array_type *, OGDFAllocator< registered_array_type * > >
 
using registry_type = Registry
 

Public Member Functions

 RegistryBase (const RegistryBase &copy)=delete
 
 RegistryBase (RegistryBase &&move) noexcept=delete
 
virtual ~RegistryBase () noexcept
 Destructor. Unregisters all associated arrays. More...
 
void copyArrayEntries (int toIndex, int fromIndex)
 Copies the entry from fromIndex to toIndex in all registered arrays. More...
 
int getArraySize () const
 Returns the current size of all registered arrays. More...
 
const registration_list_typegetRegisteredArrays () const
 Returns a reference to the list of all registered arrays. More...
 
bool isAutoShrink () const
 Returns whether the registry allows arrays to shrink when keys are removed. More...
 
void keyAdded (Key key)
 Records the addition of a new key and resizes all registered arrays if necessary. More...
 
void keyRemoved (Key key)
 Records the deletion of a key and resizes all registered arrays if auto shrink is enabled. More...
 
void keysCleared ()
 Records that all keys have been cleared. If auto shrink is enabled, all arrays are cleared and resized to 0. More...
 
void moveRegisterArray (registration_iterator_type it, registered_array_type *pArray) const
 Stores array pArray at position it in the list of registered arrays. More...
 
RegistryBaseoperator= (const RegistryBase &other)=delete
 
RegistryBaseoperator= (RegistryBase &&other) noexcept=delete
 
OGDF_NODISCARD registration_iterator_type registerArray (registered_array_type *pArray) const
 Registers a new array with this registry. More...
 
void reserveSpace (int new_keys)
 Resizes all arrays to make space of new_keys new keys. More...
 
void resizeArrays ()
 Resizes all arrays to the size requested by calculateArraySize(). Only shrinks the arrays if auto shrink is enabled. More...
 
void resizeArrays (int size)
 Resizes all arrays to size. Only shrinks the arrays if auto shrink is enabled. More...
 
void resizeArrays (int size, bool shrink)
 Resizes all arrays to size. If shrink is true, the arrays may also shrink. More...
 
void setAutoShrink (bool mAutoShrink)
 Specifies whether the registry allows arrays to shrink when keys are removed. More...
 
void swapArrayEntries (int index1, int index2)
 Swaps the entries at index1 and index2 in all registered arrays. More...
 
void unregisterArray (registration_iterator_type it) const noexcept
 Unregisters an array associated with this registry. More...
 
void unregisterArrays () noexcept
 Unregister all associated arrays. More...
 

Protected Member Functions

 RegistryBase ()=default
 

Private Attributes

bool m_autoShrink = false
 
std::mutex m_mutexRegArrays
 
registration_list_type m_registeredArrays
 
int m_size = 0
 

Detailed Description

template<typename Key, typename Registry, typename Iterator = void>
class ogdf::RegistryBase< Key, Registry, Iterator >

Abstract base class for registries.

Defines the interface for event handling regarding the indexed keys. A registry manages one key type and stores all registered arrays associated with that key. It determines the new size of all registered arrays when keys are added or removed.

The following methods must be implemented by all subclasses as they are used via the CRTP:

static inline int keyToIndex(Key key);
bool isKeyAssociated(Key key) const;
int maxKeyIndex() const;
int calculateArraySize(int add) const;
Remarks
To avoid frequent costly resize operations, the array size returned by calculateArraySize should grow in larger steps (e.g. powers of 2)
Template Parameters
KeyThe key type the registry manages.
RegistryThe class that implements the interface defined in RegistryBase.
IteratorAn iterator for all managed keys. Can be void if iterating the keys through the registered array is not required. To allow iterating over all keys, define begin() and end() methods.
See also
RegisteredArray

Definition at line 95 of file RegisteredArray.h.

Member Typedef Documentation

◆ iterator_type

template<typename Key , typename Registry , typename Iterator = void>
using ogdf::RegistryBase< Key, Registry, Iterator >::iterator_type = Iterator

Definition at line 100 of file RegisteredArray.h.

◆ key_type

template<typename Key , typename Registry , typename Iterator = void>
using ogdf::RegistryBase< Key, Registry, Iterator >::key_type = Key

Definition at line 98 of file RegisteredArray.h.

◆ registered_array_type

template<typename Key , typename Registry , typename Iterator = void>
using ogdf::RegistryBase< Key, Registry, Iterator >::registered_array_type = internal::RegisteredArrayBase<Registry>

Definition at line 97 of file RegisteredArray.h.

◆ registration_iterator_type

template<typename Key , typename Registry , typename Iterator = void>
using ogdf::RegistryBase< Key, Registry, Iterator >::registration_iterator_type = typename registration_list_type::iterator

Definition at line 103 of file RegisteredArray.h.

◆ registration_list_type

template<typename Key , typename Registry , typename Iterator = void>
using ogdf::RegistryBase< Key, Registry, Iterator >::registration_list_type = std::list<registered_array_type*, OGDFAllocator<registered_array_type*> >

Definition at line 102 of file RegisteredArray.h.

◆ registry_type

template<typename Key , typename Registry , typename Iterator = void>
using ogdf::RegistryBase< Key, Registry, Iterator >::registry_type = Registry

Definition at line 99 of file RegisteredArray.h.

Constructor & Destructor Documentation

◆ RegistryBase() [1/3]

template<typename Key , typename Registry , typename Iterator = void>
ogdf::RegistryBase< Key, Registry, Iterator >::RegistryBase ( )
protecteddefault

◆ ~RegistryBase()

template<typename Key , typename Registry , typename Iterator = void>
virtual ogdf::RegistryBase< Key, Registry, Iterator >::~RegistryBase ( )
inlinevirtualnoexcept

Destructor. Unregisters all associated arrays.

Definition at line 119 of file RegisteredArray.h.

◆ RegistryBase() [2/3]

template<typename Key , typename Registry , typename Iterator = void>
ogdf::RegistryBase< Key, Registry, Iterator >::RegistryBase ( const RegistryBase< Key, Registry, Iterator > &  copy)
delete

◆ RegistryBase() [3/3]

template<typename Key , typename Registry , typename Iterator = void>
ogdf::RegistryBase< Key, Registry, Iterator >::RegistryBase ( RegistryBase< Key, Registry, Iterator > &&  move)
deletenoexcept

Member Function Documentation

◆ copyArrayEntries()

template<typename Key , typename Registry , typename Iterator = void>
void ogdf::RegistryBase< Key, Registry, Iterator >::copyArrayEntries ( int  toIndex,
int  fromIndex 
)
inline

Copies the entry from fromIndex to toIndex in all registered arrays.

Definition at line 209 of file RegisteredArray.h.

◆ getArraySize()

template<typename Key , typename Registry , typename Iterator = void>
int ogdf::RegistryBase< Key, Registry, Iterator >::getArraySize ( ) const
inline

Returns the current size of all registered arrays.

Definition at line 236 of file RegisteredArray.h.

◆ getRegisteredArrays()

template<typename Key , typename Registry , typename Iterator = void>
const registration_list_type& ogdf::RegistryBase< Key, Registry, Iterator >::getRegisteredArrays ( ) const
inline

Returns a reference to the list of all registered arrays.

Definition at line 227 of file RegisteredArray.h.

◆ isAutoShrink()

template<typename Key , typename Registry , typename Iterator = void>
bool ogdf::RegistryBase< Key, Registry, Iterator >::isAutoShrink ( ) const
inline

Returns whether the registry allows arrays to shrink when keys are removed.

Definition at line 230 of file RegisteredArray.h.

◆ keyAdded()

template<typename Key , typename Registry , typename Iterator = void>
void ogdf::RegistryBase< Key, Registry, Iterator >::keyAdded ( Key  key)
inline

Records the addition of a new key and resizes all registered arrays if necessary.

Definition at line 162 of file RegisteredArray.h.

◆ keyRemoved()

template<typename Key , typename Registry , typename Iterator = void>
void ogdf::RegistryBase< Key, Registry, Iterator >::keyRemoved ( Key  key)
inline

Records the deletion of a key and resizes all registered arrays if auto shrink is enabled.

Definition at line 169 of file RegisteredArray.h.

◆ keysCleared()

template<typename Key , typename Registry , typename Iterator = void>
void ogdf::RegistryBase< Key, Registry, Iterator >::keysCleared ( )
inline

Records that all keys have been cleared. If auto shrink is enabled, all arrays are cleared and resized to 0.

Definition at line 176 of file RegisteredArray.h.

◆ moveRegisterArray()

template<typename Key , typename Registry , typename Iterator = void>
void ogdf::RegistryBase< Key, Registry, Iterator >::moveRegisterArray ( registration_iterator_type  it,
registered_array_type pArray 
) const
inline

Stores array pArray at position it in the list of registered arrays.

Definition at line 154 of file RegisteredArray.h.

◆ operator=() [1/2]

template<typename Key , typename Registry , typename Iterator = void>
RegistryBase& ogdf::RegistryBase< Key, Registry, Iterator >::operator= ( const RegistryBase< Key, Registry, Iterator > &  other)
delete

◆ operator=() [2/2]

template<typename Key , typename Registry , typename Iterator = void>
RegistryBase& ogdf::RegistryBase< Key, Registry, Iterator >::operator= ( RegistryBase< Key, Registry, Iterator > &&  other)
deletenoexcept

◆ registerArray()

template<typename Key , typename Registry , typename Iterator = void>
OGDF_NODISCARD registration_iterator_type ogdf::RegistryBase< Key, Registry, Iterator >::registerArray ( registered_array_type pArray) const
inline

Registers a new array with this registry.

Parameters
pArrayA pointer to the registered array.
Returns
An iterator pointing to the entry for the registered array in the list of registered arrays. This iterator is required for unregistering the array again.

Definition at line 135 of file RegisteredArray.h.

◆ reserveSpace()

template<typename Key , typename Registry , typename Iterator = void>
void ogdf::RegistryBase< Key, Registry, Iterator >::reserveSpace ( int  new_keys)
inline

Resizes all arrays to make space of new_keys new keys.

Definition at line 197 of file RegisteredArray.h.

◆ resizeArrays() [1/3]

template<typename Key , typename Registry , typename Iterator = void>
void ogdf::RegistryBase< Key, Registry, Iterator >::resizeArrays ( )
inline

Resizes all arrays to the size requested by calculateArraySize(). Only shrinks the arrays if auto shrink is enabled.

Definition at line 180 of file RegisteredArray.h.

◆ resizeArrays() [2/3]

template<typename Key , typename Registry , typename Iterator = void>
void ogdf::RegistryBase< Key, Registry, Iterator >::resizeArrays ( int  size)
inline

Resizes all arrays to size. Only shrinks the arrays if auto shrink is enabled.

Definition at line 183 of file RegisteredArray.h.

◆ resizeArrays() [3/3]

template<typename Key , typename Registry , typename Iterator = void>
void ogdf::RegistryBase< Key, Registry, Iterator >::resizeArrays ( int  size,
bool  shrink 
)
inline

Resizes all arrays to size. If shrink is true, the arrays may also shrink.

Definition at line 186 of file RegisteredArray.h.

◆ setAutoShrink()

template<typename Key , typename Registry , typename Iterator = void>
void ogdf::RegistryBase< Key, Registry, Iterator >::setAutoShrink ( bool  mAutoShrink)
inline

Specifies whether the registry allows arrays to shrink when keys are removed.

Definition at line 233 of file RegisteredArray.h.

◆ swapArrayEntries()

template<typename Key , typename Registry , typename Iterator = void>
void ogdf::RegistryBase< Key, Registry, Iterator >::swapArrayEntries ( int  index1,
int  index2 
)
inline

Swaps the entries at index1 and index2 in all registered arrays.

Definition at line 202 of file RegisteredArray.h.

◆ unregisterArray()

template<typename Key , typename Registry , typename Iterator = void>
void ogdf::RegistryBase< Key, Registry, Iterator >::unregisterArray ( registration_iterator_type  it) const
inlinenoexcept

Unregisters an array associated with this registry.

Parameters
itAn iterator pointing to the entry of the array in the list of all registered arrays.

Definition at line 146 of file RegisteredArray.h.

◆ unregisterArrays()

template<typename Key , typename Registry , typename Iterator = void>
void ogdf::RegistryBase< Key, Registry, Iterator >::unregisterArrays ( )
inlinenoexcept

Unregister all associated arrays.

Definition at line 216 of file RegisteredArray.h.

Member Data Documentation

◆ m_autoShrink

template<typename Key , typename Registry , typename Iterator = void>
bool ogdf::RegistryBase< Key, Registry, Iterator >::m_autoShrink = false
private

Definition at line 107 of file RegisteredArray.h.

◆ m_mutexRegArrays

template<typename Key , typename Registry , typename Iterator = void>
std::mutex ogdf::RegistryBase< Key, Registry, Iterator >::m_mutexRegArrays
mutableprivate

Definition at line 111 of file RegisteredArray.h.

◆ m_registeredArrays

template<typename Key , typename Registry , typename Iterator = void>
registration_list_type ogdf::RegistryBase< Key, Registry, Iterator >::m_registeredArrays
mutableprivate

Definition at line 106 of file RegisteredArray.h.

◆ m_size

template<typename Key , typename Registry , typename Iterator = void>
int ogdf::RegistryBase< Key, Registry, Iterator >::m_size = 0
private

Definition at line 108 of file RegisteredArray.h.


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