tesseract 4.1.1
Loading...
Searching...
No Matches
tesseract::DocumentCache Class Reference

#include <imagedata.h>

Public Member Functions

 DocumentCache (int64_t 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 321 of file imagedata.h.

Constructor & Destructor Documentation

◆ DocumentCache()

tesseract::DocumentCache::DocumentCache ( int64_t  max_memory)
explicit

Definition at line 574 of file imagedata.cpp.

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

◆ ~DocumentCache()

tesseract::DocumentCache::~DocumentCache ( )

Definition at line 576 of file imagedata.cpp.

576{}

Member Function Documentation

◆ AddToCache()

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

Definition at line 605 of file imagedata.cpp.

605 {
606 documents_.push_back(data);
607 return true;
608}

◆ Clear()

void tesseract::DocumentCache::Clear ( )
inline

Definition at line 327 of file imagedata.h.

327 {
328 documents_.clear();
329 num_pages_per_doc_ = 0;
330 }

◆ documents()

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

Definition at line 351 of file imagedata.h.

351 {
352 return documents_;
353 }

◆ FindDocument()

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

Definition at line 611 of file imagedata.cpp.

611 {
612 for (int i = 0; i < documents_.size(); ++i) {
613 if (documents_[i]->document_name() == document_name)
614 return documents_[i];
615 }
616 return nullptr;
617}

◆ GetPageBySerial()

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

Definition at line 344 of file imagedata.h.

344 {
345 if (cache_strategy_ == CS_SEQUENTIAL)
346 return GetPageSequential(serial);
347 else
348 return GetPageRoundRobin(serial);
349 }
@ CS_SEQUENTIAL
Definition: imagedata.h:49

◆ LoadDocuments()

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

Definition at line 580 of file imagedata.cpp.

582 {
583 cache_strategy_ = cache_strategy;
584 int64_t fair_share_memory = 0;
585 // In the round-robin case, each DocumentData handles restricting its content
586 // to its fair share of memory. In the sequential case, DocumentCache
587 // determines which DocumentDatas are held entirely in memory.
588 if (cache_strategy_ == CS_ROUND_ROBIN)
589 fair_share_memory = max_memory_ / filenames.size();
590 for (int arg = 0; arg < filenames.size(); ++arg) {
591 STRING filename = filenames[arg];
592 auto* document = new DocumentData(filename);
593 document->SetDocument(filename.string(), fair_share_memory, reader);
594 AddToCache(document);
595 }
596 if (!documents_.empty()) {
597 // Try to get the first page now to verify the list of filenames.
598 if (GetPageBySerial(0) != nullptr) return true;
599 tprintf("Load of page 0 failed!\n");
600 }
601 return false;
602}
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:35
@ CS_ROUND_ROBIN
Definition: imagedata.h:54
int size() const
Definition: genericvector.h:72
bool AddToCache(DocumentData *data)
Definition: imagedata.cpp:605
const ImageData * GetPageBySerial(int serial)
Definition: imagedata.h:344
Definition: strngs.h:45
const char * string() const
Definition: strngs.cpp:194

◆ TotalPages()

int tesseract::DocumentCache::TotalPages ( )

Definition at line 621 of file imagedata.cpp.

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

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