Doxygen
dotrunner.h
浏览该文件的文档.
1 /******************************************************************************
2 *
3 * Copyright (C) 1997-2019 by Dimitri van Heesch.
4 *
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation under the terms of the GNU General Public License is hereby
7 * granted. No representations are made about the suitability of this software
8 * for any purpose. It is provided "as is" without express or implied warranty.
9 * See the GNU General Public License for more details.
10 *
11 * Documents produced by Doxygen are derivative works derived from the
12 * input used in their production; they are not affected by this license.
13 *
14 */
15 
16 #ifndef DOTRUNNER_H
17 #define DOTRUNNER_H
18 
19 #include <string>
20 #include <thread>
21 #include <list>
22 #include <queue>
23 #include <mutex>
24 #include <condition_variable>
25 #include <memory>
26 
27 #include "qcstring.h"
28 
29 /** Helper class to run dot from doxygen from multiple threads. */
30 class DotRunner
31 {
32  struct DotJob
33  {
34  DotJob(const QCString &f, const QCString &o, const QCString &a,
35  const QCString &s,int l)
36  : format(f), output(o), args(a), srcFile(s), srcLine(l) {}
39  QCString args;
41  int srcLine;
42  };
43 
44  public:
45  /** Creates a runner for a dot \a file. */
46  DotRunner(const QCString & absDotName, const QCString& md5Hash = QCString());
47 
48  /** Adds an additional job to the run.
49  * Performing multiple jobs one file can be faster.
50  */
51  void addJob(const QCString &format,const QCString &output,const QCString &srcFile,int srcLine);
52 
53  /** Prevent cleanup of the dot file (for user provided dot files) */
54  void preventCleanUp() { m_cleanUp = false; }
55 
56  /** Runs dot for all jobs added. */
57  bool run();
58 
59  QCString getMd5Hash() { return m_md5Hash; }
60 
61  static bool readBoundingBox(const QCString &fileName, int* width, int* height, bool isEps);
62 
63  private:
67  bool m_cleanUp;
68  std::vector<DotJob> m_jobs;
69 };
70 
71 /** Queue of dot jobs to run. */
72 // all methods are thread save
74 {
75  public:
76  void enqueue(DotRunner *runner);
78  size_t size() const;
79  private:
80  std::condition_variable m_bufferNotEmpty;
81  std::queue<DotRunner *> m_queue;
82  mutable std::mutex m_mutex;
83 };
84 
85 /** Worker thread to execute a dot run */
87 {
88  public:
91  void run();
92  void start();
93  bool isRunning() { return m_thread && m_thread->joinable(); }
94  void wait() { m_thread->join(); }
95  private:
96  std::unique_ptr<std::thread> m_thread;
98 };
99 
100 #endif
DotRunner::run
bool run()
Runs dot for all jobs added.
Definition: dotrunner.cpp:172
DotRunner::DotJob::output
QCString output
Definition: dotrunner.h:64
DotRunner
Helper class to run dot from doxygen from multiple threads.
Definition: dotrunner.h:30
DotWorkerThread::isRunning
bool isRunning()
Definition: dotrunner.h:93
DotRunner::DotJob::srcFile
QCString srcFile
Definition: dotrunner.h:66
DotWorkerThread::wait
void wait()
Definition: dotrunner.h:94
DotRunnerQueue::size
size_t size() const
Definition: dotrunner.cpp:277
DotRunner::m_cleanUp
bool m_cleanUp
Definition: dotrunner.h:80
DotWorkerThread::start
void start()
Definition: dotrunner.cpp:307
qcstring.h
DotRunnerQueue::m_queue
std::queue< DotRunner * > m_queue
Definition: dotrunner.h:81
DotRunner::getMd5Hash
QCString getMd5Hash()
Definition: dotrunner.h:72
DotRunner::addJob
void addJob(const QCString &format, const QCString &output, const QCString &srcFile, int srcLine)
Adds an additional job to the run.
Definition: dotrunner.cpp:150
DotRunner::preventCleanUp
void preventCleanUp()
Prevent cleanup of the dot file (for user provided dot files)
Definition: dotrunner.h:67
DotRunner::readBoundingBox
static bool readBoundingBox(const QCString &fileName, int *width, int *height, bool isEps)
Definition: dotrunner.cpp:107
DotRunner::m_file
QCString m_file
Definition: dotrunner.h:77
DotRunnerQueue::enqueue
void enqueue(DotRunner *runner)
Definition: dotrunner.cpp:258
DotRunnerQueue
Queue of dot jobs to run.
Definition: dotrunner.h:73
DotRunner::DotJob::args
QCString args
Definition: dotrunner.h:65
DotRunner::m_md5Hash
QCString m_md5Hash
Definition: dotrunner.h:78
DotWorkerThread
Worker thread to execute a dot run
Definition: dotrunner.h:86
DotRunner::DotJob::format
QCString format
Definition: dotrunner.h:63
DotWorkerThread::run
void run()
Definition: dotrunner.cpp:298
DotRunnerQueue::m_mutex
std::mutex m_mutex
Definition: dotrunner.h:82
DotRunner::DotRunner
DotRunner(const QCString &absDotName, const QCString &md5Hash=QCString())
Creates a runner for a dot file.
Definition: dotrunner.cpp:141
DotWorkerThread::DotWorkerThread
DotWorkerThread(DotRunnerQueue *queue)
Definition: dotrunner.cpp:285
DotRunner::m_jobs
std::vector< DotJob > m_jobs
Definition: dotrunner.h:81
DotRunnerQueue::dequeue
DotRunner * dequeue()
Definition: dotrunner.cpp:265
DotRunner::DotJob
Definition: dotrunner.h:45
DotRunner::m_dotExe
QCString m_dotExe
Definition: dotrunner.h:79
DotWorkerThread::m_thread
std::unique_ptr< std::thread > m_thread
Definition: dotrunner.h:96
DotRunner::DotJob::srcLine
int srcLine
Definition: dotrunner.h:67
DotWorkerThread::~DotWorkerThread
~DotWorkerThread()
Definition: dotrunner.cpp:290
DotRunnerQueue::m_bufferNotEmpty
std::condition_variable m_bufferNotEmpty
Definition: dotrunner.h:80
DotWorkerThread::m_queue
DotRunnerQueue * m_queue
Definition: dotrunner.h:97
DotRunner::DotJob::DotJob
DotJob(const QCString &f, const QCString &o, const QCString &a, const QCString &s, int l)
Definition: dotrunner.h:60
QCString
This is an alternative implementation of QCString.
Definition: qcstring.h:108