tesseract  4.00.00dev
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 (TFile *fp)
 
bool DeSerializeElement (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
 
unsigned int unsigned_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 (tesseract::TFile *f, TessResultCallback2< bool, tesseract::TFile *, T * * > *cb)
 
bool Serialize (FILE *fp) const
 
bool Serialize (tesseract::TFile *fp) const
 
bool DeSerialize (bool swap, FILE *fp)
 
bool DeSerialize (tesseract::TFile *fp)
 
bool SerializeClasses (FILE *fp) const
 
bool SerializeClasses (tesseract::TFile *fp) const
 
bool DeSerializeClasses (bool swap, FILE *fp)
 
bool DeSerializeClasses (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 (TFile *fp, inT32 *size)
 
static bool DeSerializeSkip (TFile *fp)
 
- Static Public Member Functions inherited from GenericVector< T *>
static bool SkipDeSerialize (tesseract::TFile *fp)
 
static bool SkipDeSerializeClasses (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 455 of file genericvector.h.

Constructor & Destructor Documentation

◆ PointerVector() [1/3]

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

Definition at line 457 of file genericvector.h.

◆ PointerVector() [2/3]

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

Definition at line 458 of file genericvector.h.

◆ ~PointerVector()

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

Definition at line 459 of file genericvector.h.

459  {
460  // Clear must be called here, even though it is called again by the base,
461  // as the base will call the wrong clear.
462  clear();
463  }

◆ PointerVector() [3/3]

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

Definition at line 466 of file genericvector.h.

466  : GenericVector<T*>(other) {
467  this->init(other.size());
468  this->operator+=(other);
469  }
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 527 of file genericvector.h.

◆ compact()

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

Definition at line 503 of file genericvector.h.

503  {
504  int new_size = 0;
505  int old_index = 0;
506  // Until the callback returns true, the elements stay the same.
507  while (old_index < GenericVector<T*>::size_used_ &&
508  !delete_cb->Run(GenericVector<T*>::data_[old_index++]))
509  ++new_size;
510  // Now just copy anything else that gets false from delete_cb.
511  for (; old_index < GenericVector<T*>::size_used_; ++old_index) {
512  if (!delete_cb->Run(GenericVector<T*>::data_[old_index])) {
513  GenericVector<T*>::data_[new_size++] =
514  GenericVector<T*>::data_[old_index];
515  } else {
516  delete GenericVector<T*>::data_[old_index];
517  }
518  }
520  delete delete_cb;
521  }
virtual R Run(A1)=0

◆ DeSerialize() [1/2]

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

Definition at line 564 of file genericvector.h.

564  {
565  inT32 reserved;
566  if (fread(&reserved, sizeof(reserved), 1, fp) != 1) return false;
567  if (swap) Reverse32(&reserved);
568  GenericVector<T*>::reserve(reserved);
569  truncate(0);
570  for (int i = 0; i < reserved; ++i) {
571  inT8 non_null;
572  if (fread(&non_null, sizeof(non_null), 1, fp) != 1) return false;
573  T* item = NULL;
574  if (non_null) {
575  item = new T;
576  if (!item->DeSerialize(swap, fp)) {
577  delete item;
578  return false;
579  }
580  this->push_back(item);
581  } else {
582  // Null elements should keep their place in the vector.
583  this->push_back(NULL);
584  }
585  }
586  return true;
587  }
int32_t inT32
Definition: host.h:38
void reserve(int size)
void swap(int index1, int index2)
int push_back(T * object)
int8_t inT8
Definition: host.h:34
void Reverse32(void *ptr)
Definition: helpers.h:200

◆ DeSerialize() [2/2]

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

Definition at line 588 of file genericvector.h.

588  {
589  inT32 reserved;
590  if (!DeSerializeSize(fp, &reserved)) return false;
591  GenericVector<T*>::reserve(reserved);
592  truncate(0);
593  for (int i = 0; i < reserved; ++i) {
594  if (!DeSerializeElement(fp)) return false;
595  }
596  return true;
597  }
bool DeSerializeElement(TFile *fp)
int32_t inT32
Definition: host.h:38
void reserve(int size)
static bool DeSerializeSize(TFile *fp, inT32 *size)

◆ DeSerializeElement()

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

Definition at line 606 of file genericvector.h.

606  {
607  inT8 non_null;
608  if (fp->FRead(&non_null, sizeof(non_null), 1) != 1) return false;
609  T* item = NULL;
610  if (non_null) {
611  item = new T;
612  if (!item->DeSerialize(fp)) {
613  delete item;
614  return false;
615  }
616  this->push_back(item);
617  } else {
618  // Null elements should keep their place in the vector.
619  this->push_back(NULL);
620  }
621  return true;
622  }
int push_back(T * object)
int8_t inT8
Definition: host.h:34

◆ DeSerializeSize()

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

Definition at line 602 of file genericvector.h.

602  {
603  return fp->FReadEndian(size, sizeof(*size), 1) == 1;
604  }
voidpf void uLong size
Definition: ioapi.h:39

◆ DeSerializeSkip()

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

Definition at line 624 of file genericvector.h.

624  {
625  inT8 non_null;
626  if (fp->FRead(&non_null, sizeof(non_null), 1) != 1) return false;
627  if (non_null) {
628  if (!T::SkipDeSerialize(fp)) return false;
629  }
630  return true;
631  }
int8_t inT8
Definition: host.h:34

◆ operator+=()

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

Definition at line 470 of file genericvector.h.

470  {
471  this->reserve(this->size_used_ + other.size_used_);
472  for (int i = 0; i < other.size(); ++i) {
473  this->push_back(new T(*other.data_[i]));
474  }
475  return *this;
476  }
void reserve(int size)
int push_back(T * object)

◆ operator=()

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

Definition at line 478 of file genericvector.h.

478  {
479  if (&other != this) {
480  this->truncate(0);
481  this->operator+=(other);
482  }
483  return *this;
484  }
PointerVector< T > & operator+=(const PointerVector &other)

◆ remove()

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

Definition at line 488 of file genericvector.h.

488  {
489  delete GenericVector<T*>::data_[index];
491  }
void remove(int index)

◆ Serialize() [1/2]

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

Definition at line 537 of file genericvector.h.

537  {
539  if (fwrite(&used, sizeof(used), 1, fp) != 1) return false;
540  for (int i = 0; i < used; ++i) {
541  inT8 non_null = GenericVector<T*>::data_[i] != NULL;
542  if (fwrite(&non_null, sizeof(non_null), 1, fp) != 1) return false;
543  if (non_null && !GenericVector<T*>::data_[i]->Serialize(fp)) return false;
544  }
545  return true;
546  }
int32_t inT32
Definition: host.h:38
int8_t inT8
Definition: host.h:34
bool Serialize(FILE *fp) const

◆ Serialize() [2/2]

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

Definition at line 547 of file genericvector.h.

547  {
549  if (fp->FWrite(&used, sizeof(used), 1) != 1) return false;
550  for (int i = 0; i < used; ++i) {
551  inT8 non_null = GenericVector<T*>::data_[i] != NULL;
552  if (fp->FWrite(&non_null, sizeof(non_null), 1) != 1) return false;
553  if (non_null && !GenericVector<T*>::data_[i]->Serialize(fp)) return false;
554  }
555  return true;
556  }
int32_t inT32
Definition: host.h:38
int8_t inT8
Definition: host.h:34
bool Serialize(FILE *fp) const

◆ sort()

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

Definition at line 635 of file genericvector.h.

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

◆ truncate()

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

Definition at line 495 of file genericvector.h.

495  {
496  for (int i = size; i < GenericVector<T*>::size_used_; ++i)
497  delete GenericVector<T*>::data_[i];
499  }
voidpf void uLong size
Definition: ioapi.h:39
void truncate(int size)

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