knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
Blank.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 <optional>
7 #include "knowrob/terms/Blank.h"
8 #include "knowrob/integration/python/utils.h"
9 
10 using namespace knowrob;
11 
12 std::shared_ptr<knowrob::Blank> Blank::Tabled(std::string_view name) {
13  auto it = Atom::table().find(name);
14  if (it != table().end()) {
15  if (auto atomPtr = it->second.value().lock()) {
16  if (atomPtr->isBlank()) {
17  return std::static_pointer_cast<Blank>(atomPtr);
18  }
19  }
20  }
21  // Atom does not exist or was destroyed, create a new one
22  auto inserted = table().emplace(name, std::nullopt);
23  auto &jt = inserted.first;
24  auto atom = std::make_shared<knowrob::Blank>(jt->first);
25  jt->second = atom;
26  auto locked = jt->second.value().lock();
27  if (!locked) {
28  throw std::runtime_error("Failed to lock Blank");
29  }
30  return std::static_pointer_cast<Blank>(locked);
31 }
32 
33 namespace knowrob::py {
34  template<>
36  using namespace boost::python;
37  class_<Blank, std::shared_ptr<Blank>, bases<Atom, RDFNode>>
38  ("Blank", init<std::string_view>());
39  }
40 }
static AtomTable & table()
Definition: Atom.cpp:11
static std::shared_ptr< Blank > Tabled(std::string_view stringForm)
Definition: Blank.cpp:12
StringRule & atom()
Definition: strings.cpp:54
void createType< Blank >()
Definition: Blank.cpp:35