Explorar el Código

making some methods constant

Patrik Kovacs hace 7 años
padre
commit
c8b07cd16c
Se han modificado 5 ficheros con 29 adiciones y 29 borrados
  1. 1 1
      include/hdf4cpp/HdfAttribute.h
  2. 10 10
      include/hdf4cpp/HdfFile.h
  3. 6 6
      include/hdf4cpp/HdfItem.h
  4. 8 8
      lib/HdfFile.cpp
  5. 4 4
      lib/HdfItem.cpp

+ 1 - 1
include/hdf4cpp/HdfAttribute.h

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

+ 10 - 10
include/hdf4cpp/HdfFile.h

@@ -21,12 +21,12 @@ class HdfFile {
     HdfFile& operator=(const HdfFile& file) = delete;
     HdfFile& operator=(HdfFile&& file);
     ~HdfFile();
-    bool isValid();
+    bool isValid() const;
 
-    explicit operator bool() { return isValid(); }
+    explicit operator bool() const { return isValid(); }
 
-    HdfItem get(const std::string& name);
-    std::vector<HdfItem> getAll(const std::string& name);
+    HdfItem get(const std::string& name) const;
+    std::vector<HdfItem> getAll(const std::string& name) const;
 
     HdfAttribute getAttribute(const std::string& name);
 
@@ -38,13 +38,13 @@ class HdfFile {
   private:
     void destroy();
 
-    int32 getDatasetId(const std::string& name);
-    int32 getGroupId(const std::string& name);
-    int32 getDataId(const std::string& name);
+    int32 getDatasetId(const std::string& name) const;
+    int32 getGroupId(const std::string& name) const;
+    int32 getDataId(const std::string& name) const;
 
-    std::vector<int32> getDatasetIds(const std::string& name);
-    std::vector<int32> getGroupIds(const std::string& name);
-    std::vector<int32> getDataIds(const std::string& name);
+    std::vector<int32> getDatasetIds(const std::string& name) const;
+    std::vector<int32> getGroupIds(const std::string& name) const;
+    std::vector<int32> getDataIds(const std::string& name) const;
 
     int32 sId;
     int32 vId;

+ 6 - 6
include/hdf4cpp/HdfItem.h

@@ -99,7 +99,7 @@ public:
         return read(dest, ranges);
     }
 
-    virtual HdfAttribute getAttribute(const std::string& name) = 0;
+    virtual HdfAttribute getAttribute(const std::string& name) const = 0;
 
 protected:
     int32 id;
@@ -117,7 +117,7 @@ public:
     std::string getName() const;
     std::vector<int32> getDims();
     intn size() const;
-    HdfAttribute getAttribute(const std::string& name);
+    HdfAttribute getAttribute(const std::string& name) const;
 
     template <class T> bool read(std::vector<T>& dest, std::vector<Range>& ranges) {
         if(_size == FAIL) {
@@ -187,7 +187,7 @@ public:
     std::vector<int32> getDims();
     intn size() const;
 
-    HdfAttribute getAttribute(const std::string& name);
+    HdfAttribute getAttribute(const std::string& name) const;
 
 private:
     std::string name;
@@ -211,7 +211,7 @@ public:
 
     intn size() const;
 
-    HdfAttribute getAttribute(const std::string &name);
+    HdfAttribute getAttribute(const std::string &name) const;
 
     template<class T>
     bool read(std::vector<T> &dest, const std::string &field, int32 records) {
@@ -304,13 +304,13 @@ public:
     HdfItem& operator=(const HdfItem& item) = delete;
     HdfItem& operator=(HdfItem&& it);
     bool isValid() const;
-    explicit operator bool() { return isValid(); }
+    explicit operator bool() const { return isValid(); }
 
     Type getType() const;
     std::string getName() const;
     std::vector<int32> getDims();
     intn size() const;
-    HdfAttribute getAttribute(const std::string& name);
+    HdfAttribute getAttribute(const std::string& name) const;
 
     template <class T> bool read(std::vector<T>& dest) {
         if(!isValid()) {

+ 8 - 8
lib/HdfFile.cpp

@@ -53,19 +53,19 @@ void hdf4cpp::HdfFile::destroy() {
 hdf4cpp::HdfFile::~HdfFile() {
     destroy();
 }
-int32 hdf4cpp::HdfFile::getDatasetId(const std::string &name) {
+int32 hdf4cpp::HdfFile::getDatasetId(const std::string &name) const {
     int32 index = SDnametoindex(sId, name.c_str());
     return (index == FAIL) ? (FAIL) : (SDselect(sId, index));
 }
-int32 hdf4cpp::HdfFile::getGroupId(const std::string &name) {
+int32 hdf4cpp::HdfFile::getGroupId(const std::string &name) const {
     int32 ref = Vfind(vId, name.c_str());
     return (!ref) ? (FAIL) : (Vattach(vId, ref, "r"));
 }
-int32 hdf4cpp::HdfFile::getDataId(const std::string &name) {
+int32 hdf4cpp::HdfFile::getDataId(const std::string &name) const {
     int32 ref = VSfind(vId, name.c_str());
     return (!ref) ? (FAIL) : (VSattach(vId, ref, "r"));
 }
-hdf4cpp::HdfItem hdf4cpp::HdfFile::get(const std::string& name) {
+hdf4cpp::HdfItem hdf4cpp::HdfFile::get(const std::string& name) const {
     int32 id = getDatasetId(name);
     if(id == FAIL) {
         id = getGroupId(name);
@@ -80,7 +80,7 @@ hdf4cpp::HdfItem hdf4cpp::HdfFile::get(const std::string& name) {
     }
     return HdfItem(new HdfDatasetItem(id), sId, vId);
 }
-std::vector<int32> hdf4cpp::HdfFile::getDatasetIds(const std::string &name) {
+std::vector<int32> hdf4cpp::HdfFile::getDatasetIds(const std::string &name) const {
     std::vector<int32> ids;
     char nameDataset[MAX_NAME_LENGTH];
     int32 datasets, attrs;
@@ -97,7 +97,7 @@ std::vector<int32> hdf4cpp::HdfFile::getDatasetIds(const std::string &name) {
     }
     return ids;
 }
-std::vector<int32> hdf4cpp::HdfFile::getGroupIds(const std::string &name) {
+std::vector<int32> hdf4cpp::HdfFile::getGroupIds(const std::string &name) const {
     std::vector<int32> ids;
     char nameGroup[MAX_NAME_LENGTH];
     int32 ref = Vgetid(vId, -1);
@@ -113,7 +113,7 @@ std::vector<int32> hdf4cpp::HdfFile::getGroupIds(const std::string &name) {
     }
     return ids;
 }
-std::vector<hdf4cpp::HdfItem> hdf4cpp::HdfFile::getAll(const std::string& name) {
+std::vector<hdf4cpp::HdfItem> hdf4cpp::HdfFile::getAll(const std::string& name) const {
     std::vector<HdfItem> items;
     std::vector<int32> ids;
     ids = getDatasetIds(name);
@@ -129,7 +129,7 @@ std::vector<hdf4cpp::HdfItem> hdf4cpp::HdfFile::getAll(const std::string& name)
 hdf4cpp::HdfAttribute hdf4cpp::HdfFile::getAttribute(const std::string &name) {
     return HdfAttribute(new HdfDatasetAttribute(sId, name));
 }
-bool hdf4cpp::HdfFile::isValid() {
+bool hdf4cpp::HdfFile::isValid() const {
     return sId != FAIL || vId != FAIL;
 }
 hdf4cpp::HdfFile::Iterator hdf4cpp::HdfFile::begin() const {

+ 4 - 4
lib/HdfItem.cpp

@@ -29,7 +29,7 @@ std::vector<int32> hdf4cpp::HdfDatasetItem::getDims() {
     SDgetinfo(id, name, &size, dims, &dataType, &nrAtt);
     return std::vector<int32>(dims, dims + size);
 }
-hdf4cpp::HdfAttribute hdf4cpp::HdfDatasetItem::getAttribute(const std::string &name) {
+hdf4cpp::HdfAttribute hdf4cpp::HdfDatasetItem::getAttribute(const std::string &name) const {
     return HdfAttribute(new HdfDatasetAttribute(id, name));
 }
 hdf4cpp::Type hdf4cpp::HdfDatasetItem::getType() const {
@@ -60,7 +60,7 @@ hdf4cpp::HdfGroupItem::HdfGroupItem(int32 id) : HdfItemBase(id) {
 std::vector<int32> hdf4cpp::HdfGroupItem::getDims() {
     throw std::runtime_error("HDF4CPP: getDims not defined for HdfGroupItem");
 }
-hdf4cpp::HdfAttribute hdf4cpp::HdfGroupItem::getAttribute(const std::string &name) {
+hdf4cpp::HdfAttribute hdf4cpp::HdfGroupItem::getAttribute(const std::string &name) const {
     return HdfAttribute(new HdfGroupAttribute(id, name));
 }
 hdf4cpp::Type hdf4cpp::HdfGroupItem::getType() const {
@@ -99,7 +99,7 @@ hdf4cpp::HdfDataItem::~HdfDataItem() {
         VSdetach(id);
     }
 }
-hdf4cpp::HdfAttribute hdf4cpp::HdfDataItem::getAttribute(const std::string &name) {
+hdf4cpp::HdfAttribute hdf4cpp::HdfDataItem::getAttribute(const std::string &name) const {
     return HdfAttribute(new HdfDataAttribute(id, name));
 }
 hdf4cpp::Type hdf4cpp::HdfDataItem::getType() const {
@@ -136,7 +136,7 @@ std::vector<int32> hdf4cpp::HdfItem::getDims() {
         return std::vector<int32>();
     }
 }
-hdf4cpp::HdfAttribute hdf4cpp::HdfItem::getAttribute(const std::string &name) {
+hdf4cpp::HdfAttribute hdf4cpp::HdfItem::getAttribute(const std::string &name) const {
     return item->getAttribute(name);
 }
 hdf4cpp::Type hdf4cpp::HdfItem::getType() const {