Skip to content

ROCrate

class ROCrate

Represents an RO-Crate, a structured collection of entities and metadata.

The ROCrate class manages a collection of entities, including a root metadata entity and a root dataset entity. It provides methods to add entities, retrieve entities by their identifiers, and manage the relationships between entities.

Functions

Name Description
ROCrate Constructs an RO-Crate with a root metadata entity and a root dataset entity.
addEntity Adds an entity to the RO-Crate's entity register with the specified id.
getEntity Retrieves an entity from the RO-Crate's entity register by its id.
writeOut Serializes the RO-Crate to a JSON file at the specified path.

Function Details

ROCrate

ROCrate()

Constructs an RO-Crate with a root metadata entity and a root dataset entity.

The constructor initializes the RO-Crate with an empty entity register, creates the root metadata entity (ro-crate-metadata.json) and the root dataset entity, and adds the root dataset entity to the root metadata entity.

addEntity

void addEntity(const std::string& id, Entity& entity)

Adds an entity to the RO-Crate's entity register with the specified id.

id
The identifier for the entity.
entity
The entity to add to the RO-Crate.
Throw
std::invalid_argument if the id is empty.
Throw
std::runtime_error if an entity with the given id already exists in the RO-Crate.

getEntity

Entity& getEntity(const std::string& id)

Retrieves an entity from the RO-Crate's entity register by its id.

id
The identifier of the entity to retrieve.
Return
A reference to the entity with the specified id.
Throw
std::runtime_error if no entity with the given id is found in the RO-Crate.

writeOut

void writeOut(const std::string& path)

Serializes the RO-Crate to a JSON file at the specified path.

path
The file path where the RO-Crate JSON will be written.
Throw
std::runtime_error if there is an error writing to the file.