Triples

class omexmeta::Triples

A Triples object is a collection of Triple objects.

the implementation of Triples is hampered by the inability to clone Triple objects. Instead triples must use move semantics to get Triples in or out of a Triples object. Under the hood, the Triples object is just a std::vector<Triple>.

Public Functions

Triples()
explicit Triples(int size)

create an empty Triples object big enough for

Parameters

sizeTriple objects

explicit Triples(Triple &triple)

construct a Triples object from a single triple

The triple is moved into element 0 of a new Triples object. The Triple must be passed by reference so that the triple is moved directly, instead of copied and then moved into the Triples object (which is a memory leak).

Parameters

triple – The triple to put into triples

explicit Triples(std::vector<Triple> triples)

construct a Triples object directly from a std::vector<Triple>

bool operator==(const Triples &rhs) const
bool operator!=(const Triples &rhs) const
void moveBack(Triple &triple)

move a Triple to the back of the Triples object. Analogous to push back but with move semantics.

moves a Triple object to the back of Triples

The vector storing the Triples is increased in size by 1 and the

Parameters
  • triple – The Triple object to move.

  • triple – is moved into that slot. Therefore, ownership of the triple passes to the Triples object who is reposible for freeing the Triple.

void emplace_back(UriHandler &uriHandler, LibrdfNode subject, const PredicatePtr &predicatePtr, const LibrdfNode &resource)

construct a Triple object from the necessary components and move it to the back of Triples

this method is heavily overloaded and has several signatures all of which result in the construction and emplacement of a Triple at the back of Triples.

void emplace_back(UriHandler &uriHandler, const LibrdfNode &subject, const LibrdfNode &predicate, const LibrdfNode &resource)
void emplace_back(UriHandler &uriHandler, LibrdfNode subject, const Predicate &predicate, const LibrdfNode &resource)

construct a Triple object from the necessary components and move it to the back of Triples

this method is heavily overloaded and has several signatures all of which result in the construction and emplacement of a Triple at the back of Triples.

std::vector<std::string> getSubjectsStr()

get all subjects as strings

we do not return the subject itself because subjects cannot be copied, which complicates matters.

Returns

All subject uri’s as strings in a std::vector

std::vector<std::string> getPredicates()

get all predicates as strings

we do not return the predicate itself because Predicate objects cannot be copied.

Returns

All predicate uri’s as strings in a std::vector

std::vector<std::string> getResources()

get all resources as strings

we do not return the LibrdfNode itself because LibrdfNode objects cannot be copied.

Returns

All resource uri’s as strings in a std::vector

int size() const

get the number of triples in the Triples object

Returns

the integer number of triples in the Triples object

TripleVector::iterator begin()

the begin iterator for a Triples object

this method is simply forwarded on to std::vector::begin()

TripleVector::iterator end()

the end iterator for a Triples object

this method is simply forwarded on to std::vector::end()

void freeTriples()
Triple pop()

moves one triple of the end of triples

No copies are made. This is deliberate as it reduces risk of memory issues. When you pop, you remove from the end of the Triples object and return it. This means that responsibility for freeing the returned Triple switches to the caller.

Returns

the triple from the end of the triples vector

Triple &operator[](int index)

getter operator for Triples object

A copy is made of the Triple you want to return. To get a reference without copying see Triples::pop(). Remember that iterating over a Triples object and making copies will cause complications with freeing the objects.

Returns

a reference to the Triple at index index

const Triple &operator[](int index) const
bool isEmpty()

indicates whether Triples object is empty.

Useful for iterating over Triples in a while loop without using the [] operator, which makes unwanted copies that causes memory issues.

Returns

true if the Triples object doesn’t contain any Triple objects

int capacity()

move the from Triple object out of the Triples object

caller is responsible for Triple resources

forwarded on to std::vector::capacity

Returns

a Triple from position 0 in Triples

Returns

int the size of Triples currently allowed

Private Members

TripleVector triples_