Skip to main content

The CodeFragmentManager Class Reference

Declaration

class CodeFragmentManager { ... }

Included Headers

#include <src/codefragment.h>

Private Constructors Index

CodeFragmentManager ()

Private Destructor Index

~CodeFragmentManager ()

Public Member Functions Index

voidparseCodeFragment (OutputCodeList &codeOutList, const QCString &fileName, const QCString &blockId, const QCString &scopeName, bool showLineNumbers, bool trimLeft, bool stripCodeComments)

Private Member Attributes Index

std::unique_ptr< Private >p

Public Static Functions Index

static CodeFragmentManager &instance ()

Definition at line 29 of file codefragment.h.

Private Constructors

CodeFragmentManager()

CodeFragmentManager::CodeFragmentManager ()

Declaration at line 42 of file codefragment.h, definition at line 183 of file codefragment.cpp.

184{
185}

Reference p.

Referenced by instance and ~CodeFragmentManager.

Private Destructor

~CodeFragmentManager()

CodeFragmentManager::~CodeFragmentManager ()

Definition at line 43 of file codefragment.h.

Reference CodeFragmentManager.

Public Member Functions

parseCodeFragment()

void CodeFragmentManager::parseCodeFragment (OutputCodeList & codeOutList, const QCString & fileName, const QCString & blockId, const QCString & scopeName, bool showLineNumbers, bool trimLeft, bool stripCodeComments)

Declaration at line 33 of file codefragment.h, definition at line 238 of file codefragment.cpp.

239 const QCString & fileName,
240 const QCString & blockId,
241 const QCString & scopeName,
242 bool showLineNumbers,
243 bool trimLeft,
244 bool stripCodeComments
245 )
246{
247 AUTO_TRACE("CodeFragmentManager::parseCodeFragment({},blockId={},scopeName={},showLineNumber={},trimLeft={},stripCodeComments={}",
248 fileName, blockId, scopeName, showLineNumbers, trimLeft, stripCodeComments);
249 std::string fragmentKey=fileName.str()+":"+scopeName.str();
250 std::unordered_map< std::string,std::unique_ptr<Private::FragmentInfo> >::iterator it;
251 bool inserted = false;
252 {
253 // create new entry if it is not yet in the map
254 std::lock_guard lock(p->mutex);
255 it = p->fragments.find(fragmentKey);
256 if (it == p->fragments.end())
257 {
258 it = p->fragments.emplace(fragmentKey, std::make_unique<Private::FragmentInfo>()).first;
259 inserted = true;
260 AUTO_TRACE_ADD("new fragment");
261 }
262 }
263 // only lock the one item we are working with
264 auto &codeFragment = it->second;
265 std::lock_guard lock(codeFragment->mutex);
266 if (inserted) // new entry, need to parse the file and record the output and cache it
267 {
268 SrcLangExt langExt = getLanguageFromFileName(fileName);
269 FileInfo cfi( fileName.str() );
270 auto fd = createFileDef( cfi.dirPath(), cfi.fileName() );
271 auto intf = Doxygen::parserManager->getCodeParser(getFileNameExtension(fileName));
272 intf->resetCodeParserState();
273 bool filterSourceFiles = Config_getBool(FILTER_SOURCE_FILES);
274 bool needs2PassParsing =
275 Doxygen::parseSourcesNeeded && // we need to parse (filtered) sources for cross-references
276 !filterSourceFiles && // but user wants to show sources as-is
277 !getFileFilter(fileName,TRUE).isEmpty(); // and there is a filter used while parsing
278 codeFragment->fileContents = readTextFileByName(fileName);
279 //printf("fileContents=[%s]\n",qPrint(codeFragment->fileContents));
280 if (needs2PassParsing)
281 {
282 OutputCodeList devNullList;
283 devNullList.add<DevNullCodeGenerator>();
284 intf->parseCode(devNullList,
285 scopeName,
286 codeFragment->fileContents,
287 langExt,
288 stripCodeComments, // actually not important here
289 false,
290 QCString()
291 );
292 }
293 codeFragment->findBlockMarkers();
294 if (codeFragment->fileContents.length()>0) // parse the normal version
295 {
296 intf->parseCode(codeFragment->recorderCodeList,
297 scopeName,
298 codeFragment->fileContents,
299 langExt, // lang
300 false, // strip code comments (overruled before replaying)
301 false, // isExampleBlock
302 QCString(), // exampleName
303 fd.get(), // fileDef
304 -1, // startLine
305 -1, // endLine
306 true, // inlineFragment
307 nullptr, // memberDef
308 true, // showLineNumbers
309 nullptr, // searchCtx
310 false // collectXRefs
311 );
312 }
313 }
314 // use the recorded OutputCodeList from the cache to output a pre-recorded fragment
315 auto blockKv = codeFragment->blocksById.find(blockId.str());
316 if (blockKv != codeFragment->blocksById.end())
317 {
318 const auto &marker = blockKv->second;
319 int startLine = marker->lines[0];
320 int endLine = marker->lines[1];
321 int indent = marker->indent;
322 AUTO_TRACE_ADD("replay(start={},end={},indent={}) fileContentsTrimLeft.empty()={}",
323 startLine,endLine,indent,codeFragment->fileContentsTrimLeft.isEmpty());
324 auto recorder = codeFragment->recorderCodeList.get<OutputCodeRecorder>(OutputType::Recorder);
325 recorder->replay(codeOutList,
326 startLine+1,
327 endLine,
328 showLineNumbers,
329 stripCodeComments,
330 trimLeft ? static_cast<size_t>(indent) : 0
331 );
332 }
333 else
334 {
335 AUTO_TRACE_ADD("block not found!");
336 }
337}

References OutputCodeList::add, AUTO_TRACE, AUTO_TRACE_ADD, Config_getBool, createFileDef, FileInfo::dirPath, FileInfo::fileName, getFileFilter, getFileNameExtension, getLanguageFromFileName, QCString::isEmpty, p, Doxygen::parserManager, Doxygen::parseSourcesNeeded, readTextFileByName, Recorder, OutputCodeRecorder::replay, QCString::str and TRUE.

Referenced by DocbookDocVisitor::operator(), HtmlDocVisitor::operator(), LatexDocVisitor::operator(), ManDocVisitor::operator(), RTFDocVisitor::operator() and XmlDocVisitor::operator().

Private Member Attributes

p

std::unique_ptr<Private> CodeFragmentManager::p

Definition at line 47 of file codefragment.h.

47 std::unique_ptr<Private> p;

Referenced by CodeFragmentManager and parseCodeFragment.

Public Static Functions

instance()

CodeFragmentManager & CodeFragmentManager::instance ()
static

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


Generated via doxygen2docusaurus by Doxygen 1.14.0.