Doxygen
Loading...
Searching...
No Matches
PlantumlManager Class Reference

Singleton that manages plantuml relation actions. More...

#include <src/plantuml.h>

Public Types

enum  OutputFormat { PUML_BITMAP , PUML_EPS , PUML_SVG }
 Plant UML output image formats. More...
using FilesMap = std::map< std::string, StringVector >
using ContentMap = std::map< std::string, PlantumlContent >

Public Member Functions

bool needToRun () const
void run ()
 Run plant UML tool for all images.
StringVector writePlantUMLSource (const DString &outDirArg, const DString &fileName, const DString &content, OutputFormat format, const DString &engine, const DString &srcFile, int srcLine, bool inlineCode)
 Write a PlantUML compatible file.
void generatePlantUMLOutput (const DString &baseName, const DString &outDir, OutputFormat format, bool toIndex)
 Convert a PlantUML file to an image.

Static Public Member Functions

static PlantumlManagerinstance ()
static bool isEnabled ()
 Returns true if doxygen has been configured to run PlantUML, i.e.

Private Member Functions

 PlantumlManager ()
void insert (const std::string &key, const std::string &value, const DString &outDir, OutputFormat format, const DString &puContent, const DString &srcFile, int srcLine)
void generatePlantUmlFileNames (const DString &fileName, OutputFormat format, const DString &outDir, DString &baseName, DString &puName, DString &imgName)

Private Attributes

FilesMap m_pngPlantumlFiles
FilesMap m_svgPlantumlFiles
FilesMap m_epsPlantumlFiles
ContentMap m_pngPlantumlContent
ContentMap m_svgPlantumlContent
ContentMap m_epsPlantumlContent

Detailed Description

Singleton that manages plantuml relation actions.

Definition at line 39 of file plantuml.h.

Member Typedef Documentation

◆ ContentMap

using PlantumlManager::ContentMap = std::map< std::string, PlantumlContent >

Definition at line 88 of file plantuml.h.

◆ FilesMap

using PlantumlManager::FilesMap = std::map< std::string, StringVector >

Definition at line 87 of file plantuml.h.

Member Enumeration Documentation

◆ OutputFormat

Plant UML output image formats.

Enumerator
PUML_BITMAP 
PUML_EPS 
PUML_SVG 

Definition at line 43 of file plantuml.h.

Constructor & Destructor Documentation

◆ PlantumlManager()

PlantumlManager::PlantumlManager ( )
private

Definition at line 236 of file plantuml.cpp.

237{
238}

Referenced by instance().

Member Function Documentation

◆ generatePlantUmlFileNames()

void PlantumlManager::generatePlantUmlFileNames ( const DString & fileName,
OutputFormat format,
const DString & outDir,
DString & baseName,
DString & puName,
DString & imgName )
private

Definition at line 168 of file plantuml.cpp.

170{
171 static int umlindex=1;
172
173 if (fileName.empty()) // generate name
174 {
175 std::lock_guard<std::mutex> lock(g_PlantUmlMutex);
176 puName = "inline_umlgraph_"+DString().setNum(umlindex);
177 baseName = outDir+"/inline_umlgraph_"+DString().setNum(umlindex++);
178 }
179 else // user specified name
180 {
181 baseName = fileName;
182 if (size_t i=baseName.rfind('.'); i!=DString::npos) baseName = baseName.left(i);
183 puName = baseName;
184 baseName.prepend(outDir+"/");
185 }
186
187 switch (format)
188 {
189 case PUML_BITMAP:
190 imgName =puName+".png";
191 break;
192 case PUML_EPS:
193 imgName =puName+".eps";
194 break;
195 case PUML_SVG:
196 imgName =puName+".svg";
197 break;
198 }
199}
DString & setNum(short n)
Definition dstring.h:556
DString()=default
size_t rfind(char c, size_t pos=npos) const
Definition dstring.h:248
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:152
static constexpr size_t npos
value used to indicate 'not found' or 'to the end of the string', matching std::string::npos
Definition dstring.h:182
DString & prepend(const char *s)
Definition dstring.h:519
DString left(size_t len) const
Definition dstring.h:310
static std::mutex g_PlantUmlMutex
Definition plantuml.cpp:29

