knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
Atom.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_ATOM_H
7 #define KNOWROB_ATOM_H
8 
9 #include <unordered_map>
10 #include <optional>
11 #include <map>
12 #include "Atomic.h"
13 
14 namespace knowrob {
18  enum class AtomType {
20  REGULAR,
22  IRI
23  };
24 
28  class Atom : public Atomic {
29  public:
34  static std::shared_ptr<knowrob::Atom> Tabled(std::string_view stringForm);
35 
41  explicit Atom(std::string_view stringForm, AtomType atomType = AtomType::REGULAR);
42 
47  bool isSameAtom(const Atom &other) const;
48 
52  AtomType atomType() const { return atomType_; }
53 
54  // override Atomic
55  std::string_view stringForm() const final { return stringForm_; }
56 
57  // override Printable
58  void write(std::ostream &os) const override;
59 
60  protected:
61  std::string_view stringForm_;
62  const AtomType atomType_;
63 
64  using AtomTable = std::map<std::string, std::optional<std::weak_ptr<Atom>>, std::less<>>;
65 
66  static AtomTable &table();
67  };
68 
69  using AtomPtr = std::shared_ptr<Atom>;
70 
71 } // knowrob
72 
73 #endif //KNOWROB_ATOM_H
std::map< std::string, std::optional< std::weak_ptr< Atom > >, std::less<> > AtomTable
Definition: Atom.h:64
static std::shared_ptr< knowrob::Atom > Tabled(std::string_view stringForm)
Atom(std::string_view stringForm, AtomType atomType=AtomType::REGULAR)
const AtomType atomType_
Definition: Atom.h:62
void write(std::ostream &os) const override
AtomType atomType() const
Definition: Atom.h:52
bool isSameAtom(const Atom &other) const
std::string_view stringForm_
Definition: Atom.h:61
std::string_view stringForm() const final
Definition: Atom.h:55
static AtomTable & table()
AtomType
Definition: Atom.h:18
std::shared_ptr< Atom > AtomPtr
Definition: Atom.h:69