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

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

Static Public Member Functions

static PlantumlManagerinstance ()

Private Member Functions

 PlantumlManager ()
void insert (const std::string &key, const std::string &value, const QCString &outDir, OutputFormat format, const QCString &puContent, const QCString &srcFile, int srcLine)
void generatePlantUmlFileNames (const QCString &fileName, OutputFormat format, const QCString &outDir, QCString &baseName, QCString &puName, QCString &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 40 of file plantuml.h.

Member Typedef Documentation

◆ ContentMap

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

Definition at line 76 of file plantuml.h.

◆ FilesMap

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

Definition at line 75 of file plantuml.h.

Member Enumeration Documentation

◆ OutputFormat

Plant UML output image formats.

Enumerator
PUML_BITMAP 
PUML_EPS 
PUML_SVG 

Definition at line 44 of file plantuml.h.

Constructor & Destructor Documentation

◆ PlantumlManager()

PlantumlManager::PlantumlManager ( )
private

Definition at line 237 of file plantuml.cpp.

238{
239}

Referenced by instance().

Member Function Documentation

◆ generatePlantUmlFileNames()

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

Definition at line 168 of file plantuml.cpp.

170{
171 static int umlindex=1;
172
173 if (fileName.isEmpty()) // generate name
174 {
175 std::lock_guard<std::mutex> lock(g_PlantUmlMutex);
176 puName = "inline_umlgraph_"+QCString().setNum(umlindex);
177 baseName = outDir+"/inline_umlgraph_"+QCString().setNum(umlindex++);
178 }
179 else // user specified name
180 {
181 baseName = fileName;
182 int i=baseName.findRev('.');
183 if (i!=-1) baseName = baseName.left(i);
184 puName = baseName;
185 baseName.prepend(outDir+"/");
186 }
187
188 switch (format)
189 {
190 case PUML_BITMAP:
191 imgName =puName+".png";
192 break;
193 case PUML_EPS:
194 imgName =puName+".eps";
195 break;
196 case PUML_SVG:
197 imgName =puName+".svg";
198 break;
199 }
200}
QCString & prepend(const char *s)
Definition qcstring.h:407
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
QCString & setNum(short n)
Definition qcstring.h:444
int findRev(char c, int index=-1, bool cs=TRUE) const
Definition qcstring.cpp:91
QCString left(size_t len) const
Definition qcstring.h:214
static std::mutex g_PlantUmlMutex
Definition plantuml.cpp:29

References QCString::findRev(), g_PlantUmlMutex, QCString::isEmpty(), QCString::left(), QCString::prepend(), PUML_BITMAP, PUML_EPS, PUML_SVG, and QCString::setNum().

Referenced by writePlantUMLSource().

◆ generatePlantUMLOutput()

void PlantumlManager::generatePlantUMLOutput ( const QCString & baseName,
const QCString & outDir,
OutputFormat format )

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.

Definition at line 202 of file plantuml.cpp.

203{
204 QCString 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 int i = imgName.findRev('/');
208 if (i!=-1) // strip path
209 {
210 imgName=imgName.mid(i+1);
211 }
212 switch (format)
213 {
214 case PUML_BITMAP:
215 imgName+=".png";
216 break;
217 case PUML_EPS:
218 imgName+=".eps";
219 break;
220 case PUML_SVG:
221 imgName+=".svg";
222 break;
223 }
224
226}
static IndexList * indexList
Definition doxygen.h:134
void addImageFile(const QCString &name)
Definition indexlist.h:127
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
Definition qcstring.h:226

References QCString::findRev(), Doxygen::indexList, QCString::mid(), PUML_BITMAP, PUML_EPS, and PUML_SVG.

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 QCString & outDir,
OutputFormat format,
const QCString & puContent,
const QCString & srcFile,
int srcLine )
private

Definition at line 447 of file plantuml.cpp.

