knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
CompoundFormula.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 <knowrob/formulas/CompoundFormula.h>
7 #include <algorithm>
8 #include "knowrob/integration/python/utils.h"
9 
10 using namespace knowrob;
11 
13  const std::vector<std::shared_ptr<Formula>> &formulae)
14  : Formula(type),
15  formulae_(formulae) {
16  isGround_ = isGround1();
17 }
18 
19 bool CompoundFormula::isGround1() const {
20  return std::all_of(formulae_.begin(), formulae_.end(),
21  [](const std::shared_ptr<Formula> &x) { return x->isGround(); });
22 }
23 
24 void CompoundFormula::write(std::ostream &os) const {
25  if (formulae_.size() == 1) {
26  os << operator_symbol() << ' ';
27  os << *(formulae_[0].get());
28  } else {
29  os << '(';
30  for (uint32_t i = 0; i < formulae_.size(); i++) {
31  os << *(formulae_[i].get());
32  if (i + 1 < formulae_.size()) {
33  os << ' ' << operator_symbol() << ' ';
34  }
35  }
36  os << ')';
37  }
38 }
39 
40 namespace knowrob::py {
41  template<>
43  using namespace boost::python;
44  class_<CompoundFormula, std::shared_ptr<CompoundFormula>, boost::noncopyable, bases<Formula>>
45  ("CompoundFormula", no_init)
46  .def("formulae", &CompoundFormula::formulae, return_value_policy<copy_const_reference>());
47  }
48 }
const std::vector< FormulaPtr > & formulae() const
virtual const char * operator_symbol() const =0
const std::vector< FormulaPtr > formulae_
void write(std::ostream &os) const override
CompoundFormula(FormulaType type, const std::vector< FormulaPtr > &formulae)
void createType< CompoundFormula >()
const IRIAtomPtr type
Definition: rdf.h:15
FormulaType
Definition: Formula.h:17