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 
26  armarx::armem::clazz::fromAron(aron, objClass);
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 
57  result.memory.forEachInstance(
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::string
72  {
73  return "classReader.";
74  }
75 
78  {
80  p.memoryName = "Object";
81  p.coreSegmentName = "Class";
82  return p;
83  }
84 
85 } // namespace armarx::armem::obj::clazz
armarx::armem::detail::SuccessHeader::success
bool success
Definition: SuccessHeader.h:20
armarx::armem::obj::clazz::ClassReader::getObjectClasses
std::map< armarx::ObjectID, armem::clazz::ObjectClass > getObjectClasses(const std::vector< armarx::ObjectID > &objectIDs)
Get object class information for object class IDs.
Definition: ClassReader.cpp:35
armarx::armem::client::query::SnapshotSelector::latest
SnapshotSelector & latest()
Definition: selectors.cpp:28
armarx::armem::client::util::SimpleReaderBase::properties
const Properties & properties() const
Definition: SimpleReaderBase.cpp:55
armarx::armem::client::query::ProviderSegmentSelector::entities
EntitySelector & entities()
Start specifying entities.
Definition: selectors.cpp:123
armarx::ObjectID
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
Definition: ObjectID.h:11
armarx::armem::client::QueryResult::memory
wm::Memory memory
The slice of the memory that matched the query.
Definition: Query.h:58
armarx::ObjectID::FromString
static ObjectID FromString(const std::string &idString)
Construct from a string produced by str(), e.g. ("mydataset/myobject", "mydataset/myclass/myinstance"...
Definition: ObjectID.cpp:31
query.h
armarx::armem::wm::EntityInstance
Client-side working entity instance.
Definition: memory_definitions.h:32
armarx::armem::client::query::EntitySelector::snapshots
SnapshotSelector & snapshots()
Start specifying entity snapshots.
Definition: selectors.cpp:86
armarx::armem::obj::clazz::ClassReader::defaultProperties
Properties defaultProperties() const final
Definition: ClassReader.cpp:77
armarx::armem::client::QueryResult
Result of a QueryInput.
Definition: Query.h:50
armarx::armem::obj::clazz::ClassReader::propertyPrefix
std::string propertyPrefix() const final
Definition: ClassReader.cpp:71
armarx::armem::client::util::SimpleReaderBase::Properties::memoryName
std::string memoryName
Definition: SimpleReaderBase.h:45
armarx::armem::clazz::ObjectClass
Definition: types.h:58
armarx::armem::obj::clazz
Definition: ClassReader.cpp:7
armarx::armem::base::EntityInstanceBase::dataAs
AronDtoT dataAs() const
Get the data converted to a generated Aron DTO class.
Definition: EntityInstanceBase.h:157
armarx::armem::detail::SuccessHeader::errorMessage
std::string errorMessage
Definition: SuccessHeader.h:21
armarx::armem::obj::clazz::ClassReader::getObjectClass
std::optional< armem::clazz::ObjectClass > getObjectClass(const std::string &providerName, const armarx::ObjectID &id)
Definition: ClassReader.cpp:10
types.h
armarx::armem::client::query::Builder::coreSegments
CoreSegmentSelector & coreSegments()
Start specifying core segments.
Definition: Builder.cpp:38
armarx::armem::client::util::SimpleReaderBase::Properties::coreSegmentName
std::string coreSegmentName
Definition: SimpleReaderBase.h:46
armarx::armem::client::query::CoreSegmentSelector::withName
CoreSegmentSelector & withName(const std::string &name) override
Definition: selectors.cpp:177
armarx::armem::client::util::SimpleReaderBase::memoryReader
const armem::client::Reader & memoryReader() const
Definition: SimpleReaderBase.cpp:49
armarx::armem::base::detail::MemoryItem::id
MemoryID & id()
Definition: MemoryItem.h:27
armarx::armem::MemoryID::entityName
std::string entityName
Definition: MemoryID.h:53
armarx::armem::client::util::SimpleReaderBase::Properties
Definition: SimpleReaderBase.h:43
armarx::armem::client::query::EntitySelector::withName
EntitySelector & withName(const std::string &name) override
Definition: selectors.cpp:103
armarx::armem::base::detail::ForEachEntityInstanceMixin::forEachInstance
bool forEachInstance(InstanceFunctionT &&func)
Definition: iteration_mixins.h:146
armarx::armem::error::QueryFailed
Indicates that a query resulted in an Error.
Definition: ArMemError.h:190
armarx::armem::client::query::Builder
The query::Builder class provides a fluent-style specification of hierarchical queries.
Definition: Builder.h:22
armarx::armem::client::query::CoreSegmentSelector::providerSegments
ProviderSegmentSelector & providerSegments()
Start specifying provider segments.
Definition: selectors.cpp:160
ClassReader.h
armarx::armem::clazz::fromAron
void fromAron(const armarx::armem::arondto::Feature &dto, Feature &bo)
aron_conversions.h
armarx::armem::client::query::ProviderSegmentSelector::all
ProviderSegmentSelector & all() override
Definition: selectors.cpp:133
armarx::armem::client::Reader::getLatestSnapshotIn
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:370
armarx::armem::client::Reader::query
QueryResult query(const QueryInput &input) const
Perform a query.
Definition: Reader.cpp:33
armarx::human::MemoryID
const armem::MemoryID MemoryID
Definition: memory_ids.cpp:29