knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
Term.h
Go to the documentation of this file.
1 /*
2  * This file is part of KnowRob, please consult
3  * https://github.com/knowrob/knowrob for license details.
4  */
5 
6 #ifndef KNOWROB_TERM_H_
7 #define KNOWROB_TERM_H_
8 
9 #include <set>
10 #include <memory>
11 #include <ostream>
12 #include "knowrob/Printable.h"
13 
14 namespace knowrob {
18  enum class TermType : uint8_t {
20  ATOMIC = 0,
22  VARIABLE,
24  FUNCTION
25  };
26 
31  class Term : public Printable {
32  public:
34 
35  ~Term() override = default;
36 
41  bool operator==(const Term &other) const;
42 
47  bool operator!=(const Term &other) const { return !this->operator==(other); }
48 
52  TermType termType() const { return termType_; }
53 
57  bool isGround() const { return variables().empty(); }
58 
62  bool isAtomic() const { return termType_ == TermType::ATOMIC; }
63 
67  bool isAtom() const;
68 
72  bool isVariable() const;
73 
77  bool isFunction() const;
78 
82  bool isNumeric() const;
83 
87  bool isString() const;
88 
92  bool isIRI() const { return isIRI_; }
93 
97  bool isBlank() const { return isBlank_; }
98 
102  size_t hash() const;
103 
107  virtual const std::set<std::string_view> &variables() const = 0;
108 
109  protected:
110  static const std::set<std::string_view> noVariables_;
111  const TermType termType_;
112  bool isBlank_ = false;
113  bool isIRI_ = false;
114  };
115 
116  // alias declaration
117  using TermPtr = std::shared_ptr<Term>;
118 }
119 
120 #endif //KNOWROB_TERM_H_
bool isAtomic() const
Definition: Term.h:62
~Term() override=default
bool isVariable() const
Term(TermType termType)
Definition: Term.h:33
const TermType termType_
Definition: Term.h:111
bool isAtom() const
bool isGround() const
Definition: Term.h:57
bool isBlank() const
Definition: Term.h:97
bool operator==(const Term &other) const
Definition: Term.cpp:55
bool isFunction() const
bool isIRI_
Definition: Term.h:113
bool isNumeric() const
size_t hash() const
static const std::set< std::string_view > noVariables_
Definition: Term.h:110
bool isBlank_
Definition: Term.h:112
bool operator!=(const Term &other) const
Definition: Term.h:47
bool operator==(const Term &other) const
TermType termType() const
Definition: Term.h:52
virtual const std::set< std::string_view > & variables() const =0
bool isIRI() const
Definition: Term.h:92
bool isString() const
TermType
Definition: Term.h:18
std::shared_ptr< Term > TermPtr
Definition: Term.h:117