Tesseract  3.02
tesseract::PointerVector< T > Class Template Reference

#include <genericvector.h>

Inheritance diagram for tesseract::PointerVector< T >:
GenericVector< T * >

List of all members.

Public Member Functions

 PointerVector ()
 PointerVector (int size)
virtual ~PointerVector ()
 PointerVector (const PointerVector &other)
PointerVector< T > & operator+= (const PointerVector &other)
PointerVector< T > & operator= (const PointerVector &other)
virtual void remove (int index)
virtual void truncate (int size)
void compact (TessResultCallback1< bool, const T * > *delete_cb)
virtual void clear ()
virtual bool Serialize (FILE *fp) const
virtual bool DeSerialize (bool swap, FILE *fp)
void sort ()

Detailed Description

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

Definition at line 327 of file genericvector.h.


Constructor & Destructor Documentation

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

Definition at line 329 of file genericvector.h.

template<typename T>
tesseract::PointerVector< T >::PointerVector ( int  size) [inline, explicit]

Definition at line 330 of file genericvector.h.

template<typename T>
virtual tesseract::PointerVector< T >::~PointerVector ( ) [inline, virtual]

Definition at line 331 of file genericvector.h.

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

Definition at line 338 of file genericvector.h.

                                            {
    this->init(other.size());
    this->operator+=(other);
  }

Member Function Documentation

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

Definition at line 373 of file genericvector.h.

                                                               {
    int new_size = 0;
    int old_index = 0;
    // Until the callback returns true, the elements stay the same.
    while (old_index < GenericVector<T*>::size_used_ &&
           !delete_cb->Run(GenericVector<T*>::data_[old_index++]))
      ++new_size;
    // Now just copy anything else that gets false from delete_cb.
    for (; old_index < GenericVector<T*>::size_used_; ++old_index) {
      if (!delete_cb->Run(GenericVector<T*>::data_[old_index])) {
        GenericVector<T*>::data_[new_size++] =
            GenericVector<T*>::data_[old_index];
      } else {
        delete GenericVector<T*>::data_[old_index];
      }
    }
    GenericVector<T*>::size_used_ = new_size;
    delete delete_cb;
  }
template<typename T>
virtual bool tesseract::PointerVector< T >::DeSerialize ( bool  swap,
FILE *  fp 
) [inline, virtual]

Reimplemented from GenericVector< T * >.

Definition at line 419 of file genericvector.h.

                                                {
    inT32 reserved;
    if (fread(&reserved, sizeof(reserved), 1, fp) != 1) return false;
    if (swap) Reverse32(&reserved);
    GenericVector<T*>::reserve(reserved);
    for (int i = 0; i < reserved; ++i) {
      inT8 non_null;
      if (fread(&non_null, sizeof(non_null), 1, fp) != 1) return false;
      T* item = NULL;
      if (non_null) {
        item = new T;
        if (!item->DeSerialize(swap, fp)) return false;
      }
      this->push_back(item);
    }
    return true;
  }
template<typename T>
PointerVector<T>& tesseract::PointerVector< T >::operator+= ( const PointerVector< T > &  other) [inline]

Definition at line 342 of file genericvector.h.

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

Definition at line 350 of file genericvector.h.

                                                          {
    this->truncate(0);
    this->operator+=(other);
    return *this;
  }
template<typename T>
virtual void tesseract::PointerVector< T >::remove ( int  index) [inline, virtual]

Reimplemented from GenericVector< T * >.

Definition at line 358 of file genericvector.h.

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

Reimplemented from GenericVector< T * >.

Definition at line 404 of file genericvector.h.

                                         {
    inT32 used = GenericVector<T*>::size_used_;
    if (fwrite(&used, sizeof(used), 1, fp) != 1) return false;
    for (int i = 0; i < used; ++i) {
      inT8 non_null = GenericVector<T*>::data_[i] != NULL;
      if (fwrite(&non_null, sizeof(non_null), 1, fp) != 1) return false;
      if (non_null && !GenericVector<T*>::data_[i]->Serialize(fp)) return false;
    }
    return true;
  }
template<typename T>
void tesseract::PointerVector< T >::sort ( ) [inline]

Reimplemented from GenericVector< T * >.

Definition at line 439 of file genericvector.h.

              {
    sort(&sort_ptr_cmp<T>);
  }
template<typename T>
virtual void tesseract::PointerVector< T >::truncate ( int  size) [inline, virtual]

Reimplemented from GenericVector< T * >.

Definition at line 365 of file genericvector.h.

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

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