tesseract  4.00.00dev
tesseract::DocumentCache Class Reference

#include <imagedata.h>

Public Member Functions

 DocumentCache (inT64 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 312 of file imagedata.h.

Constructor & Destructor Documentation

◆ DocumentCache()

tesseract::DocumentCache::DocumentCache ( inT64  max_memory)
explicit

Definition at line 567 of file imagedata.cpp.

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

◆ ~DocumentCache()

tesseract::DocumentCache::~DocumentCache ( )

Definition at line 569 of file imagedata.cpp.

569 {}

Member Function Documentation

◆ AddToCache()

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

Definition at line 598 of file imagedata.cpp.

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

◆ Clear()

void tesseract::DocumentCache::Clear ( )
inline

Definition at line 318 of file imagedata.h.

318  {
319  documents_.clear();
320  num_pages_per_doc_ = 0;
321  }

◆ documents()

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

Definition at line 342 of file imagedata.h.

342  {
343  return documents_;
344  }

◆ FindDocument()

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

Definition at line 604 of file imagedata.cpp.

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

◆ GetPageBySerial()

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

Definition at line 335 of file imagedata.h.

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

◆ LoadDocuments()

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

Definition at line 573 of file imagedata.cpp.

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

◆ TotalPages()

int tesseract::DocumentCache::TotalPages ( )

Definition at line 614 of file imagedata.cpp.

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

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