Doxygen
FilterCache类 参考

Public 成员函数

 FilterCache ()
 
bool getFileContents (const QCString &fileName, BufStr &str)
 

Private 属性

std::unordered_map< std::string, FilterCacheItemm_cache
 
portable_off_t m_endPos
 

详细描述

Cache for storing the result of filtering a file

在文件 definition.cpp585 行定义.

构造及析构函数说明

◆ FilterCache()

FilterCache::FilterCache ( )
inline

在文件 definition.cpp588 行定义.

588 : m_endPos(0) { }

成员函数说明

◆ getFileContents()

bool FilterCache::getFileContents ( const QCString fileName,
BufStr str 
)
inline

在文件 definition.cpp589 行定义.

590  {
591  static bool filterSourceFiles = Config_getBool(FILTER_SOURCE_FILES);
592  QCString filter = getFileFilter(fileName,TRUE);
593  bool usePipe = !filter.isEmpty() && filterSourceFiles;
594  FILE *f=0;
595  const int blockSize = 4096;
596  char buf[blockSize];
597  auto it = m_cache.find(fileName.str());
598  if (usePipe && it!=m_cache.end()) // cache hit: reuse stored result
599  {
600  auto item = it->second;
601  //printf("getFileContents(%s): cache hit\n",qPrint(fileName));
602  // file already processed, get the results after filtering from the tmp file
603  Debug::print(Debug::FilterOutput,0,"Reusing filter result for %s from %s at offset=%d size=%d\n",
604  qPrint(fileName),qPrint(Doxygen::filterDBFileName),(int)item.filePos,(int)item.fileSize);
606  if (f)
607  {
608  bool success=TRUE;
609  str.resize(static_cast<uint>(item.fileSize+1));
610  if (Portable::fseek(f,item.filePos,SEEK_SET)==-1)
611  {
612  err("Failed to seek to position %d in filter database file %s\n",(int)item.filePos,qPrint(Doxygen::filterDBFileName));
613  success=FALSE;
614  }
615  if (success)
616  {
617  size_t numBytes = fread(str.data(),1,item.fileSize,f);
618  if (numBytes!=item.fileSize)
619  {
620  err("Failed to read %d bytes from position %d in filter database file %s: got %d bytes\n",
621  (int)item.fileSize,(int)item.filePos,qPrint(Doxygen::filterDBFileName),(int)numBytes);
622  success=FALSE;
623  }
624  }
625  str.addChar('\0');
626  fclose(f);
627  return success;
628  }
629  else
630  {
631  err("Failed to open filter database file %s\n",qPrint(Doxygen::filterDBFileName));
632  return FALSE;
633  }
634  }
635  else if (usePipe) // cache miss: filter active but file not previously processed
636  {
637  //printf("getFileContents(%s): cache miss\n",qPrint(fileName));
638  // filter file
639  QCString cmd=filter+" \""+fileName+"\"";
640  Debug::print(Debug::ExtCmd,0,"Executing popen(`%s`)\n",qPrint(cmd));
641  f = Portable::popen(cmd,"r");
642  FILE *bf = Portable::fopen(Doxygen::filterDBFileName,"a+b");
643  FilterCacheItem item;
644  item.filePos = m_endPos;
645  if (bf==0)
646  {
647  // handle error
648  err("Error opening filter database file %s\n",qPrint(Doxygen::filterDBFileName));
649  str.addChar('\0');
650  Portable::pclose(f);
651  return FALSE;
652  }
653  // append the filtered output to the database file
654  size_t size=0;
655  while (!feof(f))
656  {
657  size_t bytesRead = fread(buf,1,blockSize,f);
658  size_t bytesWritten = fwrite(buf,1,bytesRead,bf);
659  if (bytesRead!=bytesWritten)
660  {
661  // handle error
662  err("Failed to write to filter database %s. Wrote %d out of %d bytes\n",
663  qPrint(Doxygen::filterDBFileName),(int)bytesWritten,(int)bytesRead);
664  str.addChar('\0');
665  Portable::pclose(f);
666  fclose(bf);
667  return FALSE;
668  }
669  size+=bytesWritten;
670  str.addArray(buf,static_cast<uint>(bytesWritten));
671  }
672  str.addChar('\0');
673  item.fileSize = size;
674  // add location entry to the dictionary
675  m_cache.insert(std::make_pair(fileName.str(),item));
676  Debug::print(Debug::FilterOutput,0,"Storing new filter result for %s in %s at offset=%d size=%d\n",
677  qPrint(fileName),qPrint(Doxygen::filterDBFileName),(int)item.filePos,(int)item.fileSize);
678  // update end of file position
679  m_endPos += size;
680  Portable::pclose(f);
681  fclose(bf);
682  }
683  else // no filtering
684  {
685  // normal file
686  //printf("getFileContents(%s): no filter\n",qPrint(fileName));
687  f = Portable::fopen(fileName,"r");
688  while (!feof(f))
689  {
690  size_t bytesRead = fread(buf,1,blockSize,f);
691  str.addArray(buf,static_cast<uint>(bytesRead));
692  }
693  str.addChar('\0');
694  fclose(f);
695  }
696  return TRUE;
697  }