References DString::DString(), DString::empty(), g_PlantUmlMutex, DString::left(), DString::npos, DString::prepend(), PUML_BITMAP, PUML_EPS, PUML_SVG, DString::rfind(), and DString::setNum().

Referenced by writePlantUMLSource().

◆ generatePlantUMLOutput()

void PlantumlManager::generatePlantUMLOutput ( const DString & baseName,
const DString & outDir,
OutputFormat format,
bool toIndex )

Convert a PlantUML file to an image.

Parameters
[in]baseNamethe name of the generated file (as returned by writePlantUMLSource())
[in]outDirthe directory to write the resulting image into.
[in]formatthe image format to generate.
[in]toIndexadd the file to the index lists for htmlhelp / qhc etc.

Definition at line 201 of file plantuml.cpp.

202{
203 if (!toIndex) return;
204 DString imgName = baseName;
205 // The basename contains path, we need to strip the path from the filename in order
206 // to create the image file name which should be included in the index.qhp (Qt help index file).
207 if (size_t i = imgName.rfind('/'); i!=DString::npos) // strip path
208 {
209 imgName=imgName.mid(i+1);
210 }
211 switch (format)
212 {
213 case PUML_BITMAP:
214 imgName+=".png";
215 break;
216 case PUML_EPS:
217 imgName+=".eps";
218 break;
219 case PUML_SVG:
220 imgName+=".svg";
221 break;
222 }
223
225}
DString mid(size_t index, size_t len=npos) const
Definition dstring.h:322
static IndexList * indexList
Definition doxygen.h:125
void addImageFile(const DString &name)
Definition indexlist.h:124

References IndexList::addImageFile(), Doxygen::indexList, DString::mid(), DString::npos, PUML_BITMAP, PUML_EPS, PUML_SVG, and DString::rfind().

Referenced by FlowChart::printUmlTree(), DocbookDocVisitor::startPlantUmlFile(), LatexDocVisitor::startPlantUmlFile(), DocbookDocVisitor::writePlantUMLFile(), HtmlDocVisitor::writePlantUMLFile(), LatexDocVisitor::writePlantUMLFile(), and RTFDocVisitor::writePlantUMLFile().

◆ insert()

void PlantumlManager::insert ( const std::string & key,
const std::string & value,
const DString & outDir,
OutputFormat format,
const DString & puContent,
const DString & srcFile,
int srcLine )
private

Definition at line 484 of file plantuml.cpp.

487{
488 Debug::print(Debug::Plantuml,0,"*** PlantumlManager::insert key:{} ,value:{}\n",key,value);
489
490 switch (format)
491 {
492 case PUML_BITMAP:
495 addPlantumlContent(m_pngPlantumlContent,key,outDir,puContent,srcFile,srcLine);
497 break;
498 case PUML_EPS:
501 addPlantumlContent(m_epsPlantumlContent,key,outDir,puContent,srcFile,srcLine);
503 break;
504 case PUML_SVG:
507 addPlantumlContent(m_svgPlantumlContent,key,outDir,puContent,srcFile,srcLine);
509 break;
510 }
511}
@ Plantuml
Definition debug.h:40
static void print(DebugMask mask, int prio, fmt::format_string< Args... > fmt, Args &&... args)
Definition debug.h:78
ContentMap m_pngPlantumlContent
Definition plantuml.h:104
ContentMap m_epsPlantumlContent
Definition plantuml.h:106
ContentMap m_svgPlantumlContent
Definition plantuml.h:105
FilesMap m_pngPlantumlFiles
Definition plantuml.h:101
FilesMap m_svgPlantumlFiles
Definition plantuml.h:102
FilesMap m_epsPlantumlFiles
Definition plantuml.h:103
static void addPlantumlContent(PlantumlManager::ContentMap &plantumlContent, const std::string &key, const DString &outDir, const DString &puContent, const DString &srcFile, int srcLine)
Definition plantuml.cpp:472
static void print(const PlantumlManager::FilesMap &plantumlFiles)
Definition plantuml.cpp:434
static void addPlantumlFiles(PlantumlManager::FilesMap &plantumlFiles, const std::string &key, const std::string &value)
Definition plantuml.cpp:461

