diff options
Diffstat (limited to 'src/dot.cpp')
-rw-r--r-- | src/dot.cpp | 118 |
1 files changed, 61 insertions, 57 deletions
diff --git a/src/dot.cpp b/src/dot.cpp index f26bee4..ddabbc7 100644 --- a/src/dot.cpp +++ b/src/dot.cpp @@ -13,7 +13,8 @@ * */ -#include <stdlib.h> +#include <cstdlib> +#include <cassert> #include <qdir.h> @@ -83,10 +84,14 @@ DotManager *DotManager::instance() return m_theInstance; } -DotManager::DotManager() : m_runners(1009), m_filePatchers(1009) +void DotManager::deleteInstance() +{ + delete m_theInstance; + m_theInstance=0; +} + +DotManager::DotManager() : m_runners(), m_filePatchers() { - m_runners.setAutoDelete(TRUE); - m_filePatchers.setAutoDelete(TRUE); m_queue = new DotRunnerQueue; int i; int dotNumThreads = Config_getInt(DOT_NUM_THREADS); @@ -94,18 +99,17 @@ DotManager::DotManager() : m_runners(1009), m_filePatchers(1009) { for (i=0;i<dotNumThreads;i++) { - DotWorkerThread *thread = new DotWorkerThread(m_queue); + std::unique_ptr<DotWorkerThread> thread = std::make_unique<DotWorkerThread>(m_queue); thread->start(); if (thread->isRunning()) { - m_workers.append(thread); + m_workers.push_back(std::move(thread)); } else // no more threads available! { - delete thread; } } - ASSERT(m_workers.count()>0); + ASSERT(m_workers.size()>0); } } @@ -114,53 +118,56 @@ DotManager::~DotManager() delete m_queue; } -DotRunner* DotManager::createRunner(const QCString& absDotName, const QCString& md5Hash) +DotRunner* DotManager::createRunner(const std::string &absDotName, const std::string& md5Hash) { - DotRunner * run = m_runners.find(absDotName); - if (run == 0) + DotRunner* rv = nullptr; + auto const runit = m_runners.find(absDotName); + if (runit == m_runners.end()) { - run = new DotRunner(absDotName, md5Hash); - m_runners.insert(absDotName, run); + auto insobj = std::make_unique<DotRunner>(absDotName, md5Hash); + rv = insobj.get(); + m_runners.emplace(absDotName, std::move(insobj)); } else { // we have a match - if (md5Hash != QCString(run->getMd5Hash().data())) + if (md5Hash != runit->second->getMd5Hash()) { err("md5 hash does not match for two different runs of %s !\n", absDotName.data()); } + rv = runit->second.get(); } - return run; + assert(rv); + return rv; } -DotFilePatcher *DotManager::createFilePatcher(const QCString &fileName) +DotFilePatcher *DotManager::createFilePatcher(const std::string &fileName) { - DotFilePatcher *patcher = m_filePatchers.find(fileName); - if (patcher==0) - { - patcher = new DotFilePatcher(fileName); - m_filePatchers.append(fileName,patcher); - } - return patcher; + auto patcher = m_filePatchers.find(fileName); + + if (patcher != m_filePatchers.end()) return &(patcher->second); + + auto rv = m_filePatchers.emplace(fileName, fileName.c_str()); + assert(rv.second); + return &(rv.first->second); } bool DotManager::run() const { - uint numDotRuns = m_runners.count(); - uint numFilePatchers = m_filePatchers.count(); + size_t numDotRuns = m_runners.size(); + size_t numFilePatchers = m_filePatchers.size(); if (numDotRuns+numFilePatchers>1) { - if (m_workers.count()==0) + if (m_workers.size()==0) { msg("Generating dot graphs in single threaded mode...\n"); } else { - msg("Generating dot graphs using %d parallel threads...\n",QMIN(numDotRuns+numFilePatchers,m_workers.count())); + msg("Generating dot graphs using %zu parallel threads...\n",QMIN(numDotRuns+numFilePatchers,m_workers.size())); } } - int i=1; - QDictIterator<DotRunner> li(m_runners); + size_t i=1; bool setPath=FALSE; if (Config_getBool(GENERATE_HTML)) @@ -185,46 +192,45 @@ bool DotManager::run() const } Portable::sysTimerStart(); // fill work queue with dot operations - DotRunner *dr; - int prev=1; - if (m_workers.count()==0) // no threads to work with + size_t prev=1; + if (m_workers.size()==0) // no threads to work with { - for (li.toFirst();(dr=li.current());++li) + for (auto & dr : m_runners) { - msg("Running dot for graph %d/%d\n",prev,numDotRuns); - dr->run(); + msg("Running dot for graph %zu/%zu\n",prev,numDotRuns); + dr.second->run(); prev++; } } else // use multiple threads to run instances of dot in parallel { - for (li.toFirst();(dr=li.current());++li) + for (auto & dr: m_runners) { - m_queue->enqueue(dr); + m_queue->enqueue(dr.second.get()); } // wait for the queue to become empty - while ((i=m_queue->count())>0) + while ((i=m_queue->size())>0) { i = numDotRuns - i; while (i>=prev) { - msg("Running dot for graph %d/%d\n",prev,numDotRuns); + msg("Running dot for graph %zu/%zu\n",prev,numDotRuns); prev++; } Portable::sleep(100); } - while ((int)numDotRuns>=prev) + while (numDotRuns>=prev) { - msg("Running dot for graph %d/%d\n",prev,numDotRuns); + msg("Running dot for graph %zu/%zu\n",prev,numDotRuns); prev++; } // signal the workers we are done - for (i=0;i<(int)m_workers.count();i++) + for (i=0;i<m_workers.size();i++) { m_queue->enqueue(0); // add terminator for each worker } // wait for the workers to finish - for (i=0;i<(int)m_workers.count();i++) + for (i=0;i<m_workers.size();i++) { m_workers.at(i)->wait(); } @@ -237,27 +243,25 @@ bool DotManager::run() const // patch the output file and insert the maps and figures i=1; - SDict<DotFilePatcher>::Iterator di(m_filePatchers); - const DotFilePatcher *fp; // since patching the svg files may involve patching the header of the SVG // (for zoomable SVGs), and patching the .html files requires reading that - // header after the SVG is patched, we first process the .svg files and - // then the other files. - for (di.toFirst();(fp=di.current());++di) + // header after the SVG is patched, we first process the .svg files and + // then the other files. + for (auto & fp : m_filePatchers) { - if (fp->isSVGFile()) + if (fp.second.isSVGFile()) { - msg("Patching output file %d/%d\n",i,numFilePatchers); - if (!fp->run()) return FALSE; + msg("Patching output file %zu/%zu\n",i,numFilePatchers); + if (!fp.second.run()) return FALSE; i++; } } - for (di.toFirst();(fp=di.current());++di) + for (auto& fp : m_filePatchers) { - if (!fp->isSVGFile()) + if (!fp.second.isSVGFile()) { - msg("Patching output file %d/%d\n",i,numFilePatchers); - if (!fp->run()) return FALSE; + msg("Patching output file %zu/%zu\n",i,numFilePatchers); + if (!fp.second.run()) return FALSE; i++; } } @@ -280,7 +284,7 @@ void writeDotGraphFromFile(const char *inFile,const char *outDir, QCString absImgName = d.absPath().utf8()+"/"+imgName; QCString absOutFile = d.absPath().utf8()+"/"+outFile; - DotRunner dotRun(inFile, QCString()); + DotRunner dotRun(inFile); if (format==GOF_BITMAP) { dotRun.addJob(Config_getEnum(DOT_IMAGE_FORMAT),absImgName); @@ -333,7 +337,7 @@ void writeDotImageMapFromFile(FTextStream &t, QCString imgName = baseName+"."+imgExt; QCString absOutFile = d.absPath().utf8()+"/"+mapName; - DotRunner dotRun(inFile, QCString()); + DotRunner dotRun(inFile.data()); dotRun.addJob(MAP_CMD,absOutFile); dotRun.preventCleanUp(); if (!dotRun.run()) |