diff --git a/Server/DataStructures/BaseDataFacade.h b/Server/DataStructures/BaseDataFacade.h index 7b7a73762..ded7b2798 100644 --- a/Server/DataStructures/BaseDataFacade.h +++ b/Server/DataStructures/BaseDataFacade.h @@ -25,10 +25,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef QUERY_DATA_FACADE_H -#define QUERY_DATA_FACADE_H +#ifndef BASE_DATA_FACADE_H +#define BASE_DATA_FACADE_H -//Exposes all data access interfaces to the algorithms via base class ptr +// Exposes all data access interfaces to the algorithms via base class ptr #include "../../DataStructures/EdgeBasedNode.h" #include "../../DataStructures/ImportNode.h" @@ -42,85 +42,67 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -template -class BaseDataFacade { -public: +template class BaseDataFacade +{ + public: typedef EdgeBasedNode RTreeLeaf; typedef EdgeDataT EdgeData; - BaseDataFacade( ) { } - virtual ~BaseDataFacade() { } + BaseDataFacade() {} + virtual ~BaseDataFacade() {} - //search graph access + // search graph access virtual unsigned GetNumberOfNodes() const = 0; virtual unsigned GetNumberOfEdges() const = 0; - virtual unsigned GetOutDegree( const NodeID n ) const = 0; + virtual unsigned GetOutDegree(const NodeID n) const = 0; - virtual NodeID GetTarget( const EdgeID e ) const = 0; + virtual NodeID GetTarget(const EdgeID e) const = 0; - virtual EdgeDataT &GetEdgeData( const EdgeID e ) = 0; + virtual EdgeDataT &GetEdgeData(const EdgeID e) = 0; // virtual const EdgeDataT &GetEdgeData( const EdgeID e ) const = 0; - virtual EdgeID BeginEdges( const NodeID n ) const = 0; + virtual EdgeID BeginEdges(const NodeID n) const = 0; - virtual EdgeID EndEdges( const NodeID n ) const = 0; + virtual EdgeID EndEdges(const NodeID n) const = 0; - //searches for a specific edge - virtual EdgeID FindEdge( const NodeID from, const NodeID to ) const = 0; + // searches for a specific edge + virtual EdgeID FindEdge(const NodeID from, const NodeID to) const = 0; - virtual EdgeID FindEdgeInEitherDirection( - const NodeID from, - const NodeID to - ) const = 0; + virtual EdgeID FindEdgeInEitherDirection(const NodeID from, const NodeID to) const = 0; - virtual EdgeID FindEdgeIndicateIfReverse( - const NodeID from, - const NodeID to, - bool & result - ) const = 0; + virtual EdgeID + FindEdgeIndicateIfReverse(const NodeID from, const NodeID to, bool &result) const = 0; - //node and edge information access - virtual FixedPointCoordinate GetCoordinateOfNode( - const unsigned id - ) const = 0; + // node and edge information access + virtual FixedPointCoordinate GetCoordinateOfNode(const unsigned id) const = 0; - virtual bool EdgeIsCompressed( const unsigned id ) const = 0; + virtual bool EdgeIsCompressed(const unsigned id) const = 0; virtual unsigned GetGeometryIndexForEdgeID(const unsigned id) const = 0; - virtual void GetUncompressedGeometry( - const unsigned id, - std::vector & result_nodes - ) const = 0; + virtual void GetUncompressedGeometry(const unsigned id, + std::vector &result_nodes) const = 0; - virtual TurnInstruction GetTurnInstructionForEdgeID( - const unsigned id - ) const = 0; + virtual TurnInstruction GetTurnInstructionForEdgeID(const unsigned id) const = 0; - virtual bool LocateClosestEndPointForCoordinate( - const FixedPointCoordinate& input_coordinate, - FixedPointCoordinate& result, - const unsigned zoom_level = 18 - ) const = 0; + virtual bool LocateClosestEndPointForCoordinate(const FixedPointCoordinate &input_coordinate, + FixedPointCoordinate &result, + const unsigned zoom_level = 18) const = 0; - virtual bool FindPhantomNodeForCoordinate( - const FixedPointCoordinate & input_coordinate, - PhantomNode & resulting_phantom_node, - const unsigned zoom_level - ) const = 0; + virtual bool FindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate, + PhantomNode &resulting_phantom_node, + const unsigned zoom_level) const = 0; virtual unsigned GetCheckSum() const = 0; - virtual unsigned GetNameIndexFromEdgeID(const unsigned id) const = 0; + virtual unsigned GetNameIndexFromEdgeID(const unsigned id) const = 0; - virtual void GetName( - const unsigned name_id, - std::string & result - ) const = 0; + virtual void GetName(const unsigned name_id, std::string &result) const = 0; - std::string GetEscapedNameForNameID(const unsigned name_id) const { + std::string GetEscapedNameForNameID(const unsigned name_id) const + { std::string temporary_string; GetName(name_id, temporary_string); return EscapeJSONString(temporary_string); @@ -129,4 +111,4 @@ public: virtual std::string GetTimestamp() const = 0; }; -#endif // QUERY_DATA_FACADE_H +#endif // BASE_DATA_FACADE_H diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index 3e03b53ed..5f26506d8 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef INTERNAL_DATA_FACADE #define INTERNAL_DATA_FACADE -//implements all data storage when shared memory is _NOT_ used +// implements all data storage when shared memory is _NOT_ used #include "BaseDataFacade.h" @@ -48,75 +48,71 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -template -class InternalDataFacade : public BaseDataFacade { +template class InternalDataFacade : public BaseDataFacade +{ -private: - typedef BaseDataFacade super; + private: + typedef BaseDataFacade super; typedef StaticGraph QueryGraph; - typedef typename QueryGraph::InputEdge InputEdge; - typedef typename super::RTreeLeaf RTreeLeaf; + typedef typename QueryGraph::InputEdge InputEdge; + typedef typename super::RTreeLeaf RTreeLeaf; - InternalDataFacade() { } + InternalDataFacade() {} - unsigned m_check_sum; - unsigned m_number_of_nodes; - QueryGraph * m_query_graph; - std::string m_timestamp; + unsigned m_check_sum; + unsigned m_number_of_nodes; + QueryGraph *m_query_graph; + std::string m_timestamp; boost::shared_ptr::vector> m_coordinate_list; - ShM::vector m_via_node_list; - ShM::vector m_name_ID_list; - ShM::vector m_turn_instruction_list; - ShM::vector m_names_char_list; - ShM::vector m_name_begin_indices; - ShM::vector m_egde_is_compressed; - ShM::vector m_geometry_indices; - ShM::vector m_geometry_list; + ShM::vector m_via_node_list; + ShM::vector m_name_ID_list; + ShM::vector m_turn_instruction_list; + ShM::vector m_names_char_list; + ShM::vector m_name_begin_indices; + ShM::vector m_egde_is_compressed; + ShM::vector m_geometry_indices; + ShM::vector m_geometry_list; - boost::shared_ptr< - StaticRTree< - RTreeLeaf, - ShM::vector, - false - > - > m_static_rtree; + boost::shared_ptr::vector, false>> + m_static_rtree; - - void LoadTimestamp(const boost::filesystem::path & timestamp_path) { - if( boost::filesystem::exists(timestamp_path) ) { + void LoadTimestamp(const boost::filesystem::path ×tamp_path) + { + if (boost::filesystem::exists(timestamp_path)) + { SimpleLogger().Write() << "Loading Timestamp"; - boost::filesystem::ifstream timestampInStream( timestamp_path ); - if(!timestampInStream) { + boost::filesystem::ifstream timestampInStream(timestamp_path); + if (!timestampInStream) + { SimpleLogger().Write(logWARNING) << timestamp_path << " not found"; } getline(timestampInStream, m_timestamp); timestampInStream.close(); } - if(m_timestamp.empty()) { + if (m_timestamp.empty()) + { m_timestamp = "n/a"; } - if(25 < m_timestamp.length()) { + if (25 < m_timestamp.length()) + { m_timestamp.resize(25); } } - void LoadGraph(const boost::filesystem::path & hsgr_path) { + void LoadGraph(const boost::filesystem::path &hsgr_path) + { typename ShM::vector node_list; typename ShM::vector edge_list; SimpleLogger().Write() << "loading graph from " << hsgr_path.string(); - m_number_of_nodes = readHSGRFromStream( - hsgr_path, - node_list, - edge_list, - &m_check_sum - ); + m_number_of_nodes = readHSGRFromStream(hsgr_path, node_list, edge_list, &m_check_sum); BOOST_ASSERT_MSG(0 != node_list.size(), "node list empty"); // BOOST_ASSERT_MSG(0 != edge_list.size(), "edge list empty"); - SimpleLogger().Write() << "loaded " << node_list.size() << " nodes and " << edge_list.size() << " edges"; + SimpleLogger().Write() << "loaded " << node_list.size() << " nodes and " << edge_list.size() + << " edges"; m_query_graph = new QueryGraph(node_list, edge_list); BOOST_ASSERT_MSG(0 == node_list.size(), "node list not flushed"); @@ -124,57 +120,45 @@ private: SimpleLogger().Write() << "Data checksum is " << m_check_sum; } - void LoadNodeAndEdgeInformation( - const boost::filesystem::path & nodes_file, - const boost::filesystem::path & edges_file - ) { - boost::filesystem::ifstream nodes_input_stream( - nodes_file, - std::ios::binary - ); + void LoadNodeAndEdgeInformation(const boost::filesystem::path &nodes_file, + const boost::filesystem::path &edges_file) + { + boost::filesystem::ifstream nodes_input_stream(nodes_file, std::ios::binary); NodeInfo current_node; unsigned number_of_coordinates = 0; - nodes_input_stream.read( - (char *)&number_of_coordinates, - sizeof(unsigned) - ); - m_coordinate_list = boost::make_shared >(number_of_coordinates); - for(unsigned i = 0; i < number_of_coordinates; ++i) { + nodes_input_stream.read((char *)&number_of_coordinates, sizeof(unsigned)); + m_coordinate_list = + boost::make_shared>(number_of_coordinates); + for (unsigned i = 0; i < number_of_coordinates; ++i) + { nodes_input_stream.read((char *)¤t_node, sizeof(NodeInfo)); - m_coordinate_list->at(i) = FixedPointCoordinate( - current_node.lat, - current_node.lon - ); - BOOST_ASSERT( ( std::abs(m_coordinate_list->at(i).lat) >> 30) == 0 ); - BOOST_ASSERT( ( std::abs(m_coordinate_list->at(i).lon) >> 30) == 0 ); + m_coordinate_list->at(i) = FixedPointCoordinate(current_node.lat, current_node.lon); + BOOST_ASSERT((std::abs(m_coordinate_list->at(i).lat) >> 30) == 0); + BOOST_ASSERT((std::abs(m_coordinate_list->at(i).lon) >> 30) == 0); } nodes_input_stream.close(); - boost::filesystem::ifstream edges_input_stream( - edges_file, - std::ios::binary - ); + boost::filesystem::ifstream edges_input_stream(edges_file, std::ios::binary); unsigned number_of_edges = 0; - edges_input_stream.read((char*)&number_of_edges, sizeof(unsigned)); - m_via_node_list.resize (number_of_edges); - m_name_ID_list.resize (number_of_edges); + edges_input_stream.read((char *)&number_of_edges, sizeof(unsigned)); + m_via_node_list.resize(number_of_edges); + m_name_ID_list.resize(number_of_edges); m_turn_instruction_list.resize(number_of_edges); - m_egde_is_compressed.resize (number_of_edges); + m_egde_is_compressed.resize(number_of_edges); unsigned compressed = 0; OriginalEdgeData current_edge_data; - for(unsigned i = 0; i < number_of_edges; ++i) { - edges_input_stream.read( - (char*)&(current_edge_data), - sizeof(OriginalEdgeData) - ); + for (unsigned i = 0; i < number_of_edges; ++i) + { + edges_input_stream.read((char *)&(current_edge_data), sizeof(OriginalEdgeData)); m_via_node_list[i] = current_edge_data.via_node; - m_name_ID_list[i] = current_edge_data.name_id; + m_name_ID_list[i] = current_edge_data.name_id; m_turn_instruction_list[i] = current_edge_data.turn_instruction; m_egde_is_compressed[i] = current_edge_data.compressed_geometry; - if(m_egde_is_compressed[i]) { + if (m_egde_is_compressed[i]) + { ++compressed; } } @@ -182,60 +166,39 @@ private: edges_input_stream.close(); } - void LoadGeometries(const boost::filesystem::path & geometry_file) + void LoadGeometries(const boost::filesystem::path &geometry_file) { - std::ifstream geometry_stream( - geometry_file.c_str(), - std::ios::binary - ); + std::ifstream geometry_stream(geometry_file.c_str(), std::ios::binary); unsigned number_of_indices = 0; unsigned number_of_compressed_geometries = 0; - geometry_stream.read( - (char *)&number_of_indices, - sizeof(unsigned) - ); + geometry_stream.read((char *)&number_of_indices, sizeof(unsigned)); m_geometry_indices.resize(number_of_indices); - geometry_stream.read( - (char *)&(m_geometry_indices[0]), - number_of_indices*sizeof(unsigned) - ); + geometry_stream.read((char *)&(m_geometry_indices[0]), + number_of_indices * sizeof(unsigned)); - geometry_stream.read( - (char *)&number_of_compressed_geometries, - sizeof(unsigned) - ); + geometry_stream.read((char *)&number_of_compressed_geometries, sizeof(unsigned)); - BOOST_ASSERT( m_geometry_indices.back() == number_of_compressed_geometries ); - m_geometry_list.resize( number_of_compressed_geometries ); + BOOST_ASSERT(m_geometry_indices.back() == number_of_compressed_geometries); + m_geometry_list.resize(number_of_compressed_geometries); - geometry_stream.read( - (char *)&(m_geometry_list[0]), - number_of_compressed_geometries*sizeof(unsigned) - ); + geometry_stream.read((char *)&(m_geometry_list[0]), + number_of_compressed_geometries * sizeof(unsigned)); geometry_stream.close(); } - void LoadRTree( - const boost::filesystem::path & ram_index_path, - const boost::filesystem::path & file_index_path - ) { - BOOST_ASSERT_MSG( - !m_coordinate_list->empty(), - "coordinates must be loaded before r-tree" - ); + void LoadRTree(const boost::filesystem::path &ram_index_path, + const boost::filesystem::path &file_index_path) + { + BOOST_ASSERT_MSG(!m_coordinate_list->empty(), "coordinates must be loaded before r-tree"); - m_static_rtree = boost::make_shared >( - ram_index_path, - file_index_path, - m_coordinate_list - ); + m_static_rtree = boost::make_shared>( + ram_index_path, file_index_path, m_coordinate_list); } - void LoadStreetNames( - const boost::filesystem::path & names_file - ) { + void LoadStreetNames(const boost::filesystem::path &names_file) + { boost::filesystem::ifstream name_stream(names_file, std::ios::binary); unsigned number_of_names = 0; unsigned number_of_chars = 0; @@ -245,84 +208,85 @@ private: BOOST_ASSERT_MSG(0 != number_of_chars, "name file broken"); m_name_begin_indices.resize(number_of_names); - name_stream.read( - (char*)&m_name_begin_indices[0], - number_of_names*sizeof(unsigned) - ); + name_stream.read((char *)&m_name_begin_indices[0], number_of_names * sizeof(unsigned)); - m_names_char_list.resize(number_of_chars+1); //+1 gives sentinel element - name_stream.read( - (char *)&m_names_char_list[0], - number_of_chars*sizeof(char) - ); - BOOST_ASSERT_MSG( - 0 != m_names_char_list.size(), - "could not load any names" - ); + m_names_char_list.resize(number_of_chars + 1); //+1 gives sentinel element + name_stream.read((char *)&m_names_char_list[0], number_of_chars * sizeof(char)); + BOOST_ASSERT_MSG(0 != m_names_char_list.size(), "could not load any names"); name_stream.close(); } -public: - ~InternalDataFacade() { + + public: + ~InternalDataFacade() + { delete m_query_graph; m_static_rtree.reset(); } - explicit InternalDataFacade( const ServerPaths & server_paths ) { - //generate paths of data files - if( server_paths.find("hsgrdata") == server_paths.end() ) { + explicit InternalDataFacade(const ServerPaths &server_paths) + { + // generate paths of data files + if (server_paths.find("hsgrdata") == server_paths.end()) + { throw OSRMException("no hsgr file given in ini file"); } - if( server_paths.find("ramindex") == server_paths.end() ) { + if (server_paths.find("ramindex") == server_paths.end()) + { throw OSRMException("no ram index file given in ini file"); } - if( server_paths.find("fileindex") == server_paths.end() ) { + if (server_paths.find("fileindex") == server_paths.end()) + { throw OSRMException("no leaf index file given in ini file"); } - if( server_paths.find("geometries") == server_paths.end() ) { + if (server_paths.find("geometries") == server_paths.end()) + { throw OSRMException("no geometries file given in ini file"); } - if( server_paths.find("nodesdata") == server_paths.end() ) { + if (server_paths.find("nodesdata") == server_paths.end()) + { throw OSRMException("no nodes file given in ini file"); } - if( server_paths.find("edgesdata") == server_paths.end() ) { + if (server_paths.find("edgesdata") == server_paths.end()) + { throw OSRMException("no edges file given in ini file"); } - if( server_paths.find("namesdata") == server_paths.end() ) { + if (server_paths.find("namesdata") == server_paths.end()) + { throw OSRMException("no names file given in ini file"); } ServerPaths::const_iterator paths_iterator = server_paths.find("hsgrdata"); BOOST_ASSERT(server_paths.end() != paths_iterator); - const boost::filesystem::path & hsgr_path = paths_iterator->second; + const boost::filesystem::path &hsgr_path = paths_iterator->second; paths_iterator = server_paths.find("timestamp"); BOOST_ASSERT(server_paths.end() != paths_iterator); - const boost::filesystem::path & timestamp_path = paths_iterator->second; + const boost::filesystem::path ×tamp_path = paths_iterator->second; paths_iterator = server_paths.find("ramindex"); BOOST_ASSERT(server_paths.end() != paths_iterator); - const boost::filesystem::path & ram_index_path = paths_iterator->second; + const boost::filesystem::path &ram_index_path = paths_iterator->second; paths_iterator = server_paths.find("fileindex"); BOOST_ASSERT(server_paths.end() != paths_iterator); - const boost::filesystem::path & file_index_path = paths_iterator->second; + const boost::filesystem::path &file_index_path = paths_iterator->second; paths_iterator = server_paths.find("nodesdata"); BOOST_ASSERT(server_paths.end() != paths_iterator); - const boost::filesystem::path & nodes_data_path = paths_iterator->second; + const boost::filesystem::path &nodes_data_path = paths_iterator->second; paths_iterator = server_paths.find("edgesdata"); BOOST_ASSERT(server_paths.end() != paths_iterator); - const boost::filesystem::path & edges_data_path = paths_iterator->second; + const boost::filesystem::path &edges_data_path = paths_iterator->second; paths_iterator = server_paths.find("namesdata"); BOOST_ASSERT(server_paths.end() != paths_iterator); - const boost::filesystem::path & names_data_path = paths_iterator->second; + const boost::filesystem::path &names_data_path = paths_iterator->second; paths_iterator = server_paths.find("geometries"); BOOST_ASSERT(server_paths.end() != paths_iterator); - const boost::filesystem::path & geometries_path = paths_iterator->second; + const boost::filesystem::path &geometries_path = paths_iterator->second; - //load data + // load data SimpleLogger().Write() << "loading graph data"; LoadGraph(hsgr_path); SimpleLogger().Write() << "loading egde information"; LoadNodeAndEdgeInformation(nodes_data_path, edges_data_path); SimpleLogger().Write() << "loading geometries"; - LoadGeometries( geometries_path ); + LoadGeometries(geometries_path); SimpleLogger().Write() << "loading r-tree"; LoadRTree(ram_index_path, file_index_path); SimpleLogger().Write() << "loading timestamp"; @@ -331,155 +295,114 @@ public: LoadStreetNames(names_data_path); } - //search graph access - unsigned GetNumberOfNodes() const { - return m_query_graph->GetNumberOfNodes(); - } + // search graph access + unsigned GetNumberOfNodes() const { return m_query_graph->GetNumberOfNodes(); } - unsigned GetNumberOfEdges() const { - return m_query_graph->GetNumberOfEdges(); - } + unsigned GetNumberOfEdges() const { return m_query_graph->GetNumberOfEdges(); } - unsigned GetOutDegree( const NodeID n ) const { - return m_query_graph->GetOutDegree(n); - } + unsigned GetOutDegree(const NodeID n) const { return m_query_graph->GetOutDegree(n); } - NodeID GetTarget( const EdgeID e ) const { - return m_query_graph->GetTarget(e); } + NodeID GetTarget(const EdgeID e) const { return m_query_graph->GetTarget(e); } - EdgeDataT &GetEdgeData( const EdgeID e ) { - return m_query_graph->GetEdgeData(e); - } + EdgeDataT &GetEdgeData(const EdgeID e) { return m_query_graph->GetEdgeData(e); } - const EdgeDataT &GetEdgeData( const EdgeID e ) const { - return m_query_graph->GetEdgeData(e); - } + const EdgeDataT &GetEdgeData(const EdgeID e) const { return m_query_graph->GetEdgeData(e); } - EdgeID BeginEdges( const NodeID n ) const { - return m_query_graph->BeginEdges(n); - } + EdgeID BeginEdges(const NodeID n) const { return m_query_graph->BeginEdges(n); } - EdgeID EndEdges( const NodeID n ) const { - return m_query_graph->EndEdges(n); - } + EdgeID EndEdges(const NodeID n) const { return m_query_graph->EndEdges(n); } - //searches for a specific edge - EdgeID FindEdge( const NodeID from, const NodeID to ) const { + // searches for a specific edge + EdgeID FindEdge(const NodeID from, const NodeID to) const + { return m_query_graph->FindEdge(from, to); } - EdgeID FindEdgeInEitherDirection( - const NodeID from, - const NodeID to - ) const { + EdgeID FindEdgeInEitherDirection(const NodeID from, const NodeID to) const + { return m_query_graph->FindEdgeInEitherDirection(from, to); } - EdgeID FindEdgeIndicateIfReverse( - const NodeID from, - const NodeID to, - bool & result - ) const { + EdgeID FindEdgeIndicateIfReverse(const NodeID from, const NodeID to, bool &result) const + { return m_query_graph->FindEdgeIndicateIfReverse(from, to, result); } - //node and edge information access - FixedPointCoordinate GetCoordinateOfNode( - const unsigned id - ) const { + // node and edge information access + FixedPointCoordinate GetCoordinateOfNode(const unsigned id) const + { return m_coordinate_list->at(id); }; - bool EdgeIsCompressed( const unsigned id ) const { - return m_egde_is_compressed.at(id); - } + bool EdgeIsCompressed(const unsigned id) const { return m_egde_is_compressed.at(id); } - TurnInstruction GetTurnInstructionForEdgeID( - const unsigned id - ) const { + TurnInstruction GetTurnInstructionForEdgeID(const unsigned id) const + { return m_turn_instruction_list.at(id); } - bool LocateClosestEndPointForCoordinate( - const FixedPointCoordinate& input_coordinate, - FixedPointCoordinate& result, - const unsigned zoom_level = 18 - ) const { - return m_static_rtree->LocateClosestEndPointForCoordinate( - input_coordinate, - result, - zoom_level - ); + bool LocateClosestEndPointForCoordinate(const FixedPointCoordinate &input_coordinate, + FixedPointCoordinate &result, + const unsigned zoom_level = 18) const + { + return m_static_rtree->LocateClosestEndPointForCoordinate( + input_coordinate, result, zoom_level); } - bool FindPhantomNodeForCoordinate( - const FixedPointCoordinate & input_coordinate, - PhantomNode & resulting_phantom_node, - const unsigned zoom_level - ) const { - const bool found = m_static_rtree->FindPhantomNodeForCoordinate( - input_coordinate, - resulting_phantom_node, - zoom_level - ); + bool FindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate, + PhantomNode &resulting_phantom_node, + const unsigned zoom_level) const + { + const bool found = m_static_rtree->FindPhantomNodeForCoordinate( + input_coordinate, resulting_phantom_node, zoom_level); return found; } unsigned GetCheckSum() const { return m_check_sum; } - unsigned GetNameIndexFromEdgeID(const unsigned id) const { + unsigned GetNameIndexFromEdgeID(const unsigned id) const + { return m_name_ID_list.at(id); }; - void GetName( const unsigned name_id, std::string & result ) const { - if(UINT_MAX == name_id) { + void GetName(const unsigned name_id, std::string &result) const + { + if (UINT_MAX == name_id) + { result = ""; return; } - BOOST_ASSERT_MSG( - name_id < m_name_begin_indices.size(), - "name id too high" - ); + BOOST_ASSERT_MSG(name_id < m_name_begin_indices.size(), "name id too high"); const unsigned begin_index = m_name_begin_indices[name_id]; - const unsigned end_index = m_name_begin_indices[name_id+1]; - BOOST_ASSERT_MSG( - begin_index < m_names_char_list.size(), - "begin index of name too high" - ); - BOOST_ASSERT_MSG( - end_index < m_names_char_list.size(), - "end index of name too high" - ); + const unsigned end_index = m_name_begin_indices[name_id + 1]; + BOOST_ASSERT_MSG(begin_index < m_names_char_list.size(), "begin index of name too high"); + BOOST_ASSERT_MSG(end_index < m_names_char_list.size(), "end index of name too high"); BOOST_ASSERT_MSG(begin_index <= end_index, "string ends before begin"); result.clear(); result.resize(end_index - begin_index); - std::copy( - m_names_char_list.begin() + begin_index, - m_names_char_list.begin() + end_index, - result.begin() - ); + std::copy(m_names_char_list.begin() + begin_index, + m_names_char_list.begin() + end_index, + result.begin()); } - virtual unsigned GetGeometryIndexForEdgeID(const unsigned id) const { + virtual unsigned GetGeometryIndexForEdgeID(const unsigned id) const + { return m_via_node_list.at(id); } - virtual void GetUncompressedGeometry( - const unsigned id, std::vector & result_nodes - ) const { + virtual void GetUncompressedGeometry(const unsigned id, std::vector &result_nodes) + const + { const unsigned begin = m_geometry_indices.at(id); - const unsigned end = m_geometry_indices.at(id+1); + const unsigned end = m_geometry_indices.at(id + 1); result_nodes.clear(); - result_nodes.insert(result_nodes.begin(), - m_geometry_list.begin() + begin, - m_geometry_list.begin() + end); + result_nodes.insert( + result_nodes.begin(), m_geometry_list.begin() + begin, m_geometry_list.begin() + end); } - std::string GetTimestamp() const { - return m_timestamp; - } + std::string GetTimestamp() const { return m_timestamp; } }; -#endif // INTERNAL_DATA_FACADE +#endif // INTERNAL_DATA_FACADE diff --git a/Server/DataStructures/SharedBarriers.h b/Server/DataStructures/SharedBarriers.h index 9e38f51b5..36ba08b1f 100644 --- a/Server/DataStructures/SharedBarriers.h +++ b/Server/DataStructures/SharedBarriers.h @@ -31,42 +31,30 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -struct SharedBarriers { +struct SharedBarriers +{ - SharedBarriers () - : - pending_update_mutex( - boost::interprocess::open_or_create, - "pending_update" - ), - update_mutex( - boost::interprocess::open_or_create, - "update" - ), - query_mutex( - boost::interprocess::open_or_create, - "query" - ), - no_running_queries_condition( - boost::interprocess::open_or_create, - "no_running_queries" - ), - update_ongoing(false), - number_of_queries(0) - { } + SharedBarriers() + : pending_update_mutex(boost::interprocess::open_or_create, "pending_update"), + update_mutex(boost::interprocess::open_or_create, "update"), + query_mutex(boost::interprocess::open_or_create, "query"), + no_running_queries_condition(boost::interprocess::open_or_create, "no_running_queries"), + update_ongoing(false), number_of_queries(0) + { + } - // Mutex to protect access to the boolean variable - boost::interprocess::named_mutex pending_update_mutex; - boost::interprocess::named_mutex update_mutex; - boost::interprocess::named_mutex query_mutex; + // Mutex to protect access to the boolean variable + boost::interprocess::named_mutex pending_update_mutex; + boost::interprocess::named_mutex update_mutex; + boost::interprocess::named_mutex query_mutex; - // Condition that no update is running - boost::interprocess::named_condition no_running_queries_condition; + // Condition that no update is running + boost::interprocess::named_condition no_running_queries_condition; - // Is there an ongoing update? - bool update_ongoing; - // Is there any query? - int number_of_queries; + // Is there an ongoing update? + bool update_ongoing; + // Is there any query? + int number_of_queries; }; -#endif //SHARED_BARRIER_H +#endif // SHARED_BARRIER_H diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index de28a3c76..09c4f8525 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef SHARED_DATA_FACADE_H #define SHARED_DATA_FACADE_H -//implements all data storage when shared memory _IS_ used +// implements all data storage when shared memory _IS_ used #include "BaseDataFacade.h" #include "SharedDataType.h" @@ -44,244 +44,186 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -template -class SharedDataFacade : public BaseDataFacade { +template class SharedDataFacade : public BaseDataFacade +{ -private: + private: typedef EdgeDataT EdgeData; - typedef BaseDataFacade super; - typedef StaticGraph QueryGraph; + typedef BaseDataFacade super; + typedef StaticGraph QueryGraph; typedef typename StaticGraph::NodeArrayEntry GraphNode; typedef typename StaticGraph::EdgeArrayEntry GraphEdge; - typedef typename QueryGraph::InputEdge InputEdge; - typedef typename super::RTreeLeaf RTreeLeaf; - typedef typename StaticRTree::vector, true>::TreeNode RTreeNode; + typedef typename QueryGraph::InputEdge InputEdge; + typedef typename super::RTreeLeaf RTreeLeaf; + typedef typename StaticRTree::vector, true>::TreeNode + RTreeNode; - SharedDataLayout * data_layout; - char * shared_memory; - SharedDataTimestamp * data_timestamp_ptr; + SharedDataLayout *data_layout; + char *shared_memory; + SharedDataTimestamp *data_timestamp_ptr; - SharedDataType CURRENT_LAYOUT; - SharedDataType CURRENT_DATA; - unsigned CURRENT_TIMESTAMP; + SharedDataType CURRENT_LAYOUT; + SharedDataType CURRENT_DATA; + unsigned CURRENT_TIMESTAMP; - unsigned m_check_sum; - unsigned m_number_of_nodes; - boost::shared_ptr m_query_graph; - boost::shared_ptr m_layout_memory; - boost::shared_ptr m_large_memory; - std::string m_timestamp; + unsigned m_check_sum; + unsigned m_number_of_nodes; + boost::shared_ptr m_query_graph; + boost::shared_ptr m_layout_memory; + boost::shared_ptr m_large_memory; + std::string m_timestamp; - boost::shared_ptr< - ShM::vector - > m_coordinate_list; - ShM::vector m_via_node_list; - ShM::vector m_name_ID_list; - ShM::vector m_turn_instruction_list; - ShM::vector m_names_char_list; - ShM::vector m_name_begin_indices; - ShM::vector m_egde_is_compressed; - ShM::vector m_geometry_indices; - ShM::vector m_geometry_list; + boost::shared_ptr::vector> m_coordinate_list; + ShM::vector m_via_node_list; + ShM::vector m_name_ID_list; + ShM::vector m_turn_instruction_list; + ShM::vector m_names_char_list; + ShM::vector m_name_begin_indices; + ShM::vector m_egde_is_compressed; + ShM::vector m_geometry_indices; + ShM::vector m_geometry_list; - boost::shared_ptr< - StaticRTree< - RTreeLeaf, - ShM::vector, - true - > - > m_static_rtree; + boost::shared_ptr::vector, true>> + m_static_rtree; - void LoadTimestamp() { - char * timestamp_ptr = shared_memory + data_layout->GetTimeStampOffset(); + void LoadTimestamp() + { + char *timestamp_ptr = shared_memory + data_layout->GetTimeStampOffset(); m_timestamp.resize(data_layout->timestamp_length); std::copy( - timestamp_ptr, - timestamp_ptr+data_layout->timestamp_length, - m_timestamp.begin() - ); + timestamp_ptr, timestamp_ptr + data_layout->timestamp_length, m_timestamp.begin()); } - void LoadRTree( - const boost::filesystem::path & file_index_path - ) { - BOOST_ASSERT_MSG( - !m_coordinate_list->empty(), - "coordinates must be loaded before r-tree" - ); + void LoadRTree(const boost::filesystem::path &file_index_path) + { + BOOST_ASSERT_MSG(!m_coordinate_list->empty(), "coordinates must be loaded before r-tree"); - RTreeNode * tree_ptr = (RTreeNode *)( - shared_memory + data_layout->GetRSearchTreeOffset() - ); - m_static_rtree = boost::make_shared::vector, true> >( - tree_ptr, - data_layout->r_search_tree_size, - file_index_path, - m_coordinate_list - ); + RTreeNode *tree_ptr = (RTreeNode *)(shared_memory + data_layout->GetRSearchTreeOffset()); + m_static_rtree = boost::make_shared< + StaticRTree::vector, true>>( + tree_ptr, data_layout->r_search_tree_size, file_index_path, m_coordinate_list); } - void LoadGraph() { + void LoadGraph() + { m_number_of_nodes = data_layout->graph_node_list_size; - GraphNode * graph_nodes_ptr = (GraphNode *)( - shared_memory + data_layout->GetGraphNodeListOffset() - ); + GraphNode *graph_nodes_ptr = + (GraphNode *)(shared_memory + data_layout->GetGraphNodeListOffset()); - GraphEdge * graph_edges_ptr = (GraphEdge *)( - shared_memory + data_layout->GetGraphEdgeListOffset() - ); + GraphEdge *graph_edges_ptr = + (GraphEdge *)(shared_memory + data_layout->GetGraphEdgeListOffset()); - typename ShM::vector node_list( - graph_nodes_ptr, - data_layout->graph_node_list_size - ); - typename ShM::vector edge_list( - graph_edges_ptr, - data_layout->graph_edge_list_size - ); - m_query_graph.reset( - new QueryGraph(node_list, edge_list) - ); + typename ShM::vector node_list(graph_nodes_ptr, + data_layout->graph_node_list_size); + typename ShM::vector edge_list(graph_edges_ptr, + data_layout->graph_edge_list_size); + m_query_graph.reset(new QueryGraph(node_list, edge_list)); } - void LoadNodeAndEdgeInformation() { + void LoadNodeAndEdgeInformation() + { - FixedPointCoordinate * coordinate_list_ptr = (FixedPointCoordinate *)( - shared_memory + data_layout->GetCoordinateListOffset() - ); - m_coordinate_list = boost::make_shared::vector> ( - coordinate_list_ptr, - data_layout->coordinate_list_size - ); + FixedPointCoordinate *coordinate_list_ptr = + (FixedPointCoordinate *)(shared_memory + data_layout->GetCoordinateListOffset()); + m_coordinate_list = boost::make_shared::vector>( + coordinate_list_ptr, data_layout->coordinate_list_size); - TurnInstruction * turn_instruction_list_ptr = (TurnInstruction *)( - shared_memory + data_layout->GetTurnInstructionListOffset() - ); + TurnInstruction *turn_instruction_list_ptr = + (TurnInstruction *)(shared_memory + data_layout->GetTurnInstructionListOffset()); typename ShM::vector turn_instruction_list( - turn_instruction_list_ptr, - data_layout->turn_instruction_list_size - ); + turn_instruction_list_ptr, data_layout->turn_instruction_list_size); m_turn_instruction_list.swap(turn_instruction_list); - unsigned * name_id_list_ptr = (unsigned *)( - shared_memory + data_layout->GetNameIDListOffset() - ); - typename ShM::vector name_id_list( - name_id_list_ptr, - data_layout->name_id_list_size - ); + unsigned *name_id_list_ptr = + (unsigned *)(shared_memory + data_layout->GetNameIDListOffset()); + typename ShM::vector name_id_list(name_id_list_ptr, + data_layout->name_id_list_size); m_name_ID_list.swap(name_id_list); } - void LoadViaNodeList() { - NodeID * via_node_list_ptr = (NodeID *)( - shared_memory + data_layout->GetViaNodeListOffset() - ); - typename ShM::vector via_node_list( - via_node_list_ptr, - data_layout->via_node_list_size - ); + void LoadViaNodeList() + { + NodeID *via_node_list_ptr = (NodeID *)(shared_memory + data_layout->GetViaNodeListOffset()); + typename ShM::vector via_node_list(via_node_list_ptr, + data_layout->via_node_list_size); m_via_node_list.swap(via_node_list); } - void LoadNames() { - unsigned * street_names_index_ptr = (unsigned *)( - shared_memory + data_layout->GetNameIndexOffset() - ); - typename ShM::vector name_begin_indices( - street_names_index_ptr, - data_layout->name_index_list_size - ); + void LoadNames() + { + unsigned *street_names_index_ptr = + (unsigned *)(shared_memory + data_layout->GetNameIndexOffset()); + typename ShM::vector name_begin_indices(street_names_index_ptr, + data_layout->name_index_list_size); m_name_begin_indices.swap(name_begin_indices); - char * names_list_ptr = (char *)( - shared_memory + data_layout->GetNameListOffset() - ); - typename ShM::vector names_char_list( - names_list_ptr, - data_layout->name_char_list_size - ); + char *names_list_ptr = (char *)(shared_memory + data_layout->GetNameListOffset()); + typename ShM::vector names_char_list(names_list_ptr, + data_layout->name_char_list_size); m_names_char_list.swap(names_char_list); } void LoadGeometries() { - unsigned * geometries_compressed_ptr = (unsigned *)( - shared_memory + data_layout->GetGeometriesIndicatorOffset() - ); - typename ShM::vector egde_is_compressed( - geometries_compressed_ptr, - data_layout->geometries_indicators - ); + unsigned *geometries_compressed_ptr = + (unsigned *)(shared_memory + data_layout->GetGeometriesIndicatorOffset()); + typename ShM::vector egde_is_compressed(geometries_compressed_ptr, + data_layout->geometries_indicators); m_egde_is_compressed.swap(egde_is_compressed); - unsigned * geometries_index_ptr = (unsigned *)( - shared_memory + data_layout->GetGeometriesIndexListOffset() - ); + unsigned *geometries_index_ptr = + (unsigned *)(shared_memory + data_layout->GetGeometriesIndexListOffset()); typename ShM::vector geometry_begin_indices( - geometries_index_ptr, - data_layout->geometries_index_list_size - ); + geometries_index_ptr, data_layout->geometries_index_list_size); m_geometry_indices.swap(geometry_begin_indices); - unsigned * geometries_list_ptr = (unsigned *)( - shared_memory + data_layout->GetGeometryListOffset() - ); - typename ShM::vector geometry_list( - geometries_list_ptr, - data_layout->geometries_list_size - ); + unsigned *geometries_list_ptr = + (unsigned *)(shared_memory + data_layout->GetGeometryListOffset()); + typename ShM::vector geometry_list(geometries_list_ptr, + data_layout->geometries_list_size); m_geometry_list.swap(geometry_list); } -public: - SharedDataFacade( ) { + public: + SharedDataFacade() + { data_timestamp_ptr = (SharedDataTimestamp *)SharedMemoryFactory::Get( - CURRENT_REGIONS, - sizeof(SharedDataTimestamp), - false, - false - )->Ptr(); + CURRENT_REGIONS, sizeof(SharedDataTimestamp), false, false)->Ptr(); CURRENT_LAYOUT = LAYOUT_NONE; CURRENT_DATA = DATA_NONE; CURRENT_TIMESTAMP = 0; - //load data + // load data CheckAndReloadFacade(); } - void CheckAndReloadFacade() { - if( - CURRENT_LAYOUT != data_timestamp_ptr->layout || - CURRENT_DATA != data_timestamp_ptr->data || - CURRENT_TIMESTAMP != data_timestamp_ptr->timestamp - ) { + void CheckAndReloadFacade() + { + if (CURRENT_LAYOUT != data_timestamp_ptr->layout || + CURRENT_DATA != data_timestamp_ptr->data || + CURRENT_TIMESTAMP != data_timestamp_ptr->timestamp) + { // release the previous shared memory segments SharedMemory::Remove(CURRENT_LAYOUT); SharedMemory::Remove(CURRENT_DATA); - CURRENT_LAYOUT = data_timestamp_ptr->layout; - CURRENT_DATA = data_timestamp_ptr->data; + CURRENT_LAYOUT = data_timestamp_ptr->layout; + CURRENT_DATA = data_timestamp_ptr->data; CURRENT_TIMESTAMP = data_timestamp_ptr->timestamp; - m_layout_memory.reset( SharedMemoryFactory::Get(CURRENT_LAYOUT) ); + m_layout_memory.reset(SharedMemoryFactory::Get(CURRENT_LAYOUT)); - data_layout = (SharedDataLayout *)( - m_layout_memory->Ptr() - ); + data_layout = (SharedDataLayout *)(m_layout_memory->Ptr()); boost::filesystem::path ram_index_path(data_layout->ram_index_file_name); - if( !boost::filesystem::exists(ram_index_path) ) { - throw OSRMException( - "no leaf index file given. " - "Is any data loaded into shared memory?" - ); + if (!boost::filesystem::exists(ram_index_path)) + { + throw OSRMException("no leaf index file given. " + "Is any data loaded into shared memory?"); } - m_large_memory.reset( SharedMemoryFactory::Get(CURRENT_DATA) ); - shared_memory = (char *)( - m_large_memory->Ptr() - ); + m_large_memory.reset(SharedMemoryFactory::Get(CURRENT_DATA)); + shared_memory = (char *)(m_large_memory->Ptr()); LoadGraph(); LoadNodeAndEdgeInformation(); @@ -295,155 +237,116 @@ public: } } - //search graph access - unsigned GetNumberOfNodes() const { - return m_query_graph->GetNumberOfNodes(); - } + // search graph access + unsigned GetNumberOfNodes() const { return m_query_graph->GetNumberOfNodes(); } - unsigned GetNumberOfEdges() const { - return m_query_graph->GetNumberOfEdges(); - } + unsigned GetNumberOfEdges() const { return m_query_graph->GetNumberOfEdges(); } - unsigned GetOutDegree( const NodeID n ) const { - return m_query_graph->GetOutDegree(n); - } + unsigned GetOutDegree(const NodeID n) const { return m_query_graph->GetOutDegree(n); } - NodeID GetTarget( const EdgeID e ) const { - return m_query_graph->GetTarget(e); } + NodeID GetTarget(const EdgeID e) const { return m_query_graph->GetTarget(e); } - EdgeDataT &GetEdgeData( const EdgeID e ) { - return m_query_graph->GetEdgeData(e); - } + EdgeDataT &GetEdgeData(const EdgeID e) { return m_query_graph->GetEdgeData(e); } // const EdgeDataT &GetEdgeData( const EdgeID e ) const { // return m_query_graph->GetEdgeData(e); // } - EdgeID BeginEdges( const NodeID n ) const { - return m_query_graph->BeginEdges(n); - } + EdgeID BeginEdges(const NodeID n) const { return m_query_graph->BeginEdges(n); } - EdgeID EndEdges( const NodeID n ) const { - return m_query_graph->EndEdges(n); - } + EdgeID EndEdges(const NodeID n) const { return m_query_graph->EndEdges(n); } - //searches for a specific edge - EdgeID FindEdge( const NodeID from, const NodeID to ) const { + // searches for a specific edge + EdgeID FindEdge(const NodeID from, const NodeID to) const + { return m_query_graph->FindEdge(from, to); } - EdgeID FindEdgeInEitherDirection( - const NodeID from, - const NodeID to - ) const { + EdgeID FindEdgeInEitherDirection(const NodeID from, const NodeID to) const + { return m_query_graph->FindEdgeInEitherDirection(from, to); } - EdgeID FindEdgeIndicateIfReverse( - const NodeID from, - const NodeID to, - bool & result - ) const { + EdgeID FindEdgeIndicateIfReverse(const NodeID from, const NodeID to, bool &result) const + { return m_query_graph->FindEdgeIndicateIfReverse(from, to, result); } - //node and edge information access - FixedPointCoordinate GetCoordinateOfNode( - const unsigned id - ) const { + // node and edge information access + FixedPointCoordinate GetCoordinateOfNode(const unsigned id) const + { return m_coordinate_list->at(id); }; - virtual bool EdgeIsCompressed( const unsigned id ) const { - return m_egde_is_compressed.at(id); - } + virtual bool EdgeIsCompressed(const unsigned id) const { return m_egde_is_compressed.at(id); } - virtual void GetUncompressedGeometry( - const unsigned id, std::vector & result_nodes - ) const { + virtual void GetUncompressedGeometry(const unsigned id, std::vector &result_nodes) + const + { const unsigned begin = m_geometry_indices.at(id); - const unsigned end = m_geometry_indices.at(id+1); + const unsigned end = m_geometry_indices.at(id + 1); result_nodes.clear(); - result_nodes.insert(result_nodes.begin(), - m_geometry_list.begin() + begin, - m_geometry_list.begin() + end); + result_nodes.insert( + result_nodes.begin(), m_geometry_list.begin() + begin, m_geometry_list.begin() + end); } - virtual unsigned GetGeometryIndexForEdgeID(const unsigned id) const { + virtual unsigned GetGeometryIndexForEdgeID(const unsigned id) const + { return m_via_node_list.at(id); } - TurnInstruction GetTurnInstructionForEdgeID( - const unsigned id - ) const { + TurnInstruction GetTurnInstructionForEdgeID(const unsigned id) const + { return m_turn_instruction_list.at(id); } - bool LocateClosestEndPointForCoordinate( - const FixedPointCoordinate& input_coordinate, - FixedPointCoordinate& result, - const unsigned zoom_level = 18 - ) const { - return m_static_rtree->LocateClosestEndPointForCoordinate( - input_coordinate, - result, - zoom_level - ); + bool LocateClosestEndPointForCoordinate(const FixedPointCoordinate &input_coordinate, + FixedPointCoordinate &result, + const unsigned zoom_level = 18) const + { + return m_static_rtree->LocateClosestEndPointForCoordinate( + input_coordinate, result, zoom_level); } - bool FindPhantomNodeForCoordinate( - const FixedPointCoordinate & input_coordinate, - PhantomNode & resulting_phantom_node, - const unsigned zoom_level - ) const { - const bool found = m_static_rtree->FindPhantomNodeForCoordinate( - input_coordinate, - resulting_phantom_node, - zoom_level - ); + bool FindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate, + PhantomNode &resulting_phantom_node, + const unsigned zoom_level) const + { + const bool found = m_static_rtree->FindPhantomNodeForCoordinate( + input_coordinate, resulting_phantom_node, zoom_level); return found; } unsigned GetCheckSum() const { return m_check_sum; } - unsigned GetNameIndexFromEdgeID(const unsigned id) const { + unsigned GetNameIndexFromEdgeID(const unsigned id) const + { return m_name_ID_list.at(id); }; - void GetName( const unsigned name_id, std::string & result ) const { - if(UINT_MAX == name_id) { + void GetName(const unsigned name_id, std::string &result) const + { + if (UINT_MAX == name_id) + { result = ""; return; } - BOOST_ASSERT_MSG( - name_id < m_name_begin_indices.size(), - "name id too high" - ); + BOOST_ASSERT_MSG(name_id < m_name_begin_indices.size(), "name id too high"); const unsigned begin_index = m_name_begin_indices[name_id]; - const unsigned end_index = m_name_begin_indices[name_id+1]; - BOOST_ASSERT_MSG( - begin_index <= m_names_char_list.size(), - "begin index of name too high" - ); - BOOST_ASSERT_MSG( - end_index <= m_names_char_list.size(), - "end index of name too high" - ); + const unsigned end_index = m_name_begin_indices[name_id + 1]; + BOOST_ASSERT_MSG(begin_index <= m_names_char_list.size(), "begin index of name too high"); + BOOST_ASSERT_MSG(end_index <= m_names_char_list.size(), "end index of name too high"); BOOST_ASSERT_MSG(begin_index <= end_index, "string ends before begin"); result.clear(); result.resize(end_index - begin_index); - std::copy( - m_names_char_list.begin() + begin_index, - m_names_char_list.begin() + end_index, - result.begin() - ); + std::copy(m_names_char_list.begin() + begin_index, + m_names_char_list.begin() + end_index, + result.begin()); } - std::string GetTimestamp() const { - return m_timestamp; - } + std::string GetTimestamp() const { return m_timestamp; } }; -#endif // SHARED_DATA_FACADE_H +#endif // SHARED_DATA_FACADE_H diff --git a/Server/DataStructures/SharedDataType.h b/Server/DataStructures/SharedDataType.h index dd700b859..285bc5024 100644 --- a/Server/DataStructures/SharedDataType.h +++ b/Server/DataStructures/SharedDataType.h @@ -25,7 +25,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #ifndef SHARED_DATA_TYPE_H_ #define SHARED_DATA_TYPE_H_ @@ -46,7 +45,8 @@ typedef BaseDataFacade::RTreeLeaf RTreeLeaf; typedef StaticRTree::vector, true>::TreeNode RTreeNode; typedef StaticGraph QueryGraph; -struct SharedDataLayout { +struct SharedDataLayout +{ uint64_t name_index_list_size; uint64_t name_char_list_size; uint64_t name_id_list_size; @@ -65,27 +65,19 @@ struct SharedDataLayout { char ram_index_file_name[1024]; - SharedDataLayout() : - name_index_list_size(0), - name_char_list_size(0), - name_id_list_size(0), - via_node_list_size(0), - graph_node_list_size(0), - graph_edge_list_size(0), - coordinate_list_size(0), - turn_instruction_list_size(0), - r_search_tree_size(0), - geometries_index_list_size(0), - geometries_list_size(0), - geometries_indicators(0), - checksum(0), - timestamp_length(0) + SharedDataLayout() + : name_index_list_size(0), name_char_list_size(0), name_id_list_size(0), + via_node_list_size(0), graph_node_list_size(0), graph_edge_list_size(0), + coordinate_list_size(0), turn_instruction_list_size(0), r_search_tree_size(0), + geometries_index_list_size(0), geometries_list_size(0), geometries_indicators(0), + checksum(0), timestamp_length(0) { ram_index_file_name[0] = '\0'; } - void PrintInformation() const { + void PrintInformation() const + { SimpleLogger().Write(logDEBUG) << "-"; SimpleLogger().Write(logDEBUG) << "name_index_list_size: " << name_index_list_size; SimpleLogger().Write(logDEBUG) << "name_char_list_size: " << name_char_list_size; @@ -95,196 +87,184 @@ struct SharedDataLayout { SimpleLogger().Write(logDEBUG) << "graph_edge_list_size: " << graph_edge_list_size; SimpleLogger().Write(logDEBUG) << "timestamp_length: " << timestamp_length; SimpleLogger().Write(logDEBUG) << "coordinate_list_size: " << coordinate_list_size; - SimpleLogger().Write(logDEBUG) << "turn_instruction_list_size: " << turn_instruction_list_size; + SimpleLogger().Write(logDEBUG) + << "turn_instruction_list_size: " << turn_instruction_list_size; SimpleLogger().Write(logDEBUG) << "r_search_tree_size: " << r_search_tree_size; - SimpleLogger().Write(logDEBUG) << "geometries_indicators: " << geometries_indicators << "/" << ((geometries_indicators/8) + 1); - SimpleLogger().Write(logDEBUG) << "geometries_index_list_size: " << geometries_index_list_size; + SimpleLogger().Write(logDEBUG) << "geometries_indicators: " << geometries_indicators + << "/" << ((geometries_indicators / 8) + 1); + SimpleLogger().Write(logDEBUG) + << "geometries_index_list_size: " << geometries_index_list_size; SimpleLogger().Write(logDEBUG) << "geometries_list_size: " << geometries_list_size; SimpleLogger().Write(logDEBUG) << "sizeof(checksum): " << sizeof(checksum); SimpleLogger().Write(logDEBUG) << "ram index file name: " << ram_index_file_name; } - uint64_t GetSizeOfLayout() const { + uint64_t GetSizeOfLayout() const + { uint64_t result = - (name_index_list_size * sizeof(unsigned) ) + - (name_char_list_size * sizeof(char) ) + - (name_id_list_size * sizeof(unsigned) ) + - (via_node_list_size * sizeof(NodeID) ) + - (graph_node_list_size * sizeof(QueryGraph::NodeArrayEntry) ) + - (graph_edge_list_size * sizeof(QueryGraph::EdgeArrayEntry) ) + - (timestamp_length * sizeof(char) ) + - (coordinate_list_size * sizeof(FixedPointCoordinate) ) + - (turn_instruction_list_size * sizeof(TurnInstructionsClass) ) + - (r_search_tree_size * sizeof(RTreeNode) ) + - (geometries_indicators/32 + 1) * sizeof(unsigned) + - (geometries_index_list_size * sizeof(unsigned) ) + - (geometries_list_size * sizeof(unsigned) ) + - sizeof(checksum) + - 1024*sizeof(char); + (name_index_list_size * sizeof(unsigned)) + (name_char_list_size * sizeof(char)) + + (name_id_list_size * sizeof(unsigned)) + (via_node_list_size * sizeof(NodeID)) + + (graph_node_list_size * sizeof(QueryGraph::NodeArrayEntry)) + + (graph_edge_list_size * sizeof(QueryGraph::EdgeArrayEntry)) + + (timestamp_length * sizeof(char)) + + (coordinate_list_size * sizeof(FixedPointCoordinate)) + + (turn_instruction_list_size * sizeof(TurnInstructionsClass)) + + (r_search_tree_size * sizeof(RTreeNode)) + + (geometries_indicators / 32 + 1) * sizeof(unsigned) + + (geometries_index_list_size * sizeof(unsigned)) + + (geometries_list_size * sizeof(unsigned)) + sizeof(checksum) + 1024 * sizeof(char); return result; } - uint64_t GetNameIndexOffset() const { - return 0; - } - uint64_t GetNameListOffset() const { - uint64_t result = - (name_index_list_size * sizeof(unsigned) ); + uint64_t GetNameIndexOffset() const { return 0; } + uint64_t GetNameListOffset() const + { + uint64_t result = (name_index_list_size * sizeof(unsigned)); return result; } - uint64_t GetNameIDListOffset() const { + uint64_t GetNameIDListOffset() const + { uint64_t result = - (name_index_list_size * sizeof(unsigned) ) + - (name_char_list_size * sizeof(char) ); + (name_index_list_size * sizeof(unsigned)) + (name_char_list_size * sizeof(char)); return result; } - uint64_t GetViaNodeListOffset() const { - uint64_t result = - (name_index_list_size * sizeof(unsigned) ) + - (name_char_list_size * sizeof(char) ) + - (name_id_list_size * sizeof(unsigned) ); + uint64_t GetViaNodeListOffset() const + { + uint64_t result = (name_index_list_size * sizeof(unsigned)) + + (name_char_list_size * sizeof(char)) + + (name_id_list_size * sizeof(unsigned)); return result; } - uint64_t GetGraphNodeListOffset() const { + uint64_t GetGraphNodeListOffset() const + { uint64_t result = - (name_index_list_size * sizeof(unsigned) ) + - (name_char_list_size * sizeof(char) ) + - (name_id_list_size * sizeof(unsigned) ) + - (via_node_list_size * sizeof(NodeID) ); + (name_index_list_size * sizeof(unsigned)) + (name_char_list_size * sizeof(char)) + + (name_id_list_size * sizeof(unsigned)) + (via_node_list_size * sizeof(NodeID)); return result; } - uint64_t GetGraphEdgeListOffset() const { + uint64_t GetGraphEdgeListOffset() const + { uint64_t result = - (name_index_list_size * sizeof(unsigned) ) + - (name_char_list_size * sizeof(char) ) + - (name_id_list_size * sizeof(unsigned) ) + - (via_node_list_size * sizeof(NodeID) ) + - (graph_node_list_size * sizeof(QueryGraph::NodeArrayEntry)) ; + (name_index_list_size * sizeof(unsigned)) + (name_char_list_size * sizeof(char)) + + (name_id_list_size * sizeof(unsigned)) + (via_node_list_size * sizeof(NodeID)) + + (graph_node_list_size * sizeof(QueryGraph::NodeArrayEntry)); return result; } - uint64_t GetTimeStampOffset() const { + uint64_t GetTimeStampOffset() const + { uint64_t result = - (name_index_list_size * sizeof(unsigned) ) + - (name_char_list_size * sizeof(char) ) + - (name_id_list_size * sizeof(unsigned) ) + - (via_node_list_size * sizeof(NodeID) ) + - (graph_node_list_size * sizeof(QueryGraph::NodeArrayEntry)) + - (graph_edge_list_size * sizeof(QueryGraph::EdgeArrayEntry)); + (name_index_list_size * sizeof(unsigned)) + (name_char_list_size * sizeof(char)) + + (name_id_list_size * sizeof(unsigned)) + (via_node_list_size * sizeof(NodeID)) + + (graph_node_list_size * sizeof(QueryGraph::NodeArrayEntry)) + + (graph_edge_list_size * sizeof(QueryGraph::EdgeArrayEntry)); return result; } - uint64_t GetCoordinateListOffset() const { + uint64_t GetCoordinateListOffset() const + { uint64_t result = - (name_index_list_size * sizeof(unsigned) ) + - (name_char_list_size * sizeof(char) ) + - (name_id_list_size * sizeof(unsigned) ) + - (via_node_list_size * sizeof(NodeID) ) + - (graph_node_list_size * sizeof(QueryGraph::NodeArrayEntry)) + - (graph_edge_list_size * sizeof(QueryGraph::EdgeArrayEntry)) + - (timestamp_length * sizeof(char) ); + (name_index_list_size * sizeof(unsigned)) + (name_char_list_size * sizeof(char)) + + (name_id_list_size * sizeof(unsigned)) + (via_node_list_size * sizeof(NodeID)) + + (graph_node_list_size * sizeof(QueryGraph::NodeArrayEntry)) + + (graph_edge_list_size * sizeof(QueryGraph::EdgeArrayEntry)) + + (timestamp_length * sizeof(char)); return result; } - uint64_t GetTurnInstructionListOffset() const { + uint64_t GetTurnInstructionListOffset() const + { uint64_t result = - (name_index_list_size * sizeof(unsigned) ) + - (name_char_list_size * sizeof(char) ) + - (name_id_list_size * sizeof(unsigned) ) + - (via_node_list_size * sizeof(NodeID) ) + - (graph_node_list_size * sizeof(QueryGraph::NodeArrayEntry)) + - (graph_edge_list_size * sizeof(QueryGraph::EdgeArrayEntry)) + - (timestamp_length * sizeof(char) ) + - (coordinate_list_size * sizeof(FixedPointCoordinate)); + (name_index_list_size * sizeof(unsigned)) + (name_char_list_size * sizeof(char)) + + (name_id_list_size * sizeof(unsigned)) + (via_node_list_size * sizeof(NodeID)) + + (graph_node_list_size * sizeof(QueryGraph::NodeArrayEntry)) + + (graph_edge_list_size * sizeof(QueryGraph::EdgeArrayEntry)) + + (timestamp_length * sizeof(char)) + + (coordinate_list_size * sizeof(FixedPointCoordinate)); return result; } - uint64_t GetRSearchTreeOffset() const { + uint64_t GetRSearchTreeOffset() const + { uint64_t result = - (name_index_list_size * sizeof(unsigned) ) + - (name_char_list_size * sizeof(char) ) + - (name_id_list_size * sizeof(unsigned) ) + - (via_node_list_size * sizeof(NodeID) ) + - (graph_node_list_size * sizeof(QueryGraph::NodeArrayEntry) ) + - (graph_edge_list_size * sizeof(QueryGraph::EdgeArrayEntry) ) + - (timestamp_length * sizeof(char) ) + - (coordinate_list_size * sizeof(FixedPointCoordinate) ) + + (name_index_list_size * sizeof(unsigned)) + (name_char_list_size * sizeof(char)) + + (name_id_list_size * sizeof(unsigned)) + (via_node_list_size * sizeof(NodeID)) + + (graph_node_list_size * sizeof(QueryGraph::NodeArrayEntry)) + + (graph_edge_list_size * sizeof(QueryGraph::EdgeArrayEntry)) + + (timestamp_length * sizeof(char)) + + (coordinate_list_size * sizeof(FixedPointCoordinate)) + (turn_instruction_list_size * sizeof(TurnInstructionsClass)); return result; } - uint64_t GetGeometriesIndicatorOffset() const { + uint64_t GetGeometriesIndicatorOffset() const + { uint64_t result = - (name_index_list_size * sizeof(unsigned) ) + - (name_char_list_size * sizeof(char) ) + - (name_id_list_size * sizeof(unsigned) ) + - (via_node_list_size * sizeof(NodeID) ) + - (graph_node_list_size * sizeof(QueryGraph::NodeArrayEntry) ) + - (graph_edge_list_size * sizeof(QueryGraph::EdgeArrayEntry) ) + - (timestamp_length * sizeof(char) ) + - (coordinate_list_size * sizeof(FixedPointCoordinate) ) + + (name_index_list_size * sizeof(unsigned)) + (name_char_list_size * sizeof(char)) + + (name_id_list_size * sizeof(unsigned)) + (via_node_list_size * sizeof(NodeID)) + + (graph_node_list_size * sizeof(QueryGraph::NodeArrayEntry)) + + (graph_edge_list_size * sizeof(QueryGraph::EdgeArrayEntry)) + + (timestamp_length * sizeof(char)) + + (coordinate_list_size * sizeof(FixedPointCoordinate)) + (turn_instruction_list_size * sizeof(TurnInstructionsClass)) + - (r_search_tree_size * sizeof(RTreeNode) ); + (r_search_tree_size * sizeof(RTreeNode)); return result; } uint64_t GetGeometriesIndexListOffset() const - { uint64_t result = - (name_index_list_size * sizeof(unsigned) ) + - (name_char_list_size * sizeof(char) ) + - (name_id_list_size * sizeof(unsigned) ) + - (via_node_list_size * sizeof(NodeID) ) + - (graph_node_list_size * sizeof(QueryGraph::NodeArrayEntry) ) + - (graph_edge_list_size * sizeof(QueryGraph::EdgeArrayEntry) ) + - (timestamp_length * sizeof(char) ) + - (coordinate_list_size * sizeof(FixedPointCoordinate) ) + + { + uint64_t result = + (name_index_list_size * sizeof(unsigned)) + (name_char_list_size * sizeof(char)) + + (name_id_list_size * sizeof(unsigned)) + (via_node_list_size * sizeof(NodeID)) + + (graph_node_list_size * sizeof(QueryGraph::NodeArrayEntry)) + + (graph_edge_list_size * sizeof(QueryGraph::EdgeArrayEntry)) + + (timestamp_length * sizeof(char)) + + (coordinate_list_size * sizeof(FixedPointCoordinate)) + (turn_instruction_list_size * sizeof(TurnInstructionsClass)) + - (r_search_tree_size * sizeof(RTreeNode) ) + - (geometries_indicators/32 + 1) * sizeof(unsigned); + (r_search_tree_size * sizeof(RTreeNode)) + + (geometries_indicators / 32 + 1) * sizeof(unsigned); return result; } - uint64_t GetGeometryListOffset() const { + uint64_t GetGeometryListOffset() const + { uint64_t result = - (name_index_list_size * sizeof(unsigned) ) + - (name_char_list_size * sizeof(char) ) + - (name_id_list_size * sizeof(unsigned) ) + - (via_node_list_size * sizeof(NodeID) ) + - (graph_node_list_size * sizeof(QueryGraph::NodeArrayEntry) ) + - (graph_edge_list_size * sizeof(QueryGraph::EdgeArrayEntry) ) + - (timestamp_length * sizeof(char) ) + - (coordinate_list_size * sizeof(FixedPointCoordinate) ) + + (name_index_list_size * sizeof(unsigned)) + (name_char_list_size * sizeof(char)) + + (name_id_list_size * sizeof(unsigned)) + (via_node_list_size * sizeof(NodeID)) + + (graph_node_list_size * sizeof(QueryGraph::NodeArrayEntry)) + + (graph_edge_list_size * sizeof(QueryGraph::EdgeArrayEntry)) + + (timestamp_length * sizeof(char)) + + (coordinate_list_size * sizeof(FixedPointCoordinate)) + (turn_instruction_list_size * sizeof(TurnInstructionsClass)) + - (r_search_tree_size * sizeof(RTreeNode) ) + - (geometries_indicators/32 + 1) * sizeof(unsigned) + - (geometries_index_list_size * sizeof(unsigned) ); + (r_search_tree_size * sizeof(RTreeNode)) + + (geometries_indicators / 32 + 1) * sizeof(unsigned) + + (geometries_index_list_size * sizeof(unsigned)); return result; } - uint64_t GetChecksumOffset() const { + uint64_t GetChecksumOffset() const + { uint64_t result = - (name_index_list_size * sizeof(unsigned) ) + - (name_char_list_size * sizeof(char) ) + - (name_id_list_size * sizeof(unsigned) ) + - (via_node_list_size * sizeof(NodeID) ) + - (graph_node_list_size * sizeof(QueryGraph::NodeArrayEntry) ) + - (graph_edge_list_size * sizeof(QueryGraph::EdgeArrayEntry) ) + - (timestamp_length * sizeof(char) ) + - (coordinate_list_size * sizeof(FixedPointCoordinate) ) + + (name_index_list_size * sizeof(unsigned)) + (name_char_list_size * sizeof(char)) + + (name_id_list_size * sizeof(unsigned)) + (via_node_list_size * sizeof(NodeID)) + + (graph_node_list_size * sizeof(QueryGraph::NodeArrayEntry)) + + (graph_edge_list_size * sizeof(QueryGraph::EdgeArrayEntry)) + + (timestamp_length * sizeof(char)) + + (coordinate_list_size * sizeof(FixedPointCoordinate)) + (turn_instruction_list_size * sizeof(TurnInstructionsClass)) + - (r_search_tree_size * sizeof(RTreeNode) ) + - (geometries_indicators/32 + 1) * sizeof(unsigned) + - (geometries_index_list_size * sizeof(unsigned) ) + - (geometries_list_size * sizeof(unsigned) ); + (r_search_tree_size * sizeof(RTreeNode)) + + (geometries_indicators / 32 + 1) * sizeof(unsigned) + + (geometries_index_list_size * sizeof(unsigned)) + + (geometries_list_size * sizeof(unsigned)); return result; } }; -enum SharedDataType { - CURRENT_REGIONS, - LAYOUT_1, - DATA_1, - LAYOUT_2, - DATA_2, - LAYOUT_NONE, - DATA_NONE -}; +enum SharedDataType +{ CURRENT_REGIONS, + LAYOUT_1, + DATA_1, + LAYOUT_2, + DATA_2, + LAYOUT_NONE, + DATA_NONE }; -struct SharedDataTimestamp { +struct SharedDataTimestamp +{ SharedDataType layout; SharedDataType data; unsigned timestamp;