References addPlantumlContent(), addPlantumlFiles(), m_epsPlantumlContent, m_epsPlantumlFiles, m_pngPlantumlContent, m_pngPlantumlFiles, m_svgPlantumlContent, m_svgPlantumlFiles, Debug::Plantuml, Debug::print(), print(), PUML_BITMAP, PUML_EPS, and PUML_SVG.

Referenced by writePlantUMLSource().

◆ instance()

◆ isEnabled()

bool PlantumlManager::isEnabled ( )
static

Returns true if doxygen has been configured to run PlantUML, i.e.

when PLANTUML_JAR_PATH or PLANTUML_TOOL has been set.

Definition at line 240 of file plantuml.cpp.

241{
242 return !Config_getString(PLANTUML_JAR_PATH).empty() ||
243 !Config_getString(PLANTUML_TOOL).empty();
244}
#define Config_getString(name)
Definition config.h:32

References Config_getString.

Referenced by DocPara::handleCommand(), Markdown::Private::processQuotations(), and FlowChart::writeFlowChart().

◆ needToRun()

bool PlantumlManager::needToRun ( ) const
inline

Definition at line 52 of file plantuml.h.

53 {
54 return !m_pngPlantumlContent.empty() ||
55 !m_svgPlantumlContent.empty() ||
56 !m_epsPlantumlContent.empty();
57 }

References m_epsPlantumlContent, m_pngPlantumlContent, and m_svgPlantumlContent.

◆ run()

void PlantumlManager::run ( )

Run plant UML tool for all images.

Definition at line 426 of file plantuml.cpp.

427{
428 Debug::print(Debug::Plantuml,0,"*** PlantumlManager::run\n");
432}
static void runPlantumlContent(const PlantumlManager::FilesMap &plantumlFiles, const PlantumlManager::ContentMap &plantumlContent, PlantumlManager::OutputFormat format)
Definition plantuml.cpp:261

References m_epsPlantumlContent, m_epsPlantumlFiles, m_pngPlantumlContent, m_pngPlantumlFiles, m_svgPlantumlContent, m_svgPlantumlFiles, Debug::Plantuml, Debug::print(), PUML_BITMAP, PUML_EPS, PUML_SVG, and runPlantumlContent().

Referenced by generateOutput().

◆ writePlantUMLSource()

StringVector PlantumlManager::writePlantUMLSource ( const DString & outDirArg,
const DString & fileName,
const DString & content,
OutputFormat format,
const DString & engine,
const DString & srcFile,
int srcLine,
bool inlineCode )

Write a PlantUML compatible file.

Parameters
[in]outDirArgthe output directory to write the file to.
[in]fileNamethe name of the file. If empty a name will be chosen automatically.
[in]contentthe contents of the PlantUML file.
[in]formatthe image format to generate.
[in]enginethe plantuml engine to use.
[in]srcFilethe source file resulting in the write command.
[in]srcLinethe line number resulting in the write command.
[in]inlineCodethe code is coming from the \statuml ... \enduml (true) command or from the \planumlfile command (false)
Returns
The names of the generated files.

Definition at line 31 of file plantuml.cpp.

