CReason¶
This class is necessary to link two CThing instances to give the link an explaination. This enables us to link the same CThing’s multiple time.
- 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
But 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 is resonsible for 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
odb::
CReason
¶ A Reason to link two Things (Unidirectional)
Inherits from Identifiable< CReason >
Public Functions
-
CReason
()¶ Forbidden.
-
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.
-
operator std::string const&
()¶ Conversion operator will return the name of the instance.
-
void
RelationAdd
(PThing &poThingFrom, PThing &poThingTo)¶ Add the information about a link from one CThing to another regarding ‘this’ reason.
-
void
RelationSub
(PThing &poThingFrom, PThing &poThingTo)¶ Removes a link between two CThing’s.
Removes the information about a particular link from one CThing to another regarding ‘this’ reason
- Parameters
poThingFrom
: The thing the link is claimed to be made frompoThingTo
: The thing the link is claimed to be made to
-
void
print
()¶ Prints an informational output to std::cout.
Public Static Attributes
-
constexpr auto
s_csNameUnnamedReason
= {"unnamedReason"}¶ The name of an unnamed reason.
Protected Attributes
-
std::multimap<PThing, PThing>
m_mRelations
¶ A map containing links from one thing to another.
-