450{
451 Debug::print(Debug::Plantuml,0,"*** PlantumlManager::insert key:{} ,value:{}\n",key,value);
452
453 switch (format)
454 {
455 case PUML_BITMAP:
458 addPlantumlContent(m_pngPlantumlContent,key,outDir,puContent,srcFile,srcLine);
460 break;
461 case PUML_EPS:
464 addPlantumlContent(m_epsPlantumlContent,key,outDir,puContent,srcFile,srcLine);
466 break;
467 case PUML_SVG:
470 addPlantumlContent(m_svgPlantumlContent,key,outDir,puContent,srcFile,srcLine);
472 break;
473 }
474}
@ Plantuml
Definition debug.h:39
static void print(DebugMask mask, int prio, fmt::format_string< Args... > fmt, Args &&... args)
Definition debug.h:76
ContentMap m_pngPlantumlContent
Definition plantuml.h:92
ContentMap m_epsPlantumlContent
Definition plantuml.h:94
ContentMap m_svgPlantumlContent
Definition plantuml.h:93
FilesMap m_pngPlantumlFiles
Definition plantuml.h:89
FilesMap m_svgPlantumlFiles
Definition plantuml.h:90
FilesMap m_epsPlantumlFiles
Definition plantuml.h:91
static void addPlantumlContent(PlantumlManager::ContentMap &plantumlContent, const std::string &key, const QCString &outDir, const QCString &puContent, const QCString &srcFile, int srcLine)
Definition plantuml.cpp:435
static void print(const PlantumlManager::FilesMap &plantumlFiles)
Definition plantuml.cpp:397
static void addPlantumlFiles(PlantumlManager::FilesMap &plantumlFiles, const std::string &key, const std::string &value)
Definition plantuml.cpp:424

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()

◆ run()

void PlantumlManager::run ( )

Run plant UML tool for all images.

Definition at line 389 of file plantuml.cpp.

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

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 QCString & outDirArg,
const QCString & fileName,
const QCString & content,
OutputFormat format,
const QCString & engine,
const QCString & 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 QCString baseName;
37 QCString puName;
38 QCString imgName;
39 QCString 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 QCString 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 QCString 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 QCString inpName;
87 QCString 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.isEmpty())
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 QCString qcOutDir(substitute(outDir,"\\","/"));
136 uint32_t pos = qcOutDir.findRev("/");
137 QCString generateType(qcOutDir.right(qcOutDir.length() - (pos + 1)) );
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 QCString qcOutDir(substitute(outDir,"\\","/"));
157 uint32_t pos = qcOutDir.findRev("/");
158 QCString generateType(qcOutDir.right(qcOutDir.length() - (pos + 1)) );
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 generatePlantUmlFileNames(const QCString &fileName, OutputFormat format, const QCString &outDir, QCString &baseName, QCString &puName, QCString &imgName)
Definition plantuml.cpp:168
void insert(const std::string &key, const std::string &value, const QCString &outDir, OutputFormat format, const QCString &puContent, const QCString &srcFile, int srcLine)
Definition plantuml.cpp:447
static PlantumlManager & instance()
Definition plantuml.cpp:231
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:153
const std::string & str() const
Definition qcstring.h:537
void reserve(size_t size)
Reserve space for size bytes without changing the string contents.
Definition qcstring.h:172
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition qcstring.h:159
void clear()
Definition qcstring.h:169
std::vector< std::string > StringVector
Definition containers.h:33
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
Definition qcstring.cpp:477
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:98
bool isId(int c)
Definition util.h:208

References QCString::at(), QCString::clear(), QCString::data(), QCString::findRev(), generatePlantUmlFileNames(), insert(), instance(), QCString::isEmpty(), isId(), QCString::left(), QCString::length(), literal_at(), Debug::Plantuml, Debug::print(), QCString::reserve(), QCString::right(), QCString::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 94 of file plantuml.h.

Referenced by insert(), and run().

◆ m_epsPlantumlFiles

FilesMap PlantumlManager::m_epsPlantumlFiles
private

Definition at line 91 of file plantuml.h.

Referenced by insert(), and run().

◆ m_pngPlantumlContent

ContentMap PlantumlManager::m_pngPlantumlContent
private

Definition at line 92 of file plantuml.h.

Referenced by insert(), and run().

◆ m_pngPlantumlFiles

FilesMap PlantumlManager::m_pngPlantumlFiles
private

Definition at line 89 of file plantuml.h.

Referenced by insert(), and run().

◆ m_svgPlantumlContent

ContentMap PlantumlManager::m_svgPlantumlContent
private

Definition at line 93 of file plantuml.h.

Referenced by insert(), and run().

◆ m_svgPlantumlFiles

FilesMap PlantumlManager::m_svgPlantumlFiles
private

Definition at line 90 of file plantuml.h.

Referenced by insert(), and run().


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