Tesseract
3.02
|
#include <genericvector.h>
Public Member Functions | |
PointerVector () | |
PointerVector (int size) | |
virtual | ~PointerVector () |
PointerVector (const PointerVector &other) | |
PointerVector< T > & | operator+= (const PointerVector &other) |
PointerVector< T > & | operator= (const PointerVector &other) |
virtual void | remove (int index) |
virtual void | truncate (int size) |
void | compact (TessResultCallback1< bool, const T * > *delete_cb) |
virtual void | clear () |
virtual bool | Serialize (FILE *fp) const |
virtual bool | DeSerialize (bool swap, FILE *fp) |
void | sort () |
Definition at line 327 of file genericvector.h.
tesseract::PointerVector< T >::PointerVector | ( | ) | [inline] |
Definition at line 329 of file genericvector.h.
: GenericVector<T*>() { }
tesseract::PointerVector< T >::PointerVector | ( | int | size | ) | [inline, explicit] |
Definition at line 330 of file genericvector.h.
: GenericVector<T*>(size) { }
virtual tesseract::PointerVector< T >::~PointerVector | ( | ) | [inline, virtual] |
Definition at line 331 of file genericvector.h.
{ // Clear must be called here, even though it is called again by the base, // as the base will call the wrong clear. clear(); }
tesseract::PointerVector< T >::PointerVector | ( | const PointerVector< T > & | other | ) | [inline] |
Definition at line 338 of file genericvector.h.
{ this->init(other.size()); this->operator+=(other); }
virtual void tesseract::PointerVector< T >::clear | ( | ) | [inline, virtual] |
Reimplemented from GenericVector< T * >.
Definition at line 397 of file genericvector.h.
void tesseract::PointerVector< T >::compact | ( | TessResultCallback1< bool, const T * > * | delete_cb | ) | [inline] |
Definition at line 373 of file genericvector.h.
{ int new_size = 0; int old_index = 0; // Until the callback returns true, the elements stay the same. while (old_index < GenericVector<T*>::size_used_ && !delete_cb->Run(GenericVector<T*>::data_[old_index++])) ++new_size; // Now just copy anything else that gets false from delete_cb. for (; old_index < GenericVector<T*>::size_used_; ++old_index) { if (!delete_cb->Run(GenericVector<T*>::data_[old_index])) { GenericVector<T*>::data_[new_size++] = GenericVector<T*>::data_[old_index]; } else { delete GenericVector<T*>::data_[old_index]; } } GenericVector<T*>::size_used_ = new_size; delete delete_cb; }
virtual bool tesseract::PointerVector< T >::DeSerialize | ( | bool | swap, |
FILE * | fp | ||
) | [inline, virtual] |
Reimplemented from GenericVector< T * >.
Definition at line 419 of file genericvector.h.
{ inT32 reserved; if (fread(&reserved, sizeof(reserved), 1, fp) != 1) return false; if (swap) Reverse32(&reserved); GenericVector<T*>::reserve(reserved); for (int i = 0; i < reserved; ++i) { inT8 non_null; if (fread(&non_null, sizeof(non_null), 1, fp) != 1) return false; T* item = NULL; if (non_null) { item = new T; if (!item->DeSerialize(swap, fp)) return false; } this->push_back(item); } return true; }
PointerVector<T>& tesseract::PointerVector< T >::operator+= | ( | const PointerVector< T > & | other | ) | [inline] |
Definition at line 342 of file genericvector.h.
{ this->reserve(this->size_used_ + other.size_used_); for (int i = 0; i < other.size(); ++i) { this->push_back(new T(*other.data_[i])); } return *this; }
PointerVector<T>& tesseract::PointerVector< T >::operator= | ( | const PointerVector< T > & | other | ) | [inline] |
Definition at line 350 of file genericvector.h.
{ this->truncate(0); this->operator+=(other); return *this; }
virtual void tesseract::PointerVector< T >::remove | ( | int | index | ) | [inline, virtual] |
Reimplemented from GenericVector< T * >.
Definition at line 358 of file genericvector.h.
{ delete GenericVector<T*>::data_[index]; GenericVector<T*>::remove(index); }
virtual bool tesseract::PointerVector< T >::Serialize | ( | FILE * | fp | ) | const [inline, virtual] |
Reimplemented from GenericVector< T * >.
Definition at line 404 of file genericvector.h.
{ inT32 used = GenericVector<T*>::size_used_; if (fwrite(&used, sizeof(used), 1, fp) != 1) return false; for (int i = 0; i < used; ++i) { inT8 non_null = GenericVector<T*>::data_[i] != NULL; if (fwrite(&non_null, sizeof(non_null), 1, fp) != 1) return false; if (non_null && !GenericVector<T*>::data_[i]->Serialize(fp)) return false; } return true; }
void tesseract::PointerVector< T >::sort | ( | ) | [inline] |
Reimplemented from GenericVector< T * >.
Definition at line 439 of file genericvector.h.
{ sort(&sort_ptr_cmp<T>); }
virtual void tesseract::PointerVector< T >::truncate | ( | int | size | ) | [inline, virtual] |
Reimplemented from GenericVector< T * >.
Definition at line 365 of file genericvector.h.
{ for (int i = size; i < GenericVector<T*>::size_used_; ++i) delete GenericVector<T*>::data_[i]; GenericVector<T*>::truncate(size); }