12 #include <RobotAPI/interface/armem/query.h>
25 template <
class _EntityT,
class _ResultEntityT>
46 const armem::query::data::EntityQuery& query,
47 const EntityT& entity)
const override
49 if (
auto q =
dynamic_cast<const armem::query::data::entity::All*
>(&query))
53 else if (
auto q =
dynamic_cast<const armem::query::data::entity::Single*
>(&query))
57 else if (
auto q =
dynamic_cast<const armem::query::data::entity::TimeRange*
>(&query))
61 else if (
auto q =
dynamic_cast<const armem::query::data::entity::IndexRange*
>(&query))
65 else if (
auto q =
dynamic_cast<const armem::query::data::entity::TimeApprox*
>(&query))
69 else if (
auto q =
dynamic_cast<const armem::query::data::entity::BeforeOrAtTime*
>(&query))
73 else if (
auto q =
dynamic_cast<const armem::query::data::entity::BeforeTime*
>(&query))
85 const armem::query::data::entity::All& query,
99 const armem::query::data::entity::Single& query,
102 if (query.timestamp.timeSinceEpoch.microSeconds < 0)
111 const Time time = armarx::fromIce<Time>(query.timestamp);
120 std::stringstream ss;
121 ss <<
"Failed to retrieve snapshot with timestamp "
123 <<
" from entity " << entity.
id() <<
".\n"
124 <<
"Entity has timestamps: ";
125 for (
const Time& t : entity.getTimestamps())
137 const armem::query::data::entity::TimeRange& query,
140 if (query.minTimestamp.timeSinceEpoch.microSeconds <= query.maxTimestamp.timeSinceEpoch.microSeconds
141 || query.minTimestamp.timeSinceEpoch.microSeconds < 0
142 || query.maxTimestamp.timeSinceEpoch.microSeconds < 0)
144 const Time min = armarx::fromIce<Time>(query.minTimestamp);
145 const Time max = armarx::fromIce<Time>(query.maxTimestamp);
152 const armem::query::data::entity::IndexRange& query,
156 query.first, query.last,
159 this->addResultSnapshot(result, snapshot);
168 const armem::query::data::EntityQuery& query)
const
181 const armem::query::data::entity::BeforeOrAtTime& query,
184 const Time referenceTimestamp = armarx::fromIce<Time>(query.timestamp);
195 const armem::query::data::entity::BeforeTime& query,
198 const Time referenceTimestamp = armarx::fromIce<Time>(query.timestamp);
201 std::vector<const EntitySnapshotT*> befores;
204 befores.push_back(&
s);
208 if (query.maxEntries < 0)
210 num = befores.size();
214 num =
std::min(befores.size(),
static_cast<size_t>(query.maxEntries));
217 for (
size_t r = 0; r < num; ++r)
219 size_t i = befores.size() - 1 - r;
226 const armem::query::data::entity::TimeApprox& query,
229 const Time referenceTimestamp = armarx::fromIce<Time>(query.timestamp);
233 const auto isInRange = [&](
const Time & t) ->
bool
235 return query.eps.microSeconds <= 0
236 or
std::abs((t - referenceTimestamp).toMicroSeconds()) <= query.eps.microSeconds;
242 const auto timestampOfMatchBefore = beforeOrAt->id().timestamp;
243 const auto isPerfectMatch = timestampOfMatchBefore == referenceTimestamp;
244 if (isInRange(timestampOfMatchBefore))
259 const auto timestampOfMatchAfter = after->id().timestamp;
260 if (isInRange(timestampOfMatchAfter))