Doxygen
docvisitor.cpp
浏览该文件的文档.
1 /******************************************************************************
2  *
3  * Copyright (C) 1997-2020 by Dimitri van Heesch.
4  *
5  * Permission to use, copy, modify, and distribute this software and its
6  * documentation under the terms of the GNU General Public License is hereby
7  * granted. No representations are made about the suitability of this software
8  * for any purpose. It is provided "as is" without express or implied warranty.
9  * See the GNU General Public License for more details.
10  *
11  * Documents produced by Doxygen are derivative works derived from the
12  * input used in their production; they are not affected by this license.
13  */
14 
15 
16 #include <unordered_map>
17 #include <stack>
18 
19 #include "parserintf.h"
20 #include "docvisitor.h"
21 #include "util.h"
22 #include "types.h"
23 #include "doxygen.h"
24 
26 {
27  int id;
28  std::unordered_map< std::string, std::unique_ptr<CodeParserInterface> > parserFactoryMap;
29  std::stack<bool> hidden;
30 };
31 
32 DocVisitor::DocVisitor(int id) : m_p(std::make_unique<Private>())
33 {
34  m_p->id = id;
35 }
36 
38 {
39 }
40 
42 {
43  std::string ext = extension.str();
44  // for each extension we create a code parser once per visitor, so that
45  // the context of the same parser object is reused throughout multiple passes for instance
46  // for code fragments shown via dontinclude.
47  auto it = m_p->parserFactoryMap.find(ext);
48  if (it==m_p->parserFactoryMap.end())
49  {
50  auto factory = Doxygen::parserManager->getCodeParserFactory(extension);
51  auto result = m_p->parserFactoryMap.insert(std::make_pair(ext,factory()));
52  it = result.first;
53  }
54  return *it->second.get();
55 }
56 
57 int DocVisitor::id() const
58 {
59  return m_p->id;
60 }
61 
62 void DocVisitor::pushHidden(bool hide)
63 {
64  m_p->hidden.push(hide);
65 }
66 
68 {
69  if (m_p->hidden.empty()) return false;
70  bool v = m_p->hidden.top();
71  m_p->hidden.pop();
72  return v;
73 }
DocVisitor::pushHidden
void pushHidden(bool hide)
Definition: docvisitor.cpp:62
DocVisitor::DocVisitor
DocVisitor(int id)
Definition: docvisitor.cpp:32
DocVisitor::id
int id() const
Definition: docvisitor.cpp:57
types.h
This file contains a number of basic enums and types.
DocVisitor::popHidden
bool popHidden()
Definition: docvisitor.cpp:67
docvisitor.h
CodeParserInterface
Abstract interface for code parsers.
Definition: parserintf.h:83
QCString::str
std::string str() const
Definition: qcstring.h:442
DocVisitor::m_p
std::unique_ptr< Private > m_p
Definition: docvisitor.h:94
DocVisitor::~DocVisitor
virtual ~DocVisitor()
Definition: docvisitor.cpp:37
DocVisitor::getCodeParser
CodeParserInterface & getCodeParser(const QCString &langExt)
Definition: docvisitor.cpp:41
DocVisitor::Private::hidden
std::stack< bool > hidden
Definition: docvisitor.cpp:41
DocVisitor::Private
Definition: docvisitor.cpp:25
Doxygen::parserManager
static ParserManager * parserManager
Definition: doxygen.h:111
doxygen.h
parserintf.h
ParserManager::getCodeParserFactory
CodeParserFactory & getCodeParserFactory(const QCString &extension)
Get the factory for create code parser objects with a given extension.
Definition: parserintf.h:224
DocVisitor::Private::id
int id
Definition: docvisitor.cpp:39
util.h
A bunch of utility functions.
DocVisitor::Private::parserFactoryMap
std::unordered_map< std::string, std::unique_ptr< CodeParserInterface > > parserFactoryMap
Definition: docvisitor.cpp:40
QCString
This is an alternative implementation of QCString.
Definition: qcstring.h:108