34{
35 StringVector baseNameVector;
36 DString baseName;
37 DString puName;
38 DString imgName;
39 DString outDir(outDirArg);
40
41 Debug::print(Debug::Plantuml,0,"*** writePlantUMLSource fileName: {}\n",fileName);
42 Debug::print(Debug::Plantuml,0,"*** writePlantUMLSource outDir: {}\n",outDir);
43
44 // strip any trailing slashes and backslashes
45 size_t l = 0;
46 while ((l=outDir.length())>0 && (outDir.at(l-1)=='/' || outDir.at(l-1)=='\\'))
47 {
48 outDir = outDir.left(l-1);
49 }
50
51 generatePlantUmlFileNames(fileName,format,outDir,baseName,puName,imgName);
52
53 Debug::print(Debug::Plantuml,0,"*** writePlantUMLSourcebaseName: {}\n",baseName);
54 Debug::print(Debug::Plantuml,0,"*** writePlantUMLSourcebaseName puName: {}\n",puName);
55 Debug::print(Debug::Plantuml,0,"*** writePlantUMLSourcebaseName imgName: {}\n",imgName);
56
57 DString text;
58 if (inlineCode) text = "@start"+engine+" "+imgName+"\n";
59 text.reserve(text.length()+content.length()+100); // add room for image name and end marker
60 const char *p = content.data();
61 if (p)
62 {
63 char c = 0;
64 bool insideComment = false;
65 DString locEngine;
66 while ((c=*p++))
67 {
68 text+=c;
69 switch (c)
70 {
71 case '\'': insideComment=true; break;
72 case '\n': insideComment=false; break;
73 case '\t': break;
74 case ' ': break;
75 case '@':
76 if (!insideComment && literal_at(p,"start")) // @start...
77 {
78 locEngine.clear();
79 p+=5;
80 text += "start";
81 while ((c=*p++) && isId(c))
82 {
83 locEngine += c;
84 text+=c;
85 }
86 DString inpName;
87 DString rest;
88
89 // skip leading whitespace
90 if (*p && (c==' ' || c=='\t'))
91 {
92 while ((c=*p++) && (c==' ' || c=='\t')) {}
93 }
94 // get everything till end or endOfLine, and split into inpName (without extension) and rest
95 enum State { InName, InExt, InRest };
96 State state = InName;
97 while (*p && c!='\n')
98 {
99 switch (state)
100 {
101 case InName: // looking for the name part
102 if (isId(c) || c=='-') { inpName+=c; }
103 else if (c=='.') { state=InExt; }
104 else { rest+=c; state=InRest; }
105 break;
106 case InExt: // skipping over extension part
107 if (!isId(c) && c!='-') { rest+=c; state=InRest; }
108 break;
109 case InRest: // gather rest until new line
110 rest+=c;
111 break;
112 }
113 c = *p++;
114 }
115 //printf("inpName='%s' rest='%s'\n",qPrint(inpName),qPrint(rest));
116 generatePlantUmlFileNames(inpName,format,outDir,baseName,puName,imgName);
117
118 // insert the image name
119 text+=' ';
120 text+=imgName;
121
122 if (!rest.empty())
123 {
124 text += '\n';
125 text += rest;
126 }
127 if (c) text+=c;
128 }
129 else if (!insideComment && strncmp(p,("end"+locEngine).data(), 3+strlen(engine.data()))==0) // @end...
130 {
131 text += "end"+locEngine+"\n";
132 p+=3+locEngine.length();
133 if (!inlineCode)
134 {
135 DString qcOutDir(substitute(outDir,"\\","/"));
136 size_t pos = qcOutDir.rfind('/');
137 DString generateType(pos!=DString::npos ? qcOutDir.mid(pos+1) : qcOutDir);
138 Debug::print(Debug::Plantuml,0,"*** writePlantUMLSource generateType: {}\n",generateType);
139 PlantumlManager::instance().insert(generateType.str(),puName.str(),outDir,format,text,srcFile,srcLine);
140 Debug::print(Debug::Plantuml,0,"*** writePlantUMLSource generateType: {}\n",generateType);
141 baseNameVector.push_back(baseName.str());
142 text.clear();
143 }
144 }
145 break;
146 default:
147 break;
148 }
149 }
150 text+='\n';
151 }
152 if (inlineCode)
153 {
154 text +="@end"+engine+"\n";
155 //printf("content\n====\n%s\n=====\n->\n-----\n%s\n------\n",qPrint(content),qPrint(text));
156 DString qcOutDir(substitute(outDir,"\\","/"));
157 size_t pos = qcOutDir.rfind("/");
158 DString generateType(pos!=DString::npos ? qcOutDir.mid(pos+1) : qcOutDir);
159 Debug::print(Debug::Plantuml,0,"*** writePlantUMLSource generateType: {}\n",generateType);
160 PlantumlManager::instance().insert(generateType.str(),puName.str(),outDir,format,text,srcFile,srcLine);
161 Debug::print(Debug::Plantuml,0,"*** writePlantUMLSource generateType: {}\n",generateType);
162 baseNameVector.push_back(baseName.str());
163 }
164
165 return baseNameVector;
166}
void clear()
Definition dstring.h:218
void reserve(size_t size)
Reserve space for size bytes without changing the string contents.
Definition dstring.h:221
const std::string & str() const
Definition dstring.h:649
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition dstring.h:161
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:155
void insert(const std::string &key, const std::string &value, const DString &outDir, OutputFormat format, const DString &puContent, const DString &srcFile, int srcLine)
Definition plantuml.cpp:484
void generatePlantUmlFileNames(const DString &fileName, OutputFormat format, const DString &outDir, DString &baseName, DString &puName, DString &imgName)
Definition plantuml.cpp:168
static PlantumlManager & instance()
Definition plantuml.cpp:230
std::vector< std::string > StringVector
Definition containers.h:33
DString substitute(const DString &s, const DString &src, const DString &dst)
substitute all occurrences of src in s by dst
Definition dstring.cpp:481
bool isId(int c)
Returns true if c is a valid character for an identifier.
Definition dstring.h:899
bool literal_at(const char *data, const char(&str)[N])
returns true iff data points to a substring that matches string literal str
Definition stringutil.h:101

