summaryrefslogtreecommitdiffstats
path: root/src/outputgen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/outputgen.cpp')
-rw-r--r--src/outputgen.cpp113
1 files changed, 92 insertions, 21 deletions
diff --git a/src/outputgen.cpp b/src/outputgen.cpp
index b9f24fa..2c3bf46 100644
--- a/src/outputgen.cpp
+++ b/src/outputgen.cpp
@@ -1,12 +1,12 @@
/******************************************************************************
*
- *
+ *
*
* 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
+ * 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.
*
@@ -15,6 +15,8 @@
*
*/
+#include <stdexcept>
+
#include <stdlib.h>
#include <qfile.h>
@@ -23,55 +25,124 @@
#include "message.h"
#include "portable.h"
-OutputGenerator::OutputGenerator()
+OutputGenerator::OutputGenerator(const char *dir) : m_dir(dir)
{
//printf("OutputGenerator::OutputGenerator()\n");
- m_file=0;
- m_active=TRUE;
- m_genStack = new QStack<bool>;
- m_genStack->setAutoDelete(TRUE);
}
OutputGenerator::~OutputGenerator()
{
//printf("OutputGenerator::~OutputGenerator()\n");
- delete m_file;
- delete m_genStack;
+}
+
+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 = new QFile(m_fileName);
- if (!m_file->open(IO_WriteOnly))
+ 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);
+ t.setDevice(&m_file);
}
void OutputGenerator::endPlainFile()
{
t.unsetDevice();
- delete m_file;
- m_file=0;
+ 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(new bool(isEnabled()));
+ 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());
- bool *lb = m_genStack->pop();
- ASSERT(lb!=0);
- if (lb==0) return; // for some robustness against superfluous \endhtmlonly commands.
- if (*lb) enable(); else disable();
- delete lb;
+ 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;
}