All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tesseract::DocumentCache Class Reference

#include <imagedata.h>

Public Member Functions

 DocumentCache (inT64 max_memory)
 
 ~DocumentCache ()
 
bool LoadDocuments (const GenericVector< STRING > &filenames, const char *lang, FileReader reader)
 
bool AddToCache (DocumentData *data)
 
DocumentDataFindDocument (const STRING &document_name) const
 
const ImageDataGetPageBySerial (int serial)
 
const PointerVector
< DocumentData > & 
documents () const
 
int total_pages () const
 

Detailed Description

Definition at line 245 of file imagedata.h.

Constructor & Destructor Documentation

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

Definition at line 435 of file imagedata.cpp.

436  : total_pages_(0), memory_used_(0), max_memory_(max_memory) {}
tesseract::DocumentCache::~DocumentCache ( )

Definition at line 437 of file imagedata.cpp.

437 {}

Member Function Documentation

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

Definition at line 461 of file imagedata.cpp.

461  {
462  inT64 new_memory = data->memory_used();
463  memory_used_ += new_memory;
464  documents_.push_back(data);
465  total_pages_ += data->NumPages();
466  // Delete the first item in the array, and other pages of the same name
467  // while memory is full.
468  while (memory_used_ >= max_memory_ && max_memory_ > 0) {
469  tprintf("Memory used=%lld vs max=%lld, discarding doc of size %lld\n",
470  memory_used_ , max_memory_, documents_[0]->memory_used());
471  memory_used_ -= documents_[0]->memory_used();
472  total_pages_ -= documents_[0]->NumPages();
473  documents_.remove(0);
474  }
475  return true;
476 }
#define tprintf(...)
Definition: tprintf.h:31
long long int inT64
Definition: host.h:108
const PointerVector<DocumentData>& tesseract::DocumentCache::documents ( ) const
inline

Definition at line 265 of file imagedata.h.

265  {
266  return documents_;
267  }
DocumentData * tesseract::DocumentCache::FindDocument ( const STRING document_name) const

Definition at line 479 of file imagedata.cpp.

479  {
480  for (int i = 0; i < documents_.size(); ++i) {
481  if (documents_[i]->document_name() == document_name)
482  return documents_[i];
483  }
484  return NULL;
485 }
#define NULL
Definition: host.h:144
const ImageData * tesseract::DocumentCache::GetPageBySerial ( int  serial)

Definition at line 489 of file imagedata.cpp.

489  {
490  int document_index = serial % documents_.size();
491  return documents_[document_index]->GetPage(serial / documents_.size());
492 }
bool tesseract::DocumentCache::LoadDocuments ( const GenericVector< STRING > &  filenames,
const char *  lang,
FileReader  reader 
)

Definition at line 441 of file imagedata.cpp.

442  {
443  inT64 fair_share_memory = max_memory_ / filenames.size();
444  for (int arg = 0; arg < filenames.size(); ++arg) {
445  STRING filename = filenames[arg];
446  DocumentData* document = new DocumentData(filename);
447  if (document->LoadDocument(filename.string(), lang, 0,
448  fair_share_memory, reader)) {
449  AddToCache(document);
450  } else {
451  tprintf("Failed to load image %s!\n", filename.string());
452  delete document;
453  }
454  }
455  tprintf("Loaded %d pages, total %gMB\n",
456  total_pages_, memory_used_ / 1048576.0);
457  return total_pages_ > 0;
458 }
int size() const
Definition: genericvector.h:72
#define tprintf(...)
Definition: tprintf.h:31
bool AddToCache(DocumentData *data)
Definition: imagedata.cpp:461
Definition: strngs.h:44
const char * string() const
Definition: strngs.cpp:193
long long int inT64
Definition: host.h:108
int tesseract::DocumentCache::total_pages ( ) const
inline

Definition at line 268 of file imagedata.h.

268  {
269  return total_pages_;
270  }

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