From 7501f96ab9605e11c58bc0c9e6412e4db30ba7db Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Wed, 10 Mar 2021 12:52:48 -0500 Subject: Added C++11 override keyword where appropriate (#433) Added H5_OVERRIDE macro for compatibility with both C++11 and older. --- c++/src/H5DataSpace.h | 8 ++++---- c++/src/H5Exception.h | 24 ++++++++++++------------ c++/src/H5File.h | 12 ++++++------ c++/src/H5Group.h | 14 +++++++------- c++/src/H5Include.h | 7 +++++++ c++/src/H5Object.h | 6 +++--- 6 files changed, 39 insertions(+), 32 deletions(-) diff --git a/c++/src/H5DataSpace.h b/c++/src/H5DataSpace.h index f16acfc..470de74 100644 --- a/c++/src/H5DataSpace.h +++ b/c++/src/H5DataSpace.h @@ -43,7 +43,7 @@ class H5_DLLCPP DataSpace : public IdComponent { DataSpace &operator=(const DataSpace &rhs); // Closes this dataspace. - virtual void close(); + virtual void close() H5_OVERRIDE; // Makes copy of an existing dataspace. void copy(const DataSpace &like_space); @@ -115,13 +115,13 @@ class H5_DLLCPP DataSpace : public IdComponent { ///\brief Returns this class name. virtual H5std_string - fromClass() const + fromClass() const H5_OVERRIDE { return ("DataSpace"); } // Gets the dataspace id. - virtual hid_t getId() const; + virtual hid_t getId() const H5_OVERRIDE; // Deletes the global constant static void deleteConstants(); @@ -133,7 +133,7 @@ class H5_DLLCPP DataSpace : public IdComponent { protected: // Sets the dataspace id. - virtual void p_setId(const hid_t new_id); + virtual void p_setId(const hid_t new_id) H5_OVERRIDE; #endif // DOXYGEN_SHOULD_SKIP_THIS diff --git a/c++/src/H5Exception.h b/c++/src/H5Exception.h index 18974fc..9970d22 100644 --- a/c++/src/H5Exception.h +++ b/c++/src/H5Exception.h @@ -90,84 +90,84 @@ class H5_DLLCPP FileIException : public Exception { public: FileIException(const H5std_string &func_name, const H5std_string &message = DEFAULT_MSG); FileIException(); - virtual ~FileIException() throw(); + virtual ~FileIException() throw() H5_OVERRIDE; }; class H5_DLLCPP GroupIException : public Exception { public: GroupIException(const H5std_string &func_name, const H5std_string &message = DEFAULT_MSG); GroupIException(); - virtual ~GroupIException() throw(); + virtual ~GroupIException() throw() H5_OVERRIDE; }; class H5_DLLCPP DataSpaceIException : public Exception { public: DataSpaceIException(const H5std_string &func_name, const H5std_string &message = DEFAULT_MSG); DataSpaceIException(); - virtual ~DataSpaceIException() throw(); + virtual ~DataSpaceIException() throw() H5_OVERRIDE; }; class H5_DLLCPP DataTypeIException : public Exception { public: DataTypeIException(const H5std_string &func_name, const H5std_string &message = DEFAULT_MSG); DataTypeIException(); - virtual ~DataTypeIException() throw(); + virtual ~DataTypeIException() throw() H5_OVERRIDE; }; class H5_DLLCPP ObjHeaderIException : public Exception { public: ObjHeaderIException(const H5std_string &func_name, const H5std_string &message = DEFAULT_MSG); ObjHeaderIException(); - virtual ~ObjHeaderIException() throw(); + virtual ~ObjHeaderIException() throw() H5_OVERRIDE; }; class H5_DLLCPP PropListIException : public Exception { public: PropListIException(const H5std_string &func_name, const H5std_string &message = DEFAULT_MSG); PropListIException(); - virtual ~PropListIException() throw(); + virtual ~PropListIException() throw() H5_OVERRIDE; }; class H5_DLLCPP DataSetIException : public Exception { public: DataSetIException(const H5std_string &func_name, const H5std_string &message = DEFAULT_MSG); DataSetIException(); - virtual ~DataSetIException() throw(); + virtual ~DataSetIException() throw() H5_OVERRIDE; }; class H5_DLLCPP AttributeIException : public Exception { public: AttributeIException(const H5std_string &func_name, const H5std_string &message = DEFAULT_MSG); AttributeIException(); - virtual ~AttributeIException() throw(); + virtual ~AttributeIException() throw() H5_OVERRIDE; }; class H5_DLLCPP ReferenceException : public Exception { public: ReferenceException(const H5std_string &func_name, const H5std_string &message = DEFAULT_MSG); ReferenceException(); - virtual ~ReferenceException() throw(); + virtual ~ReferenceException() throw() H5_OVERRIDE; }; class H5_DLLCPP LibraryIException : public Exception { public: LibraryIException(const H5std_string &func_name, const H5std_string &message = DEFAULT_MSG); LibraryIException(); - virtual ~LibraryIException() throw(); + virtual ~LibraryIException() throw() H5_OVERRIDE; }; class H5_DLLCPP LocationException : public Exception { public: LocationException(const H5std_string &func_name, const H5std_string &message = DEFAULT_MSG); LocationException(); - virtual ~LocationException() throw(); + virtual ~LocationException() throw() H5_OVERRIDE; }; class H5_DLLCPP IdComponentException : public Exception { public: IdComponentException(const H5std_string &func_name, const H5std_string &message = DEFAULT_MSG); IdComponentException(); - virtual ~IdComponentException() throw(); + virtual ~IdComponentException() throw() H5_OVERRIDE; }; // end of IdComponentException } // namespace H5 diff --git a/c++/src/H5File.h b/c++/src/H5File.h index d287031..6126eec 100644 --- a/c++/src/H5File.h +++ b/c++/src/H5File.h @@ -39,7 +39,7 @@ class H5_DLLCPP H5File : public Group { const FileAccPropList &access_plist = FileAccPropList::DEFAULT); // Close this file. - virtual void close(); + virtual void close() H5_OVERRIDE; // Gets a copy of the access property list of this file. FileAccPropList getAccessPlist() const; @@ -96,16 +96,16 @@ class H5_DLLCPP H5File : public Group { ///\brief Returns this class name. virtual H5std_string - fromClass() const + fromClass() const H5_OVERRIDE { return ("H5File"); } // Throw file exception. - virtual void throwException(const H5std_string &func_name, const H5std_string &msg) const; + virtual void throwException(const H5std_string &func_name, const H5std_string &msg) const H5_OVERRIDE; // For CommonFG to get the file id. - virtual hid_t getLocId() const; + virtual hid_t getLocId() const H5_OVERRIDE; // Default constructor H5File(); @@ -114,7 +114,7 @@ class H5_DLLCPP H5File : public Group { H5File(const H5File &original); // Gets the HDF5 file id. - virtual hid_t getId() const; + virtual hid_t getId() const H5_OVERRIDE; // H5File destructor. virtual ~H5File(); @@ -122,7 +122,7 @@ class H5_DLLCPP H5File : public Group { protected: #ifndef DOXYGEN_SHOULD_SKIP_THIS // Sets the HDF5 file id. - virtual void p_setId(const hid_t new_id); + virtual void p_setId(const hid_t new_id) H5_OVERRIDE; #endif // DOXYGEN_SHOULD_SKIP_THIS private: diff --git a/c++/src/H5Group.h b/c++/src/H5Group.h index 6e82e21..b5f7e51 100644 --- a/c++/src/H5Group.h +++ b/c++/src/H5Group.h @@ -24,20 +24,20 @@ namespace H5 { class H5_DLLCPP Group : public H5Object, public CommonFG { public: // Close this group. - virtual void close(); + virtual void close() H5_OVERRIDE; ///\brief Returns this class name. virtual H5std_string - fromClass() const + fromClass() const H5_OVERRIDE { return ("Group"); } // Throw group exception. - virtual void throwException(const H5std_string &func_name, const H5std_string &msg) const; + virtual void throwException(const H5std_string &func_name, const H5std_string &msg) const H5_OVERRIDE; // for CommonFG to get the file id. - virtual hid_t getLocId() const; + virtual hid_t getLocId() const H5_OVERRIDE; // Creates a group by way of dereference. Group(const H5Location &loc, const void *ref, H5R_type_t ref_type = H5R_OBJECT, @@ -63,10 +63,10 @@ class H5_DLLCPP Group : public H5Object, public CommonFG { Group(const Group &original); // Gets the group id. - virtual hid_t getId() const; + virtual hid_t getId() const H5_OVERRIDE; // Destructor - virtual ~Group(); + virtual ~Group() H5_OVERRIDE; // Creates a copy of an existing group using its id. Group(const hid_t group_id); @@ -74,7 +74,7 @@ class H5_DLLCPP Group : public H5Object, public CommonFG { protected: #ifndef DOXYGEN_SHOULD_SKIP_THIS // Sets the group id. - virtual void p_setId(const hid_t new_id); + virtual void p_setId(const hid_t new_id) H5_OVERRIDE; #endif // DOXYGEN_SHOULD_SKIP_THIS private: diff --git a/c++/src/H5Include.h b/c++/src/H5Include.h index e662d90..0dc930d 100644 --- a/c++/src/H5Include.h +++ b/c++/src/H5Include.h @@ -24,3 +24,10 @@ * magic number as prefix and checksum as suffix for all chunks. */ #define H5O_VERSION_2 2 + +// Define H5_OVERRIDE to override for C++11. +#if defined(__cplusplus) && (201103L <= __cplusplus) +#define H5_OVERRIDE override +#else +#define H5_OVERRIDE +#endif diff --git a/c++/src/H5Object.h b/c++/src/H5Object.h index 868f63f..bc2f14a 100644 --- a/c++/src/H5Object.h +++ b/c++/src/H5Object.h @@ -106,7 +106,7 @@ class H5_DLLCPP H5Object : public H5Location { void removeAttr(const H5std_string &name) const; // Returns an identifier. - virtual hid_t getId() const = 0; + virtual hid_t getId() const H5_OVERRIDE = 0; // Gets the name of this HDF5 object, i.e., Group, DataSet, or // DataType. @@ -122,10 +122,10 @@ class H5_DLLCPP H5Object : public H5Location { // Sets the identifier of this object to a new value. - this one // doesn't increment reference count - virtual void p_setId(const hid_t new_id) = 0; + virtual void p_setId(const hid_t new_id) H5_OVERRIDE = 0; // Noop destructor. - virtual ~H5Object(); + virtual ~H5Object() H5_OVERRIDE; #endif // DOXYGEN_SHOULD_SKIP_THIS -- cgit v0.12