Krita Source Code Documentation
Loading...
Searching...
No Matches
KoGenericRegistry< T > Class Template Reference

#include <KoGenericRegistry.h>

Public Member Functions

void add (const QString &id, T item)
 
void add (T item)
 
void addAlias (const QString &alias, const QString &id)
 
QHash< QString, T >::const_iterator constBegin () const
 
QHash< QString, T >::const_iterator constEnd () const
 
bool contains (const QString &id) const
 
int count () const
 
QList< T > doubleEntries () const
 
get (const QString &id) const
 
QList< QString > keys () const
 
 KoGenericRegistry ()
 
void remove (const QString &id)
 
void removeAlias (const QString &alias)
 
const T value (const QString &id) const
 
QList< T > values () const
 
virtual ~KoGenericRegistry ()
 

Private Attributes

QHash< QString, QString > m_aliases
 
QList< T > m_doubleEntries
 
QHash< QString, T > m_hash
 

Detailed Description

template<typename T>
class KoGenericRegistry< T >

Base class for registry objects.

Registered objects are owned by the registry.

Items are mapped by QString as a unique Id.

Example of use:

class KoMyClassRegistry : public KoGenericRegistry<MyClass*> {
public:
static KoMyClassRegistry * instance();
private:
static KoMyClassRegistry* s_instance;
};
KoMyClassRegistry *KoMyClassRegistry::s_instance = 0;
KoMyClassRegistry * KoMyClassRegistry::instance()
{
if(s_instance == 0)
{
s_instance = new KoMyClassRegistry;
}
return s_instance;
}
PythonPluginManager * instance

Definition at line 46 of file KoGenericRegistry.h.

Constructor & Destructor Documentation

◆ KoGenericRegistry()

template<typename T >
KoGenericRegistry< T >::KoGenericRegistry ( )
inline

Definition at line 49 of file KoGenericRegistry.h.

49{ }

◆ ~KoGenericRegistry()

template<typename T >
virtual KoGenericRegistry< T >::~KoGenericRegistry ( )
inlinevirtual

Definition at line 50 of file KoGenericRegistry.h.

51 {
52 m_doubleEntries.clear();
53 m_hash.clear();
54 }
QHash< QString, T > m_hash

References KoGenericRegistry< T >::m_doubleEntries, and KoGenericRegistry< T >::m_hash.

Member Function Documentation

◆ add() [1/2]

template<typename T >
void KoGenericRegistry< T >::add ( const QString & id,
T item )
inline

add an object to the registry

Parameters
idthe id of the object
itemthe item to add

Definition at line 83 of file KoGenericRegistry.h.

84 {
87
88 if (m_hash.contains(id)) {
90 remove(id);
91 }
92 m_hash.insert(id, item);
93 }
const T value(const QString &id) const
void remove(const QString &id)
QHash< QString, QString > m_aliases
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130

References KIS_SAFE_ASSERT_RECOVER_NOOP, KIS_SAFE_ASSERT_RECOVER_RETURN, KoGenericRegistry< T >::m_aliases, KoGenericRegistry< T >::m_doubleEntries, KoGenericRegistry< T >::m_hash, KoGenericRegistry< T >::remove(), and KoGenericRegistry< T >::value().

◆ add() [2/2]

template<typename T >
void KoGenericRegistry< T >::add ( T item)
inline

Add an object to the registry. If it is a QObject, make sure it isn't in the QObject ownership hierarchy, since the registry itself is responsible for deleting it.

Parameters
itemthe item to add (NOTE: T must have an QString id() const function)

Definition at line 64 of file KoGenericRegistry.h.

65 {
67
68 const QString id = item->id();
70
71 if (m_hash.contains(id)) {
73 remove(id);
74 }
75 m_hash.insert(id, item);
76 }

References KIS_SAFE_ASSERT_RECOVER_NOOP, KIS_SAFE_ASSERT_RECOVER_RETURN, KoGenericRegistry< T >::m_aliases, KoGenericRegistry< T >::m_doubleEntries, KoGenericRegistry< T >::m_hash, KoGenericRegistry< T >::remove(), and KoGenericRegistry< T >::value().

◆ addAlias()

template<typename T >
void KoGenericRegistry< T >::addAlias ( const QString & alias,
const QString & id )
inline

Definition at line 103 of file KoGenericRegistry.h.

104 {
105 KIS_SAFE_ASSERT_RECOVER_NOOP(!m_hash.contains(alias));
106 m_aliases[alias] = id;
107 }

