33 const DString &srcFile,
int srcLine,
bool inlineCode)
46 while ((l=outDir.
length())>0 && (outDir.
at(l-1)==
'/' || outDir.
at(l-1)==
'\\'))
48 outDir = outDir.
left(l-1);
58 if (inlineCode) text =
"@start"+engine+
" "+imgName+
"\n";
60 const char *p = content.
data();
64 bool insideComment =
false;
71 case '\'': insideComment=
true;
break;
72 case '\n': insideComment=
false;
break;
81 while ((c=*p++) &&
isId(c))
90 if (*p && (c==
' ' || c==
'\t'))
92 while ((c=*p++) && (c==
' ' || c==
'\t')) {}
95 enum State { InName, InExt, InRest };
102 if (
isId(c) || c==
'-') { inpName+=c; }
103 else if (c==
'.') { state=InExt; }
104 else { rest+=c; state=InRest; }
107 if (!
isId(c) && c!=
'-') { rest+=c; state=InRest; }
129 else if (!insideComment && strncmp(p,(
"end"+locEngine).data(), 3+strlen(engine.
data()))==0)
131 text +=
"end"+locEngine+
"\n";
136 size_t pos = qcOutDir.
rfind(
'/');
141 baseNameVector.push_back(baseName.
str());
154 text +=
"@end"+engine+
"\n";
157 size_t pos = qcOutDir.
rfind(
"/");
162 baseNameVector.push_back(baseName.
str());
165 return baseNameVector;
171 static int umlindex=1;
173 if (fileName.
empty())
177 baseName = outDir+
"/inline_umlgraph_"+
DString().
setNum(umlindex++);
190 imgName =puName+
".png";
193 imgName =puName+
".eps";
196 imgName =puName+
".svg";
203 if (!toIndex)
return;
209 imgName=imgName.
mid(i+1);
264 auto it = pumlIncludePathList.begin();
265 if (it!=pumlIncludePathList.end())
267 pumlArgs +=
"-Dplantuml.include.path=\"";
268 pumlArgs += it->
c_str();
271 while (it!=pumlIncludePathList.end())
274 pumlArgs += it->
c_str();
278 if (!pumlIncludePathList.empty()) pumlArgs +=
"\" ";
279 pumlArgs +=
"-Djava.awt.headless=true -jar \""+plantumlJarPath+
"\" ";
280 if (!plantumlConfigFile.
empty())
282 pumlArgs +=
"-config \"";
283 pumlArgs += plantumlConfigFile;
292 pumlArgs +=
"-graphvizdot \"";
310 for (
const auto &[name,nb] : plantumlContent)
312 if (nb.content.empty())
continue;
314 DString pumlArguments = pumlArgs;
315 msg(
"Generating PlantUML {} Files in {}\n",pumlType,name);
316 pumlArguments+=
"-o \"";
317 pumlArguments+=nb.outDir;
318 pumlArguments+=
"\" ";
319 pumlArguments+=
"-charset UTF-8 -t";
320 pumlArguments+=pumlType;
324 puFileName+=nb.outDir;
326 pumlOutDir=puFileName;
327 puFileName+=
"inline_umlgraph_";
328 puFileName+=pumlType;
329 puFileName+=name.
c_str();
333 pumlArguments+=puFileName;
334 pumlArguments+=
"\" ";
347 err_full(nb.srcFile,nb.srcLine,
"Could not open file {} for writing",puFileName);
349 file.write( nb.content.data(), nb.content.length() );
353 if (cachedContent == nb.content)
continue;
357 err_full(nb.srcFile,nb.srcLine,
"Problems running PlantUML. Verify that the command 'java -jar \"{}\" -h' works from the command line. Exit code: {}.",
358 plantumlJarPath,exitCode);
364 auto files_kv = plantumlFiles.find(name);
365 if (files_kv!=plantumlFiles.end())
367 for (
const auto &str : files_kv->second)
369 const int maxCmdLine = 40960;
371 epstopdfArgs.
sprintf(
"\"%s%s.eps\" --outfile=\"%s%s.pdf\"",
372 pumlOutDir.
data(),str.c_str(), pumlOutDir.
data(),str.c_str());
375 err_full(nb.srcFile,nb.srcLine,
"Problems running epstopdf. Check your TeX installation! Exit code: {}.",exitCode);
379 Dir().remove(pumlOutDir.
str()+str+
".eps");
400 for (
const auto &[key,list] : plantumlFiles)
403 for (
const auto &s : list)
415 for (
const auto &[key,content] : plantumlContent)
424 const std::string &key,
const std::string &value)
426 auto kv = plantumlFiles.find(key);
427 if (kv==plantumlFiles.end())
431 kv->second.push_back(value);
435 const std::string &key,
const DString &outDir,
const DString &puContent,
436 const DString &srcFile,
int srcLine)
438 auto kv = plantumlContent.find(key);
439 if (kv==plantumlContent.end())
441 kv = plantumlContent.emplace(key,
PlantumlContent(
"",outDir,srcFile,srcLine)).first;
443 kv->second.content+=puContent;
448 const DString &srcFile,
int srcLine)
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
DString & setNum(short n)
size_t rfind(char c, size_t pos=npos) const
DString mid(size_t index, size_t len=npos) const
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
const char * c_str() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
static constexpr size_t npos
value used to indicate 'not found' or 'to the end of the string', matching std::string::npos
char & at(size_t i)
Returns a reference to the character at index i.
DString & prepend(const char *s)
DString & sprintf(const char *format,...)
void reserve(size_t size)
Reserve space for size bytes without changing the string contents.
DString left(size_t len) const
const std::string & str() const
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
size_t length() const
Returns the length of the string, not counting the 0-terminator.
static bool isFlagSet(const DebugMask mask)
static void print(DebugMask mask, int prio, fmt::format_string< Args... > fmt, Args &&... args)
static IndexList * indexList
Minimal replacement for QFileInfo.
void addImageFile(const DString &name)
ContentMap m_pngPlantumlContent
void generatePlantUMLOutput(const DString &baseName, const DString &outDir, OutputFormat format, bool toIndex)
Convert a PlantUML file to an image.
std::map< std::string, PlantumlContent > ContentMap
void insert(const std::string &key, const std::string &value, const DString &outDir, OutputFormat format, const DString &puContent, const DString &srcFile, int srcLine)
OutputFormat
Plant UML output image formats.
ContentMap m_epsPlantumlContent
std::map< std::string, StringVector > FilesMap
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 generatePlantUmlFileNames(const DString &fileName, OutputFormat format, const DString &outDir, DString &baseName, DString &puName, DString &imgName)
ContentMap m_svgPlantumlContent
FilesMap m_pngPlantumlFiles
static PlantumlManager & instance()
FilesMap m_svgPlantumlFiles
void run()
Run plant UML tool for all images.
FilesMap m_epsPlantumlFiles
#define Config_getList(name)
#define Config_getBool(name)
#define Config_getString(name)
std::vector< std::string > StringVector
DString substitute(const DString &s, const DString &src, const DString &dst)
substitute all occurrences of src in s by dst
#define err_full(file, line, fmt,...)
int system(const DString &command, const DString &args, bool commandHasConsole=true)
DString pathListSeparator()
std::ofstream openOutputStream(const DString &name, bool append=false)
static void runPlantumlContent(const PlantumlManager::FilesMap &plantumlFiles, const PlantumlManager::ContentMap &plantumlContent, PlantumlManager::OutputFormat format)
static std::mutex g_PlantUmlMutex
static void addPlantumlContent(PlantumlManager::ContentMap &plantumlContent, const std::string &key, const DString &outDir, const DString &puContent, const DString &srcFile, int srcLine)
static void print(const PlantumlManager::FilesMap &plantumlFiles)
static void addPlantumlFiles(PlantumlManager::FilesMap &plantumlFiles, const std::string &key, const std::string &value)
Portable versions of functions that are platform dependent.
Some helper functions for std::string.
bool literal_at(const char *data, const char(&str)[N])
returns true iff data points to a substring that matches string literal str
PlantumlContent(const DString &content_, const DString &outDir_, const DString &srcFile_, int srcLine_)
DString fileToString(const DString &name, bool filter, bool isSourceCode)
A bunch of utility functions.