Refactor loading code for timestamp file

This commit is contained in:
Huyen Chau Nguyen
2016-10-18 11:21:41 -07:00
parent ab1a9271c8
commit 316ef305de
3 changed files with 31 additions and 11 deletions
@@ -13,6 +13,7 @@
#include "extractor/original_edge_data.hpp"
#include "extractor/profile_properties.hpp"
#include "extractor/query_node.hpp"
#include "storage/io.hpp"
#include "storage/storage_config.hpp"
#include "storage/io.hpp"
#include "engine/geospatial_query.hpp"
@@ -71,7 +72,6 @@ class InternalDataFacade final : public BaseDataFacade
InternalDataFacade() {}
unsigned m_check_sum;
unsigned m_number_of_nodes;
std::unique_ptr<QueryGraph> m_query_graph;
std::string m_timestamp;
@@ -141,12 +141,17 @@ class InternalDataFacade final : public BaseDataFacade
void LoadTimestamp(const boost::filesystem::path &timestamp_path)
{
util::SimpleLogger().Write() << "Loading Timestamp";
boost::filesystem::ifstream timestamp_stream(timestamp_path);
if (!timestamp_stream)
{
throw util::exception("Could not open " + timestamp_path.string() + " for reading.");
}
getline(timestamp_stream, m_timestamp);
auto timestamp_size = storage::io::readTimestampSize(timestamp_stream);
char *timestamp_ptr = new char[timestamp_size]();
storage::io::readTimestamp(timestamp_stream, timestamp_ptr, timestamp_size);
m_timestamp = std::string(timestamp_ptr);
}
void LoadGraph(const boost::filesystem::path &hsgr_path)
+16 -2
View File
@@ -48,8 +48,7 @@ inline HSGRHeader readHSGRHeader(boost::filesystem::ifstream &input_stream)
return header;
}
// Needs to be called after getHSGRSize() to get the correct offset in the stream
//
// Needs to be called after HSGRHeader() to get the correct offset in the stream
template <typename NodeT, typename EdgeT>
void readHSGR(boost::filesystem::ifstream &input_stream,
NodeT *node_buffer,
@@ -61,6 +60,21 @@ void readHSGR(boost::filesystem::ifstream &input_stream,
input_stream.read(reinterpret_cast<char *>(edge_buffer), number_of_edges * sizeof(EdgeT));
}
// Returns the size of the timestamp in a file
inline std::uint32_t readTimestampSize(boost::filesystem::ifstream &timestamp_input_stream)
{
timestamp_input_stream.seekg (0, timestamp_input_stream.end);
auto length = timestamp_input_stream.tellg();
timestamp_input_stream.seekg (0, timestamp_input_stream.beg);
return length;
}
// Reads the timestamp in a file
inline void readTimestamp(boost::filesystem::ifstream &timestamp_input_stream, char *timestamp, std::size_t timestamp_length)
{
timestamp_input_stream.read(timestamp, timestamp_length * sizeof(char));
}
}
}
}