knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
knowrob::Variable Class Reference

#include <Variable.h>

Inheritance diagram for knowrob::Variable:
Collaboration diagram for knowrob::Variable:

the name of the variable.

const AtomPtr nameAtom_
 
const std::set< std::string_view > variables_
 
 Variable (std::string_view name)
 
bool operator< (const Variable &other) const
 
bool isSameVariable (const Variable &other) const
 
std::string_view name () const
 
const AtomPtrnameAtom () const
 
const std::set< std::string_view > & variables () const override
 
void write (std::ostream &os) const override
 
 Variable (std::string_view name)
 
bool operator< (const Variable &other) const
 
bool isSameVariable (const Variable &other) const
 
std::string_view name () const
 
const AtomPtrnameAtom () const
 
const std::set< std::string_view > & variables () const override
 
void write (std::ostream &os) const override
 

Additional Inherited Members

- 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
 
- Protected Attributes inherited from knowrob::Term
const TermType termType_
 
bool isBlank_ = false
 
bool isIRI_ = false
 
- Static Protected Attributes inherited from knowrob::Term
static const std::set< std::string_view > noVariables_ = {}
 

Detailed Description

A variable term. A variable is identified by a name string in the scope of a formula, i.e. within a formula two variables with the same name are considered to be equal.

Definition at line 20 of file Variable.h.

Constructor & Destructor Documentation

◆ Variable() [1/2]

Variable::Variable ( std::string_view  name)
explicit

Definition at line 12 of file Variable.cpp.

15  variables_({nameAtom_->stringForm()}) {
16 }
static std::shared_ptr< knowrob::Atom > Tabled(std::string_view stringForm)
Definition: Atom.cpp:40
Term(TermType termType)
Definition: Term.h:33
const AtomPtr nameAtom_
Definition: Variable.h:56
std::string_view name() const
Definition: Variable.h:42
const std::set< std::string_view > variables_
Definition: Variable.h:57

◆ Variable() [2/2]

knowrob::Variable::Variable ( std::string_view  name)
explicit

Member Function Documentation

◆ isSameVariable() [1/2]

bool Variable::isSameVariable ( const Variable other) const
Parameters
otheranother variable.
Returns
true if the names of the two variables are the same.

Definition at line 18 of file Variable.cpp.

18  {
19  return *nameAtom_ == *other.nameAtom_;
20 }

◆ isSameVariable() [2/2]

bool knowrob::Variable::isSameVariable ( const Variable other) const
Parameters
otheranother variable.
Returns
true if the names of the two variables are the same.

◆ name() [1/2]

std::string_view knowrob::Variable::name ( ) const
inline
Returns
the name of this variable.

Definition at line 42 of file Variable.h.

42 { return nameAtom_->stringForm(); }

◆ name() [2/2]

std::string_view knowrob::Variable::name ( ) const
inline
Returns
the name of this variable.

Definition at line 42 of file Variable.h.

42 { return nameAtom_->stringForm(); }

◆ nameAtom() [1/2]

const AtomPtr& knowrob::Variable::nameAtom ( ) const
inline
Returns
the name of this variable.

Definition at line 47 of file Variable.h.

47 { return nameAtom_; }

◆ nameAtom() [2/2]

const AtomPtr& knowrob::Variable::nameAtom ( ) const
inline
Returns
the name of this variable.

Definition at line 47 of file Variable.h.

47 { return nameAtom_; }

◆ operator<() [1/2]

bool Variable::operator< ( const Variable other) const
Parameters
otheranother variable.
Returns
true if this name is alphabetically before other

Definition at line 22 of file Variable.cpp.

22  {
23  return (this->nameAtom_->stringForm() < other.nameAtom_->stringForm());
24 }

◆ operator<() [2/2]

bool knowrob::Variable::operator< ( const Variable other) const
Parameters
otheranother variable.
Returns
true if this name is alphabetically before other

◆ variables() [1/2]

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

Implements knowrob::Term.

Definition at line 50 of file Variable.h.

50 { return variables_; }

◆ variables() [2/2]

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

Implements knowrob::Term.

Definition at line 50 of file Variable.h.

50 { return variables_; }

◆ write() [1/2]

void Variable::write ( std::ostream &  os) const
overridevirtual

Print this object to a stream.

Parameters
osthe stream to print to.

Implements knowrob::Printable.

Definition at line 26 of file Variable.cpp.

26  {
27  // prepend '?' to indicate variable if the name atom starts with a lowercase letter
28  auto name = nameAtom_->stringForm();
29  if (std::islower(name[0])) {
30  os << '?';
31  }
32  os << name;
33 }

◆ write() [2/2]

void knowrob::Variable::write ( std::ostream &  os) const
overridevirtual

Print this object to a stream.

Parameters
osthe stream to print to.

Implements knowrob::Printable.

Member Data Documentation

◆ nameAtom_

const AtomPtr knowrob::Variable::nameAtom_
protected

Definition at line 56 of file Variable.h.

◆ variables_

const std::set< std::string_view > knowrob::Variable::variables_
protected

Definition at line 57 of file Variable.h.


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