tesseract  5.0.0-alpha-619-ge9db
tesseract::NetworkScratch::Stack< T > Class Template Reference

#include <networkscratch.h>

Public Member Functions

 Stack ()
 
T * Borrow ()
 
void Return (T *item)
 

Detailed Description

template<typename T>
class tesseract::NetworkScratch::Stack< T >

Definition at line 205 of file networkscratch.h.

Constructor & Destructor Documentation

◆ Stack()

template<typename T>
tesseract::NetworkScratch::Stack< T >::Stack ( )
inline

Definition at line 207 of file networkscratch.h.

207  : stack_top_(0) {
208  }

Member Function Documentation

◆ Borrow()

template<typename T>
T* tesseract::NetworkScratch::Stack< T >::Borrow ( )
inline

Definition at line 212 of file networkscratch.h.

212  {
213  std::lock_guard<std::mutex> lock(mutex_);
214  if (stack_top_ == stack_.size()) {
215  stack_.push_back(new T);
216  flags_.push_back(false);
217  }
218  flags_[stack_top_] = true;
219  return stack_[stack_top_++];
220  }

◆ Return()

template<typename T>
void tesseract::NetworkScratch::Stack< T >::Return ( T *  item)
inline

Definition at line 226 of file networkscratch.h.

226  {
227  std::lock_guard<std::mutex> lock(mutex_);
228  // Linear search will do.
229  int index = stack_top_ - 1;
230  while (index >= 0 && stack_[index] != item) --index;
231  if (index >= 0) flags_[index] = false;
232  while (stack_top_ > 0 && !flags_[stack_top_ - 1]) --stack_top_;
233  }

The documentation for this class was generated from the following file:
GenericVector::push_back
int push_back(T object)
Definition: genericvector.h:799