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 242 of file plantuml.cpp.

243{
244}

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 174 of file plantuml.cpp.

176{
177 static int umlindex=1;
178
179 if (fileName.empty()) // generate name
180 {
181 std::lock_guard<std::mutex> lock(g_PlantUmlMutex);
182 puName = "inline_umlgraph_"+DString().setNum(umlindex);
183 baseName = outDir+"/inline_umlgraph_"+DString().setNum(umlindex++);
184 }
185 else // user specified name
186 {
187 baseName = fileName;
188 if (size_t i=baseName.rfind('.'); i!=DString::npos) baseName = baseName.left(i);
189 puName = baseName;
190 baseName.prepend(outDir+"/");
191 }
192
193 switch (format)
194 {
195 case PUML_BITMAP:
196 imgName =puName+".png";
197 break;
198 case PUML_EPS:
199 imgName =puName+".eps";
200 break;
201 case PUML_SVG:
202 imgName =puName+".svg";
203 break;
204 }
205}
DString & setNum(short n)
Definition dstring.h:552
size_t rfind(char c, size_t pos=npos) const
Definition dstring.h:244
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
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:178
DString & prepend(const char *s)
Definition dstring.h:515
DString left(size_t len) const
Definition dstring.h:306
static std::mutex g_PlantUmlMutex
Definition plantuml.cpp:35

References 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 207 of file plantuml.cpp.

208{
209 if (!toIndex) return;
210 DString imgName = baseName;
211 // The basename contains path, we need to strip the path from the filename in order
212 // to create the image file name which should be included in the index.qhp (Qt help index file).
213 if (size_t i = imgName.rfind('/'); i!=DString::npos) // strip path
214 {
215 imgName=imgName.mid(i+1);
216 }
217 switch (format)
218 {
219 case PUML_BITMAP:
220 imgName+=".png";
221 break;
222 case PUML_EPS:
223 imgName+=".eps";
224 break;
225 case PUML_SVG:
226 imgName+=".svg";
227 break;
228 }
229
231}
DString mid(size_t index, size_t len=npos) const
Definition dstring.h:318
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 490 of file plantuml.cpp.

493{
494 Debug::print(Debug::Plantuml,0,"*** PlantumlManager::insert key:{} ,value:{}\n",key,value);
495
496 switch (format)
497 {
498 case PUML_BITMAP:
501 addPlantumlContent(m_pngPlantumlContent,key,outDir,puContent,srcFile,srcLine);
503 break;
504 case PUML_EPS:
507 addPlantumlContent(m_epsPlantumlContent,key,outDir,puContent,srcFile,srcLine);
509 break;
510 case PUML_SVG:
513 addPlantumlContent(m_svgPlantumlContent,key,outDir,puContent,srcFile,srcLine);
515 break;
516 }
517}
@ 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:478
static void print(const PlantumlManager::FilesMap &plantumlFiles)
Definition plantuml.cpp:440
static void addPlantumlFiles(PlantumlManager::FilesMap &plantumlFiles, const std::string &key, const std::string &value)
Definition plantuml.cpp:467

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 246 of file plantuml.cpp.

247{
248 return !Config_getString(PLANTUML_JAR_PATH).empty() ||
249 !Config_getString(PLANTUML_TOOL).empty();
250}
#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 432 of file plantuml.cpp.

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

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 37 of file plantuml.cpp.

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