Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions
tesseract::PointerVector< T > Class Template Reference

`#include <genericvector.h>`

Inheritance diagram for tesseract::PointerVector< T >:

List of all members.

## 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 ()
Public Member Functions inherited from GenericVector< T * >
| GenericVector ()
| GenericVector (int size)
| GenericVector (const GenericVector &other)
GenericVector< T * > & | operator+= (const GenericVector &other)
void | operator+= (T *t)
GenericVector< T * > & | operator= (const GenericVector &other)
virtual | ~GenericVector ()
void | reserve (int size)
void | double_the_size ()
void | init_to_size (int size, T *t)
int | size () const
int | length () const
bool | empty () const
T *& | get (int index) const
T *& | back () const
T *& | operator[] (int index) const
int | get_index (T *object) const
bool | contains (T *object) const
T * | contains_index (int index) const
int | push_back (T *object)
int | push_back_new (T *object)
int | push_front (T *object)
void | set (T *t, int index)
void | insert (T *t, int index)
void | set_clear_callback (TessCallback1< T * > *cb)
void | set_compare_callback (TessResultCallback2< bool, T *const &, T *const & > *cb)
void | delete_data_pointers ()
void | move (GenericVector< T * > *from)
bool | write (FILE *f, TessResultCallback2< bool, FILE *, T *const & > *cb) const
bool | read (FILE *f, TessResultCallback3< bool, FILE *, T **, bool > *cb, bool swap)
bool | SerializeClasses (FILE *fp) const
bool | DeSerializeClasses (bool swap, FILE *fp)
void | sort (int(*comparator)(const void *, const void *))
bool | bool_binary_search (const T *&target) const
int | binary_search (const T *&target) const
void | compact_sorted ()
void | compact (TessResultCallback1< bool, int > *delete_cb)
T * | dot_product (const GenericVector< T * > &other) const

## Additional Inherited Members

Static Public Member Functions inherited from GenericVector< T * >
static T ** | double_the_size_memcpy (int current_size, T **data)
Protected Member Functions inherited from GenericVector< T * >
void | init (int size)
Protected Attributes inherited from GenericVector< T * >
inT32 | size_used_
inT32 | size_reserved_
T ** | data_
TessCallback1< T * > * | clear_cb_
TessResultCallback2< bool, T *const &, T *const & > * | compare_cb_
Static Protected Attributes inherited from GenericVector< T * >
static const int | kDefaultVectorSize

## Detailed Description

### template<typename T>
class tesseract::PointerVector< T >

Definition at line 327 of file genericvector.h.

## Constructor & Destructor Documentation

template<typename T>

tesseract::PointerVector< T >::PointerVector | ( |  | ) |

inline

Definition at line 329 of file genericvector.h.

: GenericVector<T*>() { }
template<typename T>

tesseract::PointerVector< T >::PointerVector | ( | int | size | ) |

inlineexplicit

Definition at line 330 of file genericvector.h.

: GenericVector<T*>(size) { }
template<typename T>

virtual tesseract::PointerVector< T >::~PointerVector | ( |  | ) |

inlinevirtual

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();
}
template<typename T>

tesseract::PointerVector< T >::PointerVector | ( | const PointerVector< T > & | other | ) |

inline

Definition at line 338 of file genericvector.h.

{
this->init(other.size());
this->operator+=(other);
}

## Member Function Documentation

template<typename T>

virtual void tesseract::PointerVector< T >::clear | ( |  | ) |

inlinevirtual

Reimplemented from GenericVector< T * >.

Definition at line 397 of file genericvector.h.

{
GenericVector<T*>::delete_data_pointers();
GenericVector<T*>::clear();
}
template<typename T>

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;
}
template<typename T>

virtual bool tesseract::PointerVector< T >::DeSerialize | ( | bool | swap,
|  | FILE * | fp
| ) |  |

inlinevirtual

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;
}
template<typename T>

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;
}
template<typename T>

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;
}
template<typename T>

virtual void tesseract::PointerVector< T >::remove | ( | int | index | ) |

inlinevirtual

Reimplemented from GenericVector< T * >.

Definition at line 358 of file genericvector.h.

{
delete GenericVector<T*>::data_[index];
GenericVector<T*>::remove(index);
}
template<typename T>

virtual bool tesseract::PointerVector< T >::Serialize | ( | FILE * | fp | ) | const

inlinevirtual

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;
}
template<typename T>

void tesseract::PointerVector< T >::sort | ( |  | ) |

inline

Reimplemented from GenericVector< T * >.

Definition at line 439 of file genericvector.h.

{
sort(&sort_ptr_cmp<T>);
}
template<typename T>

virtual void tesseract::PointerVector< T >::truncate | ( | int | size | ) |

inlinevirtual

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);
}

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

- /mnt/data/src/tesseract-ocr/ccutil/genericvector.h