diff options
Diffstat (limited to 'src/dot.cpp')
-rw-r--r-- | src/dot.cpp | 70 |
1 files changed, 34 insertions, 36 deletions
diff --git a/src/dot.cpp b/src/dot.cpp index f26bee4..acf4db9 100644 --- a/src/dot.cpp +++ b/src/dot.cpp @@ -83,10 +83,8 @@ DotManager *DotManager::instance() return m_theInstance; } -DotManager::DotManager() : m_runners(1009), m_filePatchers(1009) +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); @@ -114,40 +112,44 @@ 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(); + uint numDotRuns = m_runners.size(); + uint numFilePatchers = m_filePatchers.size(); if (numDotRuns+numFilePatchers>1) { if (m_workers.count()==0) @@ -160,7 +162,6 @@ bool DotManager::run() const } } int i=1; - QDictIterator<DotRunner> li(m_runners); bool setPath=FALSE; if (Config_getBool(GENERATE_HTML)) @@ -185,22 +186,21 @@ 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 { - for (li.toFirst();(dr=li.current());++li) + for (auto & dr : m_runners) { msg("Running dot for graph %d/%d\n",prev,numDotRuns); - dr->run(); + 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) @@ -237,27 +237,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) + 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; + 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; + if (!fp.second.run()) return FALSE; i++; } } @@ -280,7 +278,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 +331,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()) |