diff options
Diffstat (limited to 'src/dotrunner.h')
-rw-r--r-- | src/dotrunner.h | 98 |
1 files changed, 31 insertions, 67 deletions
diff --git a/src/dotrunner.h b/src/dotrunner.h index 1b68c18..1b54617 100644 --- a/src/dotrunner.h +++ b/src/dotrunner.h @@ -16,70 +16,29 @@ #ifndef DOTRUNNER_H #define DOTRUNNER_H -#include "qcstring.h" -#include "qlist.h" -#include "qwaitcondition.h" -#include "qthread.h" -#include "qqueue.h" -#include "qmutex.h" - -/** Minimal constant string class that is thread safe, once initialized. */ -class DotConstString -{ - public: - DotConstString() { m_str=0;} - ~DotConstString() { delete[] m_str;} - DotConstString(char const* s) : m_str(0) { set(s); } - DotConstString(const QCString &s) : m_str(0) { set(s); } - DotConstString(const DotConstString &s) : m_str(0) { set(s.data()); } - const char *data() const { return m_str; } - bool isEmpty() const { return m_str==0 || m_str[0]=='\0'; } - - private: - void set(char const* s) - { - delete[] m_str; - m_str=0; - if (s) - { - m_str=new char[strlen(s) + 1]; - qstrcpy(m_str,s); - } - } - - void set(const QCString &s) - { - delete[] m_str; - m_str=0; - if (!s.isEmpty()) - { - m_str=new char[s.length()+1]; - qstrcpy(m_str,s.data()); - } - } - - DotConstString &operator=(const DotConstString &); - - char *m_str; -}; +#include <string> +#include <thread> +#include <list> +#include <queue> +#include <mutex> +#include <condition_variable> +#include <memory> /** Helper class to run dot from doxygen from multiple threads. */ class DotRunner { - public: struct DotJob { - DotJob(const DotConstString & format, - const DotConstString & output, - const DotConstString & args) - : format(format), output(output), args(args) {} - DotConstString format; - DotConstString output; - DotConstString args; + DotJob(std::string f, std::string o, std::string a) + : format(f), output(o), args(a) {} + std::string format; + std::string output; + std::string args; }; + public: /** Creates a runner for a dot \a file. */ - DotRunner(const QCString& absDotName, const QCString& md5Hash); + DotRunner(const std::string& absDotName, const std::string& md5Hash = std::string()); /** Adds an additional job to the run. * Performing multiple jobs one file can be faster. @@ -87,22 +46,22 @@ class DotRunner void addJob(const char *format,const char *output); /** Prevent cleanup of the dot file (for user provided dot files) */ - void preventCleanUp() { m_cleanUp = FALSE; } + void preventCleanUp() { m_cleanUp = false; } /** Runs dot for all jobs added. */ bool run(); // DotConstString const& getFileName() { return m_file; } - DotConstString const& getMd5Hash() { return m_md5Hash; } + std::string const & getMd5Hash() { return m_md5Hash; } static bool readBoundingBox(const char* fileName, int* width, int* height, bool isEps); private: - DotConstString m_file; - DotConstString m_md5Hash; - DotConstString m_dotExe; - bool m_cleanUp; - QList<DotJob> m_jobs; + std::string m_file; + std::string m_md5Hash; + std::string m_dotExe; + bool m_cleanUp; + std::vector<DotJob> m_jobs; }; /** Queue of dot jobs to run. */ @@ -112,20 +71,25 @@ class DotRunnerQueue public: void enqueue(DotRunner *runner); DotRunner *dequeue(); - uint count() const; + size_t size() const; private: - QWaitCondition m_bufferNotEmpty; - QQueue<DotRunner> m_queue; - mutable QMutex m_mutex; + std::condition_variable m_bufferNotEmpty; + std::queue<DotRunner *> m_queue; + mutable std::mutex m_mutex; }; /** Worker thread to execute a dot run */ -class DotWorkerThread : public QThread +class DotWorkerThread { public: DotWorkerThread(DotRunnerQueue *queue); + ~DotWorkerThread(); void run(); + void start(); + bool isRunning() { return m_thread && m_thread->joinable(); } + void wait() { m_thread->join(); } private: + std::unique_ptr<std::thread> m_thread; DotRunnerQueue *m_queue; }; |