CThing

The Thing, formerly known as Object in the Object Database, renamed for the practicle reason of having a unique starting letter amongst the other code units.

It may contain an arbitrary amount of arbitrary Atoms (equivalents to Data Fields), Links to other CThing’s for specified CReason’s as well as Backlinks to Reason’ed Link sources.

The linking CThing is responsible for ressource management. It manages connections

  • from thing to thing
  • the backlink for links from itself to another thing
  • from thing to atoms
  • the backlink for links from itself to atoms

Sample code

/**
 *  @file main.cpp
 *
 *  @author Manfred Morgner
 *  @date 21.01.2018
 */

#include <iostream>

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

/// @brief Demo main program "linking things together"
int main()
    {
    // creating things
    auto oOdb    = odb::COdb();
    auto pThing1 = oOdb.MakeThing("Ulrich");
    auto pThing2 = oOdb.MakeThing("Fred");
    auto pReason = oOdb.MakeReason("pays");

    // linking them together
    pThing1->Link(pThing2, pReason);

    // 1) print the thing's view
    std::cout << "thing: " << *pThing1 << '\n';
    std::cout << "thing: " << *pThing2 << '\n';

    // 2) print complete database in simple form
    oOdb.print();

    // 3) print complete database in json format
    oOdb.print_json(std::cout);
    }

Output 1: The CThing’s explaining there content

thing: Ulrich
  Role: Leader
   => linked to: "Fred" for reason: "pays" = Ulrich pays Fred
thing: Fred
  Role: Member
   <= linked from: Ulrich

Output 2: The whole database in list format

#    TYPE     ID      NAME          RefCnt    DATA
#=========================================================
odb::CThing   id: 0   name: Ulrich   (5)
odb::CThing   id: 1   name: Fred     (5)
odb::CAtom    id: 0   name: Role     (3)      data: Leader
odb::CAtom    id: 1   name: Role     (3)      data: Member
odb::CReason  id: 0   name: pays     (3)

Output 3: The whole database in JSON format

{
"Object Database Dump":
    {
    "Things":
        [
            { "id": "0", "name": "Ulrich",
                "atoms": [ {"id": "0"} ],
                "links": [ {"thing-id": "1", "reason-id": "0"} ] },
            { "id": "1", "name": "Fred",
                "atoms": [ {"id": "1"} ],
                "links": [  ] }
        ],
    "Atoms":
        [
            { "id": "0", "name": "Role", "data": "Leader" },
            { "id": "1", "name": "Role", "data": "Member" }
        ],
    "Reasons":
        [
            { "id": "0", "name": "pays" }
        ]
    }
}
class odb::CThing

A Thing as there are many.

Author
Manfred Morgner
Since
0.1.17

Inherits from enable_shared_from_this< CThing >, Identifiable< CThing >

Public Functions

CThing()

We never construct without a name for the thing.

CThing(CThing const&)

and we don’t make copies

CThing(CThing&&)

make_shared<T> moveconstructs

CThing(std::string const &crsName)

Normal constructor, receiving the name of the reason.

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

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

virtual ~CThing()

Nothings special here.

void clear()

We need to unbind all relations in the odb before destructing.

PProperty Append(PProperty poProperty)

Appends an CProperty to its property list.

Appending an CProperty to this CThing requires the thing to inform the appended Property about this CThing is linking to it

Parameters
  • poProperty: A Property to bind with the Thing

PAtom Append(PAtom poAtom)

Appends an CAtom to its atom list.

Appending an CAtom to this CThing requires the thing to inform the appended Atom about this CThing is linking to it

Parameters
  • poAtom: An Atom to bind into the Thing

PThing Link(PThing po2Thing, PReason po4Reason)

Links this CThing to another CThing for a CReason.

Parameters
  • po2Thing: A Thing to Link to
  • po4Reason: The Reason we link for

PThing Unlink(PThing po2Thing, PReason po4Reason)

Removes a link to a specific CThing with a specific CReason.

Parameters
  • po2Thing: A Thing to Linked to
  • po4Reason: The Reason we linked for

PThing RelatingThingAdd(PThing poThing)

adds a CThing as referencing to this

Parameters
  • poThing: A CThing that links to us notifies us, we register it

PThing RelatingThingSub(PThing poThing)

subtract a CThing as referencing to this

Parameters
  • poThing: A CThing that linked to us notifies us, we deregister it

Public Static Attributes

constexpr auto s_csNameUnnamedThing = {"unnamedThing"}

The name of the thing.

constexpr bool s_bDebug = {false}

Do we generate debug output?

Protected Attributes

Holds the links to another CThing for CReason.

Parameters
  • PThing: The PThing we link to
  • PReason: The PReason we link for
  • Compare: Function to compare two CThings

std::set<PThing, lessIdentifiableId<PThing>> m_spoThingsRelating

Registers PThings relating to itself.

Parameters
  • PThing: The PThing we are linked from
  • Compare: Function to compare two CThing’s

std::set<PProperty, lessIdentifiableName<PProperty>> m_spoProperties

Registers PProperties of this CThing.

Parameters
  • PProperty: PProperties we have
  • Compare: Function to compare two PAtom’s

std::set<PAtom, lessIdentifiableId<PAtom>> m_spoAtoms

Registers PAtoms of this CThing.

Parameters
  • PAtom: PAtom’s we own
  • Compare: Function to compare two PAtom’s

Friends

bool operator==(PThing const &croThing, std::string const &crsInput)

Compares the name with an input string.

bool operator<(PThing const &croThing, std::string const &crsInput)

Compares the name with an input string.

std::ostream &operator<<(std::ostream &ros, CThing const &crThing)

The free output operator for CThing.

Parameters
  • ros: The output stream to send the Thing to
  • crThing: The Thing to output