Browse Source

refactor HdfDestroyerChain: replace pushBack with emplaceBack
(clang-tidy cppcoreguidelines-owning-memory)

Fabian Peter Hammerle 6 years ago
parent
commit
7eae20e34e
3 changed files with 8 additions and 8 deletions
  1. 2 2
      include/hdf4cpp/HdfObject.h
  2. 3 3
      lib/HdfFile.cpp
  3. 3 3
      lib/HdfItem.cpp

+ 2 - 2
include/hdf4cpp/HdfObject.h

@@ -44,8 +44,8 @@ class HdfObject {
             : chain(other.chain) {
         }
 
-        void pushBack(HdfDestroyer *destroyer) {
-            chain.push_back(std::shared_ptr<HdfDestroyer>(destroyer));
+        void emplaceBack(const std::function<int32(int32)> &endFunction, int32 id) {
+            chain.emplace_back(new HdfDestroyer(endFunction, id));
         }
 
       private:

+ 3 - 3
lib/HdfFile.cpp

@@ -23,9 +23,9 @@ hdf4cpp::HdfFile::HdfFile(const std::string &path)
 
     Vinitialize(vId);
 
-    chain.pushBack(new HdfDestroyer(&SDend, sId));
-    chain.pushBack(new HdfDestroyer(&Vfinish, vId));
-    chain.pushBack(new HdfDestroyer(&Hclose, vId));
+    chain.emplaceBack(&SDend, sId);
+    chain.emplaceBack(&Vfinish, vId);
+    chain.emplaceBack(&Hclose, vId);
 
     int32 loneSize = Vlone(vId, nullptr, 0);
     std::vector<int32> refs((size_t)loneSize);

+ 3 - 3
lib/HdfItem.cpp

@@ -18,7 +18,7 @@ hdf4cpp::HdfItem::HdfDatasetItem::HdfDatasetItem(int32 id, const HdfDestroyerCha
     dims = std::vector<int32>(dim, dim + size);
     _size = std::accumulate(dims.begin(), dims.end(), 1, std::multiplies<int32>());
     name = std::string(_name);
-    this->chain.pushBack(new HdfDestroyer(&SDendaccess, id));
+    this->chain.emplaceBack(&SDendaccess, id);
 }
 std::vector<int32> hdf4cpp::HdfItem::HdfDatasetItem::getDims() {
     return dims;
@@ -38,7 +38,7 @@ hdf4cpp::HdfItem::HdfGroupItem::HdfGroupItem(int32 id, const HdfDestroyerChain &
     char _name[MAX_NAME_LENGTH];
     Vgetname(id, _name);
     name = std::string(_name);
-    this->chain.pushBack(new HdfDestroyer(&Vdetach, id));
+    this->chain.emplaceBack(&Vdetach, id);
 }
 std::vector<int32> hdf4cpp::HdfItem::HdfGroupItem::getDims() {
     raiseException(INVALID_OPERATION);
@@ -55,7 +55,7 @@ int32 hdf4cpp::HdfItem::HdfGroupItem::getId() const {
 hdf4cpp::HdfItem::HdfGroupItem::~HdfGroupItem() = default;
 hdf4cpp::HdfItem::HdfDataItem::HdfDataItem(int32 id, const HdfDestroyerChain &chain)
     : HdfItemBase(id, VDATA, chain) {
-    this->chain.pushBack(new HdfDestroyer(&VSdetach, id));
+    this->chain.emplaceBack(&VSdetach, id);
     char _name[MAX_NAME_LENGTH];
     VSinquire(id, &nrRecords, &interlace, nullptr, &recordSize, _name);
     name = std::string(_name);