tesseract  3.05.02
tesseract::PointerVector< T > Class Template Reference

#include <genericvector.h>

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

Public Member Functions

 PointerVector ()
 
 PointerVector (int size)
 
 ~PointerVector ()
 
 PointerVector (const PointerVector &other)
 
PointerVector< T > & operator+= (const PointerVector &other)
 
PointerVector< T > & operator= (const PointerVector &other)
 
void remove (int index)
 
void truncate (int size)
 
void compact (TessResultCallback1< bool, const T *> *delete_cb)
 
void clear ()
 
bool Serialize (FILE *fp) const
 
bool Serialize (TFile *fp) const
 
bool DeSerialize (bool swap, FILE *fp)
 
bool DeSerialize (bool swap, TFile *fp)
 
bool DeSerializeElement (bool swap, TFile *fp)
 
void sort ()
 
- Public Member Functions inherited from GenericVector< T *>
 GenericVector ()
 
 GenericVector (int size, T * init_val)
 
 GenericVector (const GenericVector &other)
 
GenericVector< T * > & operator+= (const GenericVector &other)
 
void operator+= (T * t)
 
GenericVector< T * > & operator= (const GenericVector &other)
 
 ~GenericVector ()
 
void reserve (int size)
 
void double_the_size ()
 
void init_to_size (int size, T * t)
 
void resize_no_init (int size)
 
int size () const
 
int size_reserved () const
 
int length () const
 
bool empty () const
 
T * & get (int index) const
 
T * & back () const
 
T * & operator[] (int index) const
 
T * pop_back ()
 
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 remove (int index)
 
void truncate (int size)
 
void set_clear_callback (TessCallback1< T * > *cb)
 
void set_compare_callback (TessResultCallback2< bool, T * const &, T * const & > *cb)
 
void clear ()
 
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 Serialize (FILE *fp) const
 
bool Serialize (tesseract::TFile *fp) const
 
bool DeSerialize (bool swap, FILE *fp)
 
bool DeSerialize (bool swap, tesseract::TFile *fp)
 
bool SerializeClasses (FILE *fp) const
 
bool SerializeClasses (tesseract::TFile *fp) const
 
bool DeSerializeClasses (bool swap, FILE *fp)
 
bool DeSerializeClasses (bool swap, tesseract::TFile *fp)
 
void reverse ()
 
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
 
int choose_nth_item (int target_index)
 
void swap (int index1, int index2)
 
bool WithinBounds (const T * &rangemin, const T * &rangemax) const
 

Static Public Member Functions

static bool DeSerializeSize (bool swap, TFile *fp, inT32 *size)
 
static bool DeSerializeSkip (bool swap, TFile *fp)
 
- Static Public Member Functions inherited from GenericVector< T *>
static bool SkipDeSerialize (bool swap, tesseract::TFile *fp)
 
static bool SkipDeSerializeClasses (bool swap, tesseract::TFile *fp)
 
static T * * double_the_size_memcpy (int current_size, T * *data)
 

Additional Inherited Members

- Protected Member Functions inherited from GenericVector< T *>
int choose_nth_item (int target_index, int start, int end, unsigned int *seed)
 
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 432 of file genericvector.h.

Constructor & Destructor Documentation

◆ PointerVector() [1/3]

template<typename T>
tesseract::PointerVector< T >::PointerVector ( )
inline

Definition at line 434 of file genericvector.h.

◆ PointerVector() [2/3]

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

Definition at line 435 of file genericvector.h.

◆ ~PointerVector()

template<typename T>
tesseract::PointerVector< T >::~PointerVector ( )
inline

Definition at line 436 of file genericvector.h.

436  {
437  // Clear must be called here, even though it is called again by the base,
438  // as the base will call the wrong clear.
439  clear();
440  }

◆ PointerVector() [3/3]

template<typename T>
tesseract::PointerVector< T >::PointerVector ( const PointerVector< T > &  other)
inline

Definition at line 443 of file genericvector.h.

443  : GenericVector<T*>(other) {
444  this->init(other.size());
445  this->operator+=(other);
446  }
PointerVector< T > & operator+=(const PointerVector &other)
void init(int size)

