.. _program_listing_file__tmp_ws_src_warehouse_ros_include_warehouse_ros_impl_message_collection_impl.hpp: Program Listing for File message_collection_impl.hpp ==================================================== |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/warehouse_ros/include/warehouse_ros/impl/message_collection_impl.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // Copyright 2008 Willow Garage, Inc. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // // * Neither the name of the Willow Garage, Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. #include #include #include #include namespace warehouse_ros { template MessageCollection::MessageCollection(MessageCollectionHelper::Ptr collection) : collection_(collection) { const std::string datatype = rosidl_generator_traits::data_type(); // TODO: Convert ros message MD5Sum value // typedef typename ros::message_traits::MD5Sum Md5; std::string md5_str(MD5_DIGEST_LENGTH, '\0'); MD5(reinterpret_cast(datatype.c_str()), datatype.size(), reinterpret_cast(&md5_str[0])); md5sum_matches_ = collection_->initialize(datatype, md5_str); } template void MessageCollection::insert(const M& msg, Metadata::Ptr metadata) { if (!md5sum_matches_) throw Md5SumException("Cannot insert additional elements."); metadata->append("creation_time", rclcpp::Clock(RCL_SYSTEM_TIME).now().seconds()); rclcpp::SerializedMessage serialized_msg; static rclcpp::Serialization serializer; serializer.serialize_message(&msg, &serialized_msg); char* data = (char*)serialized_msg.get_rcl_serialized_message().buffer; collection_->insert(data, serialized_msg.size(), metadata); } template typename QueryResults::range_t MessageCollection::query(Query::ConstPtr query, bool metadata_only, const std::string& sort_by, bool ascending) const { if (!md5sum_matches_ && !metadata_only) throw Md5SumException("Can only query metadata."); ResultIteratorHelper::Ptr results = collection_->query(query, sort_by, ascending); return typename QueryResults::range_t(ResultIterator(results, metadata_only), ResultIterator()); } template std::vector::ConstPtr> MessageCollection::queryList(Query::ConstPtr query, bool metadata_only, const std::string& sort_by, bool ascending) const { typename QueryResults::range_t res = this->query(query, metadata_only, sort_by, ascending); return std::vector::ConstPtr>(res.first, res.second); } template typename MessageWithMetadata::ConstPtr MessageCollection::findOne(Query::ConstPtr query, const bool metadata_only) const { typename QueryResults::range_t res = this->query(query, metadata_only); if (res.first == res.second) throw NoMatchingMessageException(collection_->collectionName()); return *res.first; } template unsigned MessageCollection::removeMessages(Query::ConstPtr query) { return collection_->removeMessages(query); } template void MessageCollection::modifyMetadata(Query::ConstPtr q, Metadata::ConstPtr m) { collection_->modifyMetadata(q, m); } template unsigned MessageCollection::count() { return collection_->count(); } template bool MessageCollection::md5SumMatches() const { return md5sum_matches_; } template Query::Ptr MessageCollection::createQuery() const { return collection_->createQuery(); } template Metadata::Ptr MessageCollection::createMetadata() const { return collection_->createMetadata(); } } // namespace warehouse_ros