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

#include <genericvector.h>

Inheritance diagram for tesseract::PointerVector< T >:
tesseract::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 clear ()
 
bool Serialize (FILE *fp) const
 
bool Serialize (TFile *fp) const
 
bool DeSerialize (bool swap, FILE *fp)
 
void sort ()
 
- Public Member Functions inherited from tesseract::GenericVector< T * >
 GenericVector ()
 
 GenericVector (int size, const T * &init_val)
 
 GenericVector (const GenericVector &other)
 
GenericVector< T * > & operator+= (const GenericVector &other)
 
void operator+= (const T * &t)
 
GenericVector< T * > & operator= (const GenericVector &other)
 
 ~GenericVector ()
 
void reserve (int size)
 
void double_the_size ()
 
void init_to_size (int size, const T * &t)
 
void resize (int size, const T * &t)
 
void resize_no_init (int size)
 
unsigned size () const
 
size_t unsigned_size () const
 
int size_reserved () const
 
bool empty () const
 
T * & at (int index) const
 
T * & back () const
 
T * & operator[] (int index) const
 
T * pop_back ()
 
int get_index (const T * &object) const
 
int push_back (T * object)
 
int push_back_new (const T * &object)
 
int push_front (const T * &object)
 
void set (const T * &t, int index)
 
void insert (const T * &t, int index)
 
void remove (int index)
 
void truncate (int size)
 
void set_clear_callback (std::function< void(T *)> cb)
 
void clear ()
 
void delete_data_pointers ()
 
void move (GenericVector< T * > *from)
 
bool write (FILE *f, std::function< bool(FILE *, const T * &)> cb) const
 
bool read (TFile *f, std::function< bool(TFile *, T * *)> cb)
 
bool Serialize (FILE *fp) const
 
bool Serialize (TFile *fp) const
 
bool DeSerialize (bool swap, FILE *fp)
 
bool DeSerialize (TFile *fp)
 
bool SerializeClasses (FILE *fp) const
 
bool SerializeClasses (TFile *fp) const
 
bool DeSerializeClasses (bool swap, FILE *fp)
 
bool DeSerializeClasses (TFile *fp)
 
void reverse ()
 
void sort ()
 
void sort (int(*comparator)(const void *, const void *))
 
int binary_search (const T * &target) const
 
void swap (int index1, int index2)
 

Additional Inherited Members

- Static Public Member Functions inherited from tesseract::GenericVector< T * >
static T * * double_the_size_memcpy (int current_size, T * *data)
 
- Protected Member Functions inherited from tesseract::GenericVector< T * >
void init (int size)
 
- Protected Attributes inherited from tesseract::GenericVector< T * >
int32_t size_used_
 
int32_t size_reserved_
 
T * * data_
 
std::function< void(T *)> clear_cb_
 
- Static Protected Attributes inherited from tesseract::GenericVector< T * >
static const int kDefaultVectorSize
 

Detailed Description

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

Definition at line 353 of file genericvector.h.

Constructor & Destructor Documentation

◆ PointerVector() [1/3]

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

Definition at line 355 of file genericvector.h.

355 : GenericVector<T *>() {}

◆ PointerVector() [2/3]

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

Definition at line 356 of file genericvector.h.

356 : GenericVector<T *>(size) {}

◆ ~PointerVector()

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

Definition at line 357 of file genericvector.h.

357  {
358  // Clear must be called here, even though it is called again by the base,
359  // as the base will call the wrong clear.
360  clear();
361  }

◆ PointerVector() [3/3]

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

Definition at line 364 of file genericvector.h.

364  : GenericVector<T *>(other) {
365  this->init(other.size());
366  this->operator+=(other);
367  }
PointerVector< T > & operator+=(const PointerVector &other)

Member Function Documentation

◆ clear()

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

Definition at line 404 of file genericvector.h.

◆ DeSerialize()

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

Definition at line 453 of file genericvector.h.

453  {
454  uint32_t reserved;
455  if (fread(&reserved, sizeof(reserved), 1, fp) != 1) {
456  return false;
457  }
458  if (swap) {
459  Reverse32(&reserved);
460  }
461  // Arbitrarily limit the number of elements to protect against bad data.
462  assert(reserved <= UINT16_MAX);
463  if (reserved > UINT16_MAX) {
464  return false;
465  }
466  GenericVector<T *>::reserve(reserved);
467  truncate(0);
468  for (uint32_t i = 0; i < reserved; ++i) {
469  int8_t non_null;
470  if (fread(&non_null, sizeof(non_null), 1, fp) != 1) {
471  return false;
472  }
473  T *item = nullptr;
474  if (non_null != 0) {
475  item = new T;
476  if (!item->DeSerialize(swap, fp)) {
477  delete item;
478  return false;
479  }
480  this->push_back(item);
481  } else {
482  // Null elements should keep their place in the vector.
483  this->push_back(nullptr);
484  }
485  }
486  return true;
487  }
void Reverse32(void *ptr)
Definition: helpers.h:206
void swap(int index1, int index2)

◆ operator+=()

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

Definition at line 368 of file genericvector.h.

368  {
369  this->reserve(this->size_used_ + other.size_used_);
370  for (unsigned i = 0; i < other.size(); ++i) {
371  this->push_back(new T(*other.data_[i]));
372  }
373  return *this;
374  }

◆ operator=()

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

Definition at line 376 of file genericvector.h.

376  {
377  if (&other != this) {
378  this->truncate(0);
379  this->operator+=(other);
380  }
381  return *this;
382  }

◆ remove()

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

Definition at line 386 of file genericvector.h.

386  {
387  delete GenericVector<T *>::data_[index];
389  }
void remove(int index)

◆ Serialize() [1/2]

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

Definition at line 414 of file genericvector.h.

414  {
415  int32_t used = GenericVector<T *>::size_used_;
416  if (fwrite(&used, sizeof(used), 1, fp) != 1) {
417  return false;
418  }
419  for (int i = 0; i < used; ++i) {
420  int8_t non_null = GenericVector<T *>::data_[i] != nullptr;
421  if (fwrite(&non_null, sizeof(non_null), 1, fp) != 1) {
422  return false;
423  }
424  if (non_null && !GenericVector<T *>::data_[i]->Serialize(fp)) {
425  return false;
426  }
427  }
428  return true;
429  }
bool Serialize(FILE *fp) const

◆ Serialize() [2/2]

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

Definition at line 430 of file genericvector.h.

430  {
431  int32_t used = GenericVector<T *>::size_used_;
432  if (fp->FWrite(&used, sizeof(used), 1) != 1) {
433  return false;
434  }
435  for (int i = 0; i < used; ++i) {
436  int8_t non_null = GenericVector<T *>::data_[i] != nullptr;
437  if (fp->FWrite(&non_null, sizeof(non_null), 1) != 1) {
438  return false;
439  }
440  if (non_null && !GenericVector<T *>::data_[i]->Serialize(fp)) {
441  return false;
442  }
443  }
444  return true;
445  }

◆ sort()

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

Definition at line 491 of file genericvector.h.

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

◆ truncate()

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

Definition at line 393 of file genericvector.h.

393  {
394  for (int i = size; i < GenericVector<T *>::size_used_; ++i) {
395  delete GenericVector<T *>::data_[i];
396  }
398  }

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