RAII for auto-closing file streams

Small fixes I didn't want to include in unrelated PRs.

There are a few left in `storage.cpp` but since it's a single function
in 600 lines of code, I didn't want to touch the mess. The others are
safe to remove, cucumber and test run on Finland gives 👍.
This commit is contained in:
Daniel J. Hofmann
2016-03-07 15:25:47 +01:00
parent ae4161b780
commit ac0279aa83
13 changed files with 5 additions and 40 deletions
-1
View File
@@ -45,7 +45,6 @@ FixedPointCoordinateListPtr loadCoordinates(const boost::filesystem::path &nodes
BOOST_ASSERT((std::abs(coords->at(i).lat) >> 30) == 0);
BOOST_ASSERT((std::abs(coords->at(i).lon) >> 30) == 0);
}
nodes_input_stream.close();
return coords;
}
-6
View File
@@ -212,7 +212,6 @@ std::size_t Contractor::LoadEdgeExpandedGraph(
// Load all the query nodes into a vector
nodes_input_stream.read(reinterpret_cast<char *>(&(internal_to_external_node_map[0])), number_of_nodes * sizeof(extractor::QueryNode));
nodes_input_stream.close();
}
std::vector<unsigned> m_geometry_indices;
@@ -246,7 +245,6 @@ std::size_t Contractor::LoadEdgeExpandedGraph(
geometry_stream.read((char *)&(m_geometry_list[0]),
number_of_compressed_geometries * sizeof(extractor::CompressedEdgeContainer::CompressedEdge));
}
geometry_stream.close();
}
// Now, we iterate over all the segments stored in the StaticRTree, updating
@@ -256,7 +254,6 @@ std::size_t Contractor::LoadEdgeExpandedGraph(
using LeafNode = util::StaticRTree<extractor::EdgeBasedNode>::LeafNode;
// Open file for reading *and* writing
std::ifstream leaf_node_file(rtree_leaf_filename, std::ios::binary | std::ios::in);
if (!leaf_node_file)
{
@@ -336,8 +333,6 @@ std::size_t Contractor::LoadEdgeExpandedGraph(
m_element_count -= current_node.object_count;
}
leaf_node_file.close();
}
// Now save out the updated compressed geometries
@@ -353,7 +348,6 @@ std::size_t Contractor::LoadEdgeExpandedGraph(
geometry_stream.write(reinterpret_cast<char *>(&(m_geometry_indices[0])), number_of_indices * sizeof(unsigned));
geometry_stream.write(reinterpret_cast<const char *>(&number_of_compressed_geometries), sizeof(unsigned));
geometry_stream.write(reinterpret_cast<char *>(&(m_geometry_list[0])), number_of_compressed_geometries * sizeof(extractor::CompressedEdgeContainer::CompressedEdge));
geometry_stream.close();
}
@@ -84,8 +84,6 @@ void CompressedEdgeContainer::SerializeInternalVector(const std::string &path) c
}
}
BOOST_ASSERT(control_sum == prefix_sum_of_list_indices);
// all done, let's close the resource
geometry_out_stream.close();
}
// Adds info for a compressed edge to the container. edge_id_2
@@ -476,7 +476,6 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
edge_data_file.seekp(std::ios::beg);
edge_data_file.write((char *)&original_edges_counter, sizeof(unsigned));
edge_data_file.close();
util::SimpleLogger().Write() << "Generated " << m_edge_based_node_list.size()
<< " edge based nodes";
-4
View File
@@ -90,8 +90,6 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name,
PrepareEdges(segment_state);
WriteEdges(file_out_stream);
file_out_stream.close();
PrepareRestrictions();
WriteRestrictions(restrictions_file_name);
@@ -139,7 +137,6 @@ void ExtractionContainers::WriteNames(const std::string &names_file_name) const
name_file_stream.write(write_buffer, buffer_len);
name_file_stream.close();
TIMER_STOP(write_name_index);
std::cout << "ok, after " << TIMER_SEC(write_name_index) << "s" << std::endl;
}
@@ -586,7 +583,6 @@ void ExtractionContainers::WriteRestrictions(const std::string &path) const
}
restrictions_out_stream.seekp(count_position);
restrictions_out_stream.write((char *)&written_restriction_count, sizeof(unsigned));
restrictions_out_stream.close();
util::SimpleLogger().Write() << "usable restrictions: " << written_restriction_count;
}
-3
View File
@@ -134,7 +134,6 @@ int Extractor::run()
boost::filesystem::ofstream timestamp_out(config.timestamp_file_name);
timestamp_out.write(timestamp.c_str(), timestamp.length());
timestamp_out.close();
// initialize vectors holding parsed objects
tbb::concurrent_vector<std::pair<std::size_t, ExtractionNode>> resulting_nodes;
@@ -558,7 +557,6 @@ void Extractor::WriteNodeMapping(const std::vector<QueryNode> &internal_to_exter
node_stream.write((char *)internal_to_external_node_map.data(),
size_of_mapping * sizeof(QueryNode));
}
node_stream.close();
}
/**
@@ -630,7 +628,6 @@ void Extractor::WriteEdgeBasedGraph(
util::SimpleLogger().Write() << "ok, after " << TIMER_SEC(write_edges) << "s" << std::endl;
util::SimpleLogger().Write() << "Processed " << number_of_used_edges << " edges";
file_out_stream.close();
}
}
}
-1
View File
@@ -288,7 +288,6 @@ int Storage::Run()
else
{
getline(timestamp_stream, m_timestamp);
timestamp_stream.close();
}
}
if (m_timestamp.empty())
-2
View File
@@ -233,7 +233,6 @@ int main(int argc, char *argv[]) try
{
random_csv << i << ", " << timing_results_raw_random[i] << std::endl;
}
random_csv.close();
osrm::tools::runStatistics(timing_results_raw_random, stats);
osrm::util::SimpleLogger().Write() << "raw random I/O: " << std::setprecision(5)
@@ -305,7 +304,6 @@ int main(int argc, char *argv[]) try
{
seq_csv << i << ", " << timing_results_raw_seq[i] << std::endl;
}
seq_csv.close();
osrm::tools::runStatistics(timing_results_raw_seq, stats);
osrm::util::SimpleLogger().Write() << "raw sequential I/O: " << std::setprecision(5)
<< std::fixed << "min: " << stats.min << "ms, "