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