CNode

The Node, formerly known as Object in the Object Database, is an entity representing some ‘thing’ or some ‘person’. Or, if you see animals neigther as thing nor as person, some ‘animal’. We are living in a database world so this distinguation makes no difference, at least for the database.

A node may contain an arbitrary amount of arbitrary

  • CAtom’s (equivalent to Data Fields)
  • CProperty’s (minimal data units, multiusable)
  • Links to other CNode’s for specified CReason’s
  • as well as Backlinks to Reason’ed Link sources.

Basically the linking CNode manages the following resources:

  • from node to node
  • the backlink for links from itself to another nodes
  • from node to atoms
  • the backlink for links from itself to atoms

Sample code

/**
    @file nodes.cpp
 
    @author Manfred Morgner
    @date 15.04.2018

    Demonstration of how Nodes are made and how they can be connected to
    each other using specific unidirectional reasons.
 */

#include <iostream>

#include "odb.h"

auto oOdb = odb::COdb();


// Demo main program
int main()
    {
    // 3 people
    oOdb.MakeNode("Udo");
    oOdb.MakeNode("Ina");
    oOdb.MakeNode("Rob");

    // 3 kind of relation
    oOdb.MakeReason("is father of");
    oOdb.MakeReason("knows");
    oOdb.MakeReason("loves");
    
    // 3 bindings
    oOdb.LinkNode2Node("Udo", "is father of", "Ina");
    oOdb.LinkNode2Node("Udo", "knows"       , "Rob");
    oOdb.LinkNode2Node("Ina", "loves"       , "Rob");

    // show us
    std::cout << "---------------- all nodes" << '\n';
    for ( auto const & a:oOdb.Nodes() )
        {
        std::cout << *a << '\n';
        }
    }

Output

---------------- all nodes
Udo
   => linked to: "Ina" for reason: "is father of"
   => linked to: "Rob" for reason: "knows"
Ina
   => linked to: "Rob" for reason: "loves"
   <= linked from: Udo
Rob
   <= linked from: Ina
   <= linked from: Udo
class CNode : public enable_shared_from_this<CNode>, public Identifiable<CNode>

A Node as you imagine it.

A CNode, or Node, is a main structure element in a GrapDB like odb. The counterpart is a CReason. CNode’s will be linked unidirectional to another CNode’s. There may be an arbitrary amount of Links between CNodes e.g.

  • Node, (Link-)Reason, Node
  • Mary, wrote, a book
  • Mary, read, a book
  • Mary, loves, Jack

Author
Manfred Morgner
Since
0.1.17

Public Functions

CNode()

DELETED: We never construct without a name for the node.

CNode(CNode const&)

DELETED: and we don’t make copies.

CNode(CNode&&)

Move-Contructor, noexcept and default. make_shared<T> move-constructs. Function return of CNode’s moves too.

CNode(std::string const &crsName)

Normal constructor, receiving the name of the Node.

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

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

virtual ~CNode()

Destructor (default). Nothings special here.

void clear()

We need to unbind all relations in the COdb before letting us destruct

PProperty Append(PProperty poProperty)

Appends an CProperty to its property list.

Appending an CProperty to this CNode includes the Node to inform the appended Property about this Node is linking to it

Parameters
  • poProperty: A Property to bind with the Node

PAtom Append(PAtom poAtom)

Appends an CAtom to its atom list.

Appending an CAtom to this CNode includes the Node to inform the appended Atom about this CNode is linking to it

Parameters
  • poAtom: An Atom to bind into the Node

PNode Link(PNode po2Node, PReason po4Reason)

Links this CNode to another CNode for a CReason.

Parameters
  • po2Node: A Node to Link to
  • po4Reason: The Reason we link for

PNode Unlink(PNode po2Node, PReason po4Reason)

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

Parameters
  • po2Node: A Node to Linked to
  • po4Reason: The Reason we linked for

PNode RelatingNodeAdd(PNode poNode)

adds a CNode as referencing to this

Parameters
  • poNode: A CNode that links to us notifies us, we register it

PNode RelatingNodeSub(PNode poNode)

subtract a CNode as referencing to this

Parameters
  • poNode: A CNode that linked to us notifies us, we deregister it

auto IsUnUsed()

returns if the instance is ‘free’

MLinkets const &Linkets() const

Nodes linking to this Node.

SNodes const &Nodes() const

Nodes linked by this Node.

SProperties const &Properties() const

Properties assigned to this Node.

SAtoms const &Atoms() const

CAtoms used by this Node.

Public Static Attributes

constexpr auto s_csNameUnnamedNode = {"unnamedNode"}

The name of the node.

constexpr bool s_bDebug = {false}

Do we generate debug output?

Friends

std::ostream &operator<<(std::ostream &ros, CNode const &crNode)

The free output operator for CNode.

The ouput operator prints all information about the CNode instance to the given output stream. This is:

Parameters
  • ros: The output stream to send the Node to
  • crNode: The Node to output