tesseract  3.05.00
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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

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

Definition at line 550 of file imagedata.cpp.

551  : num_pages_per_doc_(0), max_memory_(max_memory) {}
tesseract::DocumentCache::~DocumentCache ( )

Definition at line 552 of file imagedata.cpp.

552 {}

Member Function Documentation

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

Definition at line 582 of file imagedata.cpp.

582  {
583  inT64 new_memory = data->memory_used();
584  documents_.push_back(data);
585  return true;
586 }
long long int inT64
Definition: host.h:108
void tesseract::DocumentCache::Clear ( )
inline

Definition at line 320 of file imagedata.h.

320  {
321  documents_.clear();
322  num_pages_per_doc_ = 0;
323  }
const PointerVector<DocumentData>& tesseract::DocumentCache::documents ( ) const
inline

Definition at line 344 of file imagedata.h.

344  {
345  return documents_;
346  }
DocumentData * tesseract::DocumentCache::FindDocument ( const STRING document_name) const

Definition at line 589 of file imagedata.cpp.

589  {
590  for (int i = 0; i < documents_.size(); ++i) {
591  if (documents_[i]->document_name() == document_name)
592  return documents_[i];
593  }
594  return NULL;
595 }
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  }
bool tesseract::DocumentCache::LoadDocuments ( const GenericVector< STRING > &  filenames,
const char *  lang,
CachingStrategy  cache_strategy,
FileReader  reader 
)

Definition at line 556 of file imagedata.cpp.

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

Definition at line 599 of file imagedata.cpp.

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

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