knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
knowrob::Atomic Class Referenceabstract

#include <Atomic.h>

Inheritance diagram for knowrob::Atomic:
Collaboration diagram for knowrob::Atomic:

Public Member Functions

 Atomic (AtomicType atomicType)
 
 ~Atomic () override=default
 
bool isSameAtomic (const Atomic &other) const
 
AtomicType atomicType () const
 
size_t hashOfAtomic () const
 
virtual std::string_view stringForm () const =0
 
const std::set< std::string_view > & variables () const final
 
void write (std::ostream &os) const override
 
 Atomic (AtomicType atomicType)
 
 ~Atomic () override=default
 
bool isSameAtomic (const Atomic &other) const
 
AtomicType atomicType () const
 
size_t hashOfAtomic () const
 
virtual std::string_view stringForm () const =0
 
const std::set< std::string_view > & variables () const final
 
void write (std::ostream &os) const override
 
- Public Member Functions inherited from knowrob::Term
 Term (TermType termType)
 
 ~Term () override=default
 
bool operator== (const Term &other) const
 
bool operator!= (const Term &other) const
 
TermType termType () const
 
bool isGround () const
 
bool isAtomic () const
 
bool isAtom () const
 
bool isVariable () const
 
bool isFunction () const
 
bool isNumeric () const
 
bool isString () const
 
bool isIRI () const
 
bool isBlank () const
 
size_t hash () const
 
 Term (TermType termType)
 
 ~Term () override=default
 
bool operator== (const Term &other) const
 
bool operator!= (const Term &other) const
 
TermType termType () const
 
bool isGround () const
 
bool isAtomic () const
 
bool isAtom () const
 
bool isVariable () const
 
bool isFunction () const
 
bool isNumeric () const
 
bool isString () const
 
bool isIRI () const
 
bool isBlank () const
 
size_t hash () const
 
- Public Member Functions inherited from knowrob::Printable
virtual ~Printable ()=default
 
virtual std::string format () const
 
virtual ~Printable ()=default
 
virtual std::string format () const
 

Static Public Member Functions

static std::shared_ptr< AtomicmakeTripleValue (const Triple &triple)
 
static std::shared_ptr< AtomicmakeTripleValue (const Triple &triple)
 

Protected Attributes

const AtomicType atomicType_
 
- Protected Attributes inherited from knowrob::Term
const TermType termType_
 
bool isBlank_ = false
 
bool isIRI_ = false
 

Additional Inherited Members

- Static Protected Attributes inherited from knowrob::Term
static const std::set< std::string_view > noVariables_ = {}
 

Detailed Description

An atomic term is a term that is not a compound term.

Definition at line 32 of file Atomic.h.

Constructor & Destructor Documentation

◆ Atomic() [1/2]

knowrob::Atomic::Atomic ( AtomicType  atomicType)
inlineexplicit

Definition at line 34 of file Atomic.h.

const AtomicType atomicType_
Definition: Atomic.h:75
AtomicType atomicType() const
Definition: Atomic.h:48
Term(TermType termType)
Definition: Term.h:33

◆ ~Atomic() [1/2]

knowrob::Atomic::~Atomic ( )
overridedefault

◆ Atomic() [2/2]

knowrob::Atomic::Atomic ( AtomicType  atomicType)
inlineexplicit

Definition at line 34 of file Atomic.h.

◆ ~Atomic() [2/2]

knowrob::Atomic::~Atomic ( )
overridedefault

Member Function Documentation

◆ atomicType() [1/2]

AtomicType knowrob::Atomic::atomicType ( ) const
inline
Returns
the type of the atomic term

Definition at line 48 of file Atomic.h.

48 { return atomicType_; }

◆ atomicType() [2/2]

AtomicType knowrob::Atomic::atomicType ( ) const
inline
Returns
the type of the atomic term

Definition at line 48 of file Atomic.h.

48 { return atomicType_; }

◆ hashOfAtomic() [1/2]

size_t Atomic::hashOfAtomic ( ) const
Returns
the hash of this atomic term.

Definition at line 62 of file Atomic.cpp.

62  {
63  return std::hash<std::string_view>{}(stringForm());
64 }
virtual std::string_view stringForm() const =0

◆ hashOfAtomic() [2/2]

size_t knowrob::Atomic::hashOfAtomic ( ) const
Returns
the hash of this atomic term.

◆ isSameAtomic() [1/2]

bool Atomic::isSameAtomic ( const Atomic other) const
Parameters
otheranother atomic
Returns
true if both atomic terms are equal

Definition at line 16 of file Atomic.cpp.

16  {
17  if (atomicType() != other.atomicType()) {
18  return false;
19  }
20  switch (atomicType()) {
21  case AtomicType::ATOM:
22  return ((Atom *) this)->isSameAtom(*((Atom *) &other));
24  return ((Numeric *) this)->isSameNumeric(*((Numeric *) &other));
25  case AtomicType::STRING:
26  return ((String *) this)->isSameString(*((String *) &other));
27  }
28  return false;
29 }

