tesseract v5.3.3.20231005
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 (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)
 
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 (const std::function< void(T *)> &cb)
 
void clear ()
 
void delete_data_pointers ()
 
void move (GenericVector< T * > *from)
 
bool write (FILE *f, const std::function< bool(FILE *, const T * &)> &cb) const
 
bool read (TFile *f, const 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 DeSerializeClasses (TFile *fp)
 
void reverse ()
 
void sort ()
 
void sort (int(*comparator)(const void *, const void *))
 
void swap (int index1, int index2)
 

Additional Inherited Members

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

Constructor & Destructor Documentation

◆ PointerVector() [1/3]

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

Definition at line 304 of file genericvector.h.

304: GenericVector<T *>() {}

◆ PointerVector() [2/3]

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

Definition at line 305 of file genericvector.h.

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

◆ ~PointerVector()

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

Definition at line 306 of file genericvector.h.

306 {
307 // Clear must be called here, even though it is called again by the base,
308 // as the base will call the wrong clear.
309 clear();
310 }

◆ PointerVector() [3/3]

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

Definition at line 313 of file genericvector.h.

313 : GenericVector<T *>(other) {
314 this->init(other.size());
315 this->operator+=(other);
316 }
PointerVector< T > & operator+=(const PointerVector &other)

Member Function Documentation

◆ clear()

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

◆ DeSerialize()

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

Definition at line 402 of file genericvector.h.

402 {
403 uint32_t reserved;
404 if (fread(&reserved, sizeof(reserved), 1, fp) != 1) {
405 return false;
406 }
407 if (swap) {
408 Reverse32(&reserved);
409 }
410 // Arbitrarily limit the number of elements to protect against bad data.
411 assert(reserved <= UINT16_MAX);
412 if (reserved > UINT16_MAX) {
413 return false;
414 }
416 truncate(0);
417 for (uint32_t i = 0; i < reserved; ++i) {
418 int8_t non_null;
419 if (fread(&non_null, sizeof(non_null), 1, fp) != 1) {
420 return false;
421 }
422 T *item = nullptr;
423 if (non_null != 0) {
424 item = new T;
425 if (!item->DeSerialize(swap, fp)) {
426 delete item;
427 return false;
428 }
429 this->push_back(item);
430 } else {
431 // Null elements should keep their place in the vector.
432 this->push_back(nullptr);
433 }
434 }
435 return true;
436 }
void Reverse32(void *ptr)
Definition: helpers.h:196
void swap(int index1, int index2)

◆ operator+=()

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

Definition at line 317 of file genericvector.h.

317 {
318 this->reserve(this->size_used_ + other.size_used_);
319 for (unsigned i = 0; i < other.size(); ++i) {
320 this->push_back(new T(*other.data_[i]));
321 }
322 return *this;
323 }

◆ operator=()

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

Definition at line 325 of file genericvector.h.

325 {
326 if (&other != this) {
327 this->truncate(0);
328 this->operator+=(other);
329 }
330 return *this;
331 }

◆ remove()

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

Definition at line 335 of file genericvector.h.

◆ Serialize() [1/2]

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

Definition at line 363 of file genericvector.h.

363 {
364 int32_t used = GenericVector<T *>::size_used_;
365 if (fwrite(&used, sizeof(used), 1, fp) != 1) {
366 return false;
367 }
368 for (int i = 0; i < used; ++i) {
369 int8_t non_null = GenericVector<T *>::data_[i] != nullptr;
370 if (fwrite(&non_null, sizeof(non_null), 1, fp) != 1) {
371 return false;
372 }
373 if (non_null && !GenericVector<T *>::data_[i]->Serialize(fp)) {
374 return false;
375 }
376 }
377 return true;
378 }
bool Serialize(FILE *fp) const

◆ Serialize() [2/2]

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

Definition at line 379 of file genericvector.h.

379 {
380 int32_t used = GenericVector<T *>::size_used_;
381 if (fp->FWrite(&used, sizeof(used), 1) != 1) {
382 return false;
383 }
384 for (int i = 0; i < used; ++i) {
385 int8_t non_null = GenericVector<T *>::data_[i] != nullptr;
386 if (fp->FWrite(&non_null, sizeof(non_null), 1) != 1) {
387 return false;
388 }
389 if (non_null && !GenericVector<T *>::data_[i]->Serialize(fp)) {
390 return false;
391 }
392 }
393 return true;
394 }

◆ sort()

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

Definition at line 440 of file genericvector.h.

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

◆ truncate()

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

Definition at line 342 of file genericvector.h.

342 {
343 for (int i = size; i < GenericVector<T *>::size_used_; ++i) {
345 }
347 }

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