outputgen.cpp
Go to the documentation of this file.
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 <stdlib.h>
19 
20 #include <qfile.h>
21 
22 #include "outputgen.h"
23 #include "message.h"
24 #include "portable.h"
25 
27 {
28  //printf("OutputGenerator::OutputGenerator()\n");
29  file=0;
30  active=TRUE;
31  genStack = new QStack<bool>;
33 }
34 
36 {
37  //printf("OutputGenerator::~OutputGenerator()\n");
38  delete file;
39  delete genStack;
40 }
41 
43 {
44  //printf("startPlainFile(%s)\n",name);
45  fileName=dir+"/"+name;
46  file = new QFile(fileName);
47  if (!file->open(IO_WriteOnly))
48  {
49  err("Could not open file %s for writing\n",fileName.data());
50  exit(1);
51  }
52  t.setDevice(file);
53 }
54 
56 {
57  t.unsetDevice();
58  delete file;
59  file=0;
60  fileName.resize(0);
61 }
62 
64 {
65  genStack->push(new bool(isEnabled()));
66  //printf("%p:pushGeneratorState(%d) enabled=%d\n",this,genStack->count(),isEnabled());
67 }
68 
70 {
71  //printf("%p:popGeneratorState(%d) enabled=%d\n",this,genStack->count(),isEnabled());
72  bool *lb = genStack->pop();
73  ASSERT(lb!=0);
74  if (lb==0) return; // for some robustness against superfluous \endhtmlonly commands.
75  if (*lb) enable(); else disable();
76  delete lb;
77 }
78 
static QCString name
Definition: declinfo.cpp:673
void setAutoDelete(bool del)
Definition: qstack.h:55
bool resize(uint newlen)
Definition: qcstring.h:225
void endPlainFile()
Definition: outputgen.cpp:55
virtual ~OutputGenerator()
Definition: outputgen.cpp:35
virtual void enable()=0
void pushGeneratorState()
Definition: outputgen.cpp:63
#define IO_WriteOnly
Definition: qiodevice.h:62
void setDevice(QIODevice *)
void unsetDevice()
void push(const type *d)
Definition: qstack.h:58
void startPlainFile(const char *name)
Definition: outputgen.cpp:42
QStack< bool > * genStack
Definition: outputgen.h:491
bool open(int)
Definition: qfile_unix.cpp:134
const char * data() const
Definition: qcstring.h:207
QFile * file
Definition: outputgen.h:487
void err(const char *fmt,...)
Definition: message.cpp:226
type * pop()
Definition: qstack.h:59
The QFile class is an I/O device that operates on files.
Definition: qfile.h:50
QCString fileName
Definition: outputgen.h:488
QCString dir
Definition: outputgen.h:489
FTextStream t
Definition: outputgen.h:486
bool isEnabled() const
Definition: outputgen.h:341
void popGeneratorState()
Definition: outputgen.cpp:69
virtual void disable()=0
const bool TRUE
Definition: qglobal.h:371
Portable versions of functions that are platform dependent.
#define ASSERT(x)
Definition: qglobal.h:590