CReason

CReason is necessary to link two CThing instances to give the link an explaination. This enables to link the same CThing’s multiple times.

thing1 - reason - thing2

For example:

Heinz - wrote - 'Trees of Estonia'
Heinz - signed - 'Trees of Estonia'

Links are unidirectional. Meaning if it’s true that

Heinz - wrote - 'Trees of Estonia'

it may not be true that

'Trees of Estonia' - wrote - Heinz

To ensure thing2 feels the link, it will be informed that a link to it became established. The linked thing registers which thing is linking to it only ones. In our example ‘Trees of Estonia’ registers, that Heinz links to it.

If some process/entity needs to know how often and for which reasons, it has to go to Heinz and ask. The linking thing cares about correct management of links, reasons and backlinks.

CReason registers each link it is used for

Demostration

#include <iostream>

#include "odb.h"
#include "thing.h"

int main()
    {
    // generating the objects
    auto oOdb    = odb::COdb();
    auto pThing1 = oOdb.MakeThing("Ulrich");
    auto pThing2 = oOdb.MakeThing("Fred");
    auto pReason = oOdb.MakeReason("pays");
    // create a connection
    pThing1->Link(pThing2, pReason);
    // let them explain the situation
    std::cout << "thing: " << *pThing1 << '\n';
    std::cout << "thing: " << *pThing2 << '\n';
    }

Output:

thing: Ulrich
   => linked to: "Fred" for reason: "pays" = Ulrich pays Fred
thing: Fred
   <= linked from: Ulrich
class CReason : public Identifiable<CReason>

A Reason to link two Nodes (Unidirectional)

Public Functions

CReason()

DELETED: Default constructor.

CReason(CReason const&)

DELETED: There is no reason to copy a CReason.

CReason(CReason&&)

DEFAULT, NOEXCEPT: move constructor, make_shared<T> move-constructs returning objects has to move too, we don’t want copies!

CReason(std::string const &crsName)

Normal constructor, receiving the name of the reason.

CReason(size_t nId, std::string const &crsName)

Load constructor, receiving the ID and name of the reason.

virtual ~CReason()

DEFAULT, NOEXCEPT: destructor.

operator std::string const&()

Conversion operator will return the name of the instance.

void RelationAdd(PNode &poNodeFrom, PNode &poNodeTo)

Add the information about linking from one CNode to another regarding ‘this’ CReason

void RelationSub(PNode &poNodeFrom, PNode &poNodeTo)

Removes a link between two CNode’s.

Removes the information about a particular link from one CNode to another regarding ‘this’ reason

Parameters
  • poNodeFrom: The node the link is claimed to be made from
  • poNodeTo: The node the link is claimed to be made to

void print()

Prints an informational output to std::cout.

auto IsUnUsed()

returns if the instance is ‘free’

MLinks const &Relations() const

Returns the links this Reason administers.

Public Static Attributes

constexpr auto s_csNameUnnamedReason = {"unnamedReason"}

The name of an unnamed reason.

Friends

std::ostream &operator<<(std::ostream &ros, CReason const &croReason)

Output operator to do an output of the instance.