72 const DString &srcFile,
int srcLine)
95 DString mmdName = baseName +
".mmd";
104 err_full(srcFile, srcLine,
"Could not open file {} for writing", mmdName);
119 if (!toIndex)
return;
123 imgName = imgName.
mid(i + 1);
132 if (diagrams.empty())
return;
146 mmdc(mmdc_), args(args_), ext(ext_), srcFile(srcFile_), srcLine(srcLine_) {}
153 std::vector<MermaidCmd> mermaidCmds;
155 for (
const auto &diagram : diagrams)
158 if (diagram.info.content.empty())
continue;
162 DString inputFile = diagram.info.baseName +
".mmd";
163 DString outputFile = diagram.info.baseName +
"." + ext;
170 if (cachedContent == diagram.info.content)
178 args +=
"-q -i \"" + inputFile +
"\" ";
179 args +=
"-o \"" + outputFile +
"\" ";
181 if (!mermaidConfigFile.
empty())
183 args +=
"-c \"" + mermaidConfigFile +
"\" ";
186 mermaidCmds.emplace_back(mmdc, args,ext, diagram.info.srcFile, diagram.info.srcLine);
189 std::size_t numThreads =
static_cast<std::size_t
>(
Config_getInt(DOT_NUM_THREADS));
191 size_t total=mermaidCmds.size();
192 msg(
"Generating {} Mermaid files using {} threads\n", total, numThreads);
196 std::vector< std::future<int> > results;
199 for (
const auto &cmd : mermaidCmds)
201 auto processFile = [&cmd]()
208 "Problems running Mermaid (mmdc). Verify that the command '{} {}' works from the command line. Exit code: {}.",
209 cmd.mmdc, cmd.args, exitCode);
213 results.emplace_back(threadPool.
queue(processFile));
217 for (
auto &f : results)
220 msg(
"Generating Mermaid file {}/{}\n", offset, total);
226 for (
const auto &cmd : mermaidCmds)
229 msg(
"Generating Mermaid file {}/{}\n", offset, total);
236 "Problems running Mermaid (mmdc). Verify that the command '{} {}' works from the command line. Exit code: {}.",
237 cmd.mmdc, cmd.args, exitCode);
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()).
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 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 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)
void run()
Run mmdc tool for all collected diagrams.
OutputFormat
Mermaid output image formats.
static MermaidManager & instance()
void setHasInlineDiagrams()
static DString imageExtension(ImageFormat imageFormat)
static ImageFormat convertToImageFormat(OutputFormat outputFormat)
void generateMermaidOutput(const DString &baseName, const DString &outDir, ImageFormat format, bool toIndex)
Register a generated Mermaid image with the index.
std::vector< MermaidDiagram > DiagramList
DString writeMermaidSource(const DString &outDirArg, const DString &fileName, const DString &content, ImageFormat format, const DString &srcFile, int srcLine)
Write a Mermaid source file and register it for CLI rendering.
Class managing a pool of worker threads.
auto queue(F &&f, Args &&... args) -> std::future< decltype(f(args...))>
Queue the callable function f for the threads to execute.
#define Config_getInt(name)
#define Config_getBool(name)
#define Config_getString(name)
#define Config_getEnum(name)
static void runMermaid(const MermaidManager::DiagramList &diagrams)
static std::mutex g_mermaidMutex
static int g_mermaidIndex
#define err_full(file, line, fmt,...)
int system(const DString &command, const DString &args, bool commandHasConsole=true)
std::ofstream openOutputStream(const DString &name, bool append=false)
Portable versions of functions that are platform dependent.
MermaidDiagramInfo(const DString &baseName_, const DString &content_, const DString &outDir_, const DString &srcFile_, int srcLine_)
DString fileToString(const DString &name, bool filter, bool isSourceCode)
DString getDotImageExtension()
A bunch of utility functions.