7 #include "knowrob/semweb/ImportHierarchy.h"
8 #include "knowrob/Logger.h"
9 #include "knowrob/integration/python/utils.h"
14 : defaultGraph_(ORIGIN_USER) {
24 return reservedOrigins.count(origin) > 0;
28 return graphs_.count(graphName) > 0;
33 return graph == originSystem || originSystem.
imports_.count(&graph) > 0;
38 return graph == originSession || originSession.
imports_.count(&graph) > 0;
42 auto it =
graphs_.find(graphName);
45 graphs_.emplace(newGraph->name(), newGraph);
50 auto it =
graphs_.find(graphName);
52 static std::set<CurrentGraph *> empty;
55 return it->second->imports_;
63 auto inserted =
graphs_.emplace(newGraph->name(), newGraph);
79 KB_WARN(
"Ignoring session graph \"{}\" import of system graph \"{}\".", importerGraphName, importedGraphName);
84 auto pair = g_importer.directImports_.insert(g_imported);
85 if (!pair.second)
return;
86 KB_DEBUG(
"Graph \"{}\" imports \"{}\".", importerGraphName, importedGraphName);
88 g_importer.imports_.insert(g_imported->imports_.begin(), g_imported->imports_.end());
89 g_importer.imports_.insert(g_imported);
93 if (it.second->imports_.count(&g_importer) > 0) {
94 it.second->imports_.insert(g_imported->imports_.begin(), g_imported->imports_.end());
95 it.second->imports_.insert(g_imported);
101 auto it =
graphs_.find(graphName);
102 if (it ==
graphs_.end())
return;
103 auto &ga = *it->second;
107 auto &gx = *jt.second;
108 if (gx.directImports_.count(&ga) > 0) {
110 gx.directImports_.erase(&ga);
111 gx.imports_.erase(&ga);
113 gx.directImports_.insert(ga.directImports_.begin(), ga.directImports_.end());
118 auto &gy = *kt.second;
119 if (gy.imports_.count(&ga) > 0) {
121 gy.imports_.erase(&ga);
134 class_<ImportHierarchy, std::shared_ptr<ImportHierarchy>, boost::noncopyable>
135 (
"ImportHierarchy", init<>())
std::set< CurrentGraph * > imports_
CurrentGraph & getCurrentGraph(std::string_view name)
std::map< std::string_view, std::unique_ptr< CurrentGraph > > graphs_
void addDirectImport(std::string_view importerGraphName, std::string_view importedGraphName)
static bool isReservedOrigin(std::string_view origin)
bool isCurrentGraph(std::string_view graphName) const
static constexpr std::string_view ORIGIN_TEST
bool isSessionOrigin(CurrentGraph &graph)
const auto & defaultGraph() const
void setDefaultGraph(std::string_view defaultGraph)
static constexpr std::string_view ORIGIN_SESSION
void removeCurrentGraph(std::string_view graphName)
static constexpr std::string_view ORIGIN_USER
static constexpr std::string_view ORIGIN_REASONER
static constexpr std::string_view ORIGIN_SYSTEM
const std::set< CurrentGraph * > & getImports(std::string_view graphName)
static constexpr std::string_view ORIGIN_ANY
void addCurrentGraph(std::string_view graphName)
bool isSystemOrigin(CurrentGraph &graph)
void createType< ImportHierarchy >()