Ver código fonte

implement move sementics for HdfDestroyerChain
(clang-tidy performance-move-const-arg)

Fabian Peter Hammerle 6 anos atrás
pai
commit
c0edf9030c
2 arquivos alterados com 22 adições e 4 exclusões
  1. 0 1
      .clang-tidy
  2. 22 3
      include/hdf4cpp/HdfObject.h

+ 0 - 1
.clang-tidy

@@ -39,4 +39,3 @@ WarningsAsErrors: >-
   -clang-diagnostic-return-type,
   -cppcoreguidelines-pro-bounds-pointer-arithmetic,
   -cppcoreguidelines-pro-type-member-init,
-  -performance-move-const-arg,

+ 22 - 3
include/hdf4cpp/HdfObject.h

@@ -24,6 +24,10 @@ class HdfObject {
             : endFunction(endFunction)
             , id(id) {
         }
+        HdfDestroyer(const HdfDestroyer& other)
+            : endFunction(other.endFunction)
+            , id(other.id) {
+        }
         ~HdfDestroyer() {
             endFunction(id);
         }
@@ -38,11 +42,21 @@ class HdfObject {
     /// then the destructor of the destroyer will call the end access function.
     class HdfDestroyerChain {
       public:
-        HdfDestroyerChain() {
-        }
-        HdfDestroyerChain(const HdfDestroyerChain &other)
+        HdfDestroyerChain() = default;
+        HdfDestroyerChain(const HdfDestroyerChain &other) noexcept
             : chain(other.chain) {
         }
+        HdfDestroyerChain(HdfDestroyerChain &&other) noexcept
+            : chain(std::move(other.chain)) {
+        }
+        HdfDestroyerChain &operator=(const HdfDestroyerChain &other) noexcept {
+            chain = other.chain; // copy
+            return *this;
+        }
+        HdfDestroyerChain &operator=(HdfDestroyerChain &&other) noexcept {
+            chain = std::move(other.chain);
+            return *this;
+        }
 
         void emplaceBack(const std::function<int32(int32)> &endFunction, int32 id) {
             chain.emplace_back(new HdfDestroyer(endFunction, id));
@@ -69,6 +83,11 @@ class HdfObject {
         , classType(classType)
         , chain(chain) {
     }
+    HdfObject(const Type &type, const ClassType &classType, HdfDestroyerChain &&chain)
+        : type(type)
+        , classType(classType)
+        , chain(std::move(chain)) {
+    }
     HdfObject(const HdfObject *object)
         : type(object->getType())
         , classType(object->getClassType())