Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: DataSet assignment operator is missing #503

Merged
merged 8 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions c++/src/H5DataSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ DataSet::DataSet(const DataSet &original) : H5Object(), AbstractDs(), id(origina
incRefCount(); // increment number of references to this id
}

//--------------------------------------------------------------------------
// Function: DataSet assignment operator
///\brief Assignment operator: same HDF5 object as \a original
///\param original - IN: DataSet instance to copy
// Programmer Lee Newberg - 2021
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not excited about programmer graffitti. I'm trying to remove author fields in comments when I find them as they are frequently meaningless. Developers should be using the history to determine this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will be adding test for this and will take care of the issues you mentioned. Thanks!

//--------------------------------------------------------------------------
DataSet &
DataSet::operator=(const DataSet &original)
{
if (this != &original) {
setId(original.id);
}
return (*this);
}

//--------------------------------------------------------------------------
Copy link
Contributor

@bmribler bmribler Mar 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider using IdComponent::setId() to ensure the current dataset ID is properly closed. setId() also handles the ref counting. Perhaps, DataType::operator= can be used as an example. Also, please add a test. Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bmribler Thank you for the feedback. The new code has H5DataSet::operator= mimicking H5DataType::operator= as you suggest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone could contribute a test that would be great. I am a little over my head there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @Leengit. I'll try to come up with a test.

// Function: DataSet overload constructor - dereference
///\brief Given a reference, ref, to an hdf5 location, creates a
Expand Down
3 changes: 3 additions & 0 deletions c++/src/H5DataSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ class H5_DLLCPP DataSet : public H5Object, public AbstractDs {
// Copy constructor - same as the original DataSet.
DataSet(const DataSet &original);

// Assignment operator
DataSet &operator=(const DataSet &original);

// Creates a copy of an existing DataSet using its id.
DataSet(const hid_t existing_id);

Expand Down