Apply clang-format on Contractor/

This commit is contained in:
Patrick Niklaus 2014-05-08 23:07:16 +02:00
parent 79d33d669c
commit d13cd4d4b3
7 changed files with 968 additions and 835 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -58,94 +58,76 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <queue> #include <queue>
#include <vector> #include <vector>
class EdgeBasedGraphFactory : boost::noncopyable { class EdgeBasedGraphFactory : boost::noncopyable
public: {
public:
struct SpeedProfileProperties; struct SpeedProfileProperties;
explicit EdgeBasedGraphFactory( explicit EdgeBasedGraphFactory(const boost::shared_ptr<NodeBasedDynamicGraph> &node_based_graph,
const boost::shared_ptr<NodeBasedDynamicGraph>& node_based_graph, std::unique_ptr<RestrictionMap> restricion_map,
std::unique_ptr<RestrictionMap> restricion_map, std::vector<NodeID> &barrier_node_list,
std::vector<NodeID> & barrier_node_list, std::vector<NodeID> &traffic_light_node_list,
std::vector<NodeID> & traffic_light_node_list, std::vector<NodeInfo> &m_node_info_list,
std::vector<NodeInfo> & m_node_info_list, SpeedProfileProperties &speed_profile);
SpeedProfileProperties & speed_profile
);
void Run( void Run(const std::string &original_edge_data_filename,
const std::string & original_edge_data_filename, const std::string &geometry_filename,
const std::string & geometry_filename, lua_State *myLuaState);
lua_State *myLuaState
);
void GetEdgeBasedEdges( DeallocatingVector< EdgeBasedEdge >& edges ); void GetEdgeBasedEdges(DeallocatingVector<EdgeBasedEdge> &edges);
void GetEdgeBasedNodes( std::vector< EdgeBasedNode> & nodes); void GetEdgeBasedNodes(std::vector<EdgeBasedNode> &nodes);
TurnInstruction AnalyzeTurn( TurnInstruction AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w) const;
const NodeID u,
const NodeID v,
const NodeID w
) const;
int GetTurnPenalty( int GetTurnPenalty(const NodeID u, const NodeID v, const NodeID w, lua_State *myLuaState) const;
const NodeID u,
const NodeID v,
const NodeID w,
lua_State *myLuaState
) const;
unsigned GetNumberOfEdgeBasedNodes() const; unsigned GetNumberOfEdgeBasedNodes() const;
struct SpeedProfileProperties{ struct SpeedProfileProperties
SpeedProfileProperties() : {
trafficSignalPenalty(0), SpeedProfileProperties()
uTurnPenalty(0), : trafficSignalPenalty(0), uTurnPenalty(0), has_turn_penalty_function(false)
has_turn_penalty_function(false) {
{ } }
int trafficSignalPenalty; int trafficSignalPenalty;
int uTurnPenalty; int uTurnPenalty;
bool has_turn_penalty_function; bool has_turn_penalty_function;
} speed_profile; } speed_profile;
private: private:
typedef NodeBasedDynamicGraph::NodeIterator NodeIterator; typedef NodeBasedDynamicGraph::NodeIterator NodeIterator;
typedef NodeBasedDynamicGraph::EdgeIterator EdgeIterator; typedef NodeBasedDynamicGraph::EdgeIterator EdgeIterator;
typedef NodeBasedDynamicGraph::EdgeData EdgeData; typedef NodeBasedDynamicGraph::EdgeData EdgeData;
unsigned m_number_of_edge_based_nodes; unsigned m_number_of_edge_based_nodes;
std::vector<NodeInfo> m_node_info_list; std::vector<NodeInfo> m_node_info_list;
std::vector<EdgeBasedNode> m_edge_based_node_list; std::vector<EdgeBasedNode> m_edge_based_node_list;
DeallocatingVector<EdgeBasedEdge> m_edge_based_edge_list; DeallocatingVector<EdgeBasedEdge> m_edge_based_edge_list;
boost::shared_ptr<NodeBasedDynamicGraph> m_node_based_graph; boost::shared_ptr<NodeBasedDynamicGraph> m_node_based_graph;
boost::unordered_set<NodeID> m_barrier_nodes; boost::unordered_set<NodeID> m_barrier_nodes;
boost::unordered_set<NodeID> m_traffic_lights; boost::unordered_set<NodeID> m_traffic_lights;
std::unique_ptr<RestrictionMap> m_restriction_map; std::unique_ptr<RestrictionMap> m_restriction_map;
GeometryCompressor m_geometry_compressor; GeometryCompressor m_geometry_compressor;
void CompressGeometry(); void CompressGeometry();
void RenumberEdges(); void RenumberEdges();
void GenerateEdgeExpandedNodes(); void GenerateEdgeExpandedNodes();
void GenerateEdgeExpandedEdges( void GenerateEdgeExpandedEdges(const std::string &original_edge_data_filename,
const std::string& original_edge_data_filename, lua_State *lua_state);
lua_State* lua_state
);
void InsertEdgeBasedNode( void InsertEdgeBasedNode(NodeBasedDynamicGraph::NodeIterator u,
NodeBasedDynamicGraph::NodeIterator u, NodeBasedDynamicGraph::NodeIterator v,
NodeBasedDynamicGraph::NodeIterator v, NodeBasedDynamicGraph::EdgeIterator e1,
NodeBasedDynamicGraph::EdgeIterator e1, bool belongsToTinyComponent);
bool belongsToTinyComponent
);
void FlushVectorToStream( void FlushVectorToStream(std::ofstream &edge_data_file,
std::ofstream & edge_data_file, std::vector<OriginalEdgeData> &original_edge_data_vector) const;
std::vector<OriginalEdgeData> & original_edge_data_vector
) const;
unsigned max_id; unsigned max_id;
}; };

