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>
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 |
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.
T | type of stored data in catalogue. |
typedef hash_map<const char*, GaCatalogueEntry<T>*, GaCataolgueHashMapComparator> Common::GaCatalogue< T >::GaCataolgueHashMap [private] |
Common::GaCatalogue< T >::GaCatalogue | ( | ) | [inline] |
Initializes empty catalogue.
Common::GaCatalogue< T >::~GaCatalogue | ( | ) | [inline] |
Frees memory used by entries (keys and user data).
static GaCatalogue<T>& GACALL Common::GaCatalogue< T >::Instance | ( | ) | [inline, static] |
Returns reference to global instance of catalogue for type T
.
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.
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.
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.
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. |
true
if data is added or replaced successfully. If data cannot be added it returns false
.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.
name | key of the desired entry. |
true
if entry with specified key is removed successfully. If entry cannot be found method returns false
.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.
NULL
pointer.T* GACALL Common::GaCatalogue< T >::GetEntryData | ( | const char * | name | ) | const [inline] |
This method is thread-safe.
name | key of the desired entry. |
NULL
pointer.T* GACALL Common::GaCatalogue< T >::operator[] | ( | const char * | name | ) | const [inline] |
This operator method is thread-safe.
name | key of the desired entry. |
NULL
pointer.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.
number | Reference to variable to which number of kesy will be stored. |
int GACALL Common::GaCatalogue< T >::GetCount | ( | ) | const [inline] |
This method is thread-safe.
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.
name | key of the desired entry. |
true
if entry with specified key exists in catalogue, otherwise return false
.
GaCatalogue< T > * Common::GaCatalogue< T >::_instance = NULL [inline, static, private] |
Pointer to global instance of catalogue for type T
.
GaCataolgueHashMap Common::GaCatalogue< T >::_entries [private] |
Hash table which stores keys and data of the catalogue.