tesseract  3.05.00
 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)
 
 ~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 427 of file genericvector.h.

Constructor & Destructor Documentation

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

Definition at line 429 of file genericvector.h.

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

Definition at line 430 of file genericvector.h.

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

Definition at line 431 of file genericvector.h.

431  {
432  // Clear must be called here, even though it is called again by the base,
433  // as the base will call the wrong clear.
434  clear();
435  }
template<typename T>
tesseract::PointerVector< T >::PointerVector ( const PointerVector< T > &  other)
inline

Definition at line 438 of file genericvector.h.

438  : GenericVector<T*>(other) {
439  this->init(other.size());
440  this->operator+=(other);
441  }
void init(int size)
PointerVector< T > & operator+=(const PointerVector &other)

Member Function Documentation

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

Definition at line 499 of file genericvector.h.

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

Definition at line 475 of file genericvector.h.

475  {
476  int new_size = 0;
477  int old_index = 0;
478  // Until the callback returns true, the elements stay the same.
479  while (old_index < GenericVector<T*>::size_used_ &&
480  !delete_cb->Run(GenericVector<T*>::data_[old_index++]))
481  ++new_size;
482  // Now just copy anything else that gets false from delete_cb.
483  for (; old_index < GenericVector<T*>::size_used_; ++old_index) {
484  if (!delete_cb->Run(GenericVector<T*>::data_[old_index])) {
485  GenericVector<T*>::data_[new_size++] =
486  GenericVector<T*>::data_[old_index];
487  } else {
488  delete GenericVector<T*>::data_[old_index];
489  }
490  }
492  delete delete_cb;
493  }
virtual R Run(A1)=0
template<typename T>
bool tesseract::PointerVector< T >::DeSerialize ( bool  swap,
FILE *  fp 
)
inline

Definition at line 536 of file genericvector.h.

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

Definition at line 560 of file genericvector.h.

560  {
561  inT32 reserved;
562  if (!DeSerializeSize(swap, fp, &reserved)) return false;
563  GenericVector<T*>::reserve(reserved);
564  truncate(0);
565  for (int i = 0; i < reserved; ++i) {
566  if (!DeSerializeElement(swap, fp)) return false;
567  }
568  return true;
569  }
bool DeSerializeElement(bool swap, TFile *fp)
void swap(int index1, int index2)
int inT32
Definition: host.h:102
void reserve(int size)
static bool DeSerializeSize(bool swap, TFile *fp, inT32 *size)
template<typename T>
bool tesseract::PointerVector< T >::DeSerializeElement ( bool  swap,
TFile fp 
)
inline

Definition at line 580 of file genericvector.h.

580  {
581  inT8 non_null;
582  if (fp->FRead(&non_null, sizeof(non_null), 1) != 1) return false;
583  T* item = NULL;
584  if (non_null) {
585  item = new T;
586  if (!item->DeSerialize(swap, fp)) {
587  delete item;
588  return false;
589  }
590  this->push_back(item);
591  } else {
592  // Null elements should keep their place in the vector.
593  this->push_back(NULL);
594  }
595  return true;
596  }
SIGNED char inT8
Definition: host.h:98
void swap(int index1, int index2)
int push_back(T *object)
template<typename T>
static bool tesseract::PointerVector< T >::DeSerializeSize ( bool  swap,
TFile fp,
inT32 size 
)
inlinestatic

Definition at line 574 of file genericvector.h.

574  {
575  if (fp->FRead(size, sizeof(*size), 1) != 1) return false;
576  if (swap) Reverse32(size);
577  return true;
578  }
void Reverse32(void *ptr)
Definition: helpers.h:193
void swap(int index1, int index2)
template<typename T>
static bool tesseract::PointerVector< T >::DeSerializeSkip ( bool  swap,
TFile fp 
)
inlinestatic

Definition at line 598 of file genericvector.h.

598  {
599  inT8 non_null;
600  if (fp->FRead(&non_null, sizeof(non_null), 1) != 1) return false;
601  if (non_null) {
602  if (!T::SkipDeSerialize(swap, fp)) return false;
603  }
604  return true;
605  }
SIGNED char inT8
Definition: host.h:98
void swap(int index1, int index2)
template<typename T>
PointerVector<T>& tesseract::PointerVector< T >::operator+= ( const PointerVector< T > &  other)
inline

Definition at line 442 of file genericvector.h.

442  {
443  this->reserve(this->size_used_ + other.size_used_);
444  for (int i = 0; i < other.size(); ++i) {
445  this->push_back(new T(*other.data_[i]));
446  }
447  return *this;
448  }
void reserve(int size)
int push_back(T *object)
template<typename T>
PointerVector<T>& tesseract::PointerVector< T >::operator= ( const PointerVector< T > &  other)
inline

Definition at line 450 of file genericvector.h.

450  {
451  if (&other != this) {
452  this->truncate(0);
453  this->operator+=(other);
454  }
455  return *this;
456  }
PointerVector< T > & operator+=(const PointerVector &other)
template<typename T>
void tesseract::PointerVector< T >::remove ( int  index)
inline

Definition at line 460 of file genericvector.h.

460  {
461  delete GenericVector<T*>::data_[index];
463  }
void remove(int index)
template<typename T>
bool tesseract::PointerVector< T >::Serialize ( FILE *  fp) const
inline

Definition at line 509 of file genericvector.h.

509  {
511  if (fwrite(&used, sizeof(used), 1, fp) != 1) return false;
512  for (int i = 0; i < used; ++i) {
513  inT8 non_null = GenericVector<T*>::data_[i] != NULL;
514  if (fwrite(&non_null, sizeof(non_null), 1, fp) != 1) return false;
515  if (non_null && !GenericVector<T*>::data_[i]->Serialize(fp)) return false;
516  }
517  return true;
518  }
SIGNED char inT8
Definition: host.h:98
int inT32
Definition: host.h:102
bool Serialize(FILE *fp) const
template<typename T>
bool tesseract::PointerVector< T >::Serialize ( TFile fp) const
inline

Definition at line 519 of file genericvector.h.

519  {
521  if (fp->FWrite(&used, sizeof(used), 1) != 1) return false;
522  for (int i = 0; i < used; ++i) {
523  inT8 non_null = GenericVector<T*>::data_[i] != NULL;
524  if (fp->FWrite(&non_null, sizeof(non_null), 1) != 1) return false;
525  if (non_null && !GenericVector<T*>::data_[i]->Serialize(fp)) return false;
526  }
527  return true;
528  }
SIGNED char inT8
Definition: host.h:98
int inT32
Definition: host.h:102
bool Serialize(FILE *fp) const
template<typename T>
void tesseract::PointerVector< T >::sort ( )
inline

Definition at line 609 of file genericvector.h.

609 { this->GenericVector<T*>::sort(&sort_ptr_cmp<T>); }
template<typename T>
void tesseract::PointerVector< T >::truncate ( int  size)
inline

Definition at line 467 of file genericvector.h.

467  {
468  for (int i = size; i < GenericVector<T*>::size_used_; ++i)
469  delete GenericVector<T*>::data_[i];
471  }
void truncate(int size)

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