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 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 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 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 NULL;
609 }

◆ 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 572 of file imagedata.cpp.

574  {
575  cache_strategy_ = cache_strategy;
576  inT64 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) != NULL) return true;
591  tprintf("Load of page 0 failed!\n");
592  }
593  return false;
594 }
const ImageData * GetPageBySerial(int serial)
Definition: imagedata.h:335
int64_t inT64
Definition: host.h:40
#define tprintf(...)
Definition: tprintf.h:31
const char * string() const
Definition: strngs.cpp:198
int size() const
Definition: genericvector.h:72
Definition: strngs.h:45
bool AddToCache(DocumentData *data)
Definition: imagedata.cpp:597
const char * filename
Definition: ioapi.h:38

◆ 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: