summaryrefslogtreecommitdiffstats
path: root/src/outputgen.cpp
blob: 5be68175bb78c05b14819d72e7985f2a943bfe76 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/******************************************************************************
 *
 *
 *
 * Copyright (C) 1997-2015 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 <stdexcept>

#include <stdlib.h>

#include <qfile.h>

#include "doxygen.h"
#include "outputgen.h"
#include "message.h"
#include "portable.h"

OutputGenerator::OutputGenerator(const char *dir) : m_dir(dir)
{
  //printf("OutputGenerator::OutputGenerator()\n");
}

OutputGenerator::~OutputGenerator()
{
  //printf("OutputGenerator::~OutputGenerator()\n");
}

OutputGenerator::OutputGenerator(const OutputGenerator &og)
{
  m_dir = og.m_dir;
  // we don't copy the other fields.
  // after copying startPlainFile() should be called
  if (og.t.device()!=nullptr)
  {
    throw std::runtime_error("OutputGenerator copy constructor called while a file is processing");
  }
}

OutputGenerator &OutputGenerator::operator=(const OutputGenerator &og)
{
  m_dir = og.m_dir;
  // we don't copy the other fields.
  // after assignment startPlainFile() should be called
  if (og.t.device()!=nullptr)
  {
    throw std::runtime_error("OutputGenerator assignment operator called while a file is processing");
  }
  return *this;
}

void OutputGenerator::startPlainFile(const char *name)
{
  //printf("startPlainFile(%s)\n",name);
  m_fileName=m_dir+"/"+name;
  m_file.setName(m_fileName);
  if (!m_file.open(IO_WriteOnly))
  {
    term("Could not open file %s for writing\n",m_fileName.data());
  }
  t.setDevice(&m_file);
}

void OutputGenerator::endPlainFile()
{
  t.unsetDevice();
  m_file.close();
  m_fileName.resize(0);
}

QCString OutputGenerator::dir() const
{
  return m_dir;
}

QCString OutputGenerator::fileName() const
{
  return m_fileName;
}

void OutputGenerator::pushGeneratorState()
{
  m_genStack.push(isEnabled());
  //printf("%p:pushGeneratorState(%d) enabled=%d\n",this,genStack->count(),isEnabled());
}

void OutputGenerator::popGeneratorState()
{
  //printf("%p:popGeneratorState(%d) enabled=%d\n",this,genStack->count(),isEnabled());
  if (!m_genStack.empty())
  {
    bool lb = m_genStack.top();
    m_genStack.pop();
    if (lb) enable(); else disable();
  }
}

void OutputGenerator::enable()
{
  if (!m_genStack.empty())
  {
    m_active=m_genStack.top();
  }
  else
  {
    m_active=true;
  }
}

void OutputGenerator::disable()
{
  m_active=false;
}

void OutputGenerator::enableIf(OutputGenerator::OutputType o)
{
  if (o==type()) enable();
}

void OutputGenerator::disableIf(OutputGenerator::OutputType o)
{
  if (o==type()) disable();
}

void OutputGenerator::disableIfNot(OutputGenerator::OutputType o)
{
  if (o!=type()) disable();
}

bool OutputGenerator::isEnabled(OutputGenerator::OutputType o)
{
  return (o==type() && m_active);
}

OutputGenerator *OutputGenerator::get(OutputGenerator::OutputType o)
{
  return (o==type()) ? this : 0;
}