refactor loading code of .datasource_indexes and .datasource_names files and move to io.hpp
This commit is contained in:
@@ -292,14 +292,12 @@ class InternalDataFacade final : public BaseDataFacade
|
||||
}
|
||||
BOOST_ASSERT(datasources_stream);
|
||||
|
||||
std::uint64_t number_of_datasources = 0;
|
||||
datasources_stream.read(reinterpret_cast<char *>(&number_of_datasources),
|
||||
sizeof(number_of_datasources));
|
||||
auto number_of_datasources = storage::io::readDatasourceIndexesSize(datasources_stream);
|
||||
if (number_of_datasources > 0)
|
||||
{
|
||||
m_datasource_list.resize(number_of_datasources);
|
||||
datasources_stream.read(reinterpret_cast<char *>(&(m_datasource_list[0])),
|
||||
number_of_datasources * sizeof(uint8_t));
|
||||
storage::io::readDatasourceIndexes(
|
||||
datasources_stream, &m_datasource_list.front(), number_of_datasources);
|
||||
}
|
||||
|
||||
boost::filesystem::ifstream datasourcenames_stream(datasource_names_file, std::ios::binary);
|
||||
@@ -309,10 +307,16 @@ class InternalDataFacade final : public BaseDataFacade
|
||||
" for reading!");
|
||||
}
|
||||
BOOST_ASSERT(datasourcenames_stream);
|
||||
std::string name;
|
||||
while (std::getline(datasourcenames_stream, name))
|
||||
|
||||
auto datasource_names_data = storage::io::readDatasourceNamesData(datasourcenames_stream);
|
||||
m_datasource_names.resize(datasource_names_data.lengths.size());
|
||||
for (std::uint32_t i = 0; i < datasource_names_data.lengths.size(); ++i)
|
||||
{
|
||||
m_datasource_names.push_back(std::move(name));
|
||||
auto name_begin =
|
||||
datasource_names_data.names.begin() + datasource_names_data.offsets[i];
|
||||
auto name_end = datasource_names_data.names.begin() + datasource_names_data.offsets[i] +
|
||||
datasource_names_data.lengths[i];
|
||||
m_datasource_names[i] = std::move(std::string(name_begin, name_end));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -98,6 +98,7 @@ inline std::uint32_t readEdgesSize(boost::filesystem::ifstream &edges_input_stre
|
||||
|
||||
// Reads edge data from .edge files which includes its
|
||||
// geometry, name ID, turn instruction, lane data ID, travel mode, entry class ID
|
||||
// Needs to be called after readEdgesSize() to get the correct offset in the stream
|
||||
template <typename GeometryIDT,
|
||||
typename NameIDT,
|
||||
typename TurnInstructionT,
|
||||
@@ -141,6 +142,7 @@ inline std::uint32_t readNodesSize(boost::filesystem::ifstream &nodes_input_stre
|
||||
}
|
||||
|
||||
// Reads coordinates and OSM node IDs from .nodes files
|
||||
// Needs to be called after readNodesSize() to get the correct offset in the stream
|
||||
template <typename CoordinateT, typename OSMNodeIDVectorT>
|
||||
void readNodesData(boost::filesystem::ifstream &nodes_input_stream,
|
||||
CoordinateT coordinate_list[],
|
||||
@@ -156,6 +158,55 @@ void readNodesData(boost::filesystem::ifstream &nodes_input_stream,
|
||||
BOOST_ASSERT(coordinate_list[i].IsValid());
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the number of indexes in a .datasource_indexes file
|
||||
// TODO: The original code used uint_64t to store the number of indexes. Can someone confirm that
|
||||
// this makes sense?
|
||||
inline std::uint64_t
|
||||
readDatasourceIndexesSize(boost::filesystem::ifstream &datasource_indexes_input_stream)
|
||||
{
|
||||
std::uint64_t number_of_datasource_indexes;
|
||||
datasource_indexes_input_stream.read(reinterpret_cast<char *>(&number_of_datasource_indexes),
|
||||
sizeof(std::uint64_t));
|
||||
return number_of_datasource_indexes;
|
||||
}
|
||||
|
||||
// Reads datasource_indexes
|
||||
// Needs to be called after readDatasourceIndexesSize() to get the correct offset in the stream
|
||||
inline void readDatasourceIndexes(boost::filesystem::ifstream &datasource_indexes_input_stream,
|
||||
uint8_t datasource_buffer[],
|
||||
std::uint32_t number_of_datasource_indexes)
|
||||
{
|
||||
datasource_indexes_input_stream.read(reinterpret_cast<char *>(datasource_buffer),
|
||||
number_of_datasource_indexes * sizeof(std::uint8_t));
|
||||
}
|
||||
|
||||
// Reads datasource names out of .datasource_names files and metadata such as
|
||||
// the length and offset of each name
|
||||
struct DatasourceNamesData
|
||||
{
|
||||
std::vector<char> names;
|
||||
std::vector<std::uint32_t> offsets;
|
||||
std::vector<std::uint32_t> lengths;
|
||||
};
|
||||
inline DatasourceNamesData
|
||||
readDatasourceNamesData(boost::filesystem::ifstream &datasource_names_input_stream)
|
||||
{
|
||||
DatasourceNamesData datasource_names_data;
|
||||
if (datasource_names_input_stream)
|
||||
{
|
||||
std::string name;
|
||||
while (std::getline(datasource_names_input_stream, name))
|
||||
{
|
||||
datasource_names_data.offsets.push_back(datasource_names_data.names.size());
|
||||
datasource_names_data.lengths.push_back(name.size());
|
||||
std::copy(name.c_str(),
|
||||
name.c_str() + name.size(),
|
||||
std::back_inserter(datasource_names_data.names));
|
||||
}
|
||||
}
|
||||
return datasource_names_data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user