Commit.cpp
Go to the documentation of this file.
1 #include "Commit.h"
2 
4 
6 
7 #include <SimoxUtility/algorithm/apply.hpp>
8 
9 
10 namespace armarx::armem
11 {
12 
13  std::ostream& operator<<(std::ostream& os, const EntityUpdate& rhs)
14  {
15  return os << "Entity update: "
16  << "\n- success: \t" << rhs.entityID
17  << "\n- timestamp: \t" << toDateTimeMilliSeconds(rhs.referencedTime)
18  << "\n- #instances: \t" << rhs.instancesData.size()
19  << "\n"
20  ;
21  }
22 
23  std::ostream& operator<<(std::ostream& os, const EntityUpdateResult& rhs)
24  {
25  return os << "Entity update result: "
26  << "\n- success: \t" << (rhs.success ? "true" : "false")
27  << "\n- snapshotID: \t" << rhs.snapshotID
28  << "\n- time arrived: \t" << toDateTimeMilliSeconds(rhs.arrivedTime)
29  << "\n- error message: \t" << rhs.errorMessage
30  << "\n"
31  ;
32  }
33 
34  std::ostream& operator<<(std::ostream& os, const Commit& rhs)
35  {
36  os << "Commit with " << rhs.updates.size() << " entity update";
37  if (rhs.updates.size() > 1)
38  {
39  os << "s";
40  }
41  os << ": \n";
42  for (size_t i = 0; i < rhs.updates.size(); ++i)
43  {
44  os << "[" << i << "] " << rhs.updates[i];
45  }
46  return os;
47  }
48  std::ostream& operator<<(std::ostream& os, const CommitResult& rhs)
49  {
50  os << "Commit results of " << rhs.results.size() << " entity update";
51  if (rhs.results.size() > 1)
52  {
53  os << "s";
54  }
55  os << ": \n";
56  for (size_t i = 0; i < rhs.results.size(); ++i)
57  {
58  os << "[" << i << "] " << rhs.results[i];
59  }
60  return os;
61  }
62 
63 
65  {
66  return std::find_if(results.begin(), results.end(), [](const EntityUpdateResult & r)
67  {
68  return !r.success;
69  }) == results.end();
70  }
71 
72  std::vector<std::string> CommitResult::allErrorMessages() const
73  {
74  return simox::alg::apply(results, [](const EntityUpdateResult & res)
75  {
76  return res.errorMessage;
77  });
78  }
79 
80 
82  {
83  return updates.emplace_back();
84  }
85 
87  {
88  return updates.emplace_back(update);
89  }
90 
91  void Commit::add(const std::vector<EntityUpdate>& updates)
92  {
93  for (const auto& update : updates)
94  {
95  add(update);
96  }
97  }
98 
99  void Commit::append(const Commit& c)
100  {
101  add(c.updates);
102  }
103 
104 }
armarx::armem::CommitResult::allErrorMessages
std::vector< std::string > allErrorMessages() const
Definition: Commit.cpp:72
armarx::armem::EntityUpdate::instancesData
std::vector< aron::data::DictPtr > instancesData
The entity data.
Definition: Commit.h:33
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::EntityUpdateResult::arrivedTime
Time arrivedTime
Definition: Commit.h:77
armarx::armem
Definition: LegacyRobotStateMemoryAdapter.cpp:31
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::armem::Commit::append
void append(const Commit &c)
Definition: Commit.cpp:99
Dict.h
armarx::armem::Commit::updates
std::vector< EntityUpdate > updates
The entity updates.
Definition: Commit.h:97
armarx::armem::operator<<
std::ostream & operator<<(std::ostream &os, const EntityUpdate &rhs)
Definition: Commit.cpp:13
armarx::armem::toDateTimeMilliSeconds
std::string toDateTimeMilliSeconds(const Time &time, int decimals=6)
Returns timeas e.g.
Definition: Time.cpp:35
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::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition: mongodb.cpp:67
armarx::armem::EntityUpdateResult::snapshotID
MemoryID snapshotID
Definition: Commit.h:76
ExpressionException.h
Commit.h
armarx::armem::EntityUpdate::referencedTime
Time referencedTime
Time when this entity update was created (e.g.
Definition: Commit.h:39
armarx::armem::Commit::add
EntityUpdate & add()
Definition: Commit.cpp:81
armarx::armem::CommitResult::results
std::vector< EntityUpdateResult > results
Definition: Commit.h:112
armarx::armem::EntityUpdateResult::errorMessage
std::string errorMessage
Definition: Commit.h:79
armarx::armem::EntityUpdate::entityID
MemoryID entityID
The entity's ID.
Definition: Commit.h:30
armarx::armem::EntityUpdateResult::success
bool success
Definition: Commit.h:74
armarx::armem::CommitResult::allSuccess
bool allSuccess() const
Definition: Commit.cpp:64