Member Function Documentation

◆ clear()

template<typename T>
void tesseract::PointerVector< T >::clear ( )
inline

Definition at line 504 of file genericvector.h.

◆ compact()

template<typename T>
void tesseract::PointerVector< T >::compact ( TessResultCallback1< bool, const T *> *  delete_cb)
inline

Definition at line 480 of file genericvector.h.

480  {
481  int new_size = 0;
482  int old_index = 0;
483  // Until the callback returns true, the elements stay the same.
484  while (old_index < GenericVector<T*>::size_used_ &&
485  !delete_cb->Run(GenericVector<T*>::data_[old_index++]))
486  ++new_size;
487  // Now just copy anything else that gets false from delete_cb.
488  for (; old_index < GenericVector<T*>::size_used_; ++old_index) {
489  if (!delete_cb->Run(GenericVector<T*>::data_[old_index])) {
490  GenericVector<T*>::data_[new_size++] =
491  GenericVector<T*>::data_[old_index];
492  } else {
493  delete GenericVector<T*>::data_[old_index];
494  }
495  }
497  delete delete_cb;
498  }
virtual R Run(A1)=0

◆ DeSerialize() [1/2]

template<typename T>
bool tesseract::PointerVector< T >::DeSerialize ( bool  swap,
FILE *  fp 
)
inline

Definition at line 541 of file genericvector.h.

541  {
542  inT32 reserved;
543  if (fread(&reserved, sizeof(reserved), 1, fp) != 1) return false;
544  if (swap) Reverse32(&reserved);
545  GenericVector<T*>::reserve(reserved);
546  truncate(0);
547  for (int i = 0; i < reserved; ++i) {
548  inT8 non_null;
549  if (fread(&non_null, sizeof(non_null), 1, fp) != 1) return false;
550  T* item = NULL;
551  if (non_null) {
552  item = new T;
553  if (!item->DeSerialize(swap, fp)) {
554  delete item;
555  return false;
556  }
557  this->push_back(item);
558  } else {
559  // Null elements should keep their place in the vector.
560  this->push_back(NULL);
561  }
562  }
563  return true;
564  }
void Reverse32(void *ptr)
Definition: helpers.h:193
void swap(int index1, int index2)
int push_back(T * object)
SIGNED char inT8
Definition: host.h:31
int inT32
Definition: host.h:35
void reserve(int size)

◆ DeSerialize() [2/2]

template<typename T>
bool tesseract::PointerVector< T >::DeSerialize ( bool  swap,
TFile fp 
)
inline

Definition at line 565 of file genericvector.h.

565  {
566  inT32 reserved;
567  if (!DeSerializeSize(swap, fp, &reserved)) return false;
568  GenericVector<T*>::reserve(reserved);
569  truncate(0);
570  for (int i = 0; i < reserved; ++i) {
571  if (!DeSerializeElement(swap, fp)) return false;
572  }
573  return true;
574  }
bool DeSerializeElement(bool swap, TFile *fp)
void swap(int index1, int index2)
int inT32
Definition: host.h:35
static bool DeSerializeSize(bool swap, TFile *fp, inT32 *size)
void reserve(int size)

◆ DeSerializeElement()

template<typename T>
bool tesseract::PointerVector< T >::DeSerializeElement ( bool  swap,
TFile fp 
)
inline

Definition at line 585 of file genericvector.h.

585  {
586  inT8 non_null;
587  if (fp->FRead(&non_null, sizeof(non_null), 1) != 1) return false;
588  T* item = NULL;
589  if (non_null) {
590  item = new T;
591  if (!item->DeSerialize(swap, fp)) {
592  delete item;
593  return false;
594  }
595  this->push_back(item);
596  } else {
597  // Null elements should keep their place in the vector.
598  this->push_back(NULL);
599  }
600  return true;
601  }
void swap(int index1, int index2)
int push_back(T * object)
SIGNED char inT8
Definition: host.h:31

◆ DeSerializeSize()

template<typename T>
static bool tesseract::PointerVector< T >::DeSerializeSize ( bool  swap,
TFile fp,
inT32 size 
)
inlinestatic

