CAtom

An CAtom is a container for a single data element, let’s say a number or a text. It stores additional information to use in a GUI as there are

  • (Field-)Name
  • Prefix
  • Suffix
  • (output) Format template

One can compare an Atom with single data field as in a conventional table oiented database. Unlike conventional databases fields/atoms do not have a fixed structure, they even do not have to exist.

CAtom may act as a template for other atoms. In such case the atom, using the other as template, does not need to fill elements which are given by the template. It will appear as if the elements of the template are elements of the using Atom, as long as they are not overwritten.

Sample code

/**
    @file atom-test.cpp
 
    @author Manfred Morgner
    @date 21.01.2018
 */

#include <iostream>

#include "odb.h"


/**
    @brief Demo main program
 */
int main()
    {
    auto oOdb = odb::COdb();
    auto atom = oOdb.MakeAtom(2.5, "gain", "is", "%");
    std::cout << "atom data: " << *atom << '\n';
    std::cout << "atom frmt: " << atom->m_sName << ' ';
    atom->print_atom_data_formated(std::cout);
    std::cout << '\n';
    oOdb.print_json(std::cout);
    } // int main()

Output

atom data: 2.5
atom frmt: gain is 2.5 %
class CAtom : public enable_shared_from_this<CAtom>, public Identifiable<CAtom>

An Atom is a data field for a CNode.

Sample Code goes here
#include <odb>

Public Functions

template <typename T>
CAtom(T tAtomData, std::string const &crsName = "", std::string const &crsPrefix = "", std::string const &crsSuffix = "", std::string const &crsFormat = "")

Constructor able to receive data of maany types.

Parameters
  • tAtomData: The data unit to encapsulate
  • crsName: The name for the atom
  • crsPrefix: The prefix for user output
  • crsSuffix: The suffix for user output
  • crsFormat: The format for user output

template <typename T>
CAtom(size_t nId, T tAtomData, std::string const &crsName = "", std::string const &crsPrefix = "", std::string const &crsSuffix = "", std::string const &crsFormat = "")

Constructor able to receive data of maany types.

Parameters
  • nId: The predefiined ID if loading a dataset
  • tAtomData: The data unit to encapsulate
  • crsName: The name for the atom
  • crsPrefix: The prefix for user output
  • crsSuffix: The suffix for user output
  • crsFormat: The format for user output

virtual ~CAtom()

Destruction as usual (=default)

void clear()

Remove all links between all objects.

This is necessary to enable freeing of all memory ressources. So we become able to put valgrind to use

void print_xml(std::ostream &out, size_t const cnDepth, bool const bFormated = false) const

todo: output the instance xml formated

void print_atom_data_formated(std::ostream &out) const

Prints the content of the instance for UI use (well formated)

auto RelatingNodeAdd(PNode poNode)

Adds the backlink from the atom to a node

Parameters
  • poNode: Inform a node about being linked from another node

auto RelatingNodeSub(PNode poNode)

Removes the backlink from the atom to a node

Parameters
  • poNode: Inform a node about no more being linked from another node

auto IsUnUsed()

returns if the instance is ‘free’

SNodes const &Relations() const

Returns the Relations using this CAtom.

Public Static Attributes

constexpr auto s_csNameUnnamedAtom = {"unnamedAtom"}

The name of an unnamed atom.

constexpr bool s_bDebug = {false}

Switch to enable/disable debug information output, regarding CAtom.

Friends

void print(CAtoms const &crContainer)

friend function to print the atom instance in an inforamtional manner

std::ostream &operator<<(std::ostream &ros, CAtom const &croAtom)

sends the data of the atom to the given ostream

template <typename T, typename U>
struct decay_equiv : public std::is_same::type<std::decay<T>::type, U>

Compares the type of a variable with a chosen type for similarity, e.g:

  • if ( decay_equiv<T, int>::value ) …