引用了 BufStr::addArray(), BufStr::addChar(), Config_getBool, BufStr::data(), err(), Debug::ExtCmd, FALSE, Portable::fclose(), FilterCacheItem::filePos, FilterCacheItem::fileSize, Doxygen::filterDBFileName, Debug::FilterOutput, Portable::fopen(), Portable::fseek(), getFileFilter(), QCString::isEmpty(), Portable::pclose(), Portable::popen(), Debug::print(), qPrint(), BufStr::resize(), QCString::str() , 以及 TRUE.

被这些函数引用 readCodeFragment().

类成员变量说明

◆ m_cache

std::unordered_map<std::string,FilterCacheItem> FilterCache::m_cache
private

在文件 definition.cpp699 行定义.

◆ m_endPos

portable_off_t FilterCache::m_endPos
private

在文件 definition.cpp700 行定义.


该类的文档由以下文件生成:
Debug::ExtCmd
@ ExtCmd
Definition: debug.h:36
Portable::popen
FILE * popen(const QCString &name, const QCString &type)
Definition: portable.cpp:452
Portable::fopen
FILE * fopen(const QCString &fileName, const QCString &mode)
Definition: portable.cpp:322
QCString::isEmpty
bool isEmpty() const
Returns TRUE iff the string is empty
Definition: qcstring.h:144
BufStr::data
char * data() const
Definition: bufstr.h:96
QCString::str
std::string str() const
Definition: qcstring.h:442
err
void err(const char *fmt,...)
Definition: message.cpp:203
uint
unsigned uint
Definition: qcstring.h:40
FilterCacheItem::filePos
portable_off_t filePos
Definition: definition.cpp:580
Portable::fclose
int fclose(FILE *f)
Definition: portable.cpp:342
Debug::print
static void print(DebugMask mask, int prio, const char *fmt,...)
Definition: debug.cpp:57
Portable::pclose
int pclose(FILE *stream)
Definition: portable.cpp:461
FilterCache::m_endPos
portable_off_t m_endPos
Definition: definition.cpp:700
Debug::FilterOutput
@ FilterOutput
Definition: debug.h:38
TRUE
#define TRUE
Definition: qcstring.h:36
FilterCacheItem
Definition: definition.cpp:578
BufStr::addArray
void addArray(const char *a, uint len)
Definition: bufstr.h:62
Portable::fseek
portable_off_t fseek(FILE *f, portable_off_t offset, int whence)
Definition: portable.cpp:300
Doxygen::filterDBFileName
static QCString filterDBFileName
Definition: doxygen.h:113
Config_getBool
#define Config_getBool(name)
Definition: config.h:33
qPrint
const char * qPrint(const char *s)
Definition: qcstring.h:589
FilterCache::m_cache
std::unordered_map< std::string, FilterCacheItem > m_cache
Definition: definition.cpp:699
getFileFilter
QCString getFileFilter(const QCString &name, bool isSourceCode)
Definition: util.cpp:1315
BufStr::resize
void resize(uint newlen)
Definition: bufstr.h:78
FilterCacheItem::fileSize
size_t fileSize
Definition: definition.cpp:581
FALSE
#define FALSE
Definition: qcstring.h:33
BufStr::addChar
void addChar(char c)
Definition: bufstr.h:57
QCString
This is an alternative implementation of QCString.
Definition: qcstring.h:108