summaryrefslogtreecommitdiffstats
path: root/src/docvisitor.cpp
blob: 506c9f871b61797b491eb2bdae5dc9ec9f00c5b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/******************************************************************************
 *
 * Copyright (C) 1997-2020 by Dimitri van Heesch.
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation under the terms of the GNU General Public License is hereby
 * granted. No representations are made about the suitability of this software
 * for any purpose. It is provided "as is" without express or implied warranty.
 * See the GNU General Public License for more details.
 *
 * Documents produced by Doxygen are derivative works derived from the
 * input used in their production; they are not affected by this license.
 */


#include <unordered_map>
#include <stack>

#include "parserintf.h"
#include "docvisitor.h"
#include "util.h"
#include "types.h"
#include "doxygen.h"

struct DocVisitor::Private
{
  int id;
  std::unordered_map< std::string, std::unique_ptr<CodeParserInterface> > parserFactoryMap;
  std::stack<bool> hidden;
};

DocVisitor::DocVisitor(int id) : m_p(std::make_unique<Private>())
{
  m_p->id = id;
}

DocVisitor::~DocVisitor()
{
}

CodeParserInterface &DocVisitor::getCodeParser(const QCString &extension)
{
  std::string ext = extension.str();
  // for each extension we create a code parser once per visitor, so that
  // the context of the same parser object is reused throughout multiple passes for instance
  // for code fragments shown via dontinclude.
  auto it = m_p->parserFactoryMap.find(ext);
  if (it==m_p->parserFactoryMap.end())
  {
    auto factory = Doxygen::parserManager->getCodeParserFactory(extension);
    auto result = m_p->parserFactoryMap.insert(std::make_pair(ext,factory()));
    it = result.first;
  }
  return *it->second.get();
}

int DocVisitor::id() const
{
  return m_p->id;
}

void DocVisitor::pushHidden(bool hide)
{
  m_p->hidden.push(hide);
}

bool DocVisitor::popHidden()
{
  if (m_p->hidden.empty()) return false;
  bool v = m_p->hidden.top();
  m_p->hidden.pop();
  return v;
}