00001 /* 00002 * Copyright 2016 The Cartographer Authors 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef CARTOGRAPHER_SENSOR_INTERNAL_DISPATCHABLE_H_ 00018 #define CARTOGRAPHER_SENSOR_INTERNAL_DISPATCHABLE_H_ 00019 00020 #include "cartographer/mapping/trajectory_builder_interface.h" 00021 #include "cartographer/sensor/data.h" 00022 00023 namespace cartographer { 00024 namespace sensor { 00025 00026 template <typename DataType> 00027 class Dispatchable : public Data { 00028 public: 00029 Dispatchable(const std::string &sensor_id, const DataType &data) 00030 : Data(sensor_id), data_(data) {} 00031 00032 common::Time GetTime() const override { return data_.time; } 00033 void AddToTrajectoryBuilder( 00034 mapping::TrajectoryBuilderInterface *const trajectory_builder) override { 00035 trajectory_builder->AddSensorData(sensor_id_, data_); 00036 } 00037 const DataType &data() const { return data_; } 00038 00039 private: 00040 const DataType data_; 00041 }; 00042 00043 template <typename DataType> 00044 std::unique_ptr<Dispatchable<DataType>> MakeDispatchable( 00045 const std::string &sensor_id, const DataType &data) { 00046 return absl::make_unique<Dispatchable<DataType>>(sensor_id, data); 00047 } 00048 00049 } // namespace sensor 00050 } // namespace cartographer 00051 00052 #endif // CARTOGRAPHER_SENSOR_INTERNAL_DISPATCHABLE_H_