tesseract  4.00.00dev
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 207 of file networkscratch.h.

Constructor & Destructor Documentation

◆ Stack()

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

Definition at line 209 of file networkscratch.h.

209  : stack_top_(0) {
210  }

Member Function Documentation

◆ Borrow()

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

Definition at line 214 of file networkscratch.h.

214  {
215  SVAutoLock lock(&mutex_);
216  if (stack_top_ == stack_.size()) {
217  stack_.push_back(new T);
218  flags_.push_back(false);
219  }
220  flags_[stack_top_] = true;
221  return stack_[stack_top_++];
222  }
int push_back(T object)

◆ Return()

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

Definition at line 228 of file networkscratch.h.

228  {
229  SVAutoLock lock(&mutex_);
230  // Linear search will do.
231  int index = stack_top_ - 1;
232  while (index >= 0 && stack_[index] != item) --index;
233  if (index >= 0) flags_[index] = false;
234  while (stack_top_ > 0 && !flags_[stack_top_ - 1]) --stack_top_;
235  }

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