Browse Source

add boolean conversion function

Patrik Kovacs 6 years ago
parent
commit
1246a99bf2
3 changed files with 5 additions and 0 deletions
  1. 1 0
      include/hdf4cpp/HdfAttribute.h
  2. 2 0
      include/hdf4cpp/HdfFile.h
  3. 2 0
      include/hdf4cpp/HdfItem.h

+ 1 - 0
include/hdf4cpp/HdfAttribute.h

@@ -99,6 +99,7 @@ public:
     HdfAttribute(const HdfAttribute&) = delete;
     HdfAttribute(HdfAttribute&& attribute);
     bool isValid() const;
+    explicit operator bool() { return isValid(); }
     Type getType() const;
 
     intn size() const;

+ 2 - 0
include/hdf4cpp/HdfFile.h

@@ -19,6 +19,8 @@ class HdfFile {
     ~HdfFile();
     bool isValid();
 
+    explicit operator bool() { return isValid(); }
+
     HdfItem get(const std::string& name);
     std::vector<HdfItem> getAll(const std::string& name);
 

+ 2 - 0
include/hdf4cpp/HdfItem.h

@@ -52,6 +52,7 @@ public:
     virtual ~HdfItemBase() {}
     virtual bool isValid() const { return id != FAIL; }
 
+
     virtual Type getType() const = 0;
     virtual int32 getId() const = 0;
     virtual std::string getName() const = 0;
@@ -301,6 +302,7 @@ public:
     HdfItem(const HdfItem& item) = delete;
     HdfItem(HdfItem&& item);
     bool isValid() const;
+    explicit operator bool() { return isValid(); }
 
     Type getType() const;
     std::string getName() const;