Branch data Line data Source code
1 : : // ----------------- BEGIN LICENSE BLOCK --------------------------------- 2 : : // 3 : : // Copyright (C) 2021 Intel Corporation 4 : : // 5 : : // SPDX-License-Identifier: LGPL-2.1-only 6 : : // 7 : : // ----------------- END LICENSE BLOCK ----------------------------------- 8 : : /** 9 : : * @file 10 : : */ 11 : : 12 : : #pragma once 13 : : 14 : : #include <ad/map/route/ConnectingRouteList.hpp> 15 : : #include <ad/rss/world/ObjectId.hpp> 16 : : #include <map> 17 : : #include <mutex> 18 : : 19 : : /*! 20 : : * @brief namespace rss 21 : : */ 22 : : namespace ad { 23 : : /*! 24 : : * @brief namespace rss 25 : : */ 26 : : namespace rss { 27 : : /*! 28 : : * @brief namespace map 29 : : */ 30 : : namespace map { 31 : : 32 : : /*! 33 : : * @brief class to cache ConnectingRouteList between vehicles to speed up world model creation 34 : : */ 35 : : class ConnectingRoutesCache 36 : : { 37 : : public: 38 : 5 : ConnectingRoutesCache() = default; 39 : : 40 : 5 : ~ConnectingRoutesCache() = default; 41 : : 42 : : /*! 43 : : * @brief clear the cache 44 : : */ 45 : : void clear(); 46 : : 47 : : /*! 48 : : * @brief add a ConnectingRouteList of two vehicles 49 : : */ 50 : : void addConnectingRoutes(ad::rss::world::ObjectId const &object_a, 51 : : ad::rss::world::ObjectId const &object_b, 52 : : ad::map::route::ConnectingRouteList const &connecting_route_list, 53 : : ad::physics::Distance const &max_connecting_route_length); 54 : : 55 : : bool getConnectingRoutes(ad::rss::world::ObjectId const &object_a, 56 : : ad::rss::world::ObjectId const &object_b, 57 : : ad::physics::Distance const &max_connecting_route_length, 58 : : ad::map::route::ConnectingRouteList &connecting_route_list); 59 : : 60 : : private: 61 : : bool findEntry(ad::rss::world::ObjectId const &object_a, 62 : : ad::rss::world::ObjectId const &object_b, 63 : : ad::physics::Distance const &max_connecting_route_length, 64 : : ad::map::route::ConnectingRouteList &connecting_route_list); 65 : : 66 : : std::mutex m_lock; 67 : : 68 : : struct ConnectingRouteStorage 69 : : { 70 : 19 : ConnectingRouteStorage(ad::map::route::ConnectingRouteList const &i_connecting_route_list, 71 : : ad::physics::Distance const &i_max_connecting_route_length) 72 : 19 : : connecting_route_list(i_connecting_route_list) 73 : 19 : , max_connecting_route_length(i_max_connecting_route_length) 74 : : { 75 : 19 : } 76 : : ad::map::route::ConnectingRouteList connecting_route_list; 77 : : ad::physics::Distance max_connecting_route_length; 78 : : }; 79 : : std::map<ad::rss::world::ObjectId, std::map<ad::rss::world::ObjectId, ConnectingRouteStorage>> m_cache; 80 : : }; 81 : : 82 : : } // namespace map 83 : : } // namespace rss 84 : : } // namespace ad