Common::GaCatalogue< T > Class Template Reference

GaCatalogue template class stores and manages catalogue (directory) for genetic operations. Data can be accessed by its key (name). When user adds new data into catalogue, catalogue takes over responsibility for memory allocated by the data. Data must come from heap. Key/data combination is stored in GaCatalogueEntry object. Duplicates of key in catalogue are not allowed. More...

#include <D:/Temp/vs/gal/source/Catalogue.h>

List of all members.

Public Member Functions

 GaCatalogue ()
 Initializes empty catalogue.
 ~GaCatalogue ()
 Frees memory used by entries (keys and user data).
bool GACALL Register (const char *name, T *data, bool replace=false)
 Register method adds data with specified key (name) to catalogue. If entry with specified key already exists in catalogue and replace is set to false, insertion will fail because duplicate of keys are not allowed. When replace is set to true, data in an entry with specified key are replaced or if such entry doesn't exist new entry is added to catalogue. Key is copied and catalogue object takes over responsibility for memory used by data. Data must be located at heap.
bool GACALL Unregister (const char *name)
 Unregister method removes entry with specified key and frees memory used by it.
GaCatalogueEntry< T > *GACALL GetEntry (const char *name) const
 This method is thread-safe.
T *GACALL GetEntryData (const char *name) const
 This method is thread-safe.
T *GACALL operator[] (const char *name) const
 This operator method is thread-safe.
char **GACALL GetKeys (int &number) const
 GetKeys method returns all kesy in catalogue. This method allocates memory for array of pointers to keys and keys but caller is responsible for it.
int GACALL GetCount () const
 This method is thread-safe.
bool GACALL IsExist (const char *name) const
 IsExist method checks existence of entry with specified key.

Static Public Member Functions

static GaCatalogue< T > &GACALL Instance ()
 Returns reference to global instance of catalogue for type T.
static void GACALL MakeInstance ()
 Method makes global instance of catalogue if it wasn't instanced before. This method must be called before using of global instance of catalogue. All built-in global instances of catalogues are instanced in GaInitialization function.
static void GACALL FreeInstance ()
 Frees memory used by global instance of the catalogue. This method must be called before application quitting application or unloading library. All built-in global instances of catalogues are freed in GaFinalize function.

Private Types

typedef hash_map< const char
*, GaCatalogueEntry< T >
*, GaCataolgueHashMapComparator
GaCataolgueHashMap

Private Attributes

GaCataolgueHashMap _entries
 Hash table which stores keys and data of the catalogue.

Static Private Attributes

static GAL_API GaCatalogue< T > * _instance = NULL
 Pointer to global instance of catalogue for type T.

Classes

class  GaCataolgueHashMapComparator
struct  GaStringComparator


Detailed Description

template<typename T>
class Common::GaCatalogue< T >

GaCatalogue template class stores and manages catalogue (directory) for genetic operations. Data can be accessed by its key (name). When user adds new data into catalogue, catalogue takes over responsibility for memory allocated by the data. Data must come from heap. Key/data combination is stored in GaCatalogueEntry object. Duplicates of key in catalogue are not allowed.

All public methods are thread-safe except MakeInstance and FreeInstance. This class has built-in synchronizator so it is allowed to use LOCK_OBJECT and LOCK_THIS_OBJECT macros with instances of this class.

Parameters:
T type of stored data in catalogue.

Member Typedef Documentation

template<typename T>
typedef hash_map<const char*, GaCatalogueEntry<T>*, GaCataolgueHashMapComparator> Common::GaCatalogue< T >::GaCataolgueHashMap [private]


Constructor & Destructor Documentation

template<typename T>
Common::GaCatalogue< T >::GaCatalogue (  )  [inline]

Initializes empty catalogue.

template<typename T>
Common::GaCatalogue< T >::~GaCatalogue (  )  [inline]

Frees memory used by entries (keys and user data).


Member Function Documentation

template<typename T>
static GaCatalogue<T>& GACALL Common::GaCatalogue< T >::Instance (  )  [inline, static]

