Skip to content
Snippets Groups Projects
Commit 76ea15da authored by Fabian Reister's avatar Fabian Reister
Browse files

query: maxEntries fix

parent 95eb3ffe
No related branches found
No related tags found
2 merge requests!157armem/dev => master,!147new queries for snapshots: TimeApprox and BeforeTime
This commit is part of merge request !157. Comments created here will be created in the context of that merge request.
#pragma once
#include <RobotAPI/interface/armem/query.h>
#include <cstdint>
#include <iterator>
#include "ArmarXCore/core/exceptions/LocalException.h"
#include "BaseQueryProcessorBase.h"
#include <RobotAPI/interface/armem/query.h>
#include <ArmarXCore/core/exceptions/LocalException.h>
#include <ArmarXCore/core/logging/Logging.h>
#include <ArmarXCore/core/exceptions/local/ExpressionException.h>
#include <RobotAPI/libraries/armem/core/error.h>
#include <RobotAPI/libraries/armem/core/ice_conversions.h>
#include "BaseQueryProcessorBase.h"
namespace armarx::armem::base::query_proc
{
......@@ -187,7 +190,7 @@ namespace armarx::armem::base::query_proc
const auto referenceTimestamp = fromIce<Time>(query.timestamp);
ARMARX_CHECK(referenceTimestamp.toMicroSeconds() >= 0) << "Reference timestamp is negative!";
const auto maxEntries = fromIce<int64>(query.maxEntries);
const auto maxEntries = fromIce<std::int64_t>(query.maxEntries);
const auto refIt = entity.history().lower_bound(referenceTimestamp);
......@@ -199,16 +202,20 @@ namespace armarx::armem::base::query_proc
const auto nEntriesBefore = std::distance(entity.history().begin(), refIt);
if (nEntriesBefore < maxEntries)
const int nEntries = [&]()
{
// TODO maybe warn that not enough elements exist, but the user will notice anyways
;
}
// see query.ice
if (maxEntries > 0)
{
return std::min(nEntriesBefore, maxEntries);
}
const int nEntries = std::min(nEntriesBefore, maxEntries);
return nEntriesBefore; // all elements before timestamp
}
();
auto it = refIt;
for (int64 i = 0; i < nEntries; i++, --it)
for (std::int64_t i = 0; i < nEntries; i++, --it)
{
addResultSnapshot(result, it);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment