Doxygen
Loading...
Searching...
No Matches
CodeFragmentManager Class Reference

#include <src/codefragment.h>

Classes

struct  Private

Public Member Functions

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

Static Public Member Functions

static CodeFragmentManagerinstance ()

Private Member Functions

 CodeFragmentManager ()
 ~CodeFragmentManager ()

Private Attributes

std::unique_ptr< Privatep

Detailed Description

Definition at line 26 of file codefragment.h.

Constructor & Destructor Documentation

◆ CodeFragmentManager()

CodeFragmentManager::CodeFragmentManager ( )
private

Definition at line 187 of file codefragment.cpp.

187 : p(std::make_unique<Private>())
188{
189}
std::unique_ptr< Private > p

References p.

Referenced by instance(), and ~CodeFragmentManager().

◆ ~CodeFragmentManager()

CodeFragmentManager::~CodeFragmentManager ( )
privatedefault

References CodeFragmentManager().

Member Function Documentation

◆ instance()

◆ parseCodeFragment()

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

Definition at line 245 of file codefragment.cpp.

253{
254 AUTO_TRACE("CodeFragmentManager::parseCodeFragment({},blockId={},scopeName={},showLineNumber={},trimLeft={},stripCodeComments={}",
255 fileName, blockId, scopeName, showLineNumbers, trimLeft, stripCodeComments);
256 std::string fragmentKey=fileName.str()+":"+scopeName.str();
257 std::unordered_map< std::string,std::unique_ptr<Private::FragmentInfo> >::iterator it;
258 bool inserted = false;
259 {
260 // create new entry if it is not yet in the map
261 std::lock_guard lock(p->mutex);
262 it = p->fragments.find(fragmentKey);
263 if (it == p->fragments.end())
264 {
265 it = p->fragments.emplace(fragmentKey, std::make_unique<Private::FragmentInfo>()).first;
266 inserted = true;
267 AUTO_TRACE_ADD("new fragment");
268 }
269 }
270 // only lock the one item we are working with
271 auto &codeFragment = it->second;
272 std::lock_guard lock(codeFragment->mutex);
273 if (inserted) // new entry, need to parse the file and record the output and cache it
274 {
275 SrcLangExt langExt = getLanguageFromFileName(fileName);
276 FileInfo cfi( fileName.str() );
277 auto fd = createFileDef( cfi.dirPath(), cfi.fileName() );
279 intf->resetCodeParserState();
280 bool filterSourceFiles = Config_getBool(FILTER_SOURCE_FILES);
281 bool needs2PassParsing =
282 Doxygen::parseSourcesNeeded && // we need to parse (filtered) sources for cross-references
283 !filterSourceFiles && // but user wants to show sources as-is
284 !getFileFilter(fileName,true).empty(); // and there is a filter used while parsing
285 codeFragment->fileContents = readTextFileByName(fileName);
286 //printf("fileContents=[%s]\n",qPrint(codeFragment->fileContents));
287 if (needs2PassParsing)
288 {
289 OutputCodeList devNullList;
290 devNullList.add<DevNullCodeGenerator>();
291 intf->parseCode(devNullList,
292 scopeName,
293 codeFragment->fileContents,
294 langExt,
295 stripCodeComments, // actually not important here
296 CodeParserOptions()
297 );
298 }
299 codeFragment->findBlockMarkers();
300 if (!codeFragment->fileContents.empty()) // parse the normal version
301 {
302 intf->parseCode(codeFragment->recorderCodeList,
303 scopeName,
304 codeFragment->fileContents,
305 langExt, // lang
306 false, // strip code comments (overruled before replaying)
307 CodeParserOptions()
308 .setFileDef(fd.get())
309 .setInlineFragment(true)
310 .setCollectXRefs(false)
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 size_t indent = marker->indent;
322 AUTO_TRACE_ADD("replay(start={},end={},indent={}) fileContentsTrimLeft.empty()={}",
323 startLine,endLine,indent,codeFragment->fileContentsTrimLeft.empty());
324 auto recorder = codeFragment->recorderCodeList.get<OutputCodeRecorder>(OutputType::Recorder);
325 recorder->replay(codeOutList,
326 startLine+1,
327 endLine,
328 showLineNumbers,
329 stripCodeComments,
330 trimLeft ? indent : 0
331 );
332 }
333 else
334 {
335 AUTO_TRACE_ADD("block not found!");
336 }
337}
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
const std::string & str() const
Definition dstring.h:645
static bool parseSourcesNeeded
Definition doxygen.h:116
static ParserManager * parserManager
Definition doxygen.h:122
void add(OutputCodeIntfPtr &&p)
Definition outputlist.h:192
std::unique_ptr< CodeParserInterface > getCodeParser(const DString &extension)
Gets the interface to the parser associated with a given extension.
Definition parserintf.h:253
static DString readTextFileByName(const DString &file)
#define Config_getBool(name)
Definition config.h:33
#define AUTO_TRACE_ADD(...)
Definition docnode.cpp:54
#define AUTO_TRACE(...)
Definition docnode.cpp:53
std::unique_ptr< FileDef > createFileDef(const DString &p, const DString &n, const DString &ref, const DString &dn)
Definition filedef.cpp:267
SrcLangExt
Definition types.h:207
DString getFileNameExtension(const DString &fn)
Definition util.cpp:4210
SrcLangExt getLanguageFromFileName(const DString &fileName, SrcLangExt defLang)
Definition util.cpp:4168
DString getFileFilter(const DString &name, bool isSourceCode)
Definition util.cpp:1020

References OutputCodeList::add(), AUTO_TRACE, AUTO_TRACE_ADD, Config_getBool, createFileDef(), FileInfo::dirPath(), DString::empty(), FileInfo::fileName(), ParserManager::getCodeParser(), getFileFilter(), getFileNameExtension(), getLanguageFromFileName(), p, Doxygen::parserManager, Doxygen::parseSourcesNeeded, readTextFileByName(), Recorder, OutputCodeRecorder::replay(), CodeParserOptions::setCollectXRefs(), CodeParserOptions::setInlineFragment(), and DString::str().

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

Member Data Documentation

◆ p

std::unique_ptr<Private> CodeFragmentManager::p
private

Definition at line 44 of file codefragment.h.

Referenced by CodeFragmentManager(), and parseCodeFragment().


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