summaryrefslogtreecommitdiffstats
path: root/c++/src/H5IdComponent.cpp
diff options
context:
space:
mode:
authorDana Robinson <derobins@hdfgroup.org>2022-04-13 21:17:29 (GMT)
committerDana Robinson <derobins@hdfgroup.org>2022-04-13 21:17:29 (GMT)
commitcabc39c3e197e2591449d2604bfee26465fb60e1 (patch)
treed5f39f5f5965584bf9bf49646a2af617adfd3e4e /c++/src/H5IdComponent.cpp
parent7355f4c505092a7a85474b47f18d5206028e2c95 (diff)
parentab69f5df770ee3cc6cd6c81d905a5317b894a002 (diff)
downloadhdf5-feature/coding_standards.zip
hdf5-feature/coding_standards.tar.gz
hdf5-feature/coding_standards.tar.bz2
Merge branch 'develop' into feature/coding_standardsfeature/coding_standards
Diffstat (limited to 'c++/src/H5IdComponent.cpp')
-rw-r--r--c++/src/H5IdComponent.cpp110
1 files changed, 58 insertions, 52 deletions
diff --git a/c++/src/H5IdComponent.cpp b/c++/src/H5IdComponent.cpp
index 40520aa..e1fc687 100644
--- a/c++/src/H5IdComponent.cpp
+++ b/c++/src/H5IdComponent.cpp
@@ -6,14 +6,13 @@
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the COPYING file, which can be found at the root of the source code *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <string>
-#include "H5private.h" // for HDmemset
#include "H5Include.h"
#include "H5Exception.h"
#include "H5Library.h"
@@ -38,7 +37,8 @@ bool IdComponent::H5dontAtexit_called = false;
///\brief Increment reference counter for a given id.
// Programmer Binh-Minh Ribler - May 2005
//--------------------------------------------------------------------------
-void IdComponent::incRefCount(const hid_t obj_id) const
+void
+IdComponent::incRefCount(const hid_t obj_id) const
{
if (p_valid_id(obj_id))
if (H5Iinc_ref(obj_id) < 0)
@@ -50,7 +50,8 @@ void IdComponent::incRefCount(const hid_t obj_id) const
///\brief Increment reference counter for the id of this object.
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-void IdComponent::incRefCount() const
+void
+IdComponent::incRefCount() const
{
incRefCount(getId());
}
@@ -63,17 +64,15 @@ void IdComponent::incRefCount() const
// Added the check for ref counter to give a little more info
// on why H5Idec_ref fails in some cases - BMR 5/19/2005
//--------------------------------------------------------------------------
-void IdComponent::decRefCount(const hid_t obj_id) const
+void
+IdComponent::decRefCount(const hid_t obj_id) const
{
if (p_valid_id(obj_id))
- if (H5Idec_ref(obj_id) < 0)
- {
+ if (H5Idec_ref(obj_id) < 0) {
if (H5Iget_ref(obj_id) <= 0)
- throw IdComponentException(inMemFunc("decRefCount"),
- "object ref count is 0 or negative");
+ throw IdComponentException(inMemFunc("decRefCount"), "object ref count is 0 or negative");
else
- throw IdComponentException(inMemFunc("decRefCount"),
- "decrementing object ref count failed");
+ throw IdComponentException(inMemFunc("decRefCount"), "decrementing object ref count failed");
}
}
@@ -82,7 +81,8 @@ void IdComponent::decRefCount(const hid_t obj_id) const
///\brief Decrement reference counter for the id of this object.
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-void IdComponent::decRefCount() const
+void
+IdComponent::decRefCount() const
{
decRefCount(getId());
}
@@ -93,14 +93,15 @@ void IdComponent::decRefCount() const
///\return Reference count
// Programmer Binh-Minh Ribler - May 2005
//--------------------------------------------------------------------------
-int IdComponent::getCounter(const hid_t obj_id) const
+int
+IdComponent::getCounter(const hid_t obj_id) const
{
int counter = 0;
- if (p_valid_id(obj_id))
- {
+ if (p_valid_id(obj_id)) {
counter = H5Iget_ref(obj_id);
if (counter < 0)
- throw IdComponentException(inMemFunc("incRefCount"), "getting object ref count failed - negative");
+ throw IdComponentException(inMemFunc("incRefCount"),
+ "getting object ref count failed - negative");
}
return (counter);
}
@@ -111,7 +112,8 @@ int IdComponent::getCounter(const hid_t obj_id) const
///\return Reference count
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-int IdComponent::getCounter() const
+int
+IdComponent::getCounter() const
{
return (getCounter(getId()));
}
@@ -130,7 +132,8 @@ int IdComponent::getCounter() const
/// input object id is invalid.
// Programmer Binh-Minh Ribler - Jul, 2005
//--------------------------------------------------------------------------
-H5I_type_t IdComponent::getHDFObjType(const hid_t obj_id)
+H5I_type_t
+IdComponent::getHDFObjType(const hid_t obj_id)
{
if (obj_id <= 0)
return H5I_BADID; // invalid
@@ -156,9 +159,10 @@ H5I_type_t IdComponent::getHDFObjType(const hid_t obj_id)
/// input object id is invalid.
// Programmer Binh-Minh Ribler - Mar, 2014
//--------------------------------------------------------------------------
-H5I_type_t IdComponent::getHDFObjType() const
+H5I_type_t
+IdComponent::getHDFObjType() const
{
- return(getHDFObjType(getId()));
+ return (getHDFObjType(getId()));
}
//--------------------------------------------------------------------------
@@ -183,14 +187,15 @@ H5I_type_t IdComponent::getHDFObjType() const
/// \li \c H5I_ERROR_STACK
// Programmer Binh-Minh Ribler - Feb, 2017
//--------------------------------------------------------------------------
-hsize_t IdComponent::getNumMembers(H5I_type_t type)
+hsize_t
+IdComponent::getNumMembers(H5I_type_t type)
{
- hsize_t nmembers = 0;
- herr_t ret_value = H5Inmembers(type, &nmembers);
+ hsize_t nmembers = 0;
+ herr_t ret_value = H5Inmembers(type, &nmembers);
if (ret_value < 0)
throw IdComponentException("getNumMembers", "H5Inmembers failed");
else
- return(nmembers);
+ return (nmembers);
}
//--------------------------------------------------------------------------
@@ -202,7 +207,8 @@ hsize_t IdComponent::getNumMembers(H5I_type_t type)
/// reference count of at least 1.
// Programmer Binh-Minh Ribler - Mar 1, 2017
//--------------------------------------------------------------------------
-bool IdComponent::isValid(hid_t an_id)
+bool
+IdComponent::isValid(hid_t an_id)
{
// Call C function
htri_t ret_value = H5Iis_valid(an_id);
@@ -236,7 +242,8 @@ bool IdComponent::isValid(hid_t an_id)
/// \li \c H5I_ERROR_STACK
// Programmer Binh-Minh Ribler - Feb, 2017
//--------------------------------------------------------------------------
-bool IdComponent::typeExists(H5I_type_t type)
+bool
+IdComponent::typeExists(H5I_type_t type)
{
// Call C function
htri_t ret_value = H5Itype_exists(type);
@@ -266,17 +273,17 @@ bool IdComponent::typeExists(H5I_type_t type)
// care of close() and setId takes care incRefCount().
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-IdComponent& IdComponent::operator=(const IdComponent& rhs)
+IdComponent &
+IdComponent::operator=(const IdComponent &rhs)
{
- if (this != &rhs)
- {
+ if (this != &rhs) {
// handling references to this id
try {
setId(rhs.getId());
// Note: a = b, so there are two objects with the same hdf5 id
// that's why incRefCount is needed, and it is called by setId
}
- catch (Exception& close_error) {
+ catch (Exception &close_error) {
throw FileIException(inMemFunc("operator="), close_error.getDetailMsg());
}
}
@@ -304,7 +311,8 @@ IdComponent& IdComponent::operator=(const IdComponent& rhs)
// the id passed to setId is that of another C++ API object, so
// setId must call incRefCount.
//--------------------------------------------------------------------------
-void IdComponent::setId(const hid_t new_id)
+void
+IdComponent::setId(const hid_t new_id)
{
// set to new_id
p_setId(new_id);
@@ -318,7 +326,9 @@ void IdComponent::setId(const hid_t new_id)
///\brief Noop destructor.
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-IdComponent::~IdComponent() {}
+IdComponent::~IdComponent()
+{
+}
//
// Implementation of protected functions for HDF5 Reference Interface
@@ -338,7 +348,8 @@ IdComponent::~IdComponent() {}
/// an exception is thrown.
// Programmer Binh-Minh Ribler - Aug 6, 2005
//--------------------------------------------------------------------------
-H5std_string IdComponent::inMemFunc(const char* func_name) const
+H5std_string
+IdComponent::inMemFunc(const char *func_name) const
{
H5std_string full_name = func_name;
full_name.insert(0, "::");
@@ -355,8 +366,7 @@ IdComponent::IdComponent()
{
// initH5cpp will register the terminating functions with atexit().
// This should only be done once.
- if (!H5cppinit)
- {
+ if (!H5cppinit) {
H5Library::initH5cpp();
H5cppinit = true;
}
@@ -374,7 +384,8 @@ IdComponent::IdComponent()
// inherits from H5Location.
// Programmer Binh-Minh Ribler - Jul, 2004
//--------------------------------------------------------------------------
-H5std_string IdComponent::p_get_file_name() const
+H5std_string
+IdComponent::p_get_file_name() const
{
hid_t temp_id = getId();
@@ -382,28 +393,25 @@ H5std_string IdComponent::p_get_file_name() const
ssize_t name_size = H5Fget_name(temp_id, NULL, 0);
// If H5Aget_name returns a negative value, raise an exception,
- if (name_size < 0)
- {
+ if (name_size < 0) {
throw IdComponentException("", "H5Fget_name failed");
}
// Call H5Fget_name again to get the actual file name
- char* name_C = new char[name_size+1]; // temporary C-string for C API
- HDmemset(name_C, 0, name_size+1); // clear buffer
+ char *name_C = new char[name_size + 1]();
- name_size = H5Fget_name(temp_id, name_C, name_size+1);
+ name_size = H5Fget_name(temp_id, name_C, name_size + 1);
// Check for failure again
- if (name_size < 0)
- {
- delete []name_C;
+ if (name_size < 0) {
+ delete[] name_C;
throw IdComponentException("", "H5Fget_name failed");
}
// Convert the C file name and return
H5std_string file_name(name_C);
- delete []name_C;
- return(file_name);
+ delete[] name_C;
+ return (file_name);
}
//
@@ -417,16 +425,14 @@ H5std_string IdComponent::p_get_file_name() const
// Return true if id is valid, false, otherwise
// Programmer Binh-Minh Ribler - May, 2005
//--------------------------------------------------------------------------
-bool IdComponent::p_valid_id(const hid_t obj_id)
+bool
+IdComponent::p_valid_id(const hid_t obj_id)
{
if (obj_id <= 0)
return false;
H5I_type_t id_type = H5Iget_type(obj_id);
- if (id_type <= H5I_BADID || id_type >= H5I_NTYPES)
- return false;
- else
- return true;
+ return (id_type > H5I_BADID && id_type < H5I_NTYPES);
}
// Notes about IdComponent::id
@@ -439,4 +445,4 @@ bool IdComponent::p_valid_id(const hid_t obj_id)
#endif // DOXYGEN_SHOULD_SKIP_THIS
-}
+} // namespace H5