View File

@ -70,14 +70,14 @@ unsigned GeometryCompressor::GetPositionForID(const EdgeID edge_id) const
void GeometryCompressor::SerializeInternalVector(const std::string &path) const void GeometryCompressor::SerializeInternalVector(const std::string &path) const
{ {
boost::filesystem::fstream geometry_out_stream(path, std::ios::binary|std::ios::out); boost::filesystem::fstream geometry_out_stream(path, std::ios::binary | std::ios::out);
const unsigned number_of_compressed_geometries = m_compressed_geometries.size() + 1; const unsigned number_of_compressed_geometries = m_compressed_geometries.size() + 1;
BOOST_ASSERT(UINT_MAX != number_of_compressed_geometries); BOOST_ASSERT(UINT_MAX != number_of_compressed_geometries);
geometry_out_stream.write((char *)&number_of_compressed_geometries, sizeof(unsigned)); geometry_out_stream.write((char *)&number_of_compressed_geometries, sizeof(unsigned));
// write indices array // write indices array
unsigned prefix_sum_of_list_indices = 0; unsigned prefix_sum_of_list_indices = 0;
for (auto & elem : m_compressed_geometries) for (auto &elem : m_compressed_geometries)
{ {
geometry_out_stream.write((char *)&prefix_sum_of_list_indices, sizeof(unsigned)); geometry_out_stream.write((char *)&prefix_sum_of_list_indices, sizeof(unsigned));
@ -94,7 +94,7 @@ void GeometryCompressor::SerializeInternalVector(const std::string &path) const
unsigned control_sum = 0; unsigned control_sum = 0;
// write compressed geometries // write compressed geometries
for (auto & elem : m_compressed_geometries) for (auto &elem : m_compressed_geometries)
{ {
const std::vector<CompressedNode> &current_vector = elem; const std::vector<CompressedNode> &current_vector = elem;
const unsigned unpacked_size = current_vector.size(); const unsigned unpacked_size = current_vector.size();
@ -146,7 +146,8 @@ void GeometryCompressor::CompressEdge(const EdgeID edge_id_1,
m_free_list.pop_back(); m_free_list.pop_back();
} }
const boost::unordered_map<EdgeID, unsigned>::const_iterator iter = m_edge_id_to_list_index_map.find(edge_id_1); const boost::unordered_map<EdgeID, unsigned>::const_iterator iter =
m_edge_id_to_list_index_map.find(edge_id_1);
BOOST_ASSERT(iter != m_edge_id_to_list_index_map.end()); BOOST_ASSERT(iter != m_edge_id_to_list_index_map.end());
const unsigned edge_bucket_id1 = iter->second; const unsigned edge_bucket_id1 = iter->second;
BOOST_ASSERT(edge_bucket_id1 == GetPositionForID(edge_id_1)); BOOST_ASSERT(edge_bucket_id1 == GetPositionForID(edge_id_1));

View File

@ -56,7 +56,7 @@ class GeometryCompressor
private: private:
void IncreaseFreeList(); void IncreaseFreeList();
std::vector<std::vector<CompressedNode> > m_compressed_geometries; std::vector<std::vector<CompressedNode>> m_compressed_geometries;
std::vector<unsigned> m_free_list; std::vector<unsigned> m_free_list;
boost::unordered_map<EdgeID, unsigned> m_edge_id_to_list_index_map; boost::unordered_map<EdgeID, unsigned> m_edge_id_to_list_index_map;
}; };

View File

@ -27,136 +27,154 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "TemporaryStorage.h" #include "TemporaryStorage.h"
TemporaryStorage::TemporaryStorage() { TemporaryStorage::TemporaryStorage() { temp_directory = boost::filesystem::temp_directory_path(); }
temp_directory = boost::filesystem::temp_directory_path();
}
TemporaryStorage & TemporaryStorage::GetInstance(){ TemporaryStorage &TemporaryStorage::GetInstance()
{
static TemporaryStorage static_instance; static TemporaryStorage static_instance;
return static_instance; return static_instance;
} }
TemporaryStorage::~TemporaryStorage() { TemporaryStorage::~TemporaryStorage() { RemoveAll(); }
RemoveAll();
}
void TemporaryStorage::RemoveAll() { void TemporaryStorage::RemoveAll()
{
boost::mutex::scoped_lock lock(mutex); boost::mutex::scoped_lock lock(mutex);
for(unsigned slot_id = 0; slot_id < stream_data_list.size(); ++slot_id) { for (unsigned slot_id = 0; slot_id < stream_data_list.size(); ++slot_id)
{
DeallocateSlot(slot_id); DeallocateSlot(slot_id);
} }
stream_data_list.clear(); stream_data_list.clear();
} }
int TemporaryStorage::AllocateSlot() { int TemporaryStorage::AllocateSlot()
{
boost::mutex::scoped_lock lock(mutex); boost::mutex::scoped_lock lock(mutex);
try { try
{
stream_data_list.push_back(StreamData()); stream_data_list.push_back(StreamData());
} catch(boost::filesystem::filesystem_error & e) { }
catch (boost::filesystem::filesystem_error &e)
{
Abort(e); Abort(e);
} }
CheckIfTemporaryDeviceFull(); CheckIfTemporaryDeviceFull();
return stream_data_list.size() - 1; return stream_data_list.size() - 1;
} }
void TemporaryStorage::DeallocateSlot(const int slot_id) { void TemporaryStorage::DeallocateSlot(const int slot_id)
try { {
StreamData & data = stream_data_list[slot_id]; try
{
StreamData &data = stream_data_list[slot_id];
boost::mutex::scoped_lock lock(*data.readWriteMutex); boost::mutex::scoped_lock lock(*data.readWriteMutex);
if(!boost::filesystem::exists(data.temp_path)) { if (!boost::filesystem::exists(data.temp_path))
{
return; return;
} }
if(data.temp_file->is_open()) { if (data.temp_file->is_open())
{
data.temp_file->close(); data.temp_file->close();
} }
boost::filesystem::remove(data.temp_path); boost::filesystem::remove(data.temp_path);
} catch(boost::filesystem::filesystem_error & e) { }
catch (boost::filesystem::filesystem_error &e)
{
Abort(e); Abort(e);
} }
} }
void TemporaryStorage::WriteToSlot( void TemporaryStorage::WriteToSlot(const int slot_id, char *pointer, const std::size_t size)
const int slot_id, {
char * pointer, try
const std::size_t size {
) { StreamData &data = stream_data_list[slot_id];
try {
StreamData & data = stream_data_list[slot_id];
BOOST_ASSERT(data.write_mode); BOOST_ASSERT(data.write_mode);
boost::mutex::scoped_lock lock(*data.readWriteMutex); boost::mutex::scoped_lock lock(*data.readWriteMutex);
BOOST_ASSERT_MSG( BOOST_ASSERT_MSG(data.write_mode, "Writing after first read is not allowed");
data.write_mode, if (1073741824 < data.buffer.size())
"Writing after first read is not allowed" {
);
if( 1073741824 < data.buffer.size() ) {
data.temp_file->write(&data.buffer[0], data.buffer.size()); data.temp_file->write(&data.buffer[0], data.buffer.size());
// data.temp_file->write(pointer, size); // data.temp_file->write(pointer, size);
data.buffer.clear(); data.buffer.clear();
CheckIfTemporaryDeviceFull(); CheckIfTemporaryDeviceFull();
} }
data.buffer.insert(data.buffer.end(), pointer, pointer+size); data.buffer.insert(data.buffer.end(), pointer, pointer + size);
}
} catch(boost::filesystem::filesystem_error & e) { catch (boost::filesystem::filesystem_error &e)
{
Abort(e); Abort(e);
} }
} }
void TemporaryStorage::ReadFromSlot( void TemporaryStorage::ReadFromSlot(const int slot_id, char *pointer, const std::size_t size)
const int slot_id, {
char * pointer, try
const std::size_t size {
) { StreamData &data = stream_data_list[slot_id];
try {
StreamData & data = stream_data_list[slot_id];
boost::mutex::scoped_lock lock(*data.readWriteMutex); boost::mutex::scoped_lock lock(*data.readWriteMutex);
if( data.write_mode ) { if (data.write_mode)
{
data.write_mode = false; data.write_mode = false;
data.temp_file->write(&data.buffer[0], data.buffer.size()); data.temp_file->write(&data.buffer[0], data.buffer.size());
data.buffer.clear(); data.buffer.clear();
data.temp_file->seekg( data.temp_file->beg ); data.temp_file->seekg(data.temp_file->beg);
BOOST_ASSERT( data.temp_file->beg == data.temp_file->tellg() ); BOOST_ASSERT(data.temp_file->beg == data.temp_file->tellg());
} }
BOOST_ASSERT( !data.write_mode ); BOOST_ASSERT(!data.write_mode);
data.temp_file->read(pointer, size); data.temp_file->read(pointer, size);
} catch(boost::filesystem::filesystem_error & e) { }
catch (boost::filesystem::filesystem_error &e)
{
Abort(e); Abort(e);
} }
} }
uint64_t TemporaryStorage::GetFreeBytesOnTemporaryDevice() { uint64_t TemporaryStorage::GetFreeBytesOnTemporaryDevice()
{
uint64_t value = -1; uint64_t value = -1;
try { try
boost::filesystem::path p = boost::filesystem::temp_directory_path(); {
boost::filesystem::space_info s = boost::filesystem::space( p ); boost::filesystem::path p = boost::filesystem::temp_directory_path();
boost::filesystem::space_info s = boost::filesystem::space(p);
value = s.free; value = s.free;
} catch(boost::filesystem::filesystem_error & e) { }
catch (boost::filesystem::filesystem_error &e)
{
Abort(e); Abort(e);
} }
return value; return value;
} }
void TemporaryStorage::CheckIfTemporaryDeviceFull() { void TemporaryStorage::CheckIfTemporaryDeviceFull()
{
boost::filesystem::path p = boost::filesystem::temp_directory_path(); boost::filesystem::path p = boost::filesystem::temp_directory_path();
boost::filesystem::space_info s = boost::filesystem::space( p ); boost::filesystem::space_info s = boost::filesystem::space(p);
if( (1024*1024) > s.free ) { if ((1024 * 1024) > s.free)
{
throw OSRMException("temporary device is full"); throw OSRMException("temporary device is full");
} }
} }
boost::filesystem::fstream::pos_type TemporaryStorage::Tell(const int slot_id) { boost::filesystem::fstream::pos_type TemporaryStorage::Tell(const int slot_id)
{
boost::filesystem::fstream::pos_type position; boost::filesystem::fstream::pos_type position;
try { try
StreamData & data = stream_data_list[slot_id]; {
StreamData &data = stream_data_list[slot_id];
boost::mutex::scoped_lock lock(*data.readWriteMutex); boost::mutex::scoped_lock lock(*data.readWriteMutex);
position = data.temp_file->tellp(); position = data.temp_file->tellp();
} catch(boost::filesystem::filesystem_error & e) { }
catch (boost::filesystem::filesystem_error &e)
{
Abort(e); Abort(e);
} }
return position; return position;
} }
void TemporaryStorage::Abort(const boost::filesystem::filesystem_error& e) { void TemporaryStorage::Abort(const boost::filesystem::filesystem_error &e)
{
RemoveAll(); RemoveAll();
throw OSRMException(e.what()); throw OSRMException(e.what());
} }

View File

@ -56,61 +56,52 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
static boost::filesystem::path temp_directory; static boost::filesystem::path temp_directory;
static std::string TemporaryFilePattern("OSRM-%%%%-%%%%-%%%%"); static std::string TemporaryFilePattern("OSRM-%%%%-%%%%-%%%%");
class TemporaryStorage { class TemporaryStorage
public: {
static TemporaryStorage & GetInstance(); public:
static TemporaryStorage &GetInstance();
virtual ~TemporaryStorage(); virtual ~TemporaryStorage();
int AllocateSlot(); int AllocateSlot();
void DeallocateSlot(const int slot_id); void DeallocateSlot(const int slot_id);
void WriteToSlot(const int slot_id, char * pointer, const std::size_t size); void WriteToSlot(const int slot_id, char *pointer, const std::size_t size);
void ReadFromSlot(const int slot_id, char * pointer, const std::size_t size); void ReadFromSlot(const int slot_id, char *pointer, const std::size_t size);
//returns the number of free bytes // returns the number of free bytes
uint64_t GetFreeBytesOnTemporaryDevice(); uint64_t GetFreeBytesOnTemporaryDevice();
boost::filesystem::fstream::pos_type Tell(const int slot_id); boost::filesystem::fstream::pos_type Tell(const int slot_id);
void RemoveAll(); void RemoveAll();
private:
private:
TemporaryStorage(); TemporaryStorage();
TemporaryStorage(TemporaryStorage const &){}; TemporaryStorage(TemporaryStorage const &) {};
TemporaryStorage & operator=(TemporaryStorage const &) { TemporaryStorage &operator=(TemporaryStorage const &) { return *this; }
return *this;
}
void Abort(const boost::filesystem::filesystem_error& e); void Abort(const boost::filesystem::filesystem_error &e);
void CheckIfTemporaryDeviceFull(); void CheckIfTemporaryDeviceFull();
struct StreamData { struct StreamData
{
bool write_mode; bool write_mode;
boost::filesystem::path temp_path; boost::filesystem::path temp_path;
boost::shared_ptr<boost::filesystem::fstream> temp_file; boost::shared_ptr<boost::filesystem::fstream> temp_file;
boost::shared_ptr<boost::mutex> readWriteMutex; boost::shared_ptr<boost::mutex> readWriteMutex;
std::vector<char> buffer; std::vector<char> buffer;
StreamData() : StreamData()
write_mode(true), : write_mode(true), temp_path(boost::filesystem::unique_path(temp_directory.append(
temp_path( TemporaryFilePattern.begin(), TemporaryFilePattern.end()))),
boost::filesystem::unique_path( temp_file(new boost::filesystem::fstream(
temp_directory.append( temp_path, std::ios::in | std::ios::out | std::ios::trunc | std::ios::binary)),
TemporaryFilePattern.begin(), readWriteMutex(boost::make_shared<boost::mutex>())
TemporaryFilePattern.end()
)
)
),
temp_file(
new boost::filesystem::fstream(
temp_path,
std::ios::in|std::ios::out|std::ios::trunc|std::ios::binary
)
),
readWriteMutex(boost::make_shared<boost::mutex>())
{ {
if( temp_file->fail() ) { if (temp_file->fail())
{
throw OSRMException("temporary file could not be created"); throw OSRMException("temporary file could not be created");
} }
} }
}; };
//vector of file streams that is used to store temporary data // vector of file streams that is used to store temporary data
boost::mutex mutex; boost::mutex mutex;
std::vector<StreamData> stream_data_list; std::vector<StreamData> stream_data_list;
}; };