Definition at line 579 of file genericvector.h.

579  {
580  if (fp->FRead(size, sizeof(*size), 1) != 1) return false;
581  if (swap) Reverse32(size);
582  return true;
583  }
void Reverse32(void *ptr)
Definition: helpers.h:193
void swap(int index1, int index2)

◆ DeSerializeSkip()

template<typename T>
static bool tesseract::PointerVector< T >::DeSerializeSkip ( bool  swap,
TFile fp 
)
inlinestatic

Definition at line 603 of file genericvector.h.

603  {
604  inT8 non_null;
605  if (fp->FRead(&non_null, sizeof(non_null), 1) != 1) return false;
606  if (non_null) {
607  if (!T::SkipDeSerialize(swap, fp)) return false;
608  }
609  return true;
610  }
void swap(int index1, int index2)
SIGNED char inT8
Definition: host.h:31

◆ operator+=()

template<typename T>
PointerVector<T>& tesseract::PointerVector< T >::operator+= ( const PointerVector< T > &  other)
inline

Definition at line 447 of file genericvector.h.

447  {
448  this->reserve(this->size_used_ + other.size_used_);
449  for (int i = 0; i < other.size(); ++i) {
450  this->push_back(new T(*other.data_[i]));
451  }
452  return *this;
453  }
int push_back(T * object)
void reserve(int size)

◆ operator=()

template<typename T>
PointerVector<T>& tesseract::PointerVector< T >::operator= ( const PointerVector< T > &  other)
inline

Definition at line 455 of file genericvector.h.

455  {
456  if (&other != this) {
457  this->truncate(0);
458  this->operator+=(other);
459  }
460  return *this;
461  }
PointerVector< T > & operator+=(const PointerVector &other)

◆ remove()

template<typename T>
void tesseract::PointerVector< T >::remove ( int  index)
inline

Definition at line 465 of file genericvector.h.

465  {
466  delete GenericVector<T*>::data_[index];
468  }
void remove(int index)

◆ Serialize() [1/2]

template<typename T>
bool tesseract::PointerVector< T >::Serialize ( FILE *  fp) const
inline

Definition at line 514 of file genericvector.h.

514  {
516  if (fwrite(&used, sizeof(used), 1, fp) != 1) return false;
517  for (int i = 0; i < used; ++i) {
518  inT8 non_null = GenericVector<T*>::data_[i] != NULL;
519  if (fwrite(&non_null, sizeof(non_null), 1, fp) != 1) return false;
520  if (non_null && !GenericVector<T*>::data_[i]->Serialize(fp)) return false;
521  }
522  return true;
523  }
SIGNED char inT8
Definition: host.h:31
int inT32
Definition: host.h:35
bool Serialize(FILE *fp) const

◆ Serialize() [2/2]

template<typename T>
bool tesseract::PointerVector< T >::Serialize ( TFile fp) const
inline

Definition at line 524 of file genericvector.h.

524  {
526  if (fp->FWrite(&used, sizeof(used), 1) != 1) return false;
527  for (int i = 0; i < used; ++i) {
528  inT8 non_null = GenericVector<T*>::data_[i] != NULL;
529  if (fp->FWrite(&non_null, sizeof(non_null), 1) != 1) return false;
530  if (non_null && !GenericVector<T*>::data_[i]->Serialize(fp)) return false;
531  }
532  return true;
533  }
SIGNED char inT8
Definition: host.h:31
int inT32
Definition: host.h:35
bool Serialize(FILE *fp) const

◆ sort()

template<typename T>
void tesseract::PointerVector< T >::sort ( )
inline

Definition at line 614 of file genericvector.h.

614 { this->GenericVector<T*>::sort(&sort_ptr_cmp<T>); }

◆ truncate()

template<typename T>
void tesseract::PointerVector< T >::truncate ( int  size)
inline

Definition at line 472 of file genericvector.h.

472  {
473  for (int i = size; i < GenericVector<T*>::size_used_; ++i)
474  delete GenericVector<T*>::data_[i];
476  }
void truncate(int size)

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