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

  • Name
  • Prefix
  • Suffix
  • Format template

One can compare an atom with single data field like in a conventional 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

#include <iostream>

#include "odb.h"
#include "atom.h"

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';
   }

Output

atom data: 2.5
atom frmt: gain is 2.5 %
class odb::CAtom

An Atom is a data field for a CThing.

Sample Code goes here
#include <odb>

Inherits from enable_shared_from_this< CAtom >, Identifiable< CAtom >

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 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 RelatingThingAdd(PThing poThing)

Adds the backlink from the atom to a thing

Parameters
  • poThing: Inform a thing about being linked from another thing

auto RelatingThingSub(PThing poThing)

Removes the backlink from the atom to a thing

Parameters
  • poThing: Inform a thing about no more being linked from another thing

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.

Protected Attributes

std::string m_sFormat = {""s}

The UI output format for the atom.

std::string m_sPrefix = {""s}

The UI prefix (if any) for the atom.

std::string m_sSuffix = {""s}

The UI suffix (if any) for the atom.

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

CThing’s Relating to this CAtom.

std::unique_ptr<const SAtomDataConcept> m_pAtomData

The pointer and holder of the data element of type T.

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

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

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

Inherits from std::is_same::type< std::decay< T >::type, U >

template <typename T>
struct SAtomData

The templated data structure to hold an arbitrary data element.

Inherits from CAtom::SAtomDataConcept

Public Functions

SAtomData(T tData)

The function to deal with the arbitrary data element.

Parameters
  • tData: The data element to hold

void ToStream(std::ostream &ros) const

Send the data element to std::ostream.

Helper function to break the boundary between non uniform data content of the atom instance and the uniform output expectation

Public Members

T m_tData

The decalartion of the data element of type T.

struct SAtomDataConcept

start of data implementation

Subclassed by CAtom::SAtomData< T >

Public Functions

virtual void ToStream(std::ostream&) const = 0

Will send the data of the atom to the given stream.