]> granicus.if.org Git - graphviz/commitdiff
store Graphics as managed pointers in Visio::Render instead of raw pointers
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 1 Apr 2021 01:55:16 +0000 (18:55 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 7 Apr 2021 04:30:38 +0000 (21:30 -0700)
This lets us clean up some manual handling of these and stop worrying about
memory management. Note that Visio::Render::ClearGraphicsAndTexts touched in
this commit is effectively a hand written destructor for this class. Presumably
it was implemented in a time before destructors were standardized. We can likely
move the other collections affected here to using smart pointers too and remove
this function entirely eventually.

plugin/visio/VisioRender.cpp
plugin/visio/VisioRender.h

index a965c0c7bb1cf5c1c30005ccd23383a02467eb2d..02d5cc5044142bdb08b89409392ce75c6043a5fa 100644 (file)
@@ -236,9 +236,6 @@ namespace Visio
        
        void Render::ClearGraphicsAndTexts()
        {
-               /* clear graphics */
-               for (Graphics::iterator nextGraphic = _graphics.begin(), lastGraphic = _graphics.end(); nextGraphic != lastGraphic; ++nextGraphic)
-                       delete *nextGraphic;
                _graphics.clear();
                
                /* clear texts */
@@ -256,7 +253,7 @@ namespace Visio
        {
                if (_inComponent)
                        /* if in component, accumulate for end node/edge */
-                       _graphics.push_back(graphic);
+                       _graphics.emplace_back(graphic);
                else
                        /* if outside, output immediately */
                        PrintOuterShape(job, *graphic);         
index cd14d79cfacf6618ee8d4ad0243afe10746d8f8b..d019a06cf613336dc084bee22108f742cf453493 100644 (file)
@@ -12,6 +12,7 @@
 #define VISIORENDER_H
 
 #include <map>
+#include <memory>
 #include <vector>
 
 #include <common/types.h>
@@ -22,7 +23,7 @@
 namespace Visio
 {
        typedef std::map<Agnode_t*, unsigned int> NodeIds;
-       typedef std::vector<Graphic*> Graphics;
+       typedef std::vector<std::unique_ptr<Graphic>> Graphics;
        typedef std::vector<const Text*> Texts;
        typedef std::vector<const Hyperlink*> Hyperlinks;