Returns reference to global instance of catalogue for type T.

Returns:
Returns reference to global instance of catalogue for type T.

template<typename T>
static void GACALL Common::GaCatalogue< T >::MakeInstance (  )  [inline, static]

Method makes global instance of catalogue if it wasn't instanced before. This method must be called before using of global instance of catalogue. All built-in global instances of catalogues are instanced in GaInitialization function.

This method is not thread safe.

template<typename T>
static void GACALL Common::GaCatalogue< T >::FreeInstance (  )  [inline, static]

Frees memory used by global instance of the catalogue. This method must be called before application quitting application or unloading library. All built-in global instances of catalogues are freed in GaFinalize function.

This method is not thread safe.

template<typename T>
bool GACALL Common::GaCatalogue< T >::Register ( const char *  name,
T *  data,
bool  replace = false 
) [inline]

Register method adds data with specified key (name) to catalogue. If entry with specified key already exists in catalogue and replace is set to false, insertion will fail because duplicate of keys are not allowed. When replace is set to true, data in an entry with specified key are replaced or if such entry doesn't exist new entry is added to catalogue. Key is copied and catalogue object takes over responsibility for memory used by data. Data must be located at heap.

This method is thread-safe.

Parameters:
name key of new or existing entry.
data reference to data which will be stored in catalogue
replace tells method whether it should replace data in an entry if it exists with specified key.
Returns:
Method returns true if data is added or replaced successfully. If data cannot be added it returns false.

template<typename T>
bool GACALL Common::GaCatalogue< T >::Unregister ( const char *  name  )  [inline]

Unregister method removes entry with specified key and frees memory used by it.

This method is thread-safe.

Parameters:
name key of the desired entry.
Returns:
Method returns true if entry with specified key is removed successfully. If entry cannot be found method returns false.

template<typename T>
GaCatalogueEntry<T>* GACALL Common::GaCatalogue< T >::GetEntry ( const char *  name  )  const [inline]

This method is thread-safe.

<param name=name">key of the desired entry.

Returns:
Method returns pointer to catalogue entry with specified key. If such entry cannot be found, method returns NULL pointer.

template<typename T>
T* GACALL Common::GaCatalogue< T >::GetEntryData ( const char *  name  )  const [inline]

This method is thread-safe.

Parameters:
name key of the desired entry.
Returns:
Method returns pointer to data of entry with specified key. If such entry cannot be found, method returns NULL pointer.

template<typename T>
T* GACALL Common::GaCatalogue< T >::operator[] ( const char *  name  )  const [inline]

This operator method is thread-safe.

Parameters:
name key of the desired entry.
Returns:
Operator returns pointer to data of entry with specified key. If such entry cannot be found, operator returns NULL pointer.

template<typename T>
char** GACALL Common::GaCatalogue< T >::GetKeys ( int &  number  )  const [inline]

GetKeys method returns all kesy in catalogue. This method allocates memory for array of pointers to keys and keys but caller is responsible for it.

This method is thread-safe.

Parameters:
number Reference to variable to which number of kesy will be stored.
Returns:
Method returns pointer to array of keys.

template<typename T>
int GACALL Common::GaCatalogue< T >::GetCount (  )  const [inline]

This method is thread-safe.

Returns:
Method returns number of entries in catalogue.

template<typename T>
bool GACALL Common::GaCatalogue< T >::IsExist ( const char *  name  )  const [inline]

IsExist method checks existence of entry with specified key.

This method is thread-safe.

Parameters:
name key of the desired entry.
Returns:
Method returns true if entry with specified key exists in catalogue, otherwise return false.


Member Data Documentation

template<typename T>
GaCatalogue< T > * Common::GaCatalogue< T >::_instance = NULL [inline, static, private]

Pointer to global instance of catalogue for type T.

template<typename T>
GaCataolgueHashMap Common::GaCatalogue< T >::_entries [private]

Hash table which stores keys and data of the catalogue.


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

Genetic Algorithm Library
Coolsoft Software Development