FunctionalVisitor.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <functional>
4 
5 #include "Visitor.h"
6 
7 
8 namespace armarx::armem::wm
9 {
10 
11  /**
12  * @brief A `Visitor` which can be parametrized by `std::function`
13  * instead of inheriting and overriding.
14  */
15  class FunctionalVisitor : public Visitor
16  {
17  public:
18 
20  virtual ~FunctionalVisitor() override;
21 
22 
23  bool visitEnter(Memory& memory) override
24  {
26  }
27  bool visitEnter(CoreSegment& coreSegment) override
28  {
29  return coreSegmentFn ? coreSegmentFn(coreSegment) : Visitor::visitEnter(coreSegment);
30  }
31  bool visitEnter(ProviderSegment& providerSegment) override
32  {
33  return providerSegmentFn ? providerSegmentFn(providerSegment) : Visitor::visitEnter(providerSegment);
34  }
35  bool visitEnter(Entity& entity) override
36  {
37  return entityFn ? entityFn(entity) : Visitor::visitEnter(entity);
38  }
39  bool visitEnter(EntitySnapshot& snapshot) override
40  {
41  return snapshotFn ? snapshotFn(snapshot) : Visitor::visitEnter(snapshot);
42  }
43 
44  bool visit(EntityInstance& instance) override
45  {
46  return instanceFn ? instanceFn(instance) : Visitor::visit(instance);
47  }
48 
49 
50 
51  // Const versions
52 
53 
54  bool visitEnter(const Memory& memory) override
55  {
57  }
58  bool visitEnter(const CoreSegment& coreSegment) override
59  {
60  return coreSegmentConstFn ? coreSegmentConstFn(coreSegment) : Visitor::visitEnter(coreSegment);
61  }
62  bool visitEnter(const ProviderSegment& providerSegment) override
63  {
64  return providerSegmentConstFn ? providerSegmentConstFn(providerSegment) : Visitor::visitEnter(providerSegment);
65  }
66  bool visitEnter(const Entity& entity) override
67  {
68  return entityConstFn ? entityConstFn(entity) : Visitor::visitEnter(entity);
69  }
70  bool visitEnter(const EntitySnapshot& snapshot) override
71  {
72  return snapshotConstFn ? snapshotConstFn(snapshot) : Visitor::visitEnter(snapshot);
73  }
74 
75  bool visit(const EntityInstance& instance) override
76  {
77  return instanceConstFn ? instanceConstFn(instance) : Visitor::visit(instance);
78  }
79 
80 
81  std::function<bool(Memory& memory)> memoryFn;
82  std::function<bool(const Memory& memory)> memoryConstFn;
83 
84  std::function<bool(CoreSegment& coreSegment)> coreSegmentFn;
85  std::function<bool(const CoreSegment& coreSegment)> coreSegmentConstFn;
86 
87  std::function<bool(ProviderSegment& providerSegment)> providerSegmentFn;
88  std::function<bool(const ProviderSegment& providerSegment)> providerSegmentConstFn;
89 
90  std::function<bool(Entity& entity)> entityFn;
91  std::function<bool(const Entity& entity)> entityConstFn;
92 
93  std::function<bool(EntitySnapshot& snapshot)> snapshotFn;
94  std::function<bool(const EntitySnapshot& snapshot)> snapshotConstFn;
95 
96  std::function<bool(EntityInstance& instance)> instanceFn;
97  std::function<bool(const EntityInstance& instance)> instanceConstFn;
98 
99  };
100 
101 }
armarx::armem::wm::FunctionalVisitor::coreSegmentConstFn
std::function< bool(const CoreSegment &coreSegment)> coreSegmentConstFn
Definition: FunctionalVisitor.h:85
armarx::armem::wm::FunctionalVisitor::entityFn
std::function< bool(Entity &entity)> entityFn
Definition: FunctionalVisitor.h:90
armarx::armem::wm::FunctionalVisitor::providerSegmentConstFn
std::function< bool(const ProviderSegment &providerSegment)> providerSegmentConstFn
Definition: FunctionalVisitor.h:88
armarx::armem::wm::ProviderSegment
Client-side working memory provider segment.
Definition: memory_definitions.h:105
armarx::armem::wm::EntityInstance
Client-side working entity instance.
Definition: memory_definitions.h:32
armarx::armem::wm::FunctionalVisitor::FunctionalVisitor
FunctionalVisitor()
Definition: FunctionalVisitor.cpp:12
armarx::armem::wm::FunctionalVisitor::visitEnter
bool visitEnter(EntitySnapshot &snapshot) override
Definition: FunctionalVisitor.h:39
armarx::armem::wm::FunctionalVisitor::visitEnter
bool visitEnter(const ProviderSegment &providerSegment) override
Definition: FunctionalVisitor.h:62
armarx::armem::wm::FunctionalVisitor::visitEnter
bool visitEnter(const Memory &memory) override
Definition: FunctionalVisitor.h:54
armarx::armem::wm::FunctionalVisitor::~FunctionalVisitor
virtual ~FunctionalVisitor() override
Definition: FunctionalVisitor.cpp:17
armarx::armem::wm::FunctionalVisitor::entityConstFn
std::function< bool(const Entity &entity)> entityConstFn
Definition: FunctionalVisitor.h:91
Visitor.h
armarx::memory
Brief description of class memory.
Definition: memory.h:39
armarx::armem::wm::FunctionalVisitor::visitEnter
bool visitEnter(const EntitySnapshot &snapshot) override
Definition: FunctionalVisitor.h:70
armarx::armem::wm::Visitor
A visitor for the hierarchical memory data structure.
Definition: Visitor.h:17
armarx::armem::wm::FunctionalVisitor::memoryFn
std::function< bool(Memory &memory)> memoryFn
Definition: FunctionalVisitor.h:81
armarx::armem::wm::FunctionalVisitor::instanceFn
std::function< bool(EntityInstance &instance)> instanceFn
Definition: FunctionalVisitor.h:96
armarx::armem::wm
Definition: MemoryNameSystem.h:46
armarx::armem::wm::FunctionalVisitor::visit
bool visit(const EntityInstance &instance) override
Definition: FunctionalVisitor.h:75
armarx::armem::wm::CoreSegment
Client-side working memory core segment.
Definition: memory_definitions.h:119
armarx::armem::wm::FunctionalVisitor::visit
bool visit(EntityInstance &instance) override
Definition: FunctionalVisitor.h:44
armarx::armem::wm::Memory
Client-side working memory.
Definition: memory_definitions.h:133
armarx::armem::wm::Visitor::visitEnter
virtual bool visitEnter(Memory &memory)
Definition: Visitor.h:33
armarx::armem::wm::FunctionalVisitor::instanceConstFn
std::function< bool(const EntityInstance &instance)> instanceConstFn
Definition: FunctionalVisitor.h:97
armarx::armem::wm::FunctionalVisitor::visitEnter
bool visitEnter(Entity &entity) override
Definition: FunctionalVisitor.h:35
armarx::armem::wm::FunctionalVisitor::coreSegmentFn
std::function< bool(CoreSegment &coreSegment)> coreSegmentFn
Definition: FunctionalVisitor.h:84
armarx::armem::wm::FunctionalVisitor::visitEnter
bool visitEnter(ProviderSegment &providerSegment) override
Definition: FunctionalVisitor.h:31
armarx::armem::wm::FunctionalVisitor::memoryConstFn
std::function< bool(const Memory &memory)> memoryConstFn
Definition: FunctionalVisitor.h:82
armarx::armem::wm::FunctionalVisitor::snapshotFn
std::function< bool(EntitySnapshot &snapshot)> snapshotFn
Definition: FunctionalVisitor.h:93
armarx::armem::wm::FunctionalVisitor::visitEnter
bool visitEnter(Memory &memory) override
Definition: FunctionalVisitor.h:23
armarx::armem::wm::EntitySnapshot
Client-side working memory entity snapshot.
Definition: memory_definitions.h:80
armarx::armem::wm::FunctionalVisitor::snapshotConstFn
std::function< bool(const EntitySnapshot &snapshot)> snapshotConstFn
Definition: FunctionalVisitor.h:94
armarx::armem::wm::FunctionalVisitor
A Visitor which can be parametrized by std::function instead of inheriting and overriding.
Definition: FunctionalVisitor.h:15
armarx::armem::wm::Entity
Client-side working memory entity.
Definition: memory_definitions.h:93
armarx::armem::wm::FunctionalVisitor::visitEnter
bool visitEnter(const CoreSegment &coreSegment) override
Definition: FunctionalVisitor.h:58
armarx::armem::wm::FunctionalVisitor::providerSegmentFn
std::function< bool(ProviderSegment &providerSegment)> providerSegmentFn
Definition: FunctionalVisitor.h:87
armarx::armem::wm::FunctionalVisitor::visitEnter
bool visitEnter(CoreSegment &coreSegment) override
Definition: FunctionalVisitor.h:27
armarx::armem::wm::FunctionalVisitor::visitEnter
bool visitEnter(const Entity &entity) override
Definition: FunctionalVisitor.h:66
armarx::armem::wm::Visitor::visit
virtual bool visit(EntityInstance &instance)
Definition: Visitor.h:75