tesseract  5.0.0
tesseract::NetworkScratch::Stack< T > Class Template Reference

#include <networkscratch.h>

Public Member Functions

 Stack ()=default
 
 ~Stack ()
 
T * Borrow ()
 
void Return (T *item)
 

Detailed Description

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

Definition at line 219 of file networkscratch.h.

Constructor & Destructor Documentation

◆ Stack()

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

◆ ~Stack()

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

Definition at line 223 of file networkscratch.h.

223  {
224  for (auto data : stack_) {
225  delete data;
226  }
227  }

Member Function Documentation

◆ Borrow()

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

Definition at line 231 of file networkscratch.h.

231  {
232  std::lock_guard<std::mutex> lock(mutex_);
233  if (stack_top_ == stack_.size()) {
234  stack_.push_back(new T);
235  flags_.push_back(false);
236  }
237  flags_[stack_top_] = true;
238  return stack_[stack_top_++];
239  }

◆ Return()

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

Definition at line 245 of file networkscratch.h.

245  {
246  std::lock_guard<std::mutex> lock(mutex_);
247  // Linear search will do.
248  int index = stack_top_;
249  while (--index >= 0 && stack_[index] != item) {
250  }
251  if (index >= 0) {
252  flags_[index] = false;
253  }
254  while (stack_top_ > 0 && !flags_[stack_top_ - 1]) {
255  --stack_top_;
256  }
257  }

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