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

#include <genericvector.h>

Inheritance diagram for tesseract::PointerVector< T >:
GenericVector< T * >

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 ()
 
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.

template<typename T>
tesseract::PointerVector< T >::PointerVector ( int  size)
inlineexplicit

Definition at line 330 of file genericvector.h.

template<typename T>
virtual tesseract::PointerVector< T >::~PointerVector ( )
inlinevirtual

Definition at line 331 of file genericvector.h.

331  {
332  // Clear must be called here, even though it is called again by the base,
333  // as the base will call the wrong clear.
334  clear();
335  }
template<typename T>
tesseract::PointerVector< T >::PointerVector ( const PointerVector< T > &  other)
inline

Definition at line 338 of file genericvector.h.

338  {
339  this->init(other.size());
340  this->operator+=(other);
341  }
void init(int size)
PointerVector< T > & operator+=(const PointerVector &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.

397  {
400  }
void delete_data_pointers()
virtual void clear()
template<typename T>
void tesseract::PointerVector< T >::compact ( TessResultCallback1< bool, const T * > *  delete_cb)
inline

Definition at line 373 of file genericvector.h.

373  {
374  int new_size = 0;
375  int old_index = 0;
376  // Until the callback returns true, the elements stay the same.
377  while (old_index < GenericVector<T*>::size_used_ &&
378  !delete_cb->Run(GenericVector<T*>::data_[old_index++]))
379  ++new_size;
380  // Now just copy anything else that gets false from delete_cb.
381  for (; old_index < GenericVector<T*>::size_used_; ++old_index) {
382  if (!delete_cb->Run(GenericVector<T*>::data_[old_index])) {
383  GenericVector<T*>::data_[new_size++] =
384  GenericVector<T*>::data_[old_index];
385  } else {
386  delete GenericVector<T*>::data_[old_index];
387  }
388  }
390  delete delete_cb;
391  }
virtual R Run(A1)=0
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.

419  {
420  inT32 reserved;
421  if (fread(&reserved, sizeof(reserved), 1, fp) != 1) return false;
422  if (swap) Reverse32(&reserved);
423  GenericVector<T*>::reserve(reserved);
424  for (int i = 0; i < reserved; ++i) {
425  inT8 non_null;
426  if (fread(&non_null, sizeof(non_null), 1, fp) != 1) return false;
427  T* item = NULL;
428  if (non_null) {
429  item = new T;
430  if (!item->DeSerialize(swap, fp)) return false;
431  }
432  this->push_back(item);
433  }
434  return true;
435  }
void Reverse32(void *ptr)
Definition: helpers.h:142
#define NULL
Definition: host.h:144
int inT32
Definition: host.h:102
int push_back(T *object)
void reserve(int size)
SIGNED char inT8
Definition: host.h:98
template<typename T>
PointerVector<T>& tesseract::PointerVector< T >::operator+= ( const PointerVector< T > &  other)
inline

Definition at line 342 of file genericvector.h.

342  {
343  this->reserve(this->size_used_ + other.size_used_);
344  for (int i = 0; i < other.size(); ++i) {
345  this->push_back(new T(*other.data_[i]));
346  }
347  return *this;
348  }
int push_back(T *object)
void reserve(int size)
template<typename T>
PointerVector<T>& tesseract::PointerVector< T >::operator= ( const PointerVector< T > &  other)
inline

Definition at line 350 of file genericvector.h.

350  {
351  this->truncate(0);
352  this->operator+=(other);
353  return *this;
354  }
PointerVector< T > & operator+=(const PointerVector &other)
virtual void truncate(int size)
template<typename T>
virtual void tesseract::PointerVector< T >::remove ( int  index)
inlinevirtual

Reimplemented from GenericVector< T * >.

Definition at line 358 of file genericvector.h.

358  {
359  delete GenericVector<T*>::data_[index];
361  }
virtual void remove(int 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.

404  {
406  if (fwrite(&used, sizeof(used), 1, fp) != 1) return false;
407  for (int i = 0; i < used; ++i) {
408  inT8 non_null = GenericVector<T*>::data_[i] != NULL;
409  if (fwrite(&non_null, sizeof(non_null), 1, fp) != 1) return false;
410  if (non_null && !GenericVector<T*>::data_[i]->Serialize(fp)) return false;
411  }
412  return true;
413  }
#define NULL
Definition: host.h:144
virtual bool Serialize(FILE *fp) const
int inT32
Definition: host.h:102
SIGNED char inT8
Definition: host.h:98
template<typename T>
void tesseract::PointerVector< T >::sort ( )
inline

Definition at line 439 of file genericvector.h.

439  {
440  sort(&sort_ptr_cmp<T>);
441  }
template<typename T>
virtual void tesseract::PointerVector< T >::truncate ( int  size)
inlinevirtual

Reimplemented from GenericVector< T * >.

Definition at line 365 of file genericvector.h.

365  {
366  for (int i = size; i < GenericVector<T*>::size_used_; ++i)
367  delete GenericVector<T*>::data_[i];
369  }
virtual void truncate(int size)

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