tesseract  3.05.02
tesseract::DocumentCache Class Reference

#include <imagedata.h>

Public Member Functions

 DocumentCache (inT64 max_memory)
 
 ~DocumentCache ()
 
void Clear ()
 
bool LoadDocuments (const GenericVector< STRING > &filenames, const char *lang, 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  max_memory)
explicit

Definition at line 552 of file imagedata.cpp.

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

◆ ~DocumentCache()

tesseract::DocumentCache::~DocumentCache ( )

Definition at line 554 of file imagedata.cpp.

554 {}

Member Function Documentation

◆ AddToCache()

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

Definition at line 584 of file imagedata.cpp.

584  {
585  inT64 new_memory = data->memory_used();
586  documents_.push_back(data);
587  return true;
588 }
long long int inT64
Definition: host.h:41

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

591  {
592  for (int i = 0; i < documents_.size(); ++i) {
593  if (documents_[i]->document_name() == document_name)
594  return documents_[i];
595  }
596  return NULL;
597 }

◆ 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,
const char *  lang,
CachingStrategy  cache_strategy,
FileReader  reader 
)

Definition at line 558 of file imagedata.cpp.

561  {
562  cache_strategy_ = cache_strategy;
563  inT64 fair_share_memory = 0;
564  // In the round-robin case, each DocumentData handles restricting its content
565  // to its fair share of memory. In the sequential case, DocumentCache
566  // determines which DocumentDatas are held entirely in memory.
567  if (cache_strategy_ == CS_ROUND_ROBIN)
568  fair_share_memory = max_memory_ / filenames.size();
569  for (int arg = 0; arg < filenames.size(); ++arg) {
570  STRING filename = filenames[arg];
571  DocumentData* document = new DocumentData(filename);
572  document->SetDocument(filename.string(), lang, fair_share_memory, reader);
573  AddToCache(document);
574  }
575  if (!documents_.empty()) {
576  // Try to get the first page now to verify the list of filenames.
577  if (GetPageBySerial(0) != NULL) return true;
578  tprintf("Load of page 0 failed!\n");
579  }
580  return false;
581 }
const ImageData * GetPageBySerial(int serial)
Definition: imagedata.h:337
bool AddToCache(DocumentData *data)
Definition: imagedata.cpp:584
long long int inT64
Definition: host.h:41
#define tprintf(...)
Definition: tprintf.h:31
Definition: strngs.h:44
int size() const
Definition: genericvector.h:72

◆ TotalPages()

int tesseract::DocumentCache::TotalPages ( )

Definition at line 601 of file imagedata.cpp.

601  {
602  if (cache_strategy_ == CS_SEQUENTIAL) {
603  // In sequential mode, we assume each doc has the same number of pages
604  // whether it is true or not.
605  if (num_pages_per_doc_ == 0) GetPageSequential(0);
606  return num_pages_per_doc_ * documents_.size();
607  }
608  int total_pages = 0;
609  int num_docs = documents_.size();
610  for (int d = 0; d < num_docs; ++d) {
611  // We have to load a page to make NumPages() valid.
612  documents_[d]->GetPage(0);
613  total_pages += documents_[d]->NumPages();
614  }
615  return total_pages;
616 }

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