Skip to content

Commit

Permalink
reformatting RequestHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisOSRM committed May 11, 2014
1 parent 584ba10 commit 07231d3
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 62 deletions.
71 changes: 39 additions & 32 deletions Util/BoostFileSystemFix.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>

//This is one big workaround for latest boost renaming woes.
// This is one big workaround for latest boost renaming woes.

#if BOOST_FILESYSTEM_VERSION < 3
#warning Boost Installation with Filesystem3 missing, activating workaround
#include <cstdio>
#endif


namespace boost {
namespace filesystem {
namespace boost
{
namespace filesystem
{

// Validator for boost::filesystem::path, that verifies that the file
// exists. The validate() function must be defined in the same namespace
Expand All @@ -67,58 +68,64 @@ namespace filesystem {
// }
// }

// adapted from: http://stackoverflow.com/questions/1746136/how-do-i-normalize-a-pathname-using-boostfilesystem
inline boost::filesystem::path portable_canonical(
const boost::filesystem::path & relative_path,
const boost::filesystem::path & current_path = boost::filesystem::current_path())
// adapted from:
// http://stackoverflow.com/questions/1746136/how-do-i-normalize-a-pathname-using-boostfilesystem
inline boost::filesystem::path
portable_canonical(const boost::filesystem::path &relative_path,
const boost::filesystem::path &current_path = boost::filesystem::current_path())
{
const boost::filesystem::path absolute_path = boost::filesystem::absolute(
relative_path,
current_path
);
const boost::filesystem::path absolute_path =
boost::filesystem::absolute(relative_path, current_path);

boost::filesystem::path canonical_path;
for(
boost::filesystem::path::const_iterator path_iterator = absolute_path.begin();
path_iterator!=absolute_path.end();
++path_iterator
) {
if( ".." == path_iterator->string() ) {
for (auto path_iterator = absolute_path.begin(); path_iterator != absolute_path.end();
++path_iterator)
{
if (".." == path_iterator->string())
{
// /a/b/.. is not necessarily /a if b is a symbolic link
if( boost::filesystem::is_symlink(canonical_path) ) {
if (boost::filesystem::is_symlink(canonical_path))
{
canonical_path /= *path_iterator;
} else if( ".." == canonical_path.filename() ) {
}
else if (".." == canonical_path.filename())
{
// /a/b/../.. is not /a/b/.. under most circumstances
// We can end up with ..s in our result because of symbolic links
canonical_path /= *path_iterator;
} else {
}
else
{
// Otherwise it should be safe to resolve the parent
canonical_path = canonical_path.parent_path();
}
} else if( "." == path_iterator->string() ) {
}
else if ("." == path_iterator->string())
{
// Ignore
} else {
}
else
{
// Just cat other path entries
canonical_path /= *path_iterator;
}
}
BOOST_ASSERT( canonical_path.is_absolute() );
BOOST_ASSERT( boost::filesystem::exists( canonical_path ) );
BOOST_ASSERT(canonical_path.is_absolute());
BOOST_ASSERT(boost::filesystem::exists(canonical_path));
return canonical_path;
}

#if BOOST_FILESYSTEM_VERSION < 3

inline path temp_directory_path() {
char * buffer;
buffer = tmpnam (NULL);
inline path temp_directory_path()
{
char *buffer;
buffer = tmpnam(NULL);

return path(buffer);
return path(buffer);
}

inline path unique_path(const path&) {
return temp_directory_path();
}
inline path unique_path(const path &) { return temp_directory_path(); }

#endif
}
Expand Down
26 changes: 12 additions & 14 deletions Util/ComputeAngle.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,20 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <cmath>

/* Get angle of line segment (A,C)->(C,B), atan2 magic, formerly cosine theorem*/
template<class CoordinateT>
inline static double GetAngleBetweenThreeFixedPointCoordinates (
const CoordinateT & A,
const CoordinateT & C,
const CoordinateT & B
) {
const double v1x = (A.lon - C.lon)/COORDINATE_PRECISION;
const double v1y = lat2y(A.lat/COORDINATE_PRECISION) - lat2y(C.lat/COORDINATE_PRECISION);
const double v2x = (B.lon - C.lon)/COORDINATE_PRECISION;
const double v2y = lat2y(B.lat/COORDINATE_PRECISION) - lat2y(C.lat/COORDINATE_PRECISION);

double angle = (atan2(v2y,v2x) - atan2(v1y,v1x) )*180/M_PI;
while(angle < 0)
template <class CoordinateT>
inline static double GetAngleBetweenThreeFixedPointCoordinates(const CoordinateT &A,
const CoordinateT &C,
const CoordinateT &B)
{
const double v1x = (A.lon - C.lon) / COORDINATE_PRECISION;
const double v1y = lat2y(A.lat / COORDINATE_PRECISION) - lat2y(C.lat / COORDINATE_PRECISION);
const double v2x = (B.lon - C.lon) / COORDINATE_PRECISION;
const double v2y = lat2y(B.lat / COORDINATE_PRECISION) - lat2y(C.lat / COORDINATE_PRECISION);

double angle = (atan2(v2y, v2x) - atan2(v1y, v1x)) * 180 / M_PI;
while (angle < 0)
angle += 360;
return angle;
}


#endif // COMPUTE_ANGLE_H
35 changes: 19 additions & 16 deletions Util/ContainerUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,39 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <algorithm>
#include <vector>

template<typename T>
inline void sort_unique_resize(std::vector<T> & vector) {
std::sort(vector.begin(), vector.end());
unsigned number_of_unique_elements = std::unique(vector.begin(), vector.end()) - vector.begin();
vector.resize(number_of_unique_elements);
template <typename T> inline void sort_unique_resize(std::vector<T> &vector)
{
std::sort(vector.begin(), vector.end());
unsigned number_of_unique_elements = std::unique(vector.begin(), vector.end()) - vector.begin();
vector.resize(number_of_unique_elements);
}

template<typename T>
inline void sort_unique_resize_shrink_vector(std::vector<T> & vector) {
sort_unique_resize(vector);
std::vector<T>().swap(vector);
template <typename T> inline void sort_unique_resize_shrink_vector(std::vector<T> &vector)
{
sort_unique_resize(vector);
std::vector<T>().swap(vector);
}

template<typename T>
inline void remove_consecutive_duplicates_from_vector(std::vector<T> & vector) {
template <typename T> inline void remove_consecutive_duplicates_from_vector(std::vector<T> &vector)
{
unsigned number_of_unique_elements = std::unique(vector.begin(), vector.end()) - vector.begin();
vector.resize(number_of_unique_elements);
}

template< typename FwdIter, typename Func >
Func for_each_pair( FwdIter iter_begin, FwdIter iter_end, Func func ) {
if( iter_begin == iter_end ) {
template <typename FwdIter, typename Func>
Func for_each_pair(FwdIter iter_begin, FwdIter iter_end, Func func)
{
if (iter_begin == iter_end)
{
return func;
}

FwdIter iter_next = iter_begin;
++iter_next;

for( ; iter_next != iter_end; ++iter_begin, ++iter_next ){
func( *iter_begin, *iter_next );
for (; iter_next != iter_end; ++iter_begin, ++iter_next)
{
func(*iter_begin, *iter_next);
}
return func;
}
Expand Down

0 comments on commit 07231d3

Please sign in to comment.