tesseract  5.0.0-alpha-619-ge9db
UnicityTable< T > Class Template Reference

#include <fontinfo.h>

Inheritance diagram for UnicityTable< T >:
UnicityTableEqEq< T >

Public Member Functions

 UnicityTable ()
 
 ~UnicityTable ()
 Clear the structures and deallocate internal structures. More...
 
void reserve (int size)
 
int size () const
 Return the size used. More...
 
const T & get (int id) const
 Return the object from an id. More...
 
T * get_mutable (int id)
 
int get_id (T object) const
 
bool contains (T object) const
 Return true if T is in the table. More...
 
contains_id (int id) const
 Return true if the id is valid. More...
 
int push_back (T object)
 Add an element in the table. More...
 
void set_clear_callback (std::function< void(T)> cb)
 
void set_compare_callback (std::function< bool(const T &, const T &)> cb)
 
void clear ()
 
void move (UnicityTable< T > *from)
 
bool write (FILE *f, std::function< bool(FILE *, const T &)> cb) const
 
bool read (tesseract::TFile *f, std::function< bool(tesseract::TFile *, T *)> cb)
 

Detailed Description

template<typename T>
class UnicityTable< T >

Definition at line 30 of file fontinfo.h.

Constructor & Destructor Documentation

◆ UnicityTable()

template<typename T >
UnicityTable< T >::UnicityTable ( )

Definition at line 116 of file unicity_table.h.

116  :
117  compare_cb_(nullptr) {
118 }

◆ ~UnicityTable()

template<typename T >
UnicityTable< T >::~UnicityTable ( )

Clear the structures and deallocate internal structures.

Definition at line 122 of file unicity_table.h.

122  {
123  clear();
124 }

Member Function Documentation

◆ clear()

template<typename T >
void UnicityTable< T >::clear ( )

Clear the table, calling the callback function if any. All the owned Callbacks are also deleted. If you don't want the Callbacks to be deleted, before calling clear, set the callback to nullptr.

Definition at line 178 of file unicity_table.h.

178  {
179  table_.clear();
180 }

◆ contains()

template<typename T>
bool UnicityTable< T >::contains ( object) const

Return true if T is in the table.

Definition at line 162 of file unicity_table.h.

162  {
163  return get_id(object) != -1;
164 }

◆ contains_id()

template<typename T >
T UnicityTable< T >::contains_id ( int  id) const

Return true if the id is valid.

Definition at line 150 of file unicity_table.h.

150  {
151  return table_.contains_index(id);
152 }

◆ get()

template<typename T >
const T & UnicityTable< T >::get ( int  id) const

Return the object from an id.

Definition at line 140 of file unicity_table.h.

140  {
141  return table_.get(id);
142 }

◆ get_id()

template<typename T>
int UnicityTable< T >::get_id ( object) const

Return the id of the T object. This method NEEDS a compare_callback to be passed to set_compare_callback.

Definition at line 156 of file unicity_table.h.

156  {
157  return table_.get_index(object);
158 }

◆ get_mutable()

template<typename T >
T * UnicityTable< T >::get_mutable ( int  id)

Definition at line 145 of file unicity_table.h.

145  {
146  return &(table_.get(id));
147 }

◆ move()

template<typename T>
void UnicityTable< T >::move ( UnicityTable< T > *  from)

This method clear the current object, then, does a shallow copy of its argument, and finally invalidate its argument.

Definition at line 185 of file unicity_table.h.

185  {
186  table_.move(&from->table_);
187 }

◆ push_back()

template<typename T>
int UnicityTable< T >::push_back ( object)

Add an element in the table.

Definition at line 168 of file unicity_table.h.

168  {
169  int idx = get_id(object);
170  if (idx == -1) {
171  idx = table_.push_back(object);
172  }
173  return idx;
174 }

◆ read()

template<typename T>
bool UnicityTable< T >::read ( tesseract::TFile f,
std::function< bool(tesseract::TFile *, T *)>  cb 
)
inline

Definition at line 96 of file unicity_table.h.

96  {
97  return table_.read(f, cb);
98  }

◆ reserve()

template<typename T >
void UnicityTable< T >::reserve ( int  size)

Reserve some memory. If there is size or more elements, the table will then allocate size * 2 elements.

Definition at line 134 of file unicity_table.h.

134  {
135  table_.reserve(size);
136 }

◆ set_clear_callback()

template<typename T>
void UnicityTable< T >::set_clear_callback ( std::function< void(T)>  cb)
inline

Add a callback to be called to delete the elements when the table took their ownership.

Definition at line 68 of file unicity_table.h.

68  {
69  table_.set_clear_callback(cb);
70  }

◆ set_compare_callback()

template<typename T>
void UnicityTable< T >::set_compare_callback ( std::function< bool(const T &, const T &)>  cb)
inline

Add a callback to be called to compare the elements when needed (contains, get_id, ...)

Definition at line 74 of file unicity_table.h.

74  {
75  table_.set_compare_callback(cb);
76  compare_cb_ = cb;
77  }

◆ size()

template<typename T >
int UnicityTable< T >::size ( ) const

Return the size used.

Definition at line 127 of file unicity_table.h.

127  {
128  return table_.size();
129 }

◆ write()

template<typename T>
bool UnicityTable< T >::write ( FILE *  f,
std::function< bool(FILE *, const T &)>  cb 
) const
inline

Read/Write the table to a file. This does NOT read/write the callbacks. The Callback given must be permanent since they will be called more than once. The given callback will be deleted at the end. Returns false on read/write error.

Definition at line 93 of file unicity_table.h.

93  {
94  return table_.write(f, cb);
95  }

The documentation for this class was generated from the following files:
UnicityTable::get_id
int get_id(T object) const
Definition: unicity_table.h:156
UnicityTable::size
int size() const
Return the size used.
Definition: unicity_table.h:127
UnicityTable::clear
void clear()
Definition: unicity_table.h:178