tesseract  4.0.0-1-g2a2b
tesseract::DocumentCache Class Reference

#include <imagedata.h>

Public Member Functions

 DocumentCache (int64_t max_memory)
 
 ~DocumentCache ()
 
void Clear ()
 
bool LoadDocuments (const GenericVector< STRING > &filenames, CachingStrategy cache_strategy, FileReader reader)
 
bool AddToCache (DocumentData *data)
 
DocumentDataFindDocument (const STRING &document_name) const
 
const ImageDataGetPageBySerial (int serial)
 
const PointerVector< DocumentData > & documents () const
 
int TotalPages ()
 

Detailed Description

Definition at line 314 of file imagedata.h.

Constructor & Destructor Documentation

◆ DocumentCache()

tesseract::DocumentCache::DocumentCache ( int64_t  max_memory)
explicit

Definition at line 566 of file imagedata.cpp.

567  : num_pages_per_doc_(0), max_memory_(max_memory) {}

◆ ~DocumentCache()

tesseract::DocumentCache::~DocumentCache ( )

Definition at line 568 of file imagedata.cpp.

568 {}

Member Function Documentation

◆ AddToCache()

bool tesseract::DocumentCache::AddToCache ( DocumentData data)

Definition at line 597 of file imagedata.cpp.

597  {
598  documents_.push_back(data);
599  return true;
600 }

◆ Clear()

void tesseract::DocumentCache::Clear ( )
inline

Definition at line 320 of file imagedata.h.

320  {
321  documents_.clear();
322  num_pages_per_doc_ = 0;
323  }

◆ documents()

const PointerVector<DocumentData>& tesseract::DocumentCache::documents ( ) const
inline

Definition at line 344 of file imagedata.h.

344  {
345  return documents_;
346  }

◆ FindDocument()

DocumentData * tesseract::DocumentCache::FindDocument ( const STRING document_name) const

Definition at line 603 of file imagedata.cpp.

603  {
604  for (int i = 0; i < documents_.size(); ++i) {
605  if (documents_[i]->document_name() == document_name)
606  return documents_[i];
607  }
608  return nullptr;
609 }

◆ GetPageBySerial()

const ImageData* tesseract::DocumentCache::GetPageBySerial ( int  serial)
inline

Definition at line 337 of file imagedata.h.

337  {
338  if (cache_strategy_ == CS_SEQUENTIAL)
339  return GetPageSequential(serial);
340  else
341  return GetPageRoundRobin(serial);
342  }

◆ LoadDocuments()

bool tesseract::DocumentCache::LoadDocuments ( const GenericVector< STRING > &  filenames,
CachingStrategy  cache_strategy,
FileReader  reader 
)

Definition at line 572 of file imagedata.cpp.

574  {
575  cache_strategy_ = cache_strategy;
576  int64_t fair_share_memory = 0;
577  // In the round-robin case, each DocumentData handles restricting its content
578  // to its fair share of memory. In the sequential case, DocumentCache
579  // determines which DocumentDatas are held entirely in memory.
580  if (cache_strategy_ == CS_ROUND_ROBIN)
581  fair_share_memory = max_memory_ / filenames.size();
582  for (int arg = 0; arg < filenames.size(); ++arg) {
583  STRING filename = filenames[arg];
584  DocumentData* document = new DocumentData(filename);
585  document->SetDocument(filename.string(), fair_share_memory, reader);
586  AddToCache(document);
587  }
588  if (!documents_.empty()) {
589  // Try to get the first page now to verify the list of filenames.
590  if (GetPageBySerial(0) != nullptr) return true;
591  tprintf("Load of page 0 failed!\n");
592  }
593  return false;
594 }
int size() const
Definition: genericvector.h:71
const char * string() const
Definition: strngs.cpp:196
const ImageData * GetPageBySerial(int serial)
Definition: imagedata.h:337
bool AddToCache(DocumentData *data)
Definition: imagedata.cpp:597
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
Definition: strngs.h:45

◆ TotalPages()

int tesseract::DocumentCache::TotalPages ( )

Definition at line 613 of file imagedata.cpp.

613  {
614  if (cache_strategy_ == CS_SEQUENTIAL) {
615  // In sequential mode, we assume each doc has the same number of pages
616  // whether it is true or not.
617  if (num_pages_per_doc_ == 0) GetPageSequential(0);
618  return num_pages_per_doc_ * documents_.size();
619  }
620  int total_pages = 0;
621  int num_docs = documents_.size();
622  for (int d = 0; d < num_docs; ++d) {
623  // We have to load a page to make NumPages() valid.
624  documents_[d]->GetPage(0);
625  total_pages += documents_[d]->NumPages();
626  }
627  return total_pages;
628 }

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