Doxygen
outputgen.cpp
浏览该文件的文档.
1 /******************************************************************************
2  *
3  *
4  *
5  * Copyright (C) 1997-2015 by Dimitri van Heesch.
6  *
7  * Permission to use, copy, modify, and distribute this software and its
8  * documentation under the terms of the GNU General Public License is hereby
9  * granted. No representations are made about the suitability of this software
10  * for any purpose. It is provided "as is" without express or implied warranty.
11  * See the GNU General Public License for more details.
12  *
13  * Documents produced by Doxygen are derivative works derived from the
14  * input used in their production; they are not affected by this license.
15  *
16  */
17 
18 #include <stdexcept>
19 
20 #include <stdlib.h>
21 
22 #include "doxygen.h"
23 #include "outputgen.h"
24 #include "message.h"
25 #include "portable.h"
26 
27 OutputGenerator::OutputGenerator(const QCString &dir) : m_t(nullptr), m_dir(dir)
28 {
29  //printf("OutputGenerator::OutputGenerator()\n");
30 }
31 
33 {
34  //printf("OutputGenerator::~OutputGenerator()\n");
35 }
36 
38 {
39  m_dir = og.m_dir;
40  // we don't copy the other fields.
41  // after copying startPlainFile() should be called
42  if (og.m_t.stream()!=nullptr)
43  {
44  throw std::runtime_error("OutputGenerator copy constructor called while a file is processing");
45  }
46 }
47 
49 {
50  m_dir = og.m_dir;
51  // we don't copy the other fields.
52  // after assignment startPlainFile() should be called
53  if (og.m_t.stream()!=nullptr)
54  {
55  throw std::runtime_error("OutputGenerator assignment operator called while a file is processing");
56  }
57  return *this;
58 }
59 
61 {
62  //printf("startPlainFile(%s)\n",qPrint(name));
63  m_fileName=m_dir+"/"+name;
65  if (m_file==0)
66  {
67  term("Could not open file %s for writing\n",qPrint(m_fileName));
68  }
70 }
71 
73 {
74  m_t.flush();
75  m_t.setStream(nullptr);
77  m_fileName.resize(0);
78 }
79 
81 {
82  return m_dir;
83 }
84 
86 {
87  return m_fileName;
88 }
89 
91 {
92  m_genStack.push(isEnabled());
93  //printf("%p:pushGeneratorState(%d) enabled=%d\n",this,genStack->count(),isEnabled());
94 }
95 
97 {
98  //printf("%p:popGeneratorState(%d) enabled=%d\n",this,genStack->count(),isEnabled());
99  if (!m_genStack.empty())
100  {
101  bool lb = m_genStack.top();
102  m_genStack.pop();
103  if (lb) enable(); else disable();
104  }
105 }
106 
108 {
109  if (!m_genStack.empty())
110  {
111  m_active=m_genStack.top();
112  }
113  else
114  {
115  m_active=true;
116  }
117 }
118 
120 {
121  m_active=false;
122 }
123 
125 {
126  if (o==type()) enable();
127 }
128 
130 {
131  if (o==type()) disable();
132 }
133 
135 {
136  if (o!=type()) disable();
137 }
138 
140 {
141  return (o==type() && m_active);
142 }
143 
145 {
146  return (o==type()) ? this : 0;
147 }
148 
OutputGenerator::fileName
QCString fileName() const
Definition: outputgen.cpp:85
OutputGenerator::~OutputGenerator
virtual ~OutputGenerator()
Definition: outputgen.cpp:32
OutputGenerator::disable
void disable()
Definition: outputgen.cpp:119
OutputGenerator::type
virtual OutputType type() const =0
OutputGenerator::m_active
bool m_active
Definition: outputgen.h:516
TextStream::setStream
void setStream(std::ostream *s)
Sets or changes the std::ostream to write to.
Definition: textstream.h:79
Portable::fopen
FILE * fopen(const QCString &fileName, const QCString &mode)
Definition: portable.cpp:322
OutputGenerator::m_file
FILE * m_file
Definition: outputgen.h:515
OutputGenerator::enable
void enable()
Definition: outputgen.cpp:107
OutputGenerator::m_fileName
QCString m_fileName
Definition: outputgen.h:514
TextStream::setFile
void setFile(FILE *f)
Definition: textstream.h:86
TextStream::stream
std::ostream * stream() const
Returns the attached std::ostream object.
Definition: textstream.h:96
OutputGenerator::isEnabled
bool isEnabled() const
Definition: outputgen.h:359
TextStream::flush
void flush()
Flushes the buffer.
Definition: textstream.h:188
OutputGenerator::m_dir
QCString m_dir
Definition: outputgen.h:513
outputgen.h
OutputGenerator::m_t
TextStream m_t
Definition: outputgen.h:511
OutputGenerator::m_genStack
std::stack< bool > m_genStack
Definition: outputgen.h:517
message.h
Portable::fclose
int fclose(FILE *f)
Definition: portable.cpp:342
OutputGenerator::disableIf
void disableIf(OutputType o)
Definition: outputgen.cpp:129
doxygen.h
OutputGenerator::popGeneratorState
void popGeneratorState()
Definition: outputgen.cpp:96
OutputGenerator::dir
QCString dir() const
Definition: outputgen.cpp:80
OutputGenerator::disableIfNot
void disableIfNot(OutputType o)
Definition: outputgen.cpp:134
OutputGenerator::get
OutputGenerator * get(OutputType o)
Definition: outputgen.cpp:144
OutputGenerator
Abstract output generator.
Definition: outputgen.h:330
term
void term(const char *fmt,...)
Definition: message.cpp:220
qPrint
const char * qPrint(const char *s)
Definition: qcstring.h:589
QCString::data
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string
Definition: qcstring.h:153
OutputGenerator::pushGeneratorState
void pushGeneratorState()
Definition: outputgen.cpp:90
OutputGenerator::operator=
OutputGenerator & operator=(const OutputGenerator &o)
Definition: outputgen.cpp:48
OutputGenerator::endPlainFile
void endPlainFile()
Definition: outputgen.cpp:72
OutputGenerator::OutputType
OutputType
Definition: outputgen.h:333
portable.h
Portable versions of functions that are platform dependent.
OutputGenerator::OutputGenerator
OutputGenerator(const QCString &dir)
Definition: outputgen.cpp:27
OutputGenerator::enableIf
void enableIf(OutputType o)
Definition: outputgen.cpp:124
OutputGenerator::startPlainFile
void startPlainFile(const QCString &name)
Definition: outputgen.cpp:60
QCString::resize
bool resize(size_t newlen)
Resizes the string to hold newlen characters (this value should also count the 0-terminator).
Definition: qcstring.h:164
QCString
This is an alternative implementation of QCString.
Definition: qcstring.h:108