References KIS_SAFE_ASSERT_RECOVER_NOOP, KoGenericRegistry< T >::m_aliases, and KoGenericRegistry< T >::m_hash.

◆ constBegin()

template<typename T >
QHash< QString, T >::const_iterator KoGenericRegistry< T >::constBegin ( ) const
inline

Definition at line 179 of file KoGenericRegistry.h.

179 {
180 return m_hash.constBegin();
181 }

References KoGenericRegistry< T >::m_hash.

◆ constEnd()

template<typename T >
QHash< QString, T >::const_iterator KoGenericRegistry< T >::constEnd ( ) const
inline

Definition at line 183 of file KoGenericRegistry.h.

183 {
184 return m_hash.constEnd();
185 }

References KoGenericRegistry< T >::m_hash.

◆ contains()

template<typename T >
bool KoGenericRegistry< T >::contains ( const QString & id) const
inline
Returns
if there is an object stored in the registry identified by the id.
Parameters
idthe unique identifier string

Definition at line 130 of file KoGenericRegistry.h.

131 {
132 bool result = m_hash.contains(id);
133
134 if (!result && m_aliases.contains(id)) {
135 result = m_hash.contains(m_aliases.value(id));
136 }
137
138 return result;
139 }

References KoGenericRegistry< T >::m_aliases, and KoGenericRegistry< T >::m_hash.

◆ count()

template<typename T >
int KoGenericRegistry< T >::count ( ) const
inline

Definition at line 164 of file KoGenericRegistry.h.

165 {
166 return m_hash.count();
167 }

References KoGenericRegistry< T >::m_hash.

◆ doubleEntries()

template<typename T >
QList< T > KoGenericRegistry< T >::doubleEntries ( ) const
inline

Definition at line 174 of file KoGenericRegistry.h.

175 {
176 return m_doubleEntries;
177 }

References KoGenericRegistry< T >::m_doubleEntries.

◆ get()

template<typename T >
T KoGenericRegistry< T >::get ( const QString & id) const
inline

Retrieve the object from the registry based on the unique identifier string.

Parameters
idthe id

Definition at line 120 of file KoGenericRegistry.h.

121 {
122 return value(id);
123 }

References KoGenericRegistry< T >::value().

◆ keys()

template<typename T >
QList< QString > KoGenericRegistry< T >::keys ( ) const
inline
Returns
a list of all keys

Definition at line 159 of file KoGenericRegistry.h.

160 {
161 return m_hash.keys();
162 }

References KoGenericRegistry< T >::m_hash.

◆ remove()

template<typename T >
void KoGenericRegistry< T >::remove ( const QString & id)
inline

This function removes an item from the registry

Definition at line 98 of file KoGenericRegistry.h.

99 {
100 m_hash.remove(id);
101 }

References KoGenericRegistry< T >::m_hash.

◆ removeAlias()

template<typename T >
void KoGenericRegistry< T >::removeAlias ( const QString & alias)
inline

Definition at line 109 of file KoGenericRegistry.h.

110 {
111 m_aliases.remove(alias);
112 }

References KoGenericRegistry< T >::m_aliases.

◆ value()

template<typename T >
const T KoGenericRegistry< T >::value ( const QString & id) const
inline

Retrieve the object from the registry based on the unique identifier string

Parameters
idthe id

Definition at line 145 of file KoGenericRegistry.h.

146 {
147 T result = m_hash.value(id);
148
149 if (!result && m_aliases.contains(id)) {
150 result = m_hash.value(m_aliases.value(id));
151 }
152
153 return result;
154 }

References KoGenericRegistry< T >::m_aliases, and KoGenericRegistry< T >::m_hash.

◆ values()

template<typename T >
QList< T > KoGenericRegistry< T >::values ( ) const
inline

Definition at line 169 of file KoGenericRegistry.h.

170 {
171 return m_hash.values();
172 }

References KoGenericRegistry< T >::m_hash.

Member Data Documentation

◆ m_aliases

template<typename T >
QHash<QString, QString> KoGenericRegistry< T >::m_aliases
private

Definition at line 194 of file KoGenericRegistry.h.

◆ m_doubleEntries

template<typename T >
QList<T> KoGenericRegistry< T >::m_doubleEntries
private

Definition at line 189 of file KoGenericRegistry.h.

◆ m_hash

template<typename T >
QHash<QString, T> KoGenericRegistry< T >::m_hash
private

Definition at line 193 of file KoGenericRegistry.h.


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