knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
StorageManager.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_STORAGE_MANAGER_H_
7 #define KNOWROB_STORAGE_MANAGER_H_
8 
9 #include <map>
10 #include "knowrob/semweb/Vocabulary.h"
11 #include "knowrob/plugins/PluginManager.h"
12 #include "QueryableStorage.h"
13 
14 namespace knowrob {
18  class StorageManager : public PluginManager<Storage> {
19  public:
23  explicit StorageManager(const std::shared_ptr<Vocabulary> &vocabulary);
24 
25  ~StorageManager() override = default;
26 
30  auto &vocabulary() const { return vocabulary_; }
31 
35  const auto &persistent() const { return persistent_; }
36 
40  const auto &queryable() const { return queryable_; }
41 
46  void addPlugin(const std::shared_ptr<NamedBackend> &backend);
47 
48  // override PluginManager
49  std::shared_ptr<NamedBackend> loadPlugin(const boost::property_tree::ptree &config) override;
50 
51  // override PluginManager
52  std::shared_ptr<NamedBackend> addPlugin(std::string_view reasonerID, PluginLanguage language, const StoragePtr &backend) override;
53 
54  private:
55  std::shared_ptr<Vocabulary> vocabulary_;
56  std::map<std::string_view, QueryableBackendPtr> persistent_;
57  std::map<std::string_view, QueryableBackendPtr> queryable_;
58 
59  void initBackend(const std::shared_ptr<NamedBackend> &definedKG);
60  };
61 }
62 
63 // a macro for static registration of a storage type.
64 // storage types registered with this macro are builtin storages that are not
65 // loaded from a plugin.
66 #define KNOWROB_BUILTIN_STORAGE(Name, Type) class Type ## _Registration{ static bool isRegistered; }; \
67  bool Type ## _Registration::isRegistered = knowrob::PluginManager<knowrob::Storage>::addFactory<Type>(Name);
68 
69 #endif //KNOWROB_STORAGE_MANAGER_H_
const auto & queryable() const
std::shared_ptr< NamedBackend > addPlugin(std::string_view reasonerID, PluginLanguage language, const StoragePtr &backend) override
const auto & persistent() const
~StorageManager() override=default
void addPlugin(const std::shared_ptr< NamedBackend > &backend)
std::shared_ptr< NamedBackend > loadPlugin(const boost::property_tree::ptree &config) override
StorageManager(const std::shared_ptr< Vocabulary > &vocabulary)
auto & vocabulary() const
PluginLanguage
Definition: NamedPlugin.h:16
std::shared_ptr< Storage > StoragePtr
Definition: Storage.h:154