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

#include <Function.h>

Inheritance diagram for knowrob::Function:
Collaboration diagram for knowrob::Function:

Public Member Functions

 Function (AtomPtr functor, const std::vector< TermPtr > &arguments)
 
 Function (std::string_view functor, const std::vector< TermPtr > &arguments)
 
bool isSameFunction (const Function &other) const
 
auto & functor () const
 
auto & arguments () const
 
auto arity () const
 
size_t hashOfFunction () const
 
const std::set< std::string_view > & variables () const override
 
void write (std::ostream &os) const override
 
 Function (AtomPtr functor, const std::vector< TermPtr > &arguments)
 
 Function (std::string_view functor, const std::vector< TermPtr > &arguments)
 
bool isSameFunction (const Function &other) const
 
auto & functor () const
 
auto & arguments () const
 
auto arity () const
 
size_t hashOfFunction () const
 
const std::set< std::string_view > & variables () const override
 
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
 

Protected Member Functions

std::set< std::string_view > getVariables1 () const
 
std::set< std::string_view > getVariables1 () const
 

Protected Attributes

const std::shared_ptr< Atomfunctor_
 
const std::vector< TermPtrarguments_
 
const std::set< std::string_view > variables_
 
- 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

A function term is a compound term with a functor and a list of arguments.

Definition at line 17 of file Function.h.

Constructor & Destructor Documentation

◆ Function() [1/4]

Function::Function ( AtomPtr  functor,
const std::vector< TermPtr > &  arguments 
)

Constructs a function term from a functor and a list of arguments.

Parameters
functorthe functor
argumentsthe arguments

Definition at line 13 of file Function.cpp.

15  functor_(std::move(functor)),
18 }
const std::set< std::string_view > variables_
Definition: Function.h:68
const std::shared_ptr< Atom > functor_
Definition: Function.h:66
const std::vector< TermPtr > arguments_
Definition: Function.h:67
auto & arguments() const
Definition: Function.h:47
auto & functor() const
Definition: Function.h:42
std::set< std::string_view > getVariables1() const
Definition: Function.cpp:24
Term(TermType termType)
Definition: Term.h:33

◆ Function() [2/4]

Function::Function ( std::string_view  functor,
const std::vector< TermPtr > &  arguments 
)

Constructs a function term from a functor and a list of arguments.

Parameters
functorthe functor
argumentsthe arguments

Definition at line 20 of file Function.cpp.

22 }
static std::shared_ptr< knowrob::Atom > Tabled(std::string_view stringForm)
Definition: Atom.cpp:40
Function(AtomPtr functor, const std::vector< TermPtr > &arguments)
Definition: Function.cpp:13

◆ Function() [3/4]

knowrob::Function::Function ( AtomPtr  functor,
const std::vector< TermPtr > &  arguments 
)

Constructs a function term from a functor and a list of arguments.

Parameters
functorthe functor
argumentsthe arguments

◆ Function() [4/4]

knowrob::Function::Function ( std::string_view  functor,
const std::vector< TermPtr > &  arguments 
)

Constructs a function term from a functor and a list of arguments.

Parameters
functorthe functor
argumentsthe arguments

Member Function Documentation

◆ arguments() [1/2]

auto& knowrob::Function::arguments ( ) const
inline
Returns
the arguments

Definition at line 47 of file Function.h.

47 { return arguments_; }

◆ arguments() [2/2]

auto& knowrob::Function::arguments ( ) const
inline
Returns
the arguments

Definition at line 47 of file Function.h.

47 { return arguments_; }

◆ arity() [1/2]

auto knowrob::Function::arity ( ) const
inline
Returns
the arity of the function

Definition at line 52 of file Function.h.

52 { return arguments_.size(); }

◆ arity() [2/2]

auto knowrob::Function::arity ( ) const
inline
Returns
the arity of the function

Definition at line 52 of file Function.h.

52 { return arguments_.size(); }

◆ functor() [1/2]

auto& knowrob::Function::functor ( ) const
inline
Returns
the functor

Definition at line 42 of file Function.h.

42 { return functor_; }

◆ functor() [2/2]

auto& knowrob::Function::functor ( ) const
inline
Returns
the functor

Definition at line 42 of file Function.h.

42 { return functor_; }

◆ getVariables1() [1/2]

std::set< std::string_view > Function::getVariables1 ( ) const
protected

Definition at line 24 of file Function.cpp.

24  {
25  std::set<std::string_view> out;
26  for (auto &arg: arguments_) {
27  out.insert(arg->variables().begin(), arg->variables().end());
28  }
29  return out;
30 }

◆ getVariables1() [2/2]

std::set<std::string_view> knowrob::Function::getVariables1 ( ) const
protected

◆ hashOfFunction() [1/2]

size_t Function::hashOfFunction ( ) const
Returns
the hash of this function.

Definition at line 44 of file Function.cpp.

44  {
45  auto seed = static_cast<size_t>(0);
46  hashCombine(seed, functor_->hash());
47  for (auto &arg: arguments_) {
48  hashCombine(seed, arg->hash());
49  }
50  return seed;
51 }
void hashCombine(std::size_t &seed, const std::size_t &v)
Definition: knowrob.cpp:39

◆ hashOfFunction() [2/2]

size_t knowrob::Function::hashOfFunction ( ) const
Returns
the hash of this function.

◆ isSameFunction() [1/2]

bool Function::isSameFunction ( const Function other) const
Parameters
otheranother function
Returns
true if both functions are equal

Definition at line 32 of file Function.cpp.

32  {
33  if (arguments_.size() != other.arguments_.size() || *functor_ != *other.functor_) {
34  return false;
35  }
36  for (uint32_t i = 0; i < arguments_.size(); i++) {
37  if (*arguments_[i] != *other.arguments_[i]) {
38  return false;
39  }
40  }
41  return true;
42 }

◆ isSameFunction() [2/2]

bool knowrob::Function::isSameFunction ( const Function other) const
Parameters
otheranother function
Returns
true if both functions are equal

◆ variables() [1/2]

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

Implements knowrob::Term.

Definition at line 60 of file Function.h.

60 { return variables_; }

◆ variables() [2/2]

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

Implements knowrob::Term.

Definition at line 60 of file Function.h.

60 { return variables_; }

◆ write() [1/2]

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

Print this object to a stream.

Parameters
osthe stream to print to.

Implements knowrob::Printable.

Reimplemented in knowrob::ListTerm, knowrob::GraphBuiltin, and knowrob::ListTerm.

Definition at line 53 of file Function.cpp.

53  {
54  os << *functor_;
55  if (!arguments_.empty()) {
56  os << '(';
57  for (uint32_t i = 0; i < arguments_.size(); i++) {
58  os << *arguments_[i];
59  if (i + 1 < arguments_.size()) {
60  os << ',' << ' ';
61  }
62  }
63  os << ')';
64  }
65 }

◆ write() [2/2]

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

Print this object to a stream.

Parameters
osthe stream to print to.

Implements knowrob::Printable.

Reimplemented in knowrob::ListTerm.

Member Data Documentation

◆ arguments_

const std::vector< TermPtr > knowrob::Function::arguments_
protected

Definition at line 67 of file Function.h.

◆ functor_

const std::shared_ptr< Atom > knowrob::Function::functor_
protected

Definition at line 66 of file Function.h.

◆ variables_

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

Definition at line 68 of file Function.h.


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