Remove shared pointer behaviour - #8
Open
OliverWoolland wants to merge 3 commits into
Open
Conversation
jfecroftRSE
reviewed
Sep 4, 2026
Comment on lines
231
to
247
| inline void ROCrate::addEntity(const std::string& id, Entity& entity) { | ||
| // Validate the id (reject empty) | ||
| if (id.empty()) { | ||
| throw std::invalid_argument("Entity ID cannot be empty."); | ||
| } | ||
|
|
||
| // Check if the entity with the given id already exists in the register | ||
| if (entities_.find(id) != entities_.end()) { | ||
| throw std::runtime_error("Entity with id '" + id + "' already exists in the RO-Crate."); | ||
| } | ||
|
|
||
| // Add the assigned ID to the Entity itself | ||
| entity.assignId(id); | ||
|
|
||
| // Add an entity to the RO-Crate's entity register | ||
| entities_.emplace(id, entity); | ||
| } |
There was a problem hiding this comment.
I think I would do
inline void ROCrate::addEntity(const std::string& id, Entity entity) {and
// Add an entity to the RO-Crate's entity register
entities_.emplace(id, std::move(entity));It would end up with the same behaviour. Currently Entity is passed by reference and then copied into entities_. Passing by value makes it clear that the Entity stored in the crate is a separate object.
jfecroftRSE
approved these changes
Sep 4, 2026
jfecroftRSE
left a comment
There was a problem hiding this comment.
Looks good. The example on the front page now also needs updating. Currently it makes copies of the root and rootData entities, then updates them which doesn't affect the ones in the crate
// Get the root metadata entity from the crate and set the description
//Entity root = crate.getEntity("ro-crate-metadata.json");
Entity& root = crate.getEntity("ro-crate-metadata.json");
root.set("description", "RO-Crate Metadata File Descriptor (this file)");
// Add name, description to the root data entity (./)
//Entity rootData = crate.getEntity("./");
Entity& rootData = crate.getEntity("./");
rootData.set("name", "Example RO-Crate");
rootData.set("description", "The RO-Crate Root Data Entity");
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.