Writer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <RobotAPI/interface/armem/server/WritingMemoryInterface.h>
5 
6 namespace armarx::armem::client
7 {
8 
9  /**
10  * @brief Helps a memory client sending data to a memory.
11  *
12  * You can check whether the writer is ready using the bool operator:
13  * @code
14  * client::Writer writer(writingMemoryProxy);
15  * ...
16  * if (writer)
17  * {
18  * writer.commit(...);
19  * }
20  * @endcode
21  */
22  class Writer
23  {
24  public:
25  /**
26  * @brief Construct a memory writer.
27  * @param memory The memory proxy.
28  */
29  Writer(const Writer&) = default;
30  Writer(server::WritingMemoryInterfacePrx memory = nullptr);
31 
32 
33  data::AddSegmentResult addSegment(const std::string& coreSegmentName,
34  const std::string& providerSegmentName,
35  bool clearWhenExists = false) const;
36  data::AddSegmentResult addSegment(const MemoryID& providerSegmentID,
37  bool clearWhenExists = false) const;
38  data::AddSegmentResult addSegment(const std::pair<std::string, std::string>& names,
39  bool clearWhenExists = false) const;
40  data::AddSegmentResult addSegment(const data::AddSegmentInput& input) const;
41  data::AddSegmentsResult addSegments(const data::AddSegmentsInput& input) const;
42 
43 
44  /**
45  * @brief Writes a `Commit` to the memory.
46  */
47  CommitResult commit(const Commit& commit) const;
48  /// Commit a single entity update.
50  /// Commit a single entity update.
51  EntityUpdateResult commit(const MemoryID& entityID,
52  const std::vector<aron::data::DictPtr>& instancesData,
53  Time referencedTime) const;
54 
55  // with bare-ice types
56  data::CommitResult commit(const data::Commit& commit) const;
57 
58 
59  void setWritingMemory(server::WritingMemoryInterfacePrx memory);
60 
61  operator bool() const
62  {
63  return bool(memory);
64  }
65 
66  private:
67  /// Sets `timeSent` on all entity updates and performs the commit,
68  data::CommitResult _commit(data::Commit& commit) const;
69 
70 
71  public:
72  server::WritingMemoryInterfacePrx memory;
73  };
74 
75 } // namespace armarx::armem::client
76 
78 {
79  std::ostream& operator<<(std::ostream& os, const AddSegmentInput& rhs);
80  std::ostream& operator<<(std::ostream& os, const AddSegmentsInput& rhs);
81  std::ostream& operator<<(std::ostream& os, const AddSegmentResult& rhs);
82  std::ostream& operator<<(std::ostream& os, const AddSegmentsResult& rhs);
83 } // namespace armarx::armem::data
armarx::armem::client::Writer::addSegment
data::AddSegmentResult addSegment(const std::string &coreSegmentName, const std::string &providerSegmentName, bool clearWhenExists=false) const
Definition: Writer.cpp:16
armarx::armem::Commit
A bundle of updates to be sent to the memory.
Definition: Commit.h:89
armarx::armem::EntityUpdateResult
Result of an EntityUpdate.
Definition: Commit.h:72
armarx::armem::client::Writer::setWritingMemory
void setWritingMemory(server::WritingMemoryInterfacePrx memory)
Definition: Writer.cpp:105
armarx::armem::client
This file is part of ArmarX.
Definition: forward_declarations.h:7
armarx::memory
Brief description of class memory.
Definition: memory.h:39
armarx::armem::data::operator<<
std::ostream & operator<<(std::ostream &os, const AddSegmentInput &rhs)
Definition: Writer.cpp:164
armarx::armem::client::Writer::addSegments
data::AddSegmentsResult addSegments(const data::AddSegmentsInput &input) const
Definition: Writer.cpp:50
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:19
armarx::armem::EntityUpdate
An update of an entity for a specific point in time.
Definition: Commit.h:27
armarx::armem::CommitResult
Result of a Commit.
Definition: Commit.h:110
armarx::armem::client::Writer
Helps a memory client sending data to a memory.
Definition: Writer.h:22
armarx::armem::client::Writer::commit
CommitResult commit(const Commit &commit) const
Writes a Commit to the memory.
Definition: Writer.cpp:59
armarx::armem::client::Writer::Writer
Writer(const Writer &)=default
Construct a memory writer.
armarx::armem::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition: mongodb.cpp:67
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::viz::data::ElementFlags::names
const simox::meta::IntEnumNames names
Definition: json_elements.cpp:14
armarx::armem::data
Definition: Writer.h:77
ice_conversions.h
armarx::armem::client::Writer::memory
server::WritingMemoryInterfacePrx memory
Definition: Writer.h:72