ClassReader.cpp
Go to the documentation of this file.
1#include "ClassReader.h"
2
6
8{
9 std::optional<armem::clazz::ObjectClass>
10 ClassReader::getObjectClass(const std::string& providerName, const ObjectID& id)
11 {
12 auto mid = armarx::armem::MemoryID();
13 mid.memoryName = properties().memoryName;
14 mid.coreSegmentName = properties().coreSegmentName;
15 mid.providerSegmentName = providerName;
16 mid.entityName = id.str();
17
18 auto i = this->memoryReader().getLatestSnapshotIn(mid);
19
20 if (i.has_value() && i->size() == 1)
21 {
22 auto& instance = i->getInstance(0);
23 auto aron = instance.dataAs<armarx::armem::arondto::ObjectClass>();
24
27
28 return objClass;
29 }
30
31 return std::nullopt;
32 }
33
34 std::map<ObjectID, armem::clazz::ObjectClass>
35 ClassReader::getObjectClasses(const std::vector<ObjectID>& objectIDs)
36 {
38 auto& entities = builder.coreSegments()
39 .withName(properties().coreSegmentName)
41 .all()
42 .entities();
43
44 for (const ObjectID& objectID : objectIDs)
45 {
46 entities.withName(objectID.getClassID().str()).snapshots().latest();
47 }
48
49 const armem::client::QueryResult result = memoryReader().query(builder);
50 if (not result.success)
51 {
53 }
54
55 std::map<ObjectID, armem::clazz::ObjectClass> objectClasses;
56
58 [&objectClasses](const armem::wm::EntityInstance& instance) -> bool
59 {
60 const ObjectID classID = ObjectID::FromString(instance.id().entityName);
61 auto aron = instance.dataAs<armarx::armem::arondto::ObjectClass>();
62 armarx::armem::clazz::fromAron(aron, objectClasses[classID]);
63
64 return true;
65 });
66
67 return objectClasses;
68 }
69
70 std::map<ObjectID, armem::clazz::ObjectClass>
72 {
74
75 // clang-format off
76 builder
77 .coreSegments().withName(properties().coreSegmentName)
79 .entities().all()
80 .snapshots().latest();
81 // clang-format on
82
83 const armem::client::QueryResult result = memoryReader().query(builder);
84 if (not result.success)
85 {
87 }
88
89 std::map<ObjectID, armem::clazz::ObjectClass> objectClasses;
90
92 [&objectClasses](const armem::wm::EntityInstance& instance) -> bool
93 {
94 const ObjectID classID = ObjectID::FromString(instance.id().entityName);
95 auto aron = instance.dataAs<armarx::armem::arondto::ObjectClass>();
96 armarx::armem::clazz::fromAron(aron, objectClasses[classID]);
97
98 return true;
99 });
100
101 return objectClasses;
102 }
103
104 std::string
106 {
107 return "classReader.";
108 }
109
112 {
114 p.memoryName = "Object";
115 p.coreSegmentName = "Class";
116 return p;
117 }
118
119} // namespace armarx::armem::obj::clazz
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
Definition ObjectID.h:11
static ObjectID FromString(const std::string &idString)
Construct from a string produced by str(), e.g. ("mydataset/myobject", "mydataset/myclass/myinstance"...
Definition ObjectID.cpp:34
QueryResult query(const QueryInput &input) const
Perform a query on the WM.
Definition Reader.cpp:119
std::optional< wm::EntitySnapshot > getLatestSnapshotIn(const MemoryID &id, armem::query::DataMode dataMode=armem::query::DataMode::WithData) const
Get the latest snapshot under the given memory ID.
Definition Reader.cpp:449
The query::Builder class provides a fluent-style specification of hierarchical queries.
Definition Builder.h:22
CoreSegmentSelector & coreSegments()
Start specifying core segments.
Definition Builder.cpp:42
CoreSegmentSelector & withName(const std::string &name) override
ProviderSegmentSelector & providerSegments()
Start specifying provider segments.
SnapshotSelector & snapshots()
Start specifying entity snapshots.
Definition selectors.cpp:92
EntitySelector & entities()
Start specifying entities.
ProviderSegmentSelector & all() override
const armem::client::Reader & memoryReader() const
Indicates that a query resulted in an Error.
Definition ArMemError.h:191
std::optional< armem::clazz::ObjectClass > getObjectClass(const std::string &providerName, const armarx::ObjectID &id)
std::map< armarx::ObjectID, armem::clazz::ObjectClass > getObjectClasses(const std::vector< armarx::ObjectID > &objectIDs)
Get object class information for object class IDs.
std::map< armarx::ObjectID, armem::clazz::ObjectClass > getAllObjectClasses()
Properties defaultProperties() const final
std::string propertyPrefix() const final
Client-side working entity instance.
void fromAron(const armarx::armem::arondto::Feature &dto, Feature &bo)
Result of a QueryInput.
Definition Query.h:51
wm::Memory memory
The slice of the memory that matched the query.
Definition Query.h:58