My Project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Private Attributes | Friends | List of all members
SIntDict< T > Class Template Reference

#include <sortdict.h>

Inheritance diagram for SIntDict< T >:
LetterToIndexMap< T >

Classes

class  Iterator
 
class  IteratorDict
 

Public Member Functions

 SIntDict (int size=17)
 
virtual ~SIntDict ()
 
void append (int key, const T *d)
 
void prepend (int key, const T *d)
 
bool remove (int key)
 
void sort ()
 
void inSort (int key, const T *d)
 
void setAutoDelete (bool val)
 
T * find (int key)
 
T * operator[] (int key) const
 
T * at (uint i)
 
virtual int compareValues (const T *item1, const T *item2) const
 
void clear ()
 
int count ()
 

Private Attributes

SIntList< T > * m_list
 
QIntDict< T > * m_dict
 
int m_sizeIndex
 

Friends

class Iterator
 
class IteratorDict
 

Detailed Description

template<class T>
class SIntDict< T >

Ordered dictionary of elements of type T. Internally uses a QList<T> and a QIntDict<T>.

Definition at line 74 of file sortdict.h.

Constructor & Destructor Documentation

template<class T>
SIntDict< T >::SIntDict ( int  size = 17)
inline

Create an ordered dictionary.

Parameters
sizeThe size of the dictionary. Should be a prime number for best distribution of elements.

Definition at line 457 of file sortdict.h.

{
m_list = new SIntList<T>(this);
#if AUTORESIZE
while ((uint)size>SDict_primes[m_sizeIndex]) m_sizeIndex++;
m_dict = new QIntDict<T>(SDict_primes[m_sizeIndex]);
#else
m_dict = new QIntDict<T>(size);
#endif
}
template<class T>
virtual SIntDict< T >::~SIntDict ( )
inlinevirtual

Destroys the dictionary

Definition at line 469 of file sortdict.h.

{
delete m_list;
delete m_dict;
}

Member Function Documentation

template<class T>
void SIntDict< T >::append ( int  key,
const T *  d 
)
inline

Appends a compound to the dictionary. The element is owned by the dictionary.

Parameters
keyThe unique key to use to quicky find the item later on.
dThe compound to add.
See Also
find()

Definition at line 481 of file sortdict.h.

{
m_list->append(d);
m_dict->insert(key,d);
#if AUTORESIZE
{
}
#endif
}
template<class T>
T* SIntDict< T >::at ( uint  i)
inline

Returns the item at position i in the sorted dictionary

Definition at line 567 of file sortdict.h.

{
return m_list->at(i);
}
template<class T>
void SIntDict< T >::clear ( )
inline

Clears the dictionary. Will delete items if setAutoDelete() was set to TRUE.

See Also
setAutoDelete

Definition at line 585 of file sortdict.h.

Referenced by initClassMemberIndices(), initFileMemberIndices(), and initNamespaceMemberIndices().

{
m_list->clear();
m_dict->clear();
}
template<class T>
virtual int SIntDict< T >::compareValues ( const T *  item1,
const T *  item2 
) const
inlinevirtual

Function that is used to compare two items when sorting. Overload this to properly sort items.

See Also
inSort()

Reimplemented in UsedIndexLetters, MemberGroupSDict, LetterToIndexMap< T >, and LetterToIndexMap< SearchIndexList >.

Definition at line 576 of file sortdict.h.

{
return item1!=item2;
}
template<class T>
int SIntDict< T >::count ( )
inline

Returns the number of items stored in the dictionary

Definition at line 593 of file sortdict.h.

{
return m_list->count();
}
template<class T>
T* SIntDict< T >::find ( int  key)
inline

Looks up a compound given its key.

Parameters
keyThe key to identify this element.
Returns
The requested compound or zero if it cannot be found.
See Also
append()

Definition at line 555 of file sortdict.h.

Referenced by LetterToIndexMap< SearchIndexList >::append().

{
return m_dict->find(key);
}
template<class T>
void SIntDict< T >::inSort ( int  key,
const T *  d 
)
inline

Inserts a compound into the dictionary in a sorted way.

Parameters
keyThe unique key to use to quicky find the item later on.
dThe compound to add.
See Also
find()

Definition at line 532 of file sortdict.h.

Referenced by LetterToIndexMap< SearchIndexList >::append().

{
m_list->inSort(d);
m_dict->insert(key,d);
#if AUTORESIZE
{
}
#endif
}
template<class T>
T* SIntDict< T >::operator[] ( int  key) const
inline

Equavalent to find().

Definition at line 561 of file sortdict.h.

{
return m_dict->find(key);
}
template<class T>
void SIntDict< T >::prepend ( int  key,
const T *  d 
)
inline

Prepend a compound to the dictionary. The element is owned by the dictionary.

Parameters
keyThe unique key to use to quicky find the item later on.
dThe compound to add.
See Also
find()

Definition at line 499 of file sortdict.h.

{
m_list->prepend(d);
m_dict->insert(key,d);
#if AUTORESIZE
{
}
#endif
}
template<class T>
bool SIntDict< T >::remove ( int  key)
inline

Remove an item from the dictionary

Definition at line 512 of file sortdict.h.

{
T *item = m_dict->take(key);
return item ? m_list->remove(item) : FALSE;
}
template<class T>
void SIntDict< T >::setAutoDelete ( bool  val)
inline

Indicates whether or not the dictionary owns its elements

Definition at line 545 of file sortdict.h.

Referenced by addMembersToMemberGroup(), GroupDef::GroupDef(), LetterToIndexMap< SearchIndexList >::LetterToIndexMap(), and NamespaceDef::NamespaceDef().

{
m_list->setAutoDelete(val);
}
template<class T>
void SIntDict< T >::sort ( )
inline

Sorts the members of the dictionary. First appending a number of members and then sorting them is faster (O(NlogN) than using inSort() for each member (O(N^2)).

Definition at line 522 of file sortdict.h.

Referenced by writeAlphabeticalClassList(), NamespaceDef::writeMemberGroups(), GroupDef::writeMemberGroups(), FileDef::writeMemberGroups(), and ClassDef::writeMemberGroups().

{
m_list->sort();
}

Friends And Related Function Documentation

template<class T>
friend class Iterator
friend

Definition at line 598 of file sortdict.h.

template<class T>
friend class IteratorDict
friend

Definition at line 662 of file sortdict.h.

Member Data Documentation

template<class T>
QIntDict<T>* SIntDict< T >::m_dict
private
template<class T>
SIntList<T>* SIntDict< T >::m_list
private
template<class T>
int SIntDict< T >::m_sizeIndex
private

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