#include <GLBaseOrganismStorage.h>
Public Types | |
typedef GLBaseBidirectOrganismIterator | iterator |
typedef GLBaseBidirectOrganismIteratorConst | const_iterator |
Public Member Functions | |
GLBaseOrganismStorage () | |
virtual | ~GLBaseOrganismStorage () |
virtual bool | addOrganism (GLBaseOrganism *organism, GLConstants::TTwinsFlags twins=GLConstants::NO_TWINS)=0 |
virtual void | deleteAllOrganisms (iterator *start=NULL) |
virtual void | deleteOrganisms (iterator *start=NULL) |
virtual void | emptyStorage ()=0 |
virtual int | fillFromVector (const vector< GLBaseOrganism * > &vector, GLConstants::TStorageFilling fill=GLConstants::APPEND, int size=-1) |
virtual const GLBaseOrganism * | findOrganism (const GLBaseOrganism *organism, bool soft=true) const |
virtual iterator * | getIterator ()=0 |
virtual const_iterator * | getIteratorConst () const =0 |
GLConstants::TMemoryPolicy | getMemoryPolicy () const |
virtual int | getOrganismsVector (vector< const GLBaseOrganism * > &container, GLConstants::TStorageFilling fill=GLConstants::APPEND, int size=-1, bool copy_clones=false) const |
virtual int | getOrganismsVector (vector< GLBaseOrganism * > &container, GLConstants::TStorageFilling fill=GLConstants::APPEND, int size=-1, bool copy_clones=false) |
virtual int | getSize () const =0 |
virtual void | merge (const GLBaseOrganismStorage *storage, GLConstants::TTwinsFlags twins=GLConstants::NO_TWINS)=0 |
void | setMemoryPolicy (GLConstants::TMemoryPolicy new_policy) |
virtual int | trimSize (unsigned int new_size)=0 |
virtual void | setMemoryLockForAllOrganisms (bool new_lock, iterator *start=NULL) |
Definition at line 13 of file GLBaseOrganismStorage.h.
Prototype for constant iterator.
Definition at line 23 of file GLBaseOrganismStorage.h.
Prototype for the ordinary iterator.
Definition at line 19 of file GLBaseOrganismStorage.h.
GLBaseOrganismStorage::GLBaseOrganismStorage | ( | ) |
Simple constructor. Sets the memory policy to GLConstants::DO_NOT_FREE
Definition at line 7 of file GLBaseOrganismStorage.cpp.
GLBaseOrganismStorage::~GLBaseOrganismStorage | ( | ) | [virtual] |
Destructor. Deletes the pointers, if necessary.
Definition at line 15 of file GLBaseOrganismStorage.cpp.
virtual bool GLBaseOrganismStorage::addOrganism | ( | GLBaseOrganism * | organism, | |
GLConstants::TTwinsFlags | twins = GLConstants::NO_TWINS | |||
) | [pure virtual] |
Adds the new organism to storage. If the 'no duplication' flag is set and organism is already in the storage -- do not add it.
organism | new organism to be added to storage. | |
twins | when set to NO_TWINS, check that this organism is not in the storage already. |
Implemented in GLStorageSet, and GLStorageVector.
void GLBaseOrganismStorage::deleteAllOrganisms | ( | iterator * | start = NULL |
) | [virtual] |
Frees memory allocated to all organisms in storage (but do not change the SIZE of the storage, so should be used with care) starting from iterator. If iterator == NULL then deletes all elements from the start.
start | iterator to start from. |
Definition at line 25 of file GLBaseOrganismStorage.cpp.
void GLBaseOrganismStorage::deleteOrganisms | ( | iterator * | start = NULL |
) | [virtual] |
Deletes organisms which are 'unlocked' in memory i.e. those, for which method isLockedInMemory() returns false, starting from iterator. If iterator == NULL then starts from the beginning.
start | iterator to start from. |
Definition at line 39 of file GLBaseOrganismStorage.cpp.
virtual void GLBaseOrganismStorage::emptyStorage | ( | ) | [pure virtual] |
Removes all the organisms from the storage. May free memory depending on memory policy. After this function is called the size of the storage is 0.
Implemented in GLStorageSet, and GLStorageVector.
int GLBaseOrganismStorage::fillFromVector | ( | const vector< GLBaseOrganism * > & | vector, | |
GLConstants::TStorageFilling | fill = GLConstants::APPEND , |
|||
int | size = -1 | |||
) | [virtual] |
Transfers the organisms from the vector to the storage. Note, that vector cannot be vector of constants. Base class provides implementation which for efficiency reasons can be overloaded in concrete classes.
vector | vector with organism to be placed in storage. | |
fill | if APPEND the elements will be added to the storage (only those which are not in storage already), when REPLACE the storage will be emptied before adding the content of the vector. | |
size | how many organisms from vector to be transferred. When < 0 or >- vector.size() will use all the elements from the vector. |
Definition at line 73 of file GLBaseOrganismStorage.cpp.
const GLBaseOrganism * GLBaseOrganismStorage::findOrganism | ( | const GLBaseOrganism * | organism, | |
bool | soft = true | |||
) | const [virtual] |
Checks, if the organism is already in storage (compared not pointers, but the content of the organisms). The base implementation uses simple sequential search using iterator. However, depending on implementation of the storage in concrete class it may be replaced with the more efficient verision.
organism | organism to be found. | |
soft | when true comparison is made in the 'soft' sense. |
Reimplemented in GLStorageSet.
Definition at line 115 of file GLBaseOrganismStorage.cpp.
virtual iterator* GLBaseOrganismStorage::getIterator | ( | ) | [pure virtual] |
Returns the pointer to iterator at the first element of the storage.
Implemented in GLStorageSet, and GLStorageVector.
virtual const_iterator* GLBaseOrganismStorage::getIteratorConst | ( | ) | const [pure virtual] |
Returns the pointer to constant iterator at the first element of the storage.
Implemented in GLStorageSet, and GLStorageVector.
GLConstants::TMemoryPolicy GLBaseOrganismStorage::getMemoryPolicy | ( | ) | const [inline] |
Returns the policy on freeing memory.
Definition at line 121 of file GLBaseOrganismStorage.h.
int GLBaseOrganismStorage::getOrganismsVector | ( | vector< GLBaseOrganism * > & | container, | |
GLConstants::TStorageFilling | fill = GLConstants::APPEND , |
|||
int | size = -1 , |
|||
bool | copy_clones = false | |||
) | [virtual] |
Provides the vector of pointers to the organisms in storage starting from the first one. The base version uses iterator to fill the vector, however, for real implementation of storage which uses stl containers more efficient approach should be possible.
container | vector of pointers to the organisms from storage (output value). | |
fill | when APPEND the new organisms are added to the container, when REPLACE -- the container is cleaned before adding the organisms. | |
size | number of organisms from storage to be returned in vector. if < 0 or > getSize() then returns all the organisms. | |
copy_clones | when true the pointers to the clones of the organisms will be copied, otherwise -- pointers to the original organisms. |
Reimplemented in GLStorageSet, and GLStorageVector.
Definition at line 197 of file GLBaseOrganismStorage.cpp.
int GLBaseOrganismStorage::getOrganismsVector | ( | vector< const GLBaseOrganism * > & | container, | |
GLConstants::TStorageFilling | fill = GLConstants::APPEND , |
|||
int | size = -1 , |
|||
bool | copy_clones = false | |||
) | const [virtual] |
Provides the vector of pointers to the organisms in storage starting from the first one. The base version uses iterator to fill the vector, however, for real implementation of storage which uses stl containers more efficient approach should be possible.
container | vector of pointers to the organisms from storage (output value). | |
fill | when APPEND the new organisms are added to the container, when REPLACE -- the container is cleaned before adding the organisms. | |
size | number of organisms from storage to be returned in vector. if < 0 or > getSize() then returns all the organisms. | |
copy_clones | when true the pointers to the clones of the organisms will be copied, otherwise -- pointers to the original organisms. |
Reimplemented in GLStorageSet, and GLStorageVector.
Definition at line 149 of file GLBaseOrganismStorage.cpp.
virtual int GLBaseOrganismStorage::getSize | ( | ) | const [pure virtual] |
Returns the number of elements in storage.
Implemented in GLStorageSet, and GLStorageVector.
virtual void GLBaseOrganismStorage::merge | ( | const GLBaseOrganismStorage * | storage, | |
GLConstants::TTwinsFlags | twins = GLConstants::NO_TWINS | |||
) | [pure virtual] |
Adds organisms from another storage to the current one.
storage | another organism storage. | |
twins | when equal to NO_TWINS, check that this organism is not in the storage already. |
Implemented in GLStorageSet, and GLStorageVector.
void GLBaseOrganismStorage::setMemoryLockForAllOrganisms | ( | bool | new_lock, | |
iterator * | start = NULL | |||
) | [virtual] |
Sets the memory lock (true locked, false unlocked) for all organisms in the storage starting from the iterator until end. If iterator == NULL then starts from the beginning.
new_lock | the new value for memory lock flag for all organisms. | |
start | the iterator on the first organism starting from which the locks will be changed. |
Definition at line 237 of file GLBaseOrganismStorage.cpp.
void GLBaseOrganismStorage::setMemoryPolicy | ( | GLConstants::TMemoryPolicy | new_policy | ) | [inline] |
Sets the new policy on freeing memory.
new_policy | new memory handling policy. |
Definition at line 192 of file GLBaseOrganismStorage.h.
virtual int GLBaseOrganismStorage::trimSize | ( | unsigned int | new_size | ) | [pure virtual] |
Decreases the size of the storage. If the size of storage was less, than new size, that nothing will be done. The memory allocated for organisms will be dealt with according to memory policy.
new_size | new number of organisms in the storage. |
Implemented in GLStorageSet, and GLStorageVector.