knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
Storage.cpp
Go to the documentation of this file.
1 #include "knowrob/storage/Storage.h"
2 #include "knowrob/integration/python/utils.h"
3 #include "knowrob/storage/QueryableStorage.h"
4 #include "knowrob/storage/Observer.h"
5 
6 using namespace knowrob;
7 
9  return static_cast<StorageFeature>(static_cast<std::uint8_t>(a) | static_cast<std::uint8_t>(b));
10 }
11 
13  return static_cast<std::uint8_t>(a) & static_cast<std::uint8_t>(b);
14 }
15 
16 namespace knowrob::py {
17  struct StorageWrap : public Storage, boost::python::wrapper<Storage> {
18  explicit StorageWrap(PyObject *p) : Storage(), self(p) {}
19 
20  bool initializeBackend(const PropertyTree &config) override {
21  return call_method<bool>(self, "initializeBackend", config);
22  }
23 
24  bool insertOne(const Triple &triple) override {
25  return call_method<bool>(self, "insertOne", &triple);
26  }
27 
28  bool insertAll(const TripleContainerPtr &triples) override {
29  return call_method<bool>(self, "insertAll", triples);
30  }
31 
32  bool removeOne(const Triple &triple) override {
33  return call_method<bool>(self, "removeOne", &triple);
34  }
35 
36  bool removeAll(const TripleContainerPtr &triples) override {
37  return call_method<bool>(self, "removeAll", triples);
38  }
39 
40  bool removeAllWithOrigin(std::string_view origin) override {
41  return call_method<bool>(self, "removeAllWithOrigin", origin.data());
42  }
43 
44  private:
45  PyObject *self;
46  };
47 
48  template<>
50  using namespace boost::python;
51  enum_<StorageFeature>("StorageFeature")
52  .value("NothingSpecial", StorageFeature::NothingSpecial)
53  .value("ReAssignment", StorageFeature::ReAssignment)
54  .value("TripleContext", StorageFeature::TripleContext)
55  .export_values();
56  class_<Storage, std::shared_ptr<StorageWrap>, bases<DataSourceHandler>, boost::noncopyable>
57  ("Storage", init<>())
58  .def("vocabulary", &Storage::vocabulary, return_value_policy<copy_const_reference>())
59  .def("supports", &Storage::supports)
60  .def("getVersionOfOrigin", &Storage::getVersionOfOrigin)
61  .def("setVersionOfOrigin", &Storage::setVersionOfOrigin)
62  // methods that must be implemented by backend plugins
63  .def("initializeBackend", pure_virtual(&Storage::initializeBackend))
64  .def("insertOne", pure_virtual(&Storage::insertOne))
65  .def("insertAll", pure_virtual(&Storage::insertAll))
66  .def("removeAll", pure_virtual(&Storage::removeAll))
67  .def("removeOne", pure_virtual(&Storage::removeOne))
68  .def("removeAllWithOrigin", pure_virtual(&Storage::removeAllWithOrigin));
69  register_ptr_to_python< std::shared_ptr< Storage > >();
72  }
73 }
bool supports(StorageFeature feature) const
Definition: Storage.h:84
void setVersionOfOrigin(std::string_view origin, std::optional< std::string_view > version)
Definition: Storage.h:133
std::optional< std::string > getVersionOfOrigin(std::string_view origin) const
Definition: Storage.h:125
const auto & vocabulary() const
Definition: Storage.h:73
virtual bool initializeBackend(const PropertyTree &config)=0
virtual bool insertAll(const TripleContainerPtr &triples)=0
virtual bool removeAll(const TripleContainerPtr &triples)=0
virtual bool removeAllWithOrigin(std::string_view origin)=0
virtual bool removeOne(const Triple &triple)=0
virtual bool insertOne(const Triple &triple)=0
void createType< Storage >()
Definition: Storage.cpp:49
void createType< QueryableStorage >()
void createType< Observer >()
Definition: Observer.cpp:30
StorageFeature
Definition: Storage.h:24
FormulaPtr operator|(const FormulaPtr &phi, const FormulaPtr &psi)
Definition: Disjunction.cpp:55
std::shared_ptr< TripleContainer > TripleContainerPtr
FormulaPtr operator&(const FormulaPtr &phi, const FormulaPtr &psi)
Definition: Conjunction.cpp:34