knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
Variable.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_VARIABLE_H_
7 #define KNOWROB_VARIABLE_H_
8 
9 #include <string>
10 #include <ostream>
11 #include "Term.h"
12 #include "Atom.h"
13 
14 namespace knowrob {
20  class Variable : public Term {
21  public:
25  explicit Variable(std::string_view name);
26 
31  bool operator<(const Variable &other) const;
32 
37  bool isSameVariable(const Variable &other) const;
38 
42  std::string_view name() const { return nameAtom_->stringForm(); }
43 
47  const AtomPtr &nameAtom() const { return nameAtom_; }
48 
49  // Override Term
50  const std::set<std::string_view> &variables() const override { return variables_; }
51 
52  // Override Printable
53  void write(std::ostream &os) const override;
54 
55  protected:
56  const AtomPtr nameAtom_;
57  const std::set<std::string_view> variables_;
58  };
59 
60  using VariablePtr = std::shared_ptr<Variable>;
61 
62  struct VariablePtrComparator {
63  bool operator()(const VariablePtr &lhs, const VariablePtr &rhs) const { return *lhs < *rhs; }
64  };
65 }
66 
67 #endif //KNOWROB_VARIABLE_H_
const AtomPtr nameAtom_
Definition: Variable.h:56
bool operator<(const Variable &other) const
Variable(std::string_view name)
void write(std::ostream &os) const override
bool isSameVariable(const Variable &other) const
const AtomPtr & nameAtom() const
Definition: Variable.h:47
std::string_view name() const
Definition: Variable.h:42
const std::set< std::string_view > & variables() const override
Definition: Variable.h:50
const std::set< std::string_view > variables_
Definition: Variable.h:57
std::shared_ptr< Atom > AtomPtr
Definition: Atom.h:69
std::shared_ptr< Variable > VariablePtr
Definition: Variable.h:60
bool operator()(const VariablePtr &lhs, const VariablePtr &rhs) const
Definition: Variable.h:63