diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2020-03-02 09:41:17 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@gmail.com> | 2020-03-08 15:32:44 (GMT) |
commit | 44867a8c013a2ae6b828ef12af8e81cb73795483 (patch) | |
tree | c81f902ed5de798ea88a6c4e5bd1f7d57c1936ee /Source/CPack/WiX | |
parent | 1bb7474abac4eb3aa7dd1b52d9d09d2205e104f3 (diff) | |
download | CMake-44867a8c013a2ae6b828ef12af8e81cb73795483.zip CMake-44867a8c013a2ae6b828ef12af8e81cb73795483.tar.gz CMake-44867a8c013a2ae6b828ef12af8e81cb73795483.tar.bz2 |
Modernize memory management
Update internals of various classes.
Diffstat (limited to 'Source/CPack/WiX')
-rw-r--r-- | Source/CPack/WiX/cmCPackWIXGenerator.cxx | 13 | ||||
-rw-r--r-- | Source/CPack/WiX/cmCPackWIXGenerator.h | 5 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXPatch.cxx | 2 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXPatchParser.cxx | 22 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXPatchParser.h | 8 |
5 files changed, 27 insertions, 23 deletions
diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.cxx b/Source/CPack/WiX/cmCPackWIXGenerator.cxx index e71a38f..67d3d32 100644 --- a/Source/CPack/WiX/cmCPackWIXGenerator.cxx +++ b/Source/CPack/WiX/cmCPackWIXGenerator.cxx @@ -4,6 +4,7 @@ #include <algorithm> +#include <cm/memory> #include <cm/string_view> #include "cmsys/Directory.hxx" @@ -35,22 +36,16 @@ #include "cmCMakeToWixPath.h" cmCPackWIXGenerator::cmCPackWIXGenerator() - : Patch(0) - , ComponentGuidType(cmWIXSourceWriter::WIX_GENERATED_GUID) + : ComponentGuidType(cmWIXSourceWriter::WIX_GENERATED_GUID) { } -cmCPackWIXGenerator::~cmCPackWIXGenerator() -{ - if (this->Patch) { - delete this->Patch; - } -} +cmCPackWIXGenerator::~cmCPackWIXGenerator() = default; int cmCPackWIXGenerator::InitializeInternal() { componentPackageMethod = ONE_PACKAGE; - this->Patch = new cmWIXPatch(this->Logger); + this->Patch = cm::make_unique<cmWIXPatch>(this->Logger); return this->Superclass::InitializeInternal(); } diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.h b/Source/CPack/WiX/cmCPackWIXGenerator.h index d193348..d5a16ec 100644 --- a/Source/CPack/WiX/cmCPackWIXGenerator.h +++ b/Source/CPack/WiX/cmCPackWIXGenerator.h @@ -4,6 +4,7 @@ #define cmCPackWIXGenerator_h #include <map> +#include <memory> #include <string> #include "cmCPackGenerator.h" @@ -24,6 +25,8 @@ public: cmCPackTypeMacro(cmCPackWIXGenerator, cmCPackGenerator); cmCPackWIXGenerator(); + cmCPackWIXGenerator(const cmCPackWIXGenerator&) = delete; + const cmCPackWIXGenerator& operator=(const cmCPackWIXGenerator&) = delete; ~cmCPackWIXGenerator(); protected: @@ -157,7 +160,7 @@ private: std::string CPackTopLevel; - cmWIXPatch* Patch; + std::unique_ptr<cmWIXPatch> Patch; cmWIXSourceWriter::GuidType ComponentGuidType; }; diff --git a/Source/CPack/WiX/cmWIXPatch.cxx b/Source/CPack/WiX/cmWIXPatch.cxx index ca232f9..122ffaf 100644 --- a/Source/CPack/WiX/cmWIXPatch.cxx +++ b/Source/CPack/WiX/cmWIXPatch.cxx @@ -41,7 +41,7 @@ void cmWIXPatch::ApplyFragment(std::string const& id, void cmWIXPatch::ApplyElementChildren(const cmWIXPatchElement& element, cmWIXSourceWriter& writer) { - for (cmWIXPatchNode* node : element.children) { + for (const auto& node : element.children) { switch (node->type()) { case cmWIXPatchNode::ELEMENT: ApplyElement(dynamic_cast<const cmWIXPatchElement&>(*node), writer); diff --git a/Source/CPack/WiX/cmWIXPatchParser.cxx b/Source/CPack/WiX/cmWIXPatchParser.cxx index fd9103b..5588d2d 100644 --- a/Source/CPack/WiX/cmWIXPatchParser.cxx +++ b/Source/CPack/WiX/cmWIXPatchParser.cxx @@ -2,6 +2,10 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmWIXPatchParser.h" +#include <utility> + +#include <cm/memory> + #include "cm_expat.h" #include "cmCPackGenerator.h" @@ -20,12 +24,8 @@ cmWIXPatchNode::~cmWIXPatchNode() { } -cmWIXPatchElement::~cmWIXPatchElement() -{ - for (cmWIXPatchNode* child : children) { - delete child; - } -} +cmWIXPatchElement::cmWIXPatchElement() = default; +cmWIXPatchElement::~cmWIXPatchElement() = default; cmWIXPatchParser::cmWIXPatchParser(fragment_map_t& fragments, cmCPackLog* logger) @@ -54,8 +54,7 @@ void cmWIXPatchParser::StartElement(const std::string& name, const char** atts) } else if (State == INSIDE_FRAGMENT) { cmWIXPatchElement& parent = *ElementStack.back(); - cmWIXPatchElement* element = new cmWIXPatchElement; - parent.children.push_back(element); + auto element = cm::make_unique<cmWIXPatchElement>(); element->name = name; @@ -66,7 +65,8 @@ void cmWIXPatchParser::StartElement(const std::string& name, const char** atts) element->attributes[key] = value; } - ElementStack.push_back(element); + ElementStack.push_back(element.get()); + parent.children.push_back(std::move(element)); } } @@ -130,10 +130,10 @@ void cmWIXPatchParser::CharacterDataHandler(const char* data, int length) std::string::size_type last = text.find_last_not_of(whitespace); if (first != std::string::npos && last != std::string::npos) { - cmWIXPatchText* text_node = new cmWIXPatchText; + auto text_node = cm::make_unique<cmWIXPatchText>(); text_node->text = text.substr(first, last - first + 1); - parent.children.push_back(text_node); + parent.children.push_back(std::move(text_node)); } } } diff --git a/Source/CPack/WiX/cmWIXPatchParser.h b/Source/CPack/WiX/cmWIXPatchParser.h index 87dd892..8d5d2ad 100644 --- a/Source/CPack/WiX/cmWIXPatchParser.h +++ b/Source/CPack/WiX/cmWIXPatchParser.h @@ -4,6 +4,7 @@ #define cmCPackWIXPatchParser_h #include <map> +#include <memory> #include <vector> #include "cmCPackLog.h" @@ -33,9 +34,14 @@ struct cmWIXPatchElement : cmWIXPatchNode { virtual Type type(); + cmWIXPatchElement(); + + cmWIXPatchElement(const cmWIXPatchElement&) = delete; + const cmWIXPatchElement& operator=(const cmWIXPatchElement&) = delete; + ~cmWIXPatchElement(); - using child_list_t = std::vector<cmWIXPatchNode*>; + using child_list_t = std::vector<std::unique_ptr<cmWIXPatchNode>>; using attributes_t = std::map<std::string, std::string>; std::string name; |