reformatting RequestHandler

This commit is contained in:
Dennis Luxen 2014-05-11 18:06:52 +02:00
parent 584ba10726
commit 07231d3706
3 changed files with 73 additions and 65 deletions

View File

@ -34,16 +34,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/program_options.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 #if BOOST_FILESYSTEM_VERSION < 3
#warning Boost Installation with Filesystem3 missing, activating workaround #warning Boost Installation with Filesystem3 missing, activating workaround
#include <cstdio> #include <cstdio>
#endif #endif
namespace boost
namespace boost { {
namespace filesystem { namespace filesystem
{
// Validator for boost::filesystem::path, that verifies that the file // Validator for boost::filesystem::path, that verifies that the file
// exists. The validate() function must be defined in the same namespace // exists. The validate() function must be defined in the same namespace
@ -67,58 +68,64 @@ namespace filesystem {
// } // }
// } // }
// adapted from: http://stackoverflow.com/questions/1746136/how-do-i-normalize-a-pathname-using-boostfilesystem // adapted from:
inline boost::filesystem::path portable_canonical( // http://stackoverflow.com/questions/1746136/how-do-i-normalize-a-pathname-using-boostfilesystem
const boost::filesystem::path & relative_path, inline boost::filesystem::path
const boost::filesystem::path & current_path = boost::filesystem::current_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( const boost::filesystem::path absolute_path =
relative_path, boost::filesystem::absolute(relative_path, current_path);
current_path
);
boost::filesystem::path canonical_path; boost::filesystem::path canonical_path;
for( for (auto path_iterator = absolute_path.begin(); path_iterator != absolute_path.end();
boost::filesystem::path::const_iterator path_iterator = absolute_path.begin(); ++path_iterator)
path_iterator!=absolute_path.end(); {
++path_iterator if (".." == path_iterator->string())
) { {
if( ".." == path_iterator->string() ) {
// /a/b/.. is not necessarily /a if b is a symbolic link // /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; canonical_path /= *path_iterator;
} else if( ".." == canonical_path.filename() ) { }
else if (".." == canonical_path.filename())
{
// /a/b/../.. is not /a/b/.. under most circumstances // /a/b/../.. is not /a/b/.. under most circumstances
// We can end up with ..s in our result because of symbolic links // We can end up with ..s in our result because of symbolic links
canonical_path /= *path_iterator; canonical_path /= *path_iterator;
} else { }
else
{
// Otherwise it should be safe to resolve the parent // Otherwise it should be safe to resolve the parent
canonical_path = canonical_path.parent_path(); canonical_path = canonical_path.parent_path();
} }
} else if( "." == path_iterator->string() ) { }
else if ("." == path_iterator->string())
{
// Ignore // Ignore
} else { }
else
{
// Just cat other path entries // Just cat other path entries
canonical_path /= *path_iterator; canonical_path /= *path_iterator;
} }
} }
BOOST_ASSERT( canonical_path.is_absolute() ); BOOST_ASSERT(canonical_path.is_absolute());
BOOST_ASSERT( boost::filesystem::exists( canonical_path ) ); BOOST_ASSERT(boost::filesystem::exists(canonical_path));
return canonical_path; return canonical_path;
} }
#if BOOST_FILESYSTEM_VERSION < 3 #if BOOST_FILESYSTEM_VERSION < 3
inline path temp_directory_path() { inline path temp_directory_path()
char * buffer; {
buffer = tmpnam (NULL); char *buffer;
buffer = tmpnam(NULL);
return path(buffer); return path(buffer);
} }
inline path unique_path(const path&) { inline path unique_path(const path &) { return temp_directory_path(); }
return temp_directory_path();
}
#endif #endif
} }

View File

@ -35,22 +35,20 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <cmath> #include <cmath>
/* Get angle of line segment (A,C)->(C,B), atan2 magic, formerly cosine theorem*/ /* Get angle of line segment (A,C)->(C,B), atan2 magic, formerly cosine theorem*/
template<class CoordinateT> template <class CoordinateT>
inline static double GetAngleBetweenThreeFixedPointCoordinates ( inline static double GetAngleBetweenThreeFixedPointCoordinates(const CoordinateT &A,
const CoordinateT & A, const CoordinateT &C,
const CoordinateT & C, const CoordinateT &B)
const CoordinateT & B {
) { const double v1x = (A.lon - C.lon) / COORDINATE_PRECISION;
const double v1x = (A.lon - C.lon)/COORDINATE_PRECISION; const double v1y = lat2y(A.lat / COORDINATE_PRECISION) - lat2y(C.lat / 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 v2x = (B.lon - C.lon)/COORDINATE_PRECISION; const double v2y = lat2y(B.lat / COORDINATE_PRECISION) - lat2y(C.lat / 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; double angle = (atan2(v2y, v2x) - atan2(v1y, v1x)) * 180 / M_PI;
while(angle < 0) while (angle < 0)
angle += 360; angle += 360;
return angle; return angle;
} }
#endif // COMPUTE_ANGLE_H #endif // COMPUTE_ANGLE_H

View File

@ -31,36 +31,39 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <algorithm> #include <algorithm>
#include <vector> #include <vector>
template<typename T> template <typename T> inline void sort_unique_resize(std::vector<T> &vector)
inline void sort_unique_resize(std::vector<T> & vector) { {
std::sort(vector.begin(), vector.end()); 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 remove_consecutive_duplicates_from_vector(std::vector<T> & vector) {
unsigned number_of_unique_elements = std::unique(vector.begin(), vector.end()) - vector.begin(); unsigned number_of_unique_elements = std::unique(vector.begin(), vector.end()) - vector.begin();
vector.resize(number_of_unique_elements); vector.resize(number_of_unique_elements);
} }
template< typename FwdIter, typename Func > template <typename T> inline void sort_unique_resize_shrink_vector(std::vector<T> &vector)
Func for_each_pair( FwdIter iter_begin, FwdIter iter_end, Func func ) { {
if( iter_begin == iter_end ) { sort_unique_resize(vector);
std::vector<T>().swap(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)
{
return func; return func;
} }
FwdIter iter_next = iter_begin; FwdIter iter_next = iter_begin;
++iter_next; ++iter_next;
for( ; iter_next != iter_end; ++iter_begin, ++iter_next ){ for (; iter_next != iter_end; ++iter_begin, ++iter_next)
func( *iter_begin, *iter_next ); {
func(*iter_begin, *iter_next);
} }
return func; return func;
} }