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
 
size_t 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 456 of file genericvector.h.

Constructor & Destructor Documentation

◆ PointerVector() [1/3]

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

Definition at line 458 of file genericvector.h.

◆ PointerVector() [2/3]

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

Definition at line 459 of file genericvector.h.

◆ ~PointerVector()

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

Definition at line 460 of file genericvector.h.

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

◆ PointerVector() [3/3]

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

Definition at line 467 of file genericvector.h.

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

◆ compact()

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

Definition at line 504 of file genericvector.h.

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

◆ DeSerialize() [1/2]

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

Definition at line 565 of file genericvector.h.

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

◆ DeSerialize() [2/2]

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

Definition at line 589 of file genericvector.h.

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

◆ DeSerializeElement()

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

Definition at line 607 of file genericvector.h.

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

◆ DeSerializeSize()

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

Definition at line 603 of file genericvector.h.

603  {
604  return fp->FReadEndian(size, sizeof(*size), 1) == 1;
605  }

◆ DeSerializeSkip()

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

Definition at line 625 of file genericvector.h.

625  {
626  inT8 non_null;
627  if (fp->FRead(&non_null, sizeof(non_null), 1) != 1) return false;
628  if (non_null) {
629  if (!T::SkipDeSerialize(fp)) return false;
630  }
631  return true;
632  }
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 471 of file genericvector.h.

471  {
472  this->reserve(this->size_used_ + other.size_used_);
473  for (int i = 0; i < other.size(); ++i) {
474  this->push_back(new T(*other.data_[i]));
475  }
476  return *this;
477  }
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 479 of file genericvector.h.

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

◆ remove()

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

Definition at line 489 of file genericvector.h.

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

◆ Serialize() [1/2]

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

Definition at line 538 of file genericvector.h.

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

◆ Serialize() [2/2]

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

Definition at line 548 of file genericvector.h.

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

◆ sort()

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

Definition at line 636 of file genericvector.h.

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

◆ truncate()

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

Definition at line 496 of file genericvector.h.

496  {
497  for (int i = size; i < GenericVector<T*>::size_used_; ++i)
498  delete GenericVector<T*>::data_[i];
500  }
void truncate(int size)

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