tesseract v5.3.3.20231005
tesseract::UnicityTable< T > Class Template Reference

#include <unicity_table.h>

Public Member Functions

 ~UnicityTable ()
 Clear the structures and deallocate internal structures. More...
 
void reserve (int size)
 
int size () const
 Return the size used. More...
 
const T & at (int id) const
 Return the object from an id. More...
 
T & at (int id)
 
T & operator[] (size_t id)
 
const T & operator[] (size_t id) const
 
int get_index (T object) const
 
int push_back (T object)
 Add an element in the table. More...
 
void set_clear_callback (const std::function< void(T)> &cb)
 
void clear ()
 
void move (UnicityTable< T > *from)
 
bool write (FILE *f, const std::function< bool(FILE *, const T &)> &cb) const
 
bool read (tesseract::TFile *f, const std::function< bool(tesseract::TFile *, T *)> &cb)
 

Detailed Description

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

Definition at line 37 of file unicity_table.h.

Constructor & Destructor Documentation

◆ ~UnicityTable()

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

Clear the structures and deallocate internal structures.

Definition at line 40 of file unicity_table.h.

40 {
41 clear();
42 }

Member Function Documentation

◆ at() [1/2]

template<typename T >
T & tesseract::UnicityTable< T >::at ( int  id)
inline

Definition at line 61 of file unicity_table.h.

61 {
62 return table_.at(id);
63 }

◆ at() [2/2]

template<typename T >
const T & tesseract::UnicityTable< T >::at ( int  id) const
inline

Return the object from an id.

Definition at line 56 of file unicity_table.h.

56 {
57 return table_.at(id);
58 }

◆ clear()

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

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 98 of file unicity_table.h.

98 {
99 table_.clear();
100 }

◆ get_index()

template<typename T >
int tesseract::UnicityTable< T >::get_index ( object) const
inline

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

Definition at line 75 of file unicity_table.h.

75 {
76 return table_.get_index(object);
77 }

◆ move()

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

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

Definition at line 104 of file unicity_table.h.

104 {
105 table_.move(&from->table_);
106 }

◆ operator[]() [1/2]

template<typename T >
T & tesseract::UnicityTable< T >::operator[] ( size_t  id)
inline

Definition at line 65 of file unicity_table.h.

65 {
66 return table_[id];
67 }

◆ operator[]() [2/2]

template<typename T >
const T & tesseract::UnicityTable< T >::operator[] ( size_t  id) const
inline

Definition at line 68 of file unicity_table.h.

68 {
69 return table_[id];
70 }

◆ push_back()

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

Add an element in the table.

Definition at line 80 of file unicity_table.h.

80 {
81 auto idx = get_index(object);
82 if (idx == -1) {
83 idx = table_.push_back(object);
84 }
85 return idx;
86 }
int get_index(T object) const
Definition: unicity_table.h:75

◆ read()

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

Definition at line 115 of file unicity_table.h.

115 {
116 return table_.read(f, cb);
117 }

◆ reserve()

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

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

Definition at line 46 of file unicity_table.h.

46 {
47 table_.reserve(size);
48 }
int size() const
Return the size used.
Definition: unicity_table.h:51

◆ set_clear_callback()

template<typename T >
void tesseract::UnicityTable< T >::set_clear_callback ( const 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 90 of file unicity_table.h.

90 {
91 table_.set_clear_callback(cb);
92 }

◆ size()

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

Return the size used.

Definition at line 51 of file unicity_table.h.

51 {
52 return table_.size();
53 }

◆ write()

template<typename T >
bool tesseract::UnicityTable< T >::write ( FILE *  f,
const 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 112 of file unicity_table.h.

112 {
113 return table_.write(f, cb);
114 }

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