Skip to content

Commit

Permalink
Refactoring: modernize PlantumlManager
Browse files Browse the repository at this point in the history
  • Loading branch information
doxygen committed Jan 22, 2021
1 parent 84e655b commit 74d4e12
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 137 deletions.
4 changes: 2 additions & 2 deletions src/docbookvisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ DB_VIS_C
case DocVerbatim::PlantUML:
{
static QCString docbookOutput = Config_getString(DOCBOOK_OUTPUT);
QCString baseName = PlantumlManager::instance()->writePlantUMLSource(docbookOutput,s->exampleFile(),s->text(),PlantumlManager::PUML_BITMAP);
QCString baseName = PlantumlManager::instance().writePlantUMLSource(docbookOutput,s->exampleFile(),s->text(),PlantumlManager::PUML_BITMAP);
QCString shortName = baseName;
int i;
if ((i=shortName.findRev('/'))!=-1)
Expand Down Expand Up @@ -1632,7 +1632,7 @@ DB_VIS_C
shortName=shortName.right((int)shortName.length()-i-1);
}
QCString outDir = Config_getString(DOCBOOK_OUTPUT);
PlantumlManager::instance()->generatePlantUMLOutput(baseName,outDir,PlantumlManager::PUML_BITMAP);
PlantumlManager::instance().generatePlantUMLOutput(baseName,outDir,PlantumlManager::PUML_BITMAP);
visitPreStart(m_t, s->children(), s->hasCaption(), s->relPath() + shortName + ".png", s->width(),s->height());
visitCaption(s->children());
visitPostEnd(m_t, s->hasCaption());
Expand Down
2 changes: 1 addition & 1 deletion src/doxygen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11793,7 +11793,7 @@ void generateOutput()
warn_flush();

g_s.begin("Running plantuml with JAVA...\n");
PlantumlManager::instance()->run();
PlantumlManager::instance().run();
g_s.end();

