Browse Source

move assignment operators

Patrik Kovacs 6 years ago
parent
commit
9791a257ec

+ 4 - 1
include/hdf4cpp/HdfAttribute.h

@@ -97,7 +97,10 @@ class HdfAttribute {
 public:
     HdfAttribute(HdfAttributeBase *attribute) : attribute(attribute) {}
     HdfAttribute(const HdfAttribute&) = delete;
-    HdfAttribute(HdfAttribute&& attribute);
+    HdfAttribute(HdfAttribute&& attr);
+    HdfAttribute& operator=(const HdfAttribute& attribute) = delete;
+    HdfAttribute& operator=(HdfAttribute&& attribute);
+
     bool isValid() const;
     explicit operator bool() { return isValid(); }
     Type getType() const;

+ 6 - 0
include/hdf4cpp/HdfFile.h

@@ -16,6 +16,10 @@ namespace hdf4cpp {
 class HdfFile {
   public:
     HdfFile(const std::string& path);
+    HdfFile(const HdfFile& file) = delete;
+    HdfFile(HdfFile&& file);
+    HdfFile& operator=(const HdfFile& file) = delete;
+    HdfFile& operator=(HdfFile&& file);
     ~HdfFile();
     bool isValid();
 
@@ -32,6 +36,8 @@ class HdfFile {
     Iterator end() const;
 
   private:
+    void destroy();
+
     int32 getDatasetId(const std::string& name);
     int32 getGroupId(const std::string& name);
     int32 getDataId(const std::string& name);

+ 2 - 0
include/hdf4cpp/HdfItem.h

@@ -301,6 +301,8 @@ public:
     HdfItem(HdfItemBase *item, int32 sId, int32 vId) : item(item), sId(sId), vId(vId) {}
     HdfItem(const HdfItem& item) = delete;
     HdfItem(HdfItem&& item);
+    HdfItem& operator=(const HdfItem& item) = delete;
+    HdfItem& operator=(HdfItem&& it);
     bool isValid() const;
     explicit operator bool() { return isValid(); }
 

+ 4 - 0
lib/HdfAttribute.cpp

@@ -90,6 +90,10 @@ int32 hdf4cpp::HdfDataAttribute::getDataType() const {
 }
 hdf4cpp::HdfAttribute::HdfAttribute(HdfAttribute &&other) : attribute(std::move(other.attribute)) {
 }
+hdf4cpp::HdfAttribute& hdf4cpp::HdfAttribute::operator=(HdfAttribute&& attr) {
+    attribute = std::move(attr.attribute);\
+    return *this;
+}
 bool hdf4cpp::HdfAttribute::isValid() const {
     return attribute && attribute->isValid();
 }

+ 20 - 1
lib/HdfFile.cpp

@@ -29,11 +29,30 @@ hdf4cpp::HdfFile::HdfFile(const std::string& path) {
         loneRefs.push_back(std::pair<int32, Type>(ref, VDATA));
     }
 }
-hdf4cpp::HdfFile::~HdfFile() {
+hdf4cpp::HdfFile::HdfFile(HdfFile&& file) {
+    sId = file.sId;
+    vId = file.vId;
+    loneRefs = file.loneRefs;
+    file.sId = file.vId = FAIL;
+    loneRefs.clear();
+}
+hdf4cpp::HdfFile& hdf4cpp::HdfFile::operator=(HdfFile&& file) {
+    destroy();
+    sId = file.sId;
+    vId = file.vId;
+    loneRefs = file.loneRefs;
+    file.sId = file.vId = FAIL;
+    loneRefs.clear();
+    return *this;
+}
+void hdf4cpp::HdfFile::destroy() {
     SDend(sId);
     Vend(vId);
     Hclose(vId);
 }
+hdf4cpp::HdfFile::~HdfFile() {
+    destroy();
+}
 int32 hdf4cpp::HdfFile::getDatasetId(const std::string &name) {
     int32 index = SDnametoindex(sId, name.c_str());
     return (index == FAIL) ? (FAIL) : (SDselect(sId, index));

+ 4 - 0
lib/HdfItem.cpp

@@ -125,6 +125,10 @@ int32 hdf4cpp::HdfDataItem::getDataType() const {
 }
 hdf4cpp::HdfItem::HdfItem(HdfItem&& other) : item(std::move(other.item)), sId(other.sId), vId(other.vId) {
 }
+hdf4cpp::HdfItem& hdf4cpp::HdfItem::operator=(HdfItem&& it) {
+    item = std::move(it.item);
+    return *this;
+}
 std::vector<int32> hdf4cpp::HdfItem::getDims() {
     if(isValid()) {
         return item->getDims();