From de0d57c97abe88a1025d5a26ed94a82438468349 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Sat, 23 Mar 2019 19:38:30 +0100 Subject: cmTarget: Use std::unique_ptr instead of custom smart pointer To manage the lifetime of `cmTargetInternals`, the private implementation of `cmTarget`, use `std::unique_ptr` instead of `cmTargetInternalPointer`, which is removed. `cmTarget` is made non-copyable but movable. --- Source/cmTarget.cxx | 40 ++++++---------------------------------- Source/cmTarget.h | 30 ++++++++++++------------------ 2 files changed, 18 insertions(+), 52 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index a92bb9b..38bff1b 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -215,6 +215,7 @@ public: cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, Visibility vis, cmMakefile* mf) + : impl(cm::make_unique()) { assert(mf); impl->TargetType = type; @@ -500,6 +501,11 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, } } +cmTarget::cmTarget(cmTarget&&) noexcept = default; +cmTarget::~cmTarget() = default; + +cmTarget& cmTarget::operator=(cmTarget&&) noexcept = default; + cmStateEnums::TargetType cmTarget::GetType() const { return impl->TargetType; @@ -1967,37 +1973,3 @@ bool cmTarget::GetMappedConfig(std::string const& desired_config, return true; } - -cmTargetInternalPointer::cmTargetInternalPointer() -{ - this->Pointer = new cmTargetInternals; -} - -cmTargetInternalPointer::cmTargetInternalPointer( - cmTargetInternalPointer const& r) -{ - // Ideally cmTarget instances should never be copied. However until - // we can make a sweep to remove that, this copy constructor avoids - // allowing the resources (Internals) to be copied. - this->Pointer = new cmTargetInternals(*r.Pointer); -} - -cmTargetInternalPointer::~cmTargetInternalPointer() -{ - delete this->Pointer; -} - -cmTargetInternalPointer& cmTargetInternalPointer::operator=( - cmTargetInternalPointer const& r) -{ - if (this == &r) { - return *this; - } // avoid warning on HP about self check - // Ideally cmTarget instances should never be copied. However until - // we can make a sweep to remove that, this copy constructor avoids - // allowing the resources (Internals) to be copied. - cmTargetInternals* oldPointer = this->Pointer; - this->Pointer = new cmTargetInternals(*r.Pointer); - delete oldPointer; - return *this; -} diff --git a/Source/cmTarget.h b/Source/cmTarget.h index f6ccdb4..5d90ba7 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -6,6 +6,7 @@ #include "cmConfigure.h" // IWYU pragma: keep #include +#include // IWYU pragma: keep #include #include #include @@ -26,20 +27,6 @@ class cmPropertyMap; class cmSourceFile; class cmTargetInternals; -class cmTargetInternalPointer -{ -public: - cmTargetInternalPointer(); - cmTargetInternalPointer(cmTargetInternalPointer const& r); - ~cmTargetInternalPointer(); - cmTargetInternalPointer& operator=(cmTargetInternalPointer const& r); - cmTargetInternals* operator->() const { return this->Pointer; } - cmTargetInternals* Get() const { return this->Pointer; } - -private: - cmTargetInternals* Pointer; -}; - /** \class cmTarget * \brief Represent a library or executable target loaded from a makefile. * @@ -55,9 +42,6 @@ public: VisibilityImportedGlobally }; - cmTarget(std::string const& name, cmStateEnums::TargetType type, - Visibility vis, cmMakefile* mf); - enum CustomCommandType { PRE_BUILD, @@ -65,6 +49,16 @@ public: POST_BUILD }; + cmTarget(std::string const& name, cmStateEnums::TargetType type, + Visibility vis, cmMakefile* mf); + + cmTarget(cmTarget const&) = delete; + cmTarget(cmTarget&&) noexcept; + ~cmTarget(); + + cmTarget& operator=(cmTarget const&) = delete; + cmTarget& operator=(cmTarget&&) noexcept; + ///! Return the type of target. cmStateEnums::TargetType GetType() const; @@ -263,7 +257,7 @@ private: cmStateEnums::ArtifactType artifact) const; private: - cmTargetInternalPointer impl; + std::unique_ptr impl; }; typedef std::unordered_map cmTargets; -- cgit v0.12