References DString::at(), DString::clear(), DString::data(), DString::empty(), generatePlantUmlFileNames(), insert(), instance(), isId(), DString::left(), DString::length(), literal_at(), DString::mid(), DString::npos, Debug::Plantuml, Debug::print(), DString::reserve(), DString::rfind(), DString::str(), and substitute().

Referenced by DocbookDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), LatexDocVisitor::operator()(), RTFDocVisitor::operator()(), RTFDocVisitor::operator()(), FlowChart::printUmlTree(), DocbookDocVisitor::startPlantUmlFile(), and LatexDocVisitor::startPlantUmlFile().

Member Data Documentation

◆ m_epsPlantumlContent

ContentMap PlantumlManager::m_epsPlantumlContent
private

Definition at line 106 of file plantuml.h.

Referenced by insert(), needToRun(), and run().

◆ m_epsPlantumlFiles

FilesMap PlantumlManager::m_epsPlantumlFiles
private

Definition at line 103 of file plantuml.h.

Referenced by insert(), and run().

◆ m_pngPlantumlContent

ContentMap PlantumlManager::m_pngPlantumlContent
private

Definition at line 104 of file plantuml.h.

Referenced by insert(), needToRun(), and run().

◆ m_pngPlantumlFiles

FilesMap PlantumlManager::m_pngPlantumlFiles
private

Definition at line 101 of file plantuml.h.

Referenced by insert(), and run().

◆ m_svgPlantumlContent

ContentMap PlantumlManager::m_svgPlantumlContent
private

Definition at line 105 of file plantuml.h.

Referenced by insert(), needToRun(), and run().

◆ m_svgPlantumlFiles

FilesMap PlantumlManager::m_svgPlantumlFiles
private

Definition at line 102 of file plantuml.h.

Referenced by insert(), and run().


The documentation for this class was generated from the following files: