ソースを参照

deleting unnecessary functions
fixing moving statements

Patrik Kovacs 7 年 前
コミット
275b2c6ff3
3 ファイル変更22 行追加58 行削除
  1. 1 18
      include/hdf4cpp/HdfItem.h
  2. 16 17
      lib/HdfFile.cpp
  3. 5 23
      lib/HdfItem.cpp

+ 1 - 18
include/hdf4cpp/HdfItem.h

@@ -72,9 +72,6 @@ class HdfItem : public HdfObject {
     /// \note This operation is not supported for every item type
     std::vector<int32> getDims();
 
-    /// \returns The number of data being in the item
-    int32 size() const;
-
     /// \returns the attribute of the item with the given name
     /// \param name the name of the attribute
     /// \note If there are multiple attributes with the same name then the first
@@ -155,15 +152,11 @@ class HdfItem : public HdfObject {
         virtual std::string getName() const = 0;
         /// Get the dimensions of the item
         virtual std::vector<int32> getDims() = 0;
-        /// Get the number of data from the item
-        virtual int32 size() const = 0;
         /// Get the attribute from the item given by its name
         virtual HdfAttribute getAttribute(const std::string &name) const = 0;
 
       protected:
         int32 id;
-
-        virtual int32 getDataType() const = 0;
     };
     /// Item class for the SData items
     class HdfDatasetItem : public HdfItemBase {
@@ -174,7 +167,6 @@ class HdfItem : public HdfObject {
         int32 getId() const;
         std::string getName() const;
         std::vector<int32> getDims();
-        int32 size() const;
         HdfAttribute getAttribute(const std::string &name) const;
 
         /// Reads the data in a specific range. See Range
@@ -190,7 +182,7 @@ class HdfItem : public HdfObject {
                 }
                 length *= ranges[i].size();
             }
-            auto it = typeSizeMap.find(getDataType());
+            auto it = typeSizeMap.find(dataType);
             if (it != typeSizeMap.end()) {
                 if ((size_t)it->second != sizeof(T)) {
                     raiseException(BUFFER_SIZE_NOT_ENOUGH);
@@ -227,8 +219,6 @@ class HdfItem : public HdfObject {
         int32 dataType;
         std::string name;
         std::vector<int32> dims;
-
-        int32 getDataType() const;
     };
     /// Item class for VGroup items
     class HdfGroupItem : public HdfItemBase {
@@ -239,14 +229,11 @@ class HdfItem : public HdfObject {
         int32 getId() const;
         std::string getName() const;
         std::vector<int32> getDims();
-        int32 size() const;
 
         HdfAttribute getAttribute(const std::string &name) const;
 
       private:
         std::string name;
-
-        int32 getDataType() const;
     };
     /// Item class for VData items
     class HdfDataItem : public HdfItemBase {
@@ -261,8 +248,6 @@ class HdfItem : public HdfObject {
 
         std::vector<int32> getDims();
 
-        int32 size() const;
-
         HdfAttribute getAttribute(const std::string &name) const;
 
         /// Reads a specific number of the data of a specific field
@@ -353,8 +338,6 @@ class HdfItem : public HdfObject {
         int32 nrRecords;
         int32 interlace;
         int32 recordSize;
-
-        int32 getDataType() const;
     };
 
     HdfItem(HdfItemBase *item, int32 sId, int32 vId);

+ 16 - 17
lib/HdfFile.cpp

@@ -5,11 +5,11 @@
 #include <mfhdf.h>
 #include <stdexcept>
 
+#include <hdf4cpp/HdfAttribute.h>
 #include <hdf4cpp/HdfDefines.h>
 #include <hdf4cpp/HdfException.h>
 #include <hdf4cpp/HdfFile.h>
 #include <hdf4cpp/HdfItem.h>
-#include <hdf4cpp/HdfAttribute.h>
 
 
 hdf4cpp::HdfFile::HdfFile(const std::string &path)
@@ -42,21 +42,20 @@ hdf4cpp::HdfFile::HdfFile(const std::string &path)
     }
 }
 hdf4cpp::HdfFile::HdfFile(HdfFile &&file)
-    : HdfObject(file.getType(), file.getClassType()) {
+    : HdfObject(file.getType(), file.getClassType(), std::move(file.chain)) {
     sId = file.sId;
     vId = file.vId;
-    loneRefs = file.loneRefs;
+    loneRefs = std::move(file.loneRefs);
     file.sId = file.vId = FAIL;
-    loneRefs.clear();
 }
 hdf4cpp::HdfFile &hdf4cpp::HdfFile::operator=(HdfFile &&file) {
     setType(file.getType());
     setClassType(file.getClassType());
+    chain = std::move(file.chain);
     sId = file.sId;
     vId = file.vId;
-    loneRefs = file.loneRefs;
+    loneRefs = std::move(file.loneRefs);
     file.sId = file.vId = FAIL;
-    file.loneRefs.clear();
     return *this;
 }
 hdf4cpp::HdfFile::~HdfFile() {
@@ -81,18 +80,18 @@ int32 hdf4cpp::HdfFile::getDataId(const std::string &name) const {
 }
 hdf4cpp::HdfItem hdf4cpp::HdfFile::get(const std::string &name) const {
     int32 id = getDatasetId(name);
-    if (id == FAIL) {
-        id = getGroupId(name);
-        if (id == FAIL) {
-            id = getDataId(name);
-            if (id == FAIL) {
-                raiseException(INVALID_ID);
-            }
-            return HdfItem(new HdfItem::HdfDataItem(id, chain), sId, vId);
-        }
+    if (id != FAIL) {
+        return HdfItem(new HdfItem::HdfDatasetItem(id, chain), sId, vId);
+    }
+    id = getGroupId(name);
+    if (id != FAIL) {
         return HdfItem(new HdfItem::HdfGroupItem(id, chain), sId, vId);
     }
-    return HdfItem(new HdfItem::HdfDatasetItem(id, chain), sId, vId);
+    id = getDataId(name);
+    if (id != FAIL) {
+        return HdfItem(new HdfItem::HdfDataItem(id, chain), sId, vId);
+    }
+    raiseException(INVALID_ID);
 }
 std::vector<int32> hdf4cpp::HdfFile::getDatasetIds(const std::string &name) const {
     std::vector<int32> ids;
@@ -137,7 +136,7 @@ std::vector<hdf4cpp::HdfItem> hdf4cpp::HdfFile::getAll(const std::string &name)
     for (const auto &id : ids) {
         items.push_back(HdfItem(new HdfItem::HdfGroupItem(id, chain), sId, vId));
     }
-    return std::move(items);
+    return items;
 }
 hdf4cpp::HdfAttribute hdf4cpp::HdfFile::getAttribute(const std::string &name) const {
     return HdfAttribute(new HdfAttribute::HdfDatasetAttribute(sId, name, chain));

+ 5 - 23
lib/HdfItem.cpp

@@ -6,17 +6,17 @@
 #include <hdf4cpp/HdfFile.h>
 #include <hdf4cpp/HdfItem.h>
 #include <mfhdf.h>
+#include <numeric>
 #include <sstream>
 
 hdf4cpp::HdfItem::HdfDatasetItem::HdfDatasetItem(int32 id, const HdfDestroyerChain &chain)
     : HdfItemBase(id, SDATA, chain) {
-    _size = 1;
-    std::for_each(dims.begin(), dims.end(), [this](const int32 &t) { _size *= t; });
     int32 dim[MAX_DIMENSION];
     int32 size;
     char _name[MAX_NAME_LENGTH];
     SDgetinfo(id, _name, &size, dim, &dataType, nullptr);
     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));
 }
@@ -32,14 +32,8 @@ std::string hdf4cpp::HdfItem::HdfDatasetItem::getName() const {
 int32 hdf4cpp::HdfItem::HdfDatasetItem::getId() const {
     return id;
 }
-int32 hdf4cpp::HdfItem::HdfDatasetItem::getDataType() const {
-    return dataType;
-}
 hdf4cpp::HdfItem::HdfDatasetItem::~HdfDatasetItem() {
 }
-int32 hdf4cpp::HdfItem::HdfDatasetItem::size() const {
-    return _size;
-}
 hdf4cpp::HdfItem::HdfGroupItem::HdfGroupItem(int32 id, const HdfDestroyerChain &chain)
     : HdfItemBase(id, VGROUP, chain) {
     char _name[MAX_NAME_LENGTH];
@@ -61,12 +55,6 @@ int32 hdf4cpp::HdfItem::HdfGroupItem::getId() const {
 }
 hdf4cpp::HdfItem::HdfGroupItem::~HdfGroupItem() {
 }
-int32 hdf4cpp::HdfItem::HdfGroupItem::size() const {
-    raiseException(INVALID_OPERATION);
-}
-int32 hdf4cpp::HdfItem::HdfGroupItem::getDataType() const {
-    raiseException(INVALID_OPERATION);
-}
 hdf4cpp::HdfItem::HdfDataItem::HdfDataItem(int32 id, const HdfDestroyerChain &chain)
     : HdfItemBase(id, VDATA, chain) {
     this->chain.pushBack(new HdfDestroyer(&VSdetach, id));
@@ -88,12 +76,6 @@ std::string hdf4cpp::HdfItem::HdfDataItem::getName() const {
 std::vector<int32> hdf4cpp::HdfItem::HdfDataItem::getDims() {
     raiseException(INVALID_OPERATION);
 }
-int32 hdf4cpp::HdfItem::HdfDataItem::size() const {
-    raiseException(INVALID_OPERATION);
-}
-int32 hdf4cpp::HdfItem::HdfDataItem::getDataType() const {
-    return 0;
-}
 hdf4cpp::HdfItem::HdfItem(HdfItemBase *item, int32 sId, int32 vId)
     : HdfObject(item)
     , item(item)
@@ -107,6 +89,9 @@ hdf4cpp::HdfItem::HdfItem(HdfItem &&other)
     , vId(other.vId) {
 }
 hdf4cpp::HdfItem &hdf4cpp::HdfItem::operator=(HdfItem &&it) {
+    setType(it.getType());
+    setClassType(it.getClassType());
+    chain = std::move(it.chain);
     item = std::move(it.item);
     return *this;
 }
@@ -119,9 +104,6 @@ hdf4cpp::HdfAttribute hdf4cpp::HdfItem::getAttribute(const std::string &name) co
 std::string hdf4cpp::HdfItem::getName() const {
     return item->getName();
 }
-int32 hdf4cpp::HdfItem::size() const {
-    return item->size();
-}
 hdf4cpp::HdfItem::Iterator hdf4cpp::HdfItem::begin() const {
     return Iterator(sId, vId, item->getId(), 0, getType(), chain);
 }