knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
Variable.cpp
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 #include <gtest/gtest.h>
7 #include "knowrob/terms/Variable.h"
8 #include "knowrob/integration/python/utils.h"
9 
10 using namespace knowrob;
11 
12 Variable::Variable(std::string_view name)
14  nameAtom_(Atom::Tabled(name)),
15  variables_({nameAtom_->stringForm()}) {
16 }
17 
18 bool Variable::isSameVariable(const Variable &other) const {
19  return *nameAtom_ == *other.nameAtom_;
20 }
21 
22 bool Variable::operator<(const Variable &other) const {
23  return (this->nameAtom_->stringForm() < other.nameAtom_->stringForm());
24 }
25 
26 void Variable::write(std::ostream &os) const {
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 }
34 
35 namespace knowrob::py {
36  template<>
38  using namespace boost::python;
39  class_<Variable, std::shared_ptr<Variable>, bases<Term>>
40  ("Variable", init<std::string_view>())
41  .def(self < self)
42  .def("name", &Variable::name)
43  .def("isSameVariable", &Variable::isSameVariable);
44  }
45 }
const AtomPtr nameAtom_
Definition: Variable.h:56
Variable(std::string_view name)
Definition: Variable.cpp:12
bool isSameVariable(const Variable &other) const
Definition: Variable.cpp:18
std::string_view name() const
Definition: Variable.h:42
bool operator<(const Variable &other) const
Definition: Variable.cpp:22
void write(std::ostream &os) const override
Definition: Variable.cpp:26
void createType< Variable >()
Definition: Variable.cpp:37
TermType
Definition: Term.h:18