diff --git a/Util/BoostFileSystemFix.h b/Util/BoostFileSystemFix.h index 0919857dcb1..e708333903c 100644 --- a/Util/BoostFileSystemFix.h +++ b/Util/BoostFileSystemFix.h @@ -34,16 +34,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -//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 #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 @@ -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 ¤t_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 } diff --git a/Util/ComputeAngle.h b/Util/ComputeAngle.h index ef5dad9f112..01912cc3f4e 100644 --- a/Util/ComputeAngle.h +++ b/Util/ComputeAngle.h @@ -35,22 +35,20 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include /* Get angle of line segment (A,C)->(C,B), atan2 magic, formerly cosine theorem*/ -template -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 +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 diff --git a/Util/ContainerUtils.h b/Util/ContainerUtils.h index bc77b8ef59f..84710130987 100644 --- a/Util/ContainerUtils.h +++ b/Util/ContainerUtils.h @@ -31,36 +31,39 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -template -inline void sort_unique_resize(std::vector & 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 inline void sort_unique_resize(std::vector &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 -inline void sort_unique_resize_shrink_vector(std::vector & vector) { - sort_unique_resize(vector); - std::vector().swap(vector); +template inline void sort_unique_resize_shrink_vector(std::vector &vector) +{ + sort_unique_resize(vector); + std::vector().swap(vector); } -template -inline void remove_consecutive_duplicates_from_vector(std::vector & vector) { +template inline void remove_consecutive_duplicates_from_vector(std::vector &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 +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; }