◆ isSameAtomic() [2/2]

bool knowrob::Atomic::isSameAtomic ( const Atomic other) const
Parameters
otheranother atomic
Returns
true if both atomic terms are equal

◆ makeTripleValue() [1/2]

std::shared_ptr< Atomic > Atomic::makeTripleValue ( const Triple triple)
static

Create an atomic term from a triple value.

Parameters
triplethe triple
Returns
the atomic term

Definition at line 31 of file Atomic.cpp.

31  {
32  if (triple.xsdType()) {
33  switch (triple.xsdType().value()) {
34  case XSDType::STRING:
35  return std::make_shared<String>(triple.valueAsString());
36  case XSDType::BOOLEAN:
37  return std::make_shared<Boolean>(triple.valueAsBoolean());
38  case XSDType::DOUBLE:
39  return std::make_shared<Double>(triple.valueAsDouble());
40  case XSDType::FLOAT:
41  return std::make_shared<Float>(triple.valueAsFloat());
43  case XSDType::INTEGER:
44  return std::make_shared<Integer>(triple.valueAsInt());
45  case XSDType::LONG:
46  return std::make_shared<Long>(triple.valueAsLong());
47  case XSDType::SHORT:
48  return std::make_shared<Short>(triple.valueAsShort());
50  return std::make_shared<UnsignedLong>(triple.valueAsUnsignedLong());
52  return std::make_shared<UnsignedInt>(triple.valueAsUnsignedInt());
54  return std::make_shared<UnsignedShort>(triple.valueAsUnsignedShort());
55  case XSDType::LAST:
56  break;
57  }
58  }
59  return IRIAtom::Tabled(triple.valueAsString());
60 }
static std::shared_ptr< IRIAtom > Tabled(std::string_view stringForm)
Definition: IRIAtom.cpp:25
virtual std::string_view valueAsString() const =0
auto xsdType() const
Definition: Triple.h:64
virtual short valueAsShort() const =0
virtual unsigned int valueAsUnsignedInt() const =0
virtual double valueAsDouble() const =0
virtual float valueAsFloat() const =0
virtual long valueAsLong() const =0
virtual unsigned short valueAsUnsignedShort() const =0
virtual unsigned long valueAsUnsignedLong() const =0
virtual int valueAsInt() const =0
virtual bool valueAsBoolean() const =0

◆ makeTripleValue() [2/2]

static std::shared_ptr<Atomic> knowrob::Atomic::makeTripleValue ( const Triple triple)
static

Create an atomic term from a triple value.

Parameters
triplethe triple
Returns
the atomic term

◆ stringForm() [1/2]

virtual std::string_view knowrob::Atomic::stringForm ( ) const
pure virtual

Get the lexical form of this atomic term.

Returns
the lexical form of this atomic term.

Implemented in knowrob::StringTemplate< StrType >, knowrob::NumericTemplate< T1, T2 >, knowrob::StringTemplate< StrType >, knowrob::NumericTemplate< T1, T2 >, knowrob::Atom, and knowrob::Atom.

◆ stringForm() [2/2]

virtual std::string_view knowrob::Atomic::stringForm ( ) const
pure virtual

Get the lexical form of this atomic term.

Returns
the lexical form of this atomic term.

Implemented in knowrob::StringTemplate< StrType >, knowrob::NumericTemplate< T1, T2 >, knowrob::StringTemplate< StrType >, knowrob::NumericTemplate< T1, T2 >, knowrob::Atom, and knowrob::Atom.

◆ variables() [1/2]

const std::set<std::string_view>& knowrob::Atomic::variables ( ) const
inlinefinalvirtual
Returns
set of variables of this term.

Implements knowrob::Term.

Definition at line 69 of file Atomic.h.

69 { return Term::noVariables_; }
static const std::set< std::string_view > noVariables_
Definition: Term.h:110

◆ variables() [2/2]

const std::set<std::string_view>& knowrob::Atomic::variables ( ) const
inlinefinalvirtual
Returns
set of variables of this term.

Implements knowrob::Term.

Definition at line 69 of file Atomic.h.

69 { return Term::noVariables_; }

◆ write() [1/2]

void knowrob::Atomic::write ( std::ostream &  os) const
inlineoverridevirtual

◆ write() [2/2]

void knowrob::Atomic::write ( std::ostream &  os) const
inlineoverridevirtual

Print this object to a stream.

Parameters
osthe stream to print to.

Implements knowrob::Printable.

Reimplemented in knowrob::StringTemplate< StrType >, knowrob::StringBase, knowrob::NumericTemplate< T1, T2 >, and knowrob::IRIAtom.

Definition at line 72 of file Atomic.h.

72 { os << stringForm(); }

Member Data Documentation

◆ atomicType_

const AtomicType knowrob::Atomic::atomicType_
protected

Definition at line 75 of file Atomic.h.


The documentation for this class was generated from the following files: