knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
Class.h
Go to the documentation of this file.
1 //
2 // Created by daniel on 07.04.23.
3 //
4 
5 #ifndef KNOWROB_SEMWEB_CLASS_H
6 #define KNOWROB_SEMWEB_CLASS_H
7 
8 #include <memory>
9 #include <list>
10 #include <functional>
11 #include "Resource.h"
12 
13 namespace knowrob::semweb {
14 
15  // forward declaration
16  class Class;
17 
18  // called for each parent in the property hierarchy
19  using ClassVisitor = std::function<void(Class &)>;
20  // called for each parent in the property hierarchy
21  using ClassTupleVisitor = std::function<void(Class &, Class &)>;
22 
26  class Class : public Resource, public std::enable_shared_from_this<Class> {
27  public:
31  explicit Class(std::string_view iri);
32 
36  explicit Class(const IRIAtomPtr &iri);
37 
42  void addDirectParent(const std::shared_ptr<Class> &directParent, std::optional<std::string_view> graph);
43 
48  void removeDirectParent(const std::shared_ptr<Class> &directParent, std::optional<std::string_view> graph);
49 
53  const auto &directParents() const { return directParents_; }
54 
59  bool isDirectSubClassOf(const std::shared_ptr<Class> &directParent);
60 
66  bool isSubClassOf(const std::shared_ptr<Class> &parent, bool includeSelf = true);
67 
73  void forallParents(const ClassVisitor &visitor, bool includeSelf = true, bool skipDuplicates = true);
74 
79  void forallChildren(const ClassTupleVisitor &visitor, bool skipDuplicates = true);
80 
84  void detach();
85 
86  protected:
87  struct ClassComparator {
88  bool operator()(const std::shared_ptr<Class> &lhs, const std::shared_ptr<Class> &rhs) const;
89  };
90 
91  std::map<std::shared_ptr<Class>,
92  std::set<AtomPtr, AtomComparator>,
94  std::set<std::shared_ptr<Class>, ClassComparator> directChildren_;
95  };
96 
97  using ClassPtr = std::shared_ptr<Class>;
98 
99 } // knowrob::semweb
100 
101 #endif //KNOWROB_SEMWEB_CLASS_H
std::set< std::shared_ptr< Class >, ClassComparator > directChildren_
Definition: Class.h:94
Class(const IRIAtomPtr &iri)
bool isDirectSubClassOf(const std::shared_ptr< Class > &directParent)
const auto & directParents() const
Definition: Class.h:53
void forallParents(const ClassVisitor &visitor, bool includeSelf=true, bool skipDuplicates=true)
bool isSubClassOf(const std::shared_ptr< Class > &parent, bool includeSelf=true)
Class(std::string_view iri)
void forallChildren(const ClassTupleVisitor &visitor, bool skipDuplicates=true)
void addDirectParent(const std::shared_ptr< Class > &directParent, std::optional< std::string_view > graph)
void removeDirectParent(const std::shared_ptr< Class > &directParent, std::optional< std::string_view > graph)
std::map< std::shared_ptr< Class >, std::set< AtomPtr, AtomComparator >, ClassComparator > directParents_
Definition: Class.h:93
const IRIAtomPtr Class
Definition: owl.h:18
FunctionRule & function()
Definition: terms.cpp:140
std::shared_ptr< Class > ClassPtr
Definition: Class.h:97
std::function< void(Class &)> ClassVisitor
Definition: Class.h:19
std::function< void(Class &, Class &)> ClassTupleVisitor
Definition: Class.h:21
std::shared_ptr< IRIAtom > IRIAtomPtr
Definition: IRIAtom.h:57
bool operator()(const std::shared_ptr< Class > &lhs, const std::shared_ptr< Class > &rhs) const