knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
ReasonerEvent.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/reasoner/ReasonerEvent.h"
7 #include "knowrob/integration/python/utils.h"
8 
9 using namespace knowrob;
10 using namespace knowrob::reasoner;
11 
12 template<typename T>
13 void createTriples(std::vector<TriplePtr> &triples) {
14  for (auto &triple: triples) {
15  triple.ptr = new T();
16  triple.owned = true;
17  }
18 }
19 
20 TripleEvent::TripleEvent(Type eventType, uint32_t tripleCount, bool copy)
21  : Event(eventType), triples_(tripleCount) {
22  if (copy) {
23  createTriples<TripleCopy>(triples_);
24  } else {
25  createTriples<TripleView>(triples_);
26  }
27 }
28 
29 namespace knowrob::py {
30  template<>
31  void createType<reasoner::Event>() {
32  using namespace boost::python;
33  using ReasonerEvent = reasoner::Event;
39  using ReasonerEventType = reasoner::Event::Type;
40 
41  enum_<ReasonerEventType>("ReasonerEventType")
42  .value("Assertion", ReasonerEventType::Assertion)
43  .value("Retraction", ReasonerEventType::Retraction)
44  .value("Replacement", ReasonerEventType::Replacement)
45  .value("Invalidation", ReasonerEventType::Invalidation)
46  .export_values();
47 
48  class_<ReasonerEvent, std::shared_ptr<ReasonerEvent>, boost::noncopyable>
49  ("ReasonerEvent", no_init)
50  .def("eventType", &ReasonerEvent::eventType);
51 
52  class_<TripleEvent, bases<ReasonerEvent>, std::shared_ptr<TripleEvent>, boost::noncopyable>
53  ("TripleEvent", no_init)
54  .def("triples", &TripleEvent::triples, return_value_policy<copy_const_reference>())
55  .def("triple", &TripleEvent::triple, return_value_policy<reference_existing_object>());
56 
57  class_<AssertionEvent, std::shared_ptr<AssertionEvent>, bases<TripleEvent>, boost::noncopyable>
58  ("AssertionEvent", init<uint32_t, bool>())
59  .def(init<uint32_t>());
60 
61  class_<RetractionEvent, std::shared_ptr<RetractionEvent>, bases<TripleEvent>, boost::noncopyable>
62  ("RetractionEvent", init<uint32_t, bool>())
63  .def(init<uint32_t>());
64 
65  class_<ReplacementEvent, std::shared_ptr<ReplacementEvent>, bases<TripleEvent>, boost::noncopyable>
66  ("ReplacementEvent", init<uint32_t, bool>())
67  .def(init<uint32_t>());
68 
69  class_<InvalidationEvent, std::shared_ptr<InvalidationEvent>, bases<ReasonerEvent>, boost::noncopyable>
70  ("InvalidationEvent", init<>());
71  }
72 }
void createTriples(std::vector< TriplePtr > &triples)
auto & triple(uint32_t index)
Definition: ReasonerEvent.h:73
TripleEvent(Type eventType, uint32_t tripleCount, bool copy=true)
std::vector< TriplePtr > triples_
Definition: ReasonerEvent.h:76