warn_flush();
Expand Down
6 changes: 3 additions & 3 deletions src/htmldocvisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ void HtmlDocVisitor::visit(DocVerbatim *s)
{
format = PlantumlManager::PUML_SVG;
}
QCString baseName = PlantumlManager::instance()->writePlantUMLSource(htmlOutput,s->exampleFile(),s->text(),format);
QCString baseName = PlantumlManager::instance().writePlantUMLSource(htmlOutput,s->exampleFile(),s->text(),format);
m_t << "<div class=\"plantumlgraph\">" << endl;
writePlantUMLFile(baseName,s->relPath(),s->context());
visitPreCaption(m_t, s);
Expand Down Expand Up @@ -2351,15 +2351,15 @@ void HtmlDocVisitor::writePlantUMLFile(const QCString &fileName,
QCString imgExt = getDotImageExtension();
if (imgExt=="svg")
{
PlantumlManager::instance()->generatePlantUMLOutput(fileName,outDir,PlantumlManager::PUML_SVG);
PlantumlManager::instance().generatePlantUMLOutput(fileName,outDir,PlantumlManager::PUML_SVG);
//m_t << "<iframe scrolling=\"no\" frameborder=\"0\" src=\"" << relPath << baseName << ".svg" << "\" />" << endl;
//m_t << "<p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p>";
//m_t << "</iframe>" << endl;
m_t << "<object type=\"image/svg+xml\" data=\"" << relPath << baseName << ".svg\"></object>" << endl;
}
else
{
PlantumlManager::instance()->generatePlantUMLOutput(fileName,outDir,PlantumlManager::PUML_BITMAP);
PlantumlManager::instance().generatePlantUMLOutput(fileName,outDir,PlantumlManager::PUML_BITMAP);
m_t << "<img src=\"" << relPath << baseName << ".png" << "\" />" << endl;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/latexdocvisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ void LatexDocVisitor::visit(DocVerbatim *s)
case DocVerbatim::PlantUML:
{
QCString latexOutput = Config_getString(LATEX_OUTPUT);
QCString baseName = PlantumlManager::instance()->writePlantUMLSource(latexOutput,s->exampleFile(),s->text(),PlantumlManager::PUML_EPS);
QCString baseName = PlantumlManager::instance().writePlantUMLSource(latexOutput,s->exampleFile(),s->text(),PlantumlManager::PUML_EPS);

writePlantUMLFile(baseName, s);
}
Expand Down Expand Up @@ -1946,7 +1946,7 @@ void LatexDocVisitor::writePlantUMLFile(const QCString &baseName, DocVerbatim *s
shortName=shortName.right(shortName.length()-i-1);
}
QCString outDir = Config_getString(LATEX_OUTPUT);
PlantumlManager::instance()->generatePlantUMLOutput(baseName,outDir,PlantumlManager::PUML_EPS);
PlantumlManager::instance().generatePlantUMLOutput(baseName,outDir,PlantumlManager::PUML_EPS);
visitPreStart(m_t, s->hasCaption(), shortName, s->width(), s->height());
visitCaption(this, s->children());
visitPostEnd(m_t, s->hasCaption());
Expand Down
155 changes: 47 additions & 108 deletions src/plantuml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@
#include "portable.h"
#include "config.h"
#include "doxygen.h"
#include "index.h"
#include "message.h"
#include "debug.h"

#include <qdir.h>
#include <qdict.h>
#include <qlist.h>

#include <qfileinfo.h>

QCString PlantumlManager::writePlantUMLSource(const QCString &outDirArg,const QCString &fileName,const QCString &content,OutputFormat format)
{
Expand Down Expand Up @@ -84,7 +80,7 @@ QCString PlantumlManager::writePlantUMLSource(const QCString &outDirArg,const QC
uint pos = qcOutDir.findRev("/");
QCString generateType(qcOutDir.right(qcOutDir.length() - (pos + 1)) );
Debug::print(Debug::Plantuml,0,"*** %s generateType: %s\n","writePlantUMLSource",qPrint(generateType));
PlantumlManager::instance()->insert(generateType,puName,outDir,format,text);
PlantumlManager::instance().insert(generateType.str(),puName.str(),outDir,format,text);
Debug::print(Debug::Plantuml,0,"*** %s generateType: %s\n","writePlantUMLSource",qPrint(generateType));

return baseName;
Expand Down Expand Up @@ -122,71 +118,26 @@ void PlantumlManager::generatePlantUMLOutput(const char *baseName,const char *ou

//--------------------------------------------------------------------

PlantumlManager *PlantumlManager::m_theInstance = 0;

PlantumlManager *PlantumlManager::instance()
PlantumlManager &PlantumlManager::instance()
{
if (!m_theInstance)
{
m_theInstance = new PlantumlManager;
QCString outputFilename = Config_getString(OUTPUT_DIRECTORY) + "/" + CACHE_FILENAME;
QFileInfo fi(outputFilename);
if (fi.exists())
{
m_theInstance->m_cachedPlantumlAllContent = fileToString(outputFilename);
}
else
{
m_theInstance->m_cachedPlantumlAllContent = "";
}
Debug::print(Debug::Plantuml,0,"*** instance() : m_cachedPlantumlAllContent = [%s]\n",qPrint(m_theInstance->m_cachedPlantumlAllContent));
m_theInstance->m_pngPlantumlContent.clear();
m_theInstance->m_svgPlantumlContent.clear();
m_theInstance->m_epsPlantumlContent.clear();
}
return m_theInstance;
static PlantumlManager theInstance;
return theInstance;
}

PlantumlManager::PlantumlManager()
{
}

PlantumlManager::~PlantumlManager()
{
{
QDictIterator< QList<QCString> > it( m_pngPlantumlFiles); // See QDictIterator
QList<QCString> *list;
for (it.toFirst();(list=it.current());++it)
{
(*list).clear();
}
m_pngPlantumlFiles.clear();
m_pngPlantumlContent.clear();
}
{
QDictIterator< QList<QCString> > it( m_epsPlantumlFiles); // See QDictIterator
QList<QCString> *list;
for (it.toFirst();(list=it.current());++it)
{
(*list).clear();
}
m_epsPlantumlFiles.clear();
m_epsPlantumlContent.clear();
}
QCString outputFilename = Config_getString(OUTPUT_DIRECTORY) + "/" + CACHE_FILENAME;
QFileInfo fi(outputFilename);
if (fi.exists())
{
QDictIterator< QList<QCString> > it( m_svgPlantumlFiles); // See QDictIterator
QList<QCString> *list;
for (it.toFirst();(list=it.current());++it)
{
(*list).clear();
}
m_svgPlantumlFiles.clear();
m_svgPlantumlContent.clear();
m_cachedPlantumlAllContent = fileToString(outputFilename);
}
Debug::print(Debug::Plantuml,0,"*** instance() : m_cachedPlantumlAllContent = [%s]\n",qPrint(m_cachedPlantumlAllContent));
}

static void runPlantumlContent(const QDict< QList <QCString> > &plantumlFiles,
const QDict< PlantumlContent > &plantumlContent,
static void runPlantumlContent(const PlantumlManager::FilesMap &plantumlFiles,
const PlantumlManager::ContentMap &plantumlContent,
PlantumlManager::OutputFormat format)
{
/* example : running: java -Djava.awt.headless=true
Expand Down Expand Up @@ -254,26 +205,25 @@ static void runPlantumlContent(const QDict< QList <QCString> > &plantumlFiles,
}

{
QDictIterator< PlantumlContent > it( plantumlContent); // See QDictIterator
PlantumlContent *nb;
for (it.toFirst();(nb=it.current());++it)
for (const auto &kv : plantumlContent)
{
QCString pumlArguments(pumlArgs);
msg("Generating PlantUML %s Files in %s\n",qPrint(pumlType),qPrint(it.currentKey()));
const PlantumlContent &nb = kv.second;
QCString pumlArguments = pumlArgs;
msg("Generating PlantUML %s Files in %s\n",qPrint(pumlType),kv.first.c_str());
pumlArguments+="-o \"";
pumlArguments+=nb->outDir.data();
pumlArguments+=nb.outDir;
pumlArguments+="\" ";
pumlArguments+="-charset UTF-8 -t";
pumlArguments+=pumlType;
pumlArguments+=" ";

QCString puFileName("");
puFileName+=nb->outDir.data();
puFileName+=nb.outDir;
puFileName+="/";
pumlOutDir=puFileName;
puFileName+="inline_umlgraph_";
puFileName+=pumlType;
puFileName+=it.currentKey();
puFileName+=kv.first.c_str();
puFileName+=".pu";

pumlArguments+="\"";
Expand All @@ -285,7 +235,7 @@ static void runPlantumlContent(const QDict< QList <QCString> > &plantumlFiles,
{
err("Could not open file %s for writing\n",puFileName.data());
}
file.writeBlock( nb->content, nb->content.length() );
file.writeBlock( nb.content, nb.content.length() );
file.close();
Debug::print(Debug::Plantuml,0,"*** %s Running Plantuml arguments:%s\n","PlantumlManager::runPlantumlContent",qPrint(pumlArguments));

Expand All @@ -305,16 +255,15 @@ static void runPlantumlContent(const QDict< QList <QCString> > &plantumlFiles,
if ( (format==PlantumlManager::PUML_EPS) && (Config_getBool(USE_PDFLATEX)) )
{
Debug::print(Debug::Plantuml,0,"*** %s Running epstopdf\n","PlantumlManager::runPlantumlContent");
QList<QCString> *list = plantumlFiles[it.currentKey()];
if (list)
auto files_kv = plantumlFiles.find(kv.first);
if (files_kv!=plantumlFiles.end())
{
QListIterator<QCString> li(*list);
QCString *str_p;
for (li.toFirst();(str_p=li.current());++li)
for (const auto &str : files_kv->second)
{
const int maxCmdLine = 40960;
QCString epstopdfArgs(maxCmdLine);
epstopdfArgs.sprintf("\"%s%s.eps\" --outfile=\"%s%s.pdf\"",qPrint(pumlOutDir),qPrint(*str_p),qPrint(pumlOutDir),qPrint(*str_p));
epstopdfArgs.sprintf("\"%s%s.eps\" --outfile=\"%s%s.pdf\"",
pumlOutDir.data(),str.c_str(), pumlOutDir.data(),str.c_str());
Portable::sysTimerStart();
if ((exitCode=Portable::system("epstopdf",epstopdfArgs))!=0)
{
Expand Down Expand Up @@ -345,66 +294,56 @@ void PlantumlManager::run()
file.close();
}

static void print(const QDict< QList <QCString> > &plantumlFiles)
static void print(const PlantumlManager::FilesMap &plantumlFiles)
{
if (Debug::isFlagSet(Debug::Plantuml))
{
QDictIterator< QList<QCString> > it( plantumlFiles); // See QDictIterator
QList<QCString> *list;
for (it.toFirst();(list=it.current());++it)
for (const auto &kv : plantumlFiles)
{
Debug::print(Debug::Plantuml,0,"*** %s PlantumlFiles key:%s size:%d\n","PlantumlManager::print Files",qPrint(it.currentKey()),(*list).count());
QListIterator<QCString> li(*list);
QCString *nb;
for (li.toFirst();(nb=li.current());++li)
Debug::print(Debug::Plantuml,0,"*** %s PlantumlFiles key:%s size:%zu\n","PlantumlManager::print Files",kv.first.c_str(),kv.second.size());
for (const auto &s : kv.second)
{
Debug::print(Debug::Plantuml,0,"*** %s list:%s\n","PlantumlManager::print",qPrint(*nb));
Debug::print(Debug::Plantuml,0,"*** %s list:%s\n","PlantumlManager::print",s.c_str());
}
}
}
}

static void print(const QDict<PlantumlContent> &plantumlContent)
static void print(const PlantumlManager::ContentMap &plantumlContent)
{
if (Debug::isFlagSet(Debug::Plantuml))
{
QDictIterator< PlantumlContent > it( plantumlContent); // See QDictIterator
PlantumlContent *nb;
for (it.toFirst();(nb=it.current());++it)
for (const auto &kv : plantumlContent)
{
Debug::print(Debug::Plantuml,0,"*** %s PlantumlContent key:%s\n","PlantumlManager::print Content",qPrint(it.currentKey()));
Debug::print(Debug::Plantuml,0,"*** %s Content :%s\n","PlantumlManager::print",qPrint(nb->content));
Debug::print(Debug::Plantuml,0,"*** %s PlantumlContent key:%s\n","PlantumlManager::print Content",kv.first.c_str());
Debug::print(Debug::Plantuml,0,"*** %s Content :%s\n","PlantumlManager::print",kv.second.content.data());
}
}
}

static void addPlantumlFiles(QDict< QList<QCString> > &plantumlFiles,
const QCString &key , const QCString &value)
static void addPlantumlFiles(PlantumlManager::FilesMap &plantumlFiles,
const std::string &key, const std::string &value)
{
QList<QCString> *list = plantumlFiles.find(key);
if (list==0)
auto kv = plantumlFiles.find(key);
if (kv==plantumlFiles.end())
{
list = new QList<QCString>;
plantumlFiles.insert(key,list);
kv = plantumlFiles.insert(std::make_pair(key,StringVector())).first;
}
list->append(new QCString(value));
kv->second.push_back(value);
}

static void addPlantumlContent(QDict< PlantumlContent > &plantumlContent,
const QCString &key, const QCString &outDir, const QCString &puContent)
static void addPlantumlContent(PlantumlManager::ContentMap &plantumlContent,
const std::string &key, const QCString &outDir, const QCString &puContent)
{
PlantumlContent* content = plantumlContent.find(key);
if (content == 0)
auto kv = plantumlContent.find(key);
if (kv==plantumlContent.end())
{
content = new PlantumlContent("",outDir);
plantumlContent.insert(key,content);
kv = plantumlContent.insert(std::make_pair(key,PlantumlContent("",outDir))).first;
}
(content->content)+=puContent;
kv->second.content+=puContent;
}



void PlantumlManager::insert(const QCString &key, const QCString &value,
void PlantumlManager::insert(const std::string &key, const std::string &value,
const QCString &outDir,OutputFormat format,const QCString &puContent)
{
int find;
Expand Down
Loading

0 comments on commit 74d4e12

Please sign in to comment.