Removes templating on data type. (#68)

master
Damon Kohler 2016-10-17 14:47:48 +02:00 committed by GitHub
parent 2eca021003
commit f798805c4f
2 changed files with 21 additions and 25 deletions

View File

@ -28,6 +28,7 @@
#include "cartographer/common/make_unique.h"
#include "cartographer/common/ordered_multi_queue.h"
#include "cartographer/common/time.h"
#include "cartographer/sensor/data.h"
#include "cartographer/sensor/sensor_packet_period_histogram_builder.h"
#include "glog/logging.h"
@ -49,10 +50,9 @@ inline std::ostream& operator<<(std::ostream& out,
return out << '(' << key.trajectory_id << ", " << key.sensor_id << ')';
}
template <typename SensorDataType>
class Collator {
public:
using Callback = std::function<void(int64, std::unique_ptr<SensorDataType>)>;
using Callback = std::function<void(int64, std::unique_ptr<Data>)>;
Collator() {}
@ -85,7 +85,7 @@ class Collator {
// added in time order.
void AddSensorData(const int trajectory_id, const int64 timestamp,
const string& sensor_id,
std::unique_ptr<SensorDataType> sensor_data) {
std::unique_ptr<Data> sensor_data) {
sensor_packet_period_histogram_builder_.Add(trajectory_id, timestamp,
sensor_id);
queue_.Add(
@ -113,7 +113,7 @@ class Collator {
private:
struct Value {
int64 timestamp;
std::unique_ptr<SensorDataType> sensor_data;
std::unique_ptr<Data> sensor_data;
};
// Queue keys are a pair of trajectory ID and sensor identifier.

View File

@ -28,40 +28,36 @@ namespace cartographer {
namespace sensor {
namespace {
struct TestData {
string frame_id;
};
TEST(Collator, Ordering) {
TestData first{"horizontal_laser"};
TestData second{"vertical_laser"};
TestData third{"imu"};
TestData fourth{"horizontal_laser"};
TestData fifth{"vertical_laser"};
TestData sixth{"something"};
Data first("horizontal_laser", sensor::LaserFan{});
Data second("vertical_laser", sensor::LaserFan{});
Data third("imu", Data::Imu{});
Data fourth("horizontal_laser", sensor::LaserFan{});
Data fifth("vertical_laser", sensor::LaserFan{});
Data sixth("odometry", Data::Odometry{});
const std::unordered_set<string> frame_ids = {
"horizontal_laser", "vertical_laser", "imu", "something"};
std::vector<std::pair<int64, TestData>> received;
Collator<TestData> collator;
"horizontal_laser", "vertical_laser", "imu", "odometry"};
std::vector<std::pair<int64, Data>> received;
Collator collator;
collator.AddTrajectory(
0, frame_ids,
[&received](const int64 timestamp, std::unique_ptr<TestData> packet) {
[&received](const int64 timestamp, std::unique_ptr<Data> packet) {
received.push_back(std::make_pair(timestamp, *packet));
});
collator.AddSensorData(0, 100, first.frame_id,
common::make_unique<TestData>(first));
common::make_unique<Data>(first));
collator.AddSensorData(0, 600, sixth.frame_id,
common::make_unique<TestData>(sixth));
common::make_unique<Data>(sixth));
collator.AddSensorData(0, 400, fourth.frame_id,
common::make_unique<TestData>(fourth));
common::make_unique<Data>(fourth));
collator.AddSensorData(0, 200, second.frame_id,
common::make_unique<TestData>(second));
common::make_unique<Data>(second));
collator.AddSensorData(0, 500, fifth.frame_id,
common::make_unique<TestData>(fifth));
common::make_unique<Data>(fifth));
collator.AddSensorData(0, 300, third.frame_id,
common::make_unique<TestData>(third));
common::make_unique<Data>(third));
EXPECT_EQ(3, received.size());
EXPECT_EQ(100, received[0].first);
@ -78,7 +74,7 @@ TEST(Collator, Ordering) {
EXPECT_EQ(500, received[4].first);
EXPECT_EQ("vertical_laser", received[4].second.frame_id);
EXPECT_EQ(600, received[5].first);
EXPECT_EQ("something", received[5].second.frame_id);
EXPECT_EQ("odometry", received[5].second.frame_id);
}
} // namespace