Compare commits
280 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f2ca2ccaed | |||
| 4cdf683447 | |||
| 3bce384f9b | |||
| 03bb7f4f40 | |||
| c900cd0122 | |||
| 2fbfdc93b1 | |||
| cd68e21b95 | |||
| 8677218404 | |||
| f6744f9aa1 | |||
| df623df3e9 | |||
| 6665207066 | |||
| 26262541a4 | |||
| ba0064af99 | |||
| 8d40bc7f4f | |||
| b85849b6bd | |||
| 543b54e2af | |||
| dfd5ee9134 | |||
| 19ae6db308 | |||
| 2a634041a7 | |||
| 34389f9789 | |||
| 2ee7ea87cd | |||
| 6186f3f27e | |||
| a53a34a261 | |||
| e706a9867d | |||
| 9e5689858e | |||
| 40900f6f56 | |||
| f266655b9b | |||
| 8b0ae1bc5f | |||
| 979327ec82 | |||
| 0976358fdf | |||
| 9502689ff8 | |||
| 36f5b36c6b | |||
| 101fc5d02f | |||
| e9736173b0 | |||
| 1ec7c6ab50 | |||
| f90d1db802 | |||
| 14ca66459a | |||
| e7b3590352 | |||
| c0e86c47c2 | |||
| 4a8c2f323c | |||
| d4e6ad8a05 | |||
| f95e515f20 | |||
| 85ea79701c | |||
| 357ec5acfc | |||
| 47b2268504 | |||
| 224c55dec1 | |||
| 1727187b5e | |||
| 4d28f02273 | |||
| a329b1259e | |||
| e39479b908 | |||
| 2b4935c29c | |||
| 3e15c0a164 | |||
| 7830f82b62 | |||
| 84677ddddf | |||
| c8912ad6ee | |||
| 2d956983a5 | |||
| 884f79a620 | |||
| 39f33b670d | |||
| a975dba975 | |||
| 50aea3310a | |||
| 6c1c830c0d | |||
| 772ad0d618 | |||
| 826cbc9a24 | |||
| 7451cc3150 | |||
| 0e9dcc30b7 | |||
| 222e4e8916 | |||
| a3cdba5044 | |||
| 57040e6924 | |||
| b9a817ce26 | |||
| 4130144687 | |||
| ec5934364a | |||
| 23d1ea2a32 | |||
| 28e78e6ea6 | |||
| 90925bd91d | |||
| 42f38a42db | |||
| ab8c700a94 | |||
| 10a96e3aba | |||
| 99f0abef0c | |||
| e7bb320924 | |||
| 96e5c4b518 | |||
| a3cfd49f97 | |||
| fbe722465d | |||
| 448e6cfdc7 | |||
| 8e79b29925 | |||
| bd61494cf4 | |||
| d33a75812d | |||
| 9f5f6019bf | |||
| aef70b832c | |||
| 611d265a27 | |||
| 635b13b61c | |||
| a8a4f56292 | |||
| a0ceee732e | |||
| 560ce74d06 | |||
| d7ffb0d492 | |||
| 369edbe9a7 | |||
| 94ca30c690 | |||
| ab1e5255eb | |||
| 0068d4062d | |||
| 04298b73f3 | |||
| 7657f0de22 | |||
| 7cdeeb0723 | |||
| c0b71cb62a | |||
| 253df58fdb | |||
| cd3005f9fe | |||
| 94cf796ed2 | |||
| 18995379ab | |||
| a5246cc8b8 | |||
| 3a7f527c68 | |||
| f404337383 | |||
| 7421117278 | |||
| f6173b7a48 | |||
| dffd67ef72 | |||
| 3444499cf4 | |||
| 7241438502 | |||
| 44c38146c9 | |||
| 2060088c6b | |||
| 38defe9629 | |||
| 087bb12847 | |||
| c59a6f9444 | |||
| 40c0222ffd | |||
| f763ec2664 | |||
| 186f78f01e | |||
| 1da10942d5 | |||
| 7ad253732a | |||
| 4b1c4068f2 | |||
| 57ec4e5465 | |||
| f3290ab64b | |||
| eb3c2f560e | |||
| 869b13e9db | |||
| 57d9bc5bae | |||
| 917ef160c5 | |||
| ae513dce5c | |||
| 93b5ce2968 | |||
| ba08d0b36c | |||
| 2e60e92b31 | |||
| 5a9a55544b | |||
| ee7c79641a | |||
| 6e57c31ec2 | |||
| 3d9d4f3764 | |||
| 596e7fc60a | |||
| 8845c070a2 | |||
| eaf5dd328f | |||
| 20a0a3b170 | |||
| 8d5d1a9400 | |||
| 572a306d6d | |||
| 63a9e4c6c2 | |||
| c84d4b323e | |||
| 46f717566d | |||
| 0199673d14 | |||
| 607d5408d3 | |||
| 33035fccc0 | |||
| c14e461370 | |||
| 6f4e9a1d11 | |||
| 3610e21854 | |||
| f6a3815e91 | |||
| f2efcfc588 | |||
| 2bf573dbe1 | |||
| 9bd4b77278 | |||
| fb995ad0b0 | |||
| 3a85661e45 | |||
| 0ba881c390 | |||
| c7782b2776 | |||
| 23ca80030e | |||
| f08c389faa | |||
| 47369a0036 | |||
| 253b591a87 | |||
| 5c4488d350 | |||
| 25310ff1bd | |||
| c2d52080d3 | |||
| bf681855ed | |||
| 899d216b9b | |||
| 73aeab3a57 | |||
| 61073ebc9d | |||
| 393334cabd | |||
| 01e4afe2f0 | |||
| 9b599c90f8 | |||
| 252c234221 | |||
| 888a5d04c8 | |||
| b1631eff77 | |||
| ffd5e2de99 | |||
| ea207cef6e | |||
| 893c09f6fc | |||
| 213bb71b35 | |||
| 0fd8d4d8cf | |||
| 13f0a3fb6b | |||
| 3141d3ba48 | |||
| 4ff4fcf516 | |||
| f273f0cfc5 | |||
| dc192d47a8 | |||
| 0f032f7635 | |||
| 060c7e499a | |||
| 28a241c371 | |||
| bab2887f8f | |||
| abba49a44e | |||
| 4638e7c24d | |||
| fe420e5bfc | |||
| 93ae928236 | |||
| 3b485f1426 | |||
| 5165e01a5c | |||
| 7b4e923ec4 | |||
| 007dd19cec | |||
| fd3cf02af4 | |||
| 2bb51717b9 | |||
| 4fe6346146 | |||
| c5bd2b0b1d | |||
| 71426cf760 | |||
| 0ab287e707 | |||
| 49cc0bfb09 | |||
| e132ac5c53 | |||
| 1a9776cff9 | |||
| 342a0d22bd | |||
| 251a43980a | |||
| 41ba8b5e3e | |||
| 30df2aae10 | |||
| a6f00b1856 | |||
| af26c47052 | |||
| 0a774aeef2 | |||
| a89aa68686 | |||
| 4b93107415 | |||
| e0602934b2 | |||
| fdace26222 | |||
| bef41ed667 | |||
| 4e2e95cc27 | |||
| f4c6ec90ce | |||
| eed22b343a | |||
| 08ce748a37 | |||
| 69790eb8c7 | |||
| 97b9c65c97 | |||
| 92dbadebae | |||
| fe6d854e11 | |||
| 4615b01fdf | |||
| 276b023b05 | |||
| 350cacb2f3 | |||
| 25ec6105c5 | |||
| 3e4249ad41 | |||
| 13126ac0c1 | |||
| d51aee4fbe | |||
| f9877fd8ba | |||
| a39a35df73 | |||
| 2670dd68f3 | |||
| 9adb590ce7 | |||
| 9567a7e38c | |||
| d86eaa00a0 | |||
| 54c0d50b68 | |||
| 204189c326 | |||
| acdfa546a8 | |||
| 6a9216d6e4 | |||
| 9c2a1dc37f | |||
| 26c9d357f0 | |||
| 879d73c629 | |||
| 441146eeae | |||
| d453cadc8c | |||
| 74188206e8 | |||
| 700206099b | |||
| aa952df541 | |||
| b8944da9dc | |||
| 22dda2b285 | |||
| 0ee469c4e0 | |||
| a7eef27e99 | |||
| 4b40f1253f | |||
| 5ebe8080f9 | |||
| d92b28d2c3 | |||
| ec27881f39 | |||
| c5a8ec7c31 | |||
| afbd3347da | |||
| 41bcafc3a1 | |||
| 27d24885a9 | |||
| 805402b230 | |||
| 4918549bac | |||
| 784f417857 | |||
| 0bc3e098ac | |||
| dfd3a5d554 | |||
| 9dcc472c60 | |||
| c972e2cf41 | |||
| de9ab83cea | |||
| 174e388e2d | |||
| ee41fb45b7 | |||
| 93892b9806 | |||
| 749d83a69f | |||
| 8b109904c8 |
@@ -1,54 +0,0 @@
|
||||
---
|
||||
Language: Cpp
|
||||
# BasedOnStyle: LLVM
|
||||
AccessModifierOffset: -2
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
AlignEscapedNewlinesLeft: false
|
||||
AlignTrailingComments: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: true
|
||||
AlwaysBreakTemplateDeclarations: false
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
BreakBeforeBinaryOperators: false
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BinPackParameters: false
|
||||
ColumnLimit: 100
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
DerivePointerBinding: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
IndentCaseLabels: false
|
||||
MaxEmptyLinesToKeep: 1
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
NamespaceIndentation: None
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyExcessCharacter: 1000
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerBindsToType: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
Cpp11BracedListStyle: true
|
||||
Standard: Cpp11
|
||||
IndentWidth: 4
|
||||
TabWidth: 8
|
||||
UseTab: Never
|
||||
BreakBeforeBraces: Allman
|
||||
IndentFunctionDeclarationAfterType: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInAngles: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
ContinuationIndentWidth: 4
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
|
||||
SpaceBeforeParens: ControlStatements
|
||||
...
|
||||
|
||||
+2
-95
@@ -1,95 +1,2 @@
|
||||
# Compiled source #
|
||||
###################
|
||||
*.com
|
||||
*.class
|
||||
*.dll
|
||||
*.exe
|
||||
*.o
|
||||
*.so
|
||||
|
||||
# Packages #
|
||||
############
|
||||
# it's better to unpack these files and commit the raw source
|
||||
# git has its own built in compression methods
|
||||
*.7z
|
||||
*.dmg
|
||||
*.gz
|
||||
*.iso
|
||||
*.jar
|
||||
*.rar
|
||||
*.tar
|
||||
*.zip
|
||||
|
||||
# Logs and databases #
|
||||
######################
|
||||
*.log
|
||||
*.sql
|
||||
*.sqlite
|
||||
|
||||
# OS generated files #
|
||||
######################
|
||||
.DS_Store
|
||||
ehthumbs.db
|
||||
Icon?
|
||||
Thumbs.db
|
||||
|
||||
# build related files #
|
||||
#######################
|
||||
/build/
|
||||
/Util/finger_print.cpp
|
||||
/Util/git_sha.cpp
|
||||
/cmake/postinst
|
||||
|
||||
# Eclipse related files #
|
||||
#########################
|
||||
.setting*
|
||||
.scb
|
||||
.cproject
|
||||
.project
|
||||
|
||||
# stxxl related files #
|
||||
#######################
|
||||
.stxxl
|
||||
stxxl.log
|
||||
stxxl.errlog
|
||||
|
||||
# compiled protobuffers #
|
||||
#########################
|
||||
/DataStructures/pbf-proto/*.pb.h
|
||||
/DataStructures/pbf-proto/*.pb.cc
|
||||
|
||||
# External Libs #
|
||||
#################
|
||||
/lib/
|
||||
/win/lib
|
||||
|
||||
# Visual Studio Temp + build Files #
|
||||
####################################
|
||||
/win/*.user
|
||||
/win/*.ncb
|
||||
/win/*.suo
|
||||
/win/Debug/
|
||||
/win/Release/
|
||||
/win/bin/
|
||||
/win/bin-debug/
|
||||
/osrm-extract
|
||||
/osrm-io-benchmark
|
||||
/osrm-components
|
||||
/osrm-routed
|
||||
/osrm-datastore
|
||||
/osrm-prepare
|
||||
/osrm-unlock-all
|
||||
/osrm-cli
|
||||
/osrm-check-hsgr
|
||||
/osrm-springclean
|
||||
/nohup.out
|
||||
|
||||
# Sandbox folder #
|
||||
###################
|
||||
/sandbox/
|
||||
|
||||
/test/profile.lua
|
||||
|
||||
# Deprecated config file #
|
||||
##########################
|
||||
/server.ini
|
||||
/.settings
|
||||
/.project
|
||||
|
||||
-60
@@ -1,60 +0,0 @@
|
||||
language: cpp
|
||||
compiler:
|
||||
- gcc
|
||||
# - clang
|
||||
# Make sure CMake is installed
|
||||
install:
|
||||
- sudo apt-add-repository -y ppa:ubuntu-toolchain-r/test
|
||||
- sudo add-apt-repository -y ppa:boost-latest/ppa
|
||||
- sudo apt-get update >/dev/null
|
||||
- sudo apt-get -q install protobuf-compiler libprotoc-dev libprotobuf7 libprotobuf-dev libbz2-dev libstxxl-dev libstxxl1 libxml2-dev libzip-dev lua5.1 liblua5.1-0-dev rubygems libtbb-dev
|
||||
- sudo apt-get -q install g++-4.8
|
||||
- sudo apt-get install libboost1.54-all-dev
|
||||
# luabind
|
||||
- curl https://gist.githubusercontent.com/DennisOSRM/f2eb7b948e6fe1ae319e/raw/install-luabind.sh | sudo bash
|
||||
# osmosis
|
||||
- curl -s https://gist.githubusercontent.com/DennisOSRM/803a64a9178ec375069f/raw/ | sudo bash
|
||||
# cmake
|
||||
- curl -s https://gist.githubusercontent.com/DennisOSRM/5fad9bee5c7f09fd7fc9/raw/ | sudo bash
|
||||
# osmpbf library
|
||||
- curl -s https://gist.githubusercontent.com/DennisOSRM/13b1b4fe38a57ead850e/raw/install_osmpbf.sh | sudo bash
|
||||
before_script:
|
||||
- rvm use 1.9.3
|
||||
- gem install bundler
|
||||
- bundle install
|
||||
- mkdir build
|
||||
- cd build
|
||||
- cmake .. $CMAKEOPTIONS
|
||||
script:
|
||||
- make -j 2
|
||||
- make -j 2 tests
|
||||
- ./datastructure-tests
|
||||
- cd ..
|
||||
- cucumber -p verify
|
||||
after_script:
|
||||
# - cd ..
|
||||
# - cucumber -p verify
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- develop
|
||||
cache:
|
||||
- bundler
|
||||
- apt
|
||||
env:
|
||||
- CMAKEOPTIONS="-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=g++-4.8" OSRM_PORT=5000 OSRM_TIMEOUT=60
|
||||
- CMAKEOPTIONS="-DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=g++-4.8" OSRM_PORT=5010 OSRM_TIMEOUT=60
|
||||
notifications:
|
||||
irc:
|
||||
channels:
|
||||
- irc.oftc.net#osrm
|
||||
on_success: change
|
||||
on_failure: always
|
||||
use_notice: true
|
||||
skip_join: false
|
||||
|
||||
recipients:
|
||||
- dennis@mapbox.com
|
||||
email:
|
||||
on_success: change
|
||||
on_failure: always
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
The following people contributed code to the Open Source Routing Machine:
|
||||
|
||||
Dennis Schieferdecker
|
||||
Dennis Luxen
|
||||
Pascal Neis
|
||||
Teemu Koskinen
|
||||
Nicolas Belett Vigneron
|
||||
Moyg
|
||||
Jean-Frederic
|
||||
Zbigniew Czernik
|
||||
Jonas Häggqvist
|
||||
Sabas
|
||||
Paul Spencer
|
||||
-355
@@ -1,355 +0,0 @@
|
||||
cmake_minimum_required(VERSION 2.8.8)
|
||||
|
||||
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE)
|
||||
message(FATAL_ERROR "In-source builds are not allowed.
|
||||
Please create a directory and run cmake from there, passing the path to this source directory as the last argument.
|
||||
This process created the file `CMakeCache.txt' and the directory `CMakeFiles'. Please delete them.")
|
||||
endif()
|
||||
|
||||
project(OSRM)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
include(CheckCXXCompilerFlag)
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
|
||||
include(GetGitRevisionDescription)
|
||||
git_describe(GIT_DESCRIPTION)
|
||||
|
||||
set(bitness 32)
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(bitness 64)
|
||||
message(STATUS "Building on a 64 bit system")
|
||||
else()
|
||||
message(WARNING "Building on a 32 bit system is unsupported")
|
||||
endif()
|
||||
|
||||
if (WIN32 AND MSVC_VERSION LESS 1800)
|
||||
message(FATAL_ERROR "Building with Microsoft compiler needs Visual Studio 2013 or later (Express version works too)")
|
||||
endif()
|
||||
|
||||
OPTION(WITH_TOOLS "Build OSRM tools" OFF)
|
||||
OPTION(BUILD_TOOLS "Build OSRM tools" OFF)
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/Include/)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/third_party/)
|
||||
|
||||
add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/Util/finger_print.cpp finger_print.cpp.alwaysbuild
|
||||
COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR=${CMAKE_SOURCE_DIR}
|
||||
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/FingerPrint-Config.cmake
|
||||
DEPENDS
|
||||
${CMAKE_SOURCE_DIR}/Util/finger_print.cpp.in
|
||||
COMMENT "Configuring finger_print.cpp"
|
||||
VERBATIM)
|
||||
|
||||
add_custom_target(FingerPrintConfigure DEPENDS ${CMAKE_SOURCE_DIR}/Util/finger_print.cpp)
|
||||
add_custom_target(tests DEPENDS datastructure-tests algorithm-tests)
|
||||
add_custom_target(benchmarks DEPENDS rtree-bench)
|
||||
|
||||
set(BOOST_COMPONENTS date_time filesystem iostreams program_options regex system thread unit_test_framework)
|
||||
|
||||
configure_file(
|
||||
${CMAKE_SOURCE_DIR}/Util/git_sha.cpp.in
|
||||
${CMAKE_SOURCE_DIR}/Util/git_sha.cpp
|
||||
)
|
||||
file(GLOB ExtractorGlob extractor/*.cpp)
|
||||
file(GLOB ImporterGlob data_structures/import_edge.cpp data_structures/external_memory_node.cpp)
|
||||
add_library(IMPORT OBJECT ${ImporterGlob})
|
||||
add_library(LOGGER OBJECT Util/simple_logger.cpp)
|
||||
add_library(PHANTOMNODE OBJECT data_structures/phantom_node.cpp)
|
||||
add_library(EXCEPTION OBJECT Util/osrm_exception.cpp)
|
||||
|
||||
set(ExtractorSources extract.cpp ${ExtractorGlob})
|
||||
add_executable(osrm-extract ${ExtractorSources} $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:IMPORT> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:EXCEPTION>)
|
||||
|
||||
add_library(RESTRICTION OBJECT data_structures/restriction_map.cpp)
|
||||
|
||||
file(GLOB PrepareGlob contractor/*.cpp data_structures/hilbert_value.cpp Util/compute_angle.cpp {RestrictionMapGlob})
|
||||
set(PrepareSources prepare.cpp ${PrepareGlob})
|
||||
add_executable(osrm-prepare ${PrepareSources} $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:IMPORT> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:RESTRICTION> $<TARGET_OBJECTS:EXCEPTION>)
|
||||
|
||||
file(GLOB ServerGlob Server/*.cpp)
|
||||
file(GLOB DescriptorGlob descriptors/*.cpp)
|
||||
file(GLOB DatastructureGlob data_structures/search_engine_data.cpp data_structures/route_parameters.cpp Util/bearing.cpp)
|
||||
list(REMOVE_ITEM DatastructureGlob data_structures/Coordinate.cpp)
|
||||
file(GLOB CoordinateGlob data_structures/Coordinate.cpp)
|
||||
file(GLOB AlgorithmGlob algorithms/*.cpp)
|
||||
file(GLOB HttpGlob Server/Http/*.cpp)
|
||||
file(GLOB LibOSRMGlob Library/*.cpp)
|
||||
file(GLOB DataStructureTestsGlob UnitTests/data_structures/*.cpp data_structures/hilbert_value.cpp)
|
||||
file(GLOB AlgorithmTestsGlob UnitTests/Algorithms/*.cpp)
|
||||
|
||||
set(
|
||||
OSRMSources
|
||||
${LibOSRMGlob}
|
||||
${DescriptorGlob}
|
||||
${DatastructureGlob}
|
||||
${CoordinateGlob}
|
||||
${AlgorithmGlob}
|
||||
${HttpGlob}
|
||||
)
|
||||
add_library(COORDINATE OBJECT ${CoordinateGlob})
|
||||
add_library(FINGERPRINT OBJECT Util/finger_print.cpp)
|
||||
add_library(GITDESCRIPTION OBJECT Util/git_sha.cpp)
|
||||
add_library(OSRM ${OSRMSources} $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:PHANTOMNODE> $<TARGET_OBJECTS:EXCEPTION>)
|
||||
add_dependencies(FINGERPRINT FingerPrintConfigure)
|
||||
|
||||
add_executable(osrm-routed routed.cpp ${ServerGlob} $<TARGET_OBJECTS:EXCEPTION>)
|
||||
add_executable(osrm-datastore datastore.cpp $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:EXCEPTION>)
|
||||
|
||||
# Unit tests
|
||||
add_executable(datastructure-tests EXCLUDE_FROM_ALL UnitTests/datastructure_tests.cpp ${DataStructureTestsGlob} $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:PHANTOMNODE> $<TARGET_OBJECTS:EXCEPTION>)
|
||||
add_executable(algorithm-tests EXCLUDE_FROM_ALL UnitTests/algorithm_tests.cpp ${AlgorithmTestsGlob} $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:PHANTOMNODE> $<TARGET_OBJECTS:EXCEPTION>)
|
||||
|
||||
# Benchmarks
|
||||
add_executable(rtree-bench EXCLUDE_FROM_ALL benchmarks/static_rtree.cpp $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:PHANTOMNODE> $<TARGET_OBJECTS:EXCEPTION>)
|
||||
|
||||
# Check the release mode
|
||||
if(NOT CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
endif()
|
||||
if(CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
message(STATUS "Configuring OSRM in debug mode")
|
||||
if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
message(STATUS "adding profiling flags")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -fno-inline")
|
||||
set(CMAKE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -fno-inline")
|
||||
endif()
|
||||
endif()
|
||||
if(CMAKE_BUILD_TYPE MATCHES Release)
|
||||
message(STATUS "Configuring OSRM in release mode")
|
||||
# Check if LTO is available
|
||||
set(LTO_FLAGS "")
|
||||
CHECK_CXX_COMPILER_FLAG("-flto" HAS_LTO_FLAG)
|
||||
if (HAS_LTO_FLAG)
|
||||
set(LTO_FLAGS "${LTO_FLAGS} -flto")
|
||||
|
||||
# Since gcc 4.9 the LTO format is non-standart ('slim'), so we need to use the build-in tools
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND
|
||||
NOT "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "4.9.0" AND NOT MINGW)
|
||||
message(STATUS "Using gcc specific binutils for LTO.")
|
||||
set(CMAKE_AR "/usr/bin/gcc-ar")
|
||||
set(CMAKE_RANLIB "/usr/bin/gcc-ranlib")
|
||||
endif()
|
||||
endif (HAS_LTO_FLAG)
|
||||
endif()
|
||||
|
||||
if (NOT WIN32)
|
||||
add_definitions(-DBOOST_TEST_DYN_LINK)
|
||||
endif()
|
||||
|
||||
# Configuring compilers
|
||||
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
# using Clang
|
||||
# -Weverything -Wno-c++98-compat -Wno-shadow -Wno-exit-time-destructors
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wunreachable-code -pedantic -fPIC")
|
||||
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
set(COLOR_FLAG "-fdiagnostics-color=auto")
|
||||
CHECK_CXX_COMPILER_FLAG("-fdiagnostics-color=auto" HAS_COLOR_FLAG)
|
||||
if(NOT HAS_COLOR_FLAG)
|
||||
set(COLOR_FLAG "")
|
||||
endif()
|
||||
# using GCC
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -fPIC ${COLOR_FLAG}")
|
||||
if (WIN32) # using mingw
|
||||
add_definitions(-D_USE_MATH_DEFINES) # define M_PI, M_1_PI etc.
|
||||
add_definitions(-DWIN32)
|
||||
SET(OPTIONAL_SOCKET_LIBS ws2_32 wsock32)
|
||||
endif()
|
||||
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
|
||||
# using Intel C++
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-intel -wd10237 -Wall -ipo -fPIC")
|
||||
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
# using Visual Studio C++
|
||||
set(BOOST_COMPONENTS ${BOOST_COMPONENTS} date_time chrono zlib)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
add_definitions(-DNOMINMAX) # avoid min and max macros that can break compilation
|
||||
add_definitions(-D_USE_MATH_DEFINES) # define M_PI
|
||||
add_definitions(-D_WIN32_WINNT=0x0501)
|
||||
add_definitions(-DXML_STATIC)
|
||||
find_library(ws2_32_LIBRARY_PATH ws2_32)
|
||||
target_link_libraries(osrm-extract wsock32 ws2_32)
|
||||
endif()
|
||||
|
||||
# Activate C++11
|
||||
if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
ADD_DEFINITIONS(-std=c++11)
|
||||
endif()
|
||||
|
||||
# Configuring other platform dependencies
|
||||
if(APPLE)
|
||||
set(CMAKE_OSX_ARCHITECTURES "x86_64")
|
||||
message(STATUS "Set Architecture to x64 on OS X")
|
||||
exec_program(uname ARGS -v OUTPUT_VARIABLE DARWIN_VERSION)
|
||||
string(REGEX MATCH "[0-9]+" DARWIN_VERSION ${DARWIN_VERSION})
|
||||
if(OSXLIBSTD)
|
||||
message(STATUS "linking against ${OSXLIBSTD}")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=${OSXLIBSTD}")
|
||||
elseif(DARWIN_VERSION GREATER 12)
|
||||
message(STATUS "linking against libc++")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(UNIX AND NOT APPLE)
|
||||
target_link_libraries(osrm-prepare rt)
|
||||
target_link_libraries(osrm-datastore rt)
|
||||
target_link_libraries(OSRM rt)
|
||||
endif()
|
||||
|
||||
#Check Boost
|
||||
set(BOOST_MIN_VERSION "1.49.0")
|
||||
find_package(Boost ${BOOST_MIN_VERSION} COMPONENTS ${BOOST_COMPONENTS} REQUIRED)
|
||||
if(NOT Boost_FOUND)
|
||||
message(FATAL_ERROR "Fatal error: Boost (version >= 1.49.0) required.\n")
|
||||
endif()
|
||||
include_directories(${Boost_INCLUDE_DIRS})
|
||||
|
||||
target_link_libraries(OSRM ${Boost_LIBRARIES})
|
||||
target_link_libraries(osrm-extract ${Boost_LIBRARIES})
|
||||
target_link_libraries(osrm-prepare ${Boost_LIBRARIES})
|
||||
target_link_libraries(osrm-routed ${Boost_LIBRARIES} ${OPTIONAL_SOCKET_LIBS} OSRM)
|
||||
target_link_libraries(osrm-datastore ${Boost_LIBRARIES})
|
||||
target_link_libraries(datastructure-tests ${Boost_LIBRARIES})
|
||||
target_link_libraries(algorithm-tests ${Boost_LIBRARIES} ${OPTIONAL_SOCKET_LIBS} OSRM)
|
||||
target_link_libraries(rtree-bench ${Boost_LIBRARIES})
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(osrm-extract ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries(osrm-datastore ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries(osrm-prepare ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries(OSRM ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries(datastructure-tests ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries(algorithm-tests ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries(rtree-bench ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
||||
find_package(TBB REQUIRED)
|
||||
if(WIN32 AND CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
set(TBB_LIBRARIES ${TBB_DEBUG_LIBRARIES})
|
||||
endif()
|
||||
target_link_libraries(osrm-datastore ${TBB_LIBRARIES})
|
||||
target_link_libraries(osrm-extract ${TBB_LIBRARIES})
|
||||
target_link_libraries(osrm-prepare ${TBB_LIBRARIES})
|
||||
target_link_libraries(osrm-routed ${TBB_LIBRARIES})
|
||||
target_link_libraries(datastructure-tests ${TBB_LIBRARIES})
|
||||
target_link_libraries(algorithm-tests ${TBB_LIBRARIES})
|
||||
target_link_libraries(rtree-bench ${TBB_LIBRARIES})
|
||||
include_directories(${TBB_INCLUDE_DIR})
|
||||
|
||||
find_package( Luabind REQUIRED )
|
||||
include(check_luabind)
|
||||
|
||||
include_directories(${LUABIND_INCLUDE_DIR})
|
||||
target_link_libraries(osrm-extract ${LUABIND_LIBRARY})
|
||||
target_link_libraries(osrm-prepare ${LUABIND_LIBRARY})
|
||||
|
||||
if( LUAJIT_FOUND )
|
||||
target_link_libraries(osrm-extract ${LUAJIT_LIBRARIES})
|
||||
target_link_libraries(osrm-prepare ${LUAJIT_LIBRARIES})
|
||||
else()
|
||||
target_link_libraries(osrm-extract ${LUA_LIBRARY})
|
||||
target_link_libraries(osrm-prepare ${LUA_LIBRARY})
|
||||
endif()
|
||||
include_directories(${LUA_INCLUDE_DIR})
|
||||
|
||||
find_package(EXPAT REQUIRED)
|
||||
include_directories(${EXPAT_INCLUDE_DIRS})
|
||||
target_link_libraries(osrm-extract ${EXPAT_LIBRARIES})
|
||||
|
||||
find_package( STXXL REQUIRED )
|
||||
include_directories(${STXXL_INCLUDE_DIR})
|
||||
target_link_libraries(OSRM ${STXXL_LIBRARY})
|
||||
target_link_libraries(osrm-extract ${STXXL_LIBRARY})
|
||||
target_link_libraries(osrm-prepare ${STXXL_LIBRARY})
|
||||
|
||||
if(MINGW)
|
||||
# STXXL needs OpenMP library
|
||||
target_link_libraries(osrm-extract gomp)
|
||||
endif()
|
||||
|
||||
find_package( OSMPBF REQUIRED )
|
||||
include_directories(${OSMPBF_INCLUDE_DIR})
|
||||
target_link_libraries(osrm-extract ${OSMPBF_LIBRARY})
|
||||
target_link_libraries(osrm-prepare ${OSMPBF_LIBRARY})
|
||||
|
||||
find_package(Protobuf REQUIRED)
|
||||
include_directories(${PROTOBUF_INCLUDE_DIRS})
|
||||
target_link_libraries(osrm-extract ${PROTOBUF_LIBRARY})
|
||||
target_link_libraries(osrm-prepare ${PROTOBUF_LIBRARY})
|
||||
|
||||
find_package(BZip2 REQUIRED)
|
||||
include_directories(${BZIP_INCLUDE_DIRS})
|
||||
target_link_libraries(osrm-extract ${BZIP2_LIBRARIES})
|
||||
|
||||
find_package(ZLIB REQUIRED)
|
||||
include_directories(${ZLIB_INCLUDE_DIRS})
|
||||
target_link_libraries(osrm-extract ${ZLIB_LIBRARY})
|
||||
target_link_libraries(osrm-routed ${ZLIB_LIBRARY})
|
||||
|
||||
if(WITH_TOOLS OR BUILD_TOOLS)
|
||||
message(STATUS "Activating OSRM internal tools")
|
||||
find_package(GDAL)
|
||||
if(GDAL_FOUND)
|
||||
add_executable(osrm-components tools/components.cpp $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:IMPORT> $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:RESTRICTION> $<TARGET_OBJECTS:EXCEPTION>)
|
||||
target_link_libraries(osrm-components ${TBB_LIBRARIES})
|
||||
include_directories(${GDAL_INCLUDE_DIR})
|
||||
target_link_libraries(
|
||||
osrm-components
|
||||
${GDAL_LIBRARIES} ${Boost_LIBRARIES})
|
||||
install(TARGETS osrm-components DESTINATION bin)
|
||||
else()
|
||||
message(FATAL_ERROR "libgdal and/or development headers not found")
|
||||
endif()
|
||||
add_executable(osrm-cli tools/simpleclient.cpp $<TARGET_OBJECTS:EXCEPTION> $<TARGET_OBJECTS:LOGGER>)
|
||||
target_link_libraries(osrm-cli ${Boost_LIBRARIES} ${OPTIONAL_SOCKET_LIBS} OSRM)
|
||||
target_link_libraries(osrm-cli ${TBB_LIBRARIES})
|
||||
add_executable(osrm-io-benchmark tools/io-benchmark.cpp $<TARGET_OBJECTS:EXCEPTION> $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:LOGGER>)
|
||||
target_link_libraries(osrm-io-benchmark ${Boost_LIBRARIES})
|
||||
add_executable(osrm-unlock-all tools/unlock_all_mutexes.cpp $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:EXCEPTION>)
|
||||
target_link_libraries(osrm-unlock-all ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
|
||||
if(UNIX AND NOT APPLE)
|
||||
target_link_libraries(osrm-unlock-all rt)
|
||||
endif()
|
||||
add_executable(osrm-check-hsgr tools/check-hsgr.cpp $<TARGET_OBJECTS:EXCEPTION> $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:LOGGER>)
|
||||
target_link_libraries(osrm-check-hsgr ${Boost_LIBRARIES})
|
||||
add_executable(osrm-springclean tools/springclean.cpp $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:EXCEPTION>)
|
||||
target_link_libraries(osrm-springclean ${Boost_LIBRARIES})
|
||||
|
||||
install(TARGETS osrm-cli DESTINATION bin)
|
||||
install(TARGETS osrm-io-benchmark DESTINATION bin)
|
||||
install(TARGETS osrm-unlock-all DESTINATION bin)
|
||||
install(TARGETS osrm-check-hsgr DESTINATION bin)
|
||||
install(TARGETS osrm-springclean DESTINATION bin)
|
||||
endif()
|
||||
|
||||
file(GLOB InstallGlob Include/osrm/*.h Library/OSRM.h)
|
||||
|
||||
# Add RPATH info to executables so that when they are run after being installed
|
||||
# (i.e., from /usr/local/bin/) the linker can find library dependencies. For
|
||||
# more info see http://www.cmake.org/Wiki/CMake_RPATH_handling
|
||||
set_property(TARGET osrm-extract PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||
set_property(TARGET osrm-prepare PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||
set_property(TARGET osrm-datastore PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||
set_property(TARGET osrm-routed PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||
|
||||
install(FILES ${InstallGlob} DESTINATION include/osrm)
|
||||
install(TARGETS osrm-extract DESTINATION bin)
|
||||
install(TARGETS osrm-prepare DESTINATION bin)
|
||||
install(TARGETS osrm-datastore DESTINATION bin)
|
||||
install(TARGETS osrm-routed DESTINATION bin)
|
||||
install(TARGETS OSRM DESTINATION lib)
|
||||
list(GET Boost_LIBRARIES 1 BOOST_LIBRARY_FIRST)
|
||||
get_filename_component(BOOST_LIBRARY_LISTING "${BOOST_LIBRARY_FIRST}" PATH)
|
||||
set(BOOST_LIBRARY_LISTING "-L${BOOST_LIBRARY_LISTING}")
|
||||
foreach (lib ${Boost_LIBRARIES})
|
||||
get_filename_component(BOOST_LIBRARY_NAME "${lib}" NAME_WE)
|
||||
string(REPLACE "lib" "" BOOST_LIBRARY_NAME ${BOOST_LIBRARY_NAME})
|
||||
set(BOOST_LIBRARY_LISTING "${BOOST_LIBRARY_LISTING} -l${BOOST_LIBRARY_NAME}")
|
||||
endforeach ()
|
||||
|
||||
configure_file(${CMAKE_SOURCE_DIR}/cmake/pkgconfig.in libosrm.pc @ONLY)
|
||||
install(FILES ${PROJECT_BINARY_DIR}/libosrm.pc DESTINATION lib/pkgconfig)
|
||||
|
||||
if(BUILD_DEBIAN_PACKAGE)
|
||||
include(CPackDebianConfig)
|
||||
include(CPack)
|
||||
endif()
|
||||
@@ -1,7 +0,0 @@
|
||||
source "http://rubygems.org"
|
||||
|
||||
gem "cucumber"
|
||||
gem "rake"
|
||||
gem "osmlib-base"
|
||||
gem "sys-proctable"
|
||||
gem "rspec-expectations"
|
||||
@@ -1,30 +0,0 @@
|
||||
GEM
|
||||
remote: http://rubygems.org/
|
||||
specs:
|
||||
builder (3.2.2)
|
||||
cucumber (1.3.8)
|
||||
builder (>= 2.1.2)
|
||||
diff-lcs (>= 1.1.3)
|
||||
gherkin (~> 2.12.1)
|
||||
multi_json (>= 1.7.5, < 2.0)
|
||||
multi_test (>= 0.0.2)
|
||||
diff-lcs (1.2.4)
|
||||
gherkin (2.12.1)
|
||||
multi_json (~> 1.3)
|
||||
multi_json (1.8.0)
|
||||
multi_test (0.0.2)
|
||||
osmlib-base (0.1.4)
|
||||
rake (10.1.0)
|
||||
rspec-expectations (2.14.3)
|
||||
diff-lcs (>= 1.1.3, < 2.0)
|
||||
sys-proctable (0.9.3)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
cucumber
|
||||
osmlib-base
|
||||
rake
|
||||
rspec-expectations
|
||||
sys-proctable
|
||||
@@ -1,113 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef FIXED_POINT_COORDINATE_H_
|
||||
#define FIXED_POINT_COORDINATE_H_
|
||||
|
||||
#include <iosfwd> //for std::ostream
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr float COORDINATE_PRECISION = 1000000.f;
|
||||
}
|
||||
struct FixedPointCoordinate
|
||||
{
|
||||
int lat;
|
||||
int lon;
|
||||
|
||||
FixedPointCoordinate();
|
||||
FixedPointCoordinate(int lat, int lon);
|
||||
|
||||
template<class T>
|
||||
FixedPointCoordinate(const T &coordinate) : lat(coordinate.lat), lon(coordinate.lon)
|
||||
{
|
||||
static_assert(std::is_same<decltype(lat), decltype(coordinate.lat)>::value, "coordinate types incompatible");
|
||||
static_assert(std::is_same<decltype(lon), decltype(coordinate.lon)>::value, "coordinate types incompatible");
|
||||
}
|
||||
|
||||
void Reset();
|
||||
bool isSet() const;
|
||||
bool is_valid() const;
|
||||
bool operator==(const FixedPointCoordinate &other) const;
|
||||
|
||||
static double
|
||||
ApproximateDistance(const int lat1, const int lon1, const int lat2, const int lon2);
|
||||
|
||||
static double ApproximateDistance(const FixedPointCoordinate &first_coordinate,
|
||||
const FixedPointCoordinate &second_coordinate);
|
||||
|
||||
static float ApproximateEuclideanDistance(const FixedPointCoordinate &first_coordinate,
|
||||
const FixedPointCoordinate &second_coordinate);
|
||||
|
||||
static float
|
||||
ApproximateEuclideanDistance(const int lat1, const int lon1, const int lat2, const int lon2);
|
||||
|
||||
static float ApproximateSquaredEuclideanDistance(const FixedPointCoordinate &first_coordinate,
|
||||
const FixedPointCoordinate &second_coordinate);
|
||||
|
||||
static void convertInternalLatLonToString(const int value, std::string &output);
|
||||
|
||||
static void convertInternalCoordinateToString(const FixedPointCoordinate &coordinate,
|
||||
std::string &output);
|
||||
|
||||
static void convertInternalReversedCoordinateToString(const FixedPointCoordinate &coordinate,
|
||||
std::string &output);
|
||||
|
||||
static float ComputePerpendicularDistance(const FixedPointCoordinate &segment_source,
|
||||
const FixedPointCoordinate &segment_target,
|
||||
const FixedPointCoordinate &query_location);
|
||||
|
||||
static float ComputePerpendicularDistance(const FixedPointCoordinate &segment_source,
|
||||
const FixedPointCoordinate &segment_target,
|
||||
const FixedPointCoordinate &query_location,
|
||||
FixedPointCoordinate &nearest_location,
|
||||
float &ratio);
|
||||
|
||||
static int
|
||||
OrderedPerpendicularDistanceApproximation(const FixedPointCoordinate &segment_source,
|
||||
const FixedPointCoordinate &segment_target,
|
||||
const FixedPointCoordinate &query_location);
|
||||
|
||||
static float GetBearing(const FixedPointCoordinate &A, const FixedPointCoordinate &B);
|
||||
|
||||
float GetBearing(const FixedPointCoordinate &other) const;
|
||||
|
||||
void Output(std::ostream &out) const;
|
||||
|
||||
static float DegreeToRadian(const float degree);
|
||||
static float RadianToDegree(const float radian);
|
||||
};
|
||||
|
||||
inline std::ostream &operator<<(std::ostream &out_stream, FixedPointCoordinate const &coordinate)
|
||||
{
|
||||
coordinate.Output(out_stream);
|
||||
return out_stream;
|
||||
}
|
||||
|
||||
#endif /* FIXED_POINT_COORDINATE_H_ */
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef HTTP_HEADER_H
|
||||
#define HTTP_HEADER_H
|
||||
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
namespace http
|
||||
{
|
||||
struct Header
|
||||
{
|
||||
Header& operator=(const Header& other) = default;
|
||||
Header(const std::string & name, const std::string & value) : name(name), value(value) {}
|
||||
Header(Header && other) : name(std::move(other.name)), value(std::move(other.value)) {}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
name.clear();
|
||||
value.clear();
|
||||
}
|
||||
|
||||
std::string name;
|
||||
std::string value;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // HTTP_HEADER_H
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef REPLY_H
|
||||
#define REPLY_H
|
||||
|
||||
#include "Header.h"
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace http
|
||||
{
|
||||
|
||||
const char okHTML[] = "";
|
||||
const char badRequestHTML[] = "{\"status\": 400,\"status_message\":\"Bad Request\"}";
|
||||
const char internalServerErrorHTML[] =
|
||||
"{\"status\": 500,\"status_message\":\"Internal Server Error\"}";
|
||||
const char seperators[] = {':', ' '};
|
||||
const char crlf[] = {'\r', '\n'};
|
||||
const std::string okString = "HTTP/1.0 200 OK\r\n";
|
||||
const std::string badRequestString = "HTTP/1.0 400 Bad Request\r\n";
|
||||
const std::string internalServerErrorString = "HTTP/1.0 500 Internal Server Error\r\n";
|
||||
|
||||
class Reply
|
||||
{
|
||||
public:
|
||||
enum status_type
|
||||
{ ok = 200,
|
||||
badRequest = 400,
|
||||
internalServerError = 500 } status;
|
||||
|
||||
std::vector<Header> headers;
|
||||
std::vector<boost::asio::const_buffer> ToBuffers();
|
||||
std::vector<boost::asio::const_buffer> HeaderstoBuffers();
|
||||
std::vector<char> content;
|
||||
static Reply StockReply(status_type status);
|
||||
void SetSize(const unsigned size);
|
||||
void SetUncompressedSize();
|
||||
|
||||
Reply();
|
||||
|
||||
private:
|
||||
std::string ToString(Reply::status_type status);
|
||||
boost::asio::const_buffer ToBuffer(Reply::status_type status);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // REPLY_H
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef ROUTE_PARAMETERS_H
|
||||
#define ROUTE_PARAMETERS_H
|
||||
|
||||
#include <osrm/Coordinate.h>
|
||||
|
||||
#include <boost/fusion/container/vector/vector_fwd.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct RouteParameters
|
||||
{
|
||||
RouteParameters();
|
||||
|
||||
void setZoomLevel(const short level);
|
||||
|
||||
void setNumberOfResults(const short number);
|
||||
|
||||
void setAlternateRouteFlag(const bool flag);
|
||||
|
||||
void setUTurn(const bool flag);
|
||||
|
||||
void setAllUTurns(const bool flag);
|
||||
|
||||
void setDeprecatedAPIFlag(const std::string &);
|
||||
|
||||
void setChecksum(const unsigned check_sum);
|
||||
|
||||
void setInstructionFlag(const bool flag);
|
||||
|
||||
void setService(const std::string &service);
|
||||
|
||||
void setOutputFormat(const std::string &format);
|
||||
|
||||
void setJSONpParameter(const std::string ¶meter);
|
||||
|
||||
void addHint(const std::string &hint);
|
||||
|
||||
void setLanguage(const std::string &language);
|
||||
|
||||
void setGeometryFlag(const bool flag);
|
||||
|
||||
void setCompressionFlag(const bool flag);
|
||||
|
||||
void addCoordinate(const boost::fusion::vector<double, double> &coordinates);
|
||||
|
||||
short zoom_level;
|
||||
bool print_instructions;
|
||||
bool alternate_route;
|
||||
bool geometry;
|
||||
bool compression;
|
||||
bool deprecatedAPI;
|
||||
bool uturn_default;
|
||||
unsigned check_sum;
|
||||
short num_results;
|
||||
std::string service;
|
||||
std::string output_format;
|
||||
std::string jsonp_parameter;
|
||||
std::string language;
|
||||
std::vector<std::string> hints;
|
||||
std::vector<bool> uturns;
|
||||
std::vector<FixedPointCoordinate> coordinates;
|
||||
};
|
||||
|
||||
#endif // ROUTE_PARAMETERS_H
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef SERVER_PATH_H
|
||||
#define SERVER_PATH_H
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
|
||||
typedef std::unordered_map<std::string, boost::filesystem::path> ServerPaths;
|
||||
|
||||
#endif // SERVER_PATH_H
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef OSRM_H
|
||||
#define OSRM_H
|
||||
|
||||
#include <osrm/ServerPaths.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
class OSRM_impl;
|
||||
struct RouteParameters;
|
||||
|
||||
namespace http
|
||||
{
|
||||
class Reply;
|
||||
}
|
||||
|
||||
class OSRM
|
||||
{
|
||||
private:
|
||||
std::unique_ptr<OSRM_impl> OSRM_pimpl_;
|
||||
|
||||
public:
|
||||
explicit OSRM(ServerPaths paths, const bool use_shared_memory = false);
|
||||
~OSRM();
|
||||
void RunQuery(RouteParameters &route_parameters, http::Reply &reply);
|
||||
};
|
||||
|
||||
#endif // OSRM_H
|
||||
@@ -1,165 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
namespace boost { namespace interprocess { class named_mutex; } }
|
||||
|
||||
#include "OSRM_impl.h"
|
||||
#include "OSRM.h"
|
||||
|
||||
#include <osrm/Reply.h>
|
||||
#include <osrm/RouteParameters.h>
|
||||
#include <osrm/ServerPaths.h>
|
||||
|
||||
#include "../plugins/distance_table.hpp"
|
||||
#include "../plugins/hello_world.hpp"
|
||||
#include "../plugins/locate.hpp"
|
||||
#include "../plugins/nearest.hpp"
|
||||
#include "../plugins/timestamp.hpp"
|
||||
#include "../plugins/viaroute.hpp"
|
||||
#include "../Server/DataStructures/BaseDataFacade.h"
|
||||
#include "../Server/DataStructures/InternalDataFacade.h"
|
||||
#include "../Server/DataStructures/SharedBarriers.h"
|
||||
#include "../Server/DataStructures/SharedDataFacade.h"
|
||||
#include "../Util/make_unique.hpp"
|
||||
#include "../Util/ProgramOptions.h"
|
||||
#include "../Util/simple_logger.hpp"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/interprocess/sync/named_condition.hpp>
|
||||
#include <boost/interprocess/sync/scoped_lock.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
OSRM_impl::OSRM_impl(ServerPaths server_paths, const bool use_shared_memory)
|
||||
{
|
||||
if (use_shared_memory)
|
||||
{
|
||||
barrier = osrm::make_unique<SharedBarriers>();
|
||||
query_data_facade = new SharedDataFacade<QueryEdge::EdgeData>();
|
||||
}
|
||||
else
|
||||
{
|
||||
// populate base path
|
||||
populate_base_path(server_paths);
|
||||
query_data_facade = new InternalDataFacade<QueryEdge::EdgeData>(server_paths);
|
||||
}
|
||||
|
||||
// The following plugins handle all requests.
|
||||
RegisterPlugin(new DistanceTablePlugin<BaseDataFacade<QueryEdge::EdgeData>>(query_data_facade));
|
||||
RegisterPlugin(new HelloWorldPlugin());
|
||||
RegisterPlugin(new LocatePlugin<BaseDataFacade<QueryEdge::EdgeData>>(query_data_facade));
|
||||
RegisterPlugin(new NearestPlugin<BaseDataFacade<QueryEdge::EdgeData>>(query_data_facade));
|
||||
RegisterPlugin(new TimestampPlugin<BaseDataFacade<QueryEdge::EdgeData>>(query_data_facade));
|
||||
RegisterPlugin(new ViaRoutePlugin<BaseDataFacade<QueryEdge::EdgeData>>(query_data_facade));
|
||||
}
|
||||
|
||||
OSRM_impl::~OSRM_impl()
|
||||
{
|
||||
delete query_data_facade;
|
||||
for (PluginMap::value_type &plugin_pointer : plugin_map)
|
||||
{
|
||||
delete plugin_pointer.second;
|
||||
}
|
||||
}
|
||||
|
||||
void OSRM_impl::RegisterPlugin(BasePlugin *plugin)
|
||||
{
|
||||
SimpleLogger().Write() << "loaded plugin: " << plugin->GetDescriptor();
|
||||
if (plugin_map.find(plugin->GetDescriptor()) != plugin_map.end())
|
||||
{
|
||||
delete plugin_map.find(plugin->GetDescriptor())->second;
|
||||
}
|
||||
plugin_map.emplace(plugin->GetDescriptor(), plugin);
|
||||
}
|
||||
|
||||
void OSRM_impl::RunQuery(RouteParameters &route_parameters, http::Reply &reply)
|
||||
{
|
||||
const PluginMap::const_iterator &iter = plugin_map.find(route_parameters.service);
|
||||
|
||||
if (plugin_map.end() != iter)
|
||||
{
|
||||
reply.status = http::Reply::ok;
|
||||
if (barrier)
|
||||
{
|
||||
// lock update pending
|
||||
boost::interprocess::scoped_lock<boost::interprocess::named_mutex> pending_lock(
|
||||
barrier->pending_update_mutex);
|
||||
|
||||
// lock query
|
||||
boost::interprocess::scoped_lock<boost::interprocess::named_mutex> query_lock(
|
||||
barrier->query_mutex);
|
||||
|
||||
// unlock update pending
|
||||
pending_lock.unlock();
|
||||
|
||||
// increment query count
|
||||
++(barrier->number_of_queries);
|
||||
|
||||
(static_cast<SharedDataFacade<QueryEdge::EdgeData> *>(query_data_facade))
|
||||
->CheckAndReloadFacade();
|
||||
}
|
||||
|
||||
iter->second->HandleRequest(route_parameters, reply);
|
||||
if (barrier)
|
||||
{
|
||||
// lock query
|
||||
boost::interprocess::scoped_lock<boost::interprocess::named_mutex> query_lock(
|
||||
barrier->query_mutex);
|
||||
|
||||
// decrement query count
|
||||
--(barrier->number_of_queries);
|
||||
BOOST_ASSERT_MSG(0 <= barrier->number_of_queries, "invalid number of queries");
|
||||
|
||||
// notify all processes that were waiting for this condition
|
||||
if (0 == barrier->number_of_queries)
|
||||
{
|
||||
barrier->no_running_queries_condition.notify_all();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
reply = http::Reply::StockReply(http::Reply::badRequest);
|
||||
}
|
||||
}
|
||||
|
||||
// proxy code for compilation firewall
|
||||
|
||||
OSRM::OSRM(ServerPaths paths, const bool use_shared_memory)
|
||||
: OSRM_pimpl_(osrm::make_unique<OSRM_impl>(paths, use_shared_memory))
|
||||
{
|
||||
}
|
||||
|
||||
OSRM::~OSRM() { OSRM_pimpl_.reset(); }
|
||||
|
||||
void OSRM::RunQuery(RouteParameters &route_parameters, http::Reply &reply)
|
||||
{
|
||||
OSRM_pimpl_->RunQuery(route_parameters, reply);
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef OSRM_IMPL_H
|
||||
#define OSRM_IMPL_H
|
||||
|
||||
class BasePlugin;
|
||||
namespace http { class Reply; }
|
||||
struct RouteParameters;
|
||||
|
||||
#include <osrm/ServerPaths.h>
|
||||
|
||||
#include "../data_structures/query_edge.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
|
||||
struct SharedBarriers;
|
||||
template <class EdgeDataT> class BaseDataFacade;
|
||||
|
||||
class OSRM_impl
|
||||
{
|
||||
private:
|
||||
using PluginMap = std::unordered_map<std::string, BasePlugin *>;
|
||||
|
||||
public:
|
||||
OSRM_impl(ServerPaths paths, const bool use_shared_memory);
|
||||
OSRM_impl(const OSRM_impl &) = delete;
|
||||
virtual ~OSRM_impl();
|
||||
void RunQuery(RouteParameters &route_parameters, http::Reply &reply);
|
||||
|
||||
private:
|
||||
void RegisterPlugin(BasePlugin *plugin);
|
||||
PluginMap plugin_map;
|
||||
// will only be initialized if shared memory is used
|
||||
std::unique_ptr<SharedBarriers> barrier;
|
||||
// base class pointer to the objects
|
||||
BaseDataFacade<QueryEdge::EdgeData> *query_data_facade;
|
||||
};
|
||||
|
||||
#endif // OSRM_IMPL_H
|
||||
@@ -1,41 +1,72 @@
|
||||
# Readme
|
||||
Overview
|
||||
--------
|
||||
The repository provides a Leaflet [(1)] based web frontend to the Open Source Routing Machine (Project-OSRM [(2)]).
|
||||
The frontend is implemented in Javascript.
|
||||
Data is fetched from routing and geocoding servers using JSONP queries.
|
||||
The website is XHTML 1.0 Strict compliant.
|
||||
A deployed version of the the web frontend can be seen at [(3)].
|
||||
|
||||
For instructions on how to compile and run OSRM, please consult the Wiki at
|
||||
|
||||
https://github.com/Project-OSRM/osrm-backend/wiki
|
||||
Setup
|
||||
-----
|
||||
The frontend should work directly as provided.
|
||||
Several settings - including the URL for the routing server and the geocoder server - can be specified in `OSRM.config.js`.
|
||||
Different tile servers can be specified in `OSRM.Map.js`.
|
||||
Note that the URL shortener used for generating route links only works with URLs pointing to the official Project-OSRM website.
|
||||
|
||||
or use our free and daily updated online service at
|
||||
|
||||
http://map.project-osrm.org
|
||||
Branches
|
||||
--------
|
||||
* The `master` branch will always point to the latest released version of the frontend.
|
||||
* The `develop` branch should always point to a working version with new features and bugfixes (think of it as a nightly-build).
|
||||
* Other branches contain various work in progress.
|
||||
|
||||
## References in publications
|
||||
|
||||
When using the code in a (scientific) publication, please cite
|
||||
Bugtracking
|
||||
-----------
|
||||
Please use the OSRM-Project bug tracker [(4)] for submitting any bug reports or feature requests.
|
||||
|
||||
```
|
||||
@inproceedings{luxen-vetter-2011,
|
||||
author = {Luxen, Dennis and Vetter, Christian},
|
||||
title = {Real-time routing with OpenStreetMap data},
|
||||
booktitle = {Proceedings of the 19th ACM SIGSPATIAL International Conference on Advances in Geographic Information Systems},
|
||||
series = {GIS '11},
|
||||
year = {2011},
|
||||
isbn = {978-1-4503-1031-4},
|
||||
location = {Chicago, Illinois},
|
||||
pages = {513--516},
|
||||
numpages = {4},
|
||||
url = {http://doi.acm.org/10.1145/2093973.2094062},
|
||||
doi = {10.1145/2093973.2094062},
|
||||
acmid = {2094062},
|
||||
publisher = {ACM},
|
||||
address = {New York, NY, USA},
|
||||
}
|
||||
```
|
||||
|
||||
## Current build status
|
||||
Contribute
|
||||
----------
|
||||
If you like to contribute, simply fork the project and start coding.
|
||||
It is best practice to create a new branch (from the current master) with a descriptive name for your contributions.
|
||||
When you are done, send a pull request from that branch.
|
||||
With this workflow, each pull request is isolated and can be easily merged.
|
||||
|
||||
| build config | branch | status |
|
||||
|:-------------|:--------|:------------|
|
||||
| Linux | master | [](https://travis-ci.org/DennisOSRM/Project-OSRM) |
|
||||
| Linux | develop | [](https://travis-ci.org/DennisOSRM/Project-OSRM) |
|
||||
| Windows | master/develop | [](https://ci.appveyor.com/project/DennisOSRM/osrm-backend) |
|
||||
| LUAbind fork | master | [](https://travis-ci.org/DennisOSRM/luabind) |
|
||||
|
||||
Integration into Project-OSRM repository
|
||||
----------------------------------------
|
||||
The Project-OSRM repository already contains the frontend repository as a submodule.
|
||||
It will always point to the latest deployed version.
|
||||
To successfully work a repository that contains submodules, use the following git commands (available in git 1.7.1+):
|
||||
|
||||
* `git clone --recursive`
|
||||
to clone a repository and the contained submodules
|
||||
|
||||
* `git pull && git submodule update`
|
||||
to pull the latest version of the repository and update its submodules if required
|
||||
|
||||
Note that the frontend can also be checked out independently of the Project-OSRM repository.
|
||||
|
||||
|
||||
Compatibility
|
||||
-------------
|
||||
The frontend has been tested with Firefox 3.0+, Internet Explorer 8+ and Chrome 18+.
|
||||
Certain visuals like rounded corners or moving boxes will only show in newer browser versions.
|
||||
But no actual functionality is affected by this.
|
||||
Note that the frontend will not work with Internet Explorer 6 or 7.
|
||||
|
||||
|
||||
References
|
||||
----------
|
||||
[(1)] Cloudmade Leaflet: http://leaflet.cloudmade.com/
|
||||
[(2)] Project OSRM: http://project-osrm.org/
|
||||
[(3)] Project OSRM Frontend: http://map.project-osrm.org/
|
||||
[(4)] Project OSRM Bugtracker: https://github.com/DennisOSRM/Project-OSRM/issues/
|
||||
|
||||
|
||||
[(1)]: http://leaflet.cloudmade.com/ "Cloudmade Leaflet"
|
||||
[(2)]: http://project-osrm.org/ "Project OSRM"
|
||||
[(3)]: http://map.project-osrm.org/ "Project-OSRM Frontend"
|
||||
[(4)]: https://github.com/DennisOSRM/Project-OSRM/issues/ "Project-OSRM Bugtracker"
|
||||
@@ -1,190 +0,0 @@
|
||||
require 'OSM/StreamParser'
|
||||
require 'socket'
|
||||
require 'digest/sha1'
|
||||
require 'cucumber/rake/task'
|
||||
require 'sys/proctable'
|
||||
|
||||
BUILD_FOLDER = 'build'
|
||||
DATA_FOLDER = 'sandbox'
|
||||
PROFILE = 'bicycle'
|
||||
OSRM_PORT = 5000
|
||||
PROFILES_FOLDER = '../profiles'
|
||||
|
||||
Cucumber::Rake::Task.new do |t|
|
||||
t.cucumber_opts = %w{--format pretty}
|
||||
end
|
||||
|
||||
areas = {
|
||||
:kbh => { :country => 'denmark', :bbox => 'top=55.6972 left=12.5222 right=12.624 bottom=55.6376' },
|
||||
:frd => { :country => 'denmark', :bbox => 'top=55.7007 left=12.4765 bottom=55.6576 right=12.5698' },
|
||||
:regh => { :country => 'denmark', :bbox => 'top=56.164 left=11.792 bottom=55.403 right=12.731' },
|
||||
:denmark => { :country => 'denmark', :bbox => nil },
|
||||
:skaane => { :country => 'sweden', :bbox => 'top=56.55 left=12.4 bottom=55.3 right=14.6' }
|
||||
}
|
||||
|
||||
|
||||
|
||||
osm_data_area_name = ARGV[1] ? ARGV[1].to_s.to_sym : :kbh
|
||||
raise "Unknown data area." unless areas[osm_data_area_name]
|
||||
osm_data_country = areas[osm_data_area_name][:country]
|
||||
osm_data_area_bbox = areas[osm_data_area_name][:bbox]
|
||||
|
||||
|
||||
task osm_data_area_name.to_sym {} #define empty task to prevent rake from whining. will break if area has same name as a task
|
||||
|
||||
|
||||
def each_process name, &block
|
||||
Sys::ProcTable.ps do |process|
|
||||
if process.comm.strip == name.strip && process.state != 'zombie'
|
||||
yield process.pid.to_i, process.state.strip
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def up?
|
||||
find_pid('osrm-routed') != nil
|
||||
end
|
||||
|
||||
def find_pid name
|
||||
each_process(name) { |pid,state| return pid.to_i }
|
||||
return nil
|
||||
end
|
||||
|
||||
def wait_for_shutdown name
|
||||
timeout = 10
|
||||
(timeout*10).times do
|
||||
return if find_pid(name) == nil
|
||||
sleep 0.1
|
||||
end
|
||||
raise "*** Could not terminate #{name}."
|
||||
end
|
||||
|
||||
|
||||
desc "Rebuild and run tests."
|
||||
task :default => [:build]
|
||||
|
||||
desc "Build using CMake."
|
||||
task :build do
|
||||
if Dir.exists? BUILD_FOLDER
|
||||
Dir.chdir BUILD_FOLDER do
|
||||
system "make"
|
||||
end
|
||||
else
|
||||
system "mkdir build; cd build; cmake ..; make"
|
||||
end
|
||||
end
|
||||
|
||||
desc "Setup config files."
|
||||
task :setup do
|
||||
end
|
||||
|
||||
desc "Download OSM data."
|
||||
task :download do
|
||||
Dir.mkdir "#{DATA_FOLDER}" unless File.exist? "#{DATA_FOLDER}"
|
||||
puts "Downloading..."
|
||||
puts "curl http://download.geofabrik.de/europe/#{osm_data_country}-latest.osm.pbf -o #{DATA_FOLDER}/#{osm_data_country}.osm.pbf"
|
||||
raise "Error while downloading data." unless system "curl http://download.geofabrik.de/europe/#{osm_data_country}-latest.osm.pbf -o #{DATA_FOLDER}/#{osm_data_country}.osm.pbf"
|
||||
if osm_data_area_bbox
|
||||
puts "Cropping and converting to protobuffer..."
|
||||
raise "Error while cropping data." unless system "osmosis --read-pbf file=#{DATA_FOLDER}/#{osm_data_country}.osm.pbf --bounding-box #{osm_data_area_bbox} --write-pbf file=#{DATA_FOLDER}/#{osm_data_area_name}.osm.pbf omitmetadata=true"
|
||||
end
|
||||
end
|
||||
|
||||
desc "Crop OSM data"
|
||||
task :crop do
|
||||
if osm_data_area_bbox
|
||||
raise "Error while cropping data." unless system "osmosis --read-pbf file=#{DATA_FOLDER}/#{osm_data_country}.osm.pbf --bounding-box #{osm_data_area_bbox} --write-pbf file=#{DATA_FOLDER}/#{osm_data_area_name}.osm.pbf omitmetadata=true"
|
||||
end
|
||||
end
|
||||
|
||||
desc "Reprocess OSM data."
|
||||
task :process => [:extract,:prepare] do
|
||||
end
|
||||
|
||||
desc "Extract OSM data."
|
||||
task :extract do
|
||||
Dir.chdir DATA_FOLDER do
|
||||
raise "Error while extracting data." unless system "../#{BUILD_FOLDER}/osrm-extract #{osm_data_area_name}.osm.pbf --profile ../profiles/#{PROFILE}.lua"
|
||||
end
|
||||
end
|
||||
|
||||
desc "Prepare OSM data."
|
||||
task :prepare do
|
||||
Dir.chdir DATA_FOLDER do
|
||||
raise "Error while preparing data." unless system "../#{BUILD_FOLDER}/osrm-prepare #{osm_data_area_name}.osrm --profile ../profiles/#{PROFILE}.lua"
|
||||
end
|
||||
end
|
||||
|
||||
desc "Delete preprocessing files."
|
||||
task :clean do
|
||||
File.delete *Dir.glob("#{DATA_FOLDER}/*.osrm")
|
||||
File.delete *Dir.glob("#{DATA_FOLDER}/*.osrm.*")
|
||||
end
|
||||
|
||||
desc "Run all cucumber test"
|
||||
task :test do
|
||||
system "cucumber"
|
||||
puts
|
||||
end
|
||||
|
||||
desc "Run the routing server in the terminal. Press Ctrl-C to stop."
|
||||
task :run do
|
||||
Dir.chdir DATA_FOLDER do
|
||||
system "../#{BUILD_FOLDER}/osrm-routed #{osm_data_area_name}.osrm --port #{OSRM_PORT}"
|
||||
end
|
||||
end
|
||||
|
||||
desc "Launch the routing server in the background. Use rake:down to stop it."
|
||||
task :up do
|
||||
Dir.chdir DATA_FOLDER do
|
||||
abort("Already up.") if up?
|
||||
pipe = IO.popen("../#{BUILD_FOLDER}/osrm-routed #{osm_data_area_name}.osrm --port #{OSRM_PORT} 1>>osrm-routed.log 2>>osrm-routed.log")
|
||||
timeout = 5
|
||||
(timeout*10).times do
|
||||
begin
|
||||
socket = TCPSocket.new('localhost', OSRM_PORT)
|
||||
socket.puts 'ping'
|
||||
rescue Errno::ECONNREFUSED
|
||||
sleep 0.1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
desc "Stop the routing server."
|
||||
task :down do
|
||||
pid = find_pid 'osrm-routed'
|
||||
if pid
|
||||
Process.kill 'TERM', pid
|
||||
else
|
||||
puts "Already down."
|
||||
end
|
||||
end
|
||||
|
||||
desc "Kill all osrm-extract, osrm-prepare and osrm-routed processes."
|
||||
task :kill do
|
||||
each_process('osrm-routed') { |pid,state| Process.kill 'KILL', pid }
|
||||
each_process('osrm-prepare') { |pid,state| Process.kill 'KILL', pid }
|
||||
each_process('osrm-extract') { |pid,state| Process.kill 'KILL', pid }
|
||||
wait_for_shutdown 'osrm-routed'
|
||||
wait_for_shutdown 'osrm-prepare'
|
||||
wait_for_shutdown 'osrm-extract'
|
||||
end
|
||||
|
||||
desc "Get PIDs of all osrm-extract, osrm-prepare and osrm-routed processes."
|
||||
task :pid do
|
||||
each_process 'osrm-routed' do |pid,state|
|
||||
puts "#{pid}\t#{state}"
|
||||
end
|
||||
end
|
||||
|
||||
desc "Stop, reprocess and restart."
|
||||
task :update => [:down,:process,:up] do
|
||||
end
|
||||
|
||||
|
||||
desc "Remove test cache files."
|
||||
task :sweep do
|
||||
system "rm test/cache/*"
|
||||
end
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef APIGRAMMAR_H_
|
||||
#define APIGRAMMAR_H_
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/spirit/include/qi.hpp>
|
||||
#include <boost/spirit/include/qi_action.hpp>
|
||||
|
||||
namespace qi = boost::spirit::qi;
|
||||
|
||||
template <typename Iterator, class HandlerT>
|
||||
struct APIGrammar : qi::grammar<Iterator>
|
||||
{
|
||||
explicit APIGrammar(HandlerT * h) : APIGrammar::base_type(api_call), handler(h)
|
||||
{
|
||||
api_call = qi::lit('/') >> string[boost::bind(&HandlerT::setService, handler, ::_1)] >> *(query) >> -(uturns);
|
||||
query = ('?') >> (+(zoom | output | jsonp | checksum | location | hint | u | cmp | language | instruction | geometry | alt_route | old_API | num_results) ) ;
|
||||
|
||||
zoom = (-qi::lit('&')) >> qi::lit('z') >> '=' >> qi::short_[boost::bind(&HandlerT::setZoomLevel, handler, ::_1)];
|
||||
output = (-qi::lit('&')) >> qi::lit("output") >> '=' >> string[boost::bind(&HandlerT::setOutputFormat, handler, ::_1)];
|
||||
jsonp = (-qi::lit('&')) >> qi::lit("jsonp") >> '=' >> stringwithPercent[boost::bind(&HandlerT::setJSONpParameter, handler, ::_1)];
|
||||
checksum = (-qi::lit('&')) >> qi::lit("checksum") >> '=' >> qi::uint_[boost::bind(&HandlerT::setChecksum, handler, ::_1)];
|
||||
instruction = (-qi::lit('&')) >> qi::lit("instructions") >> '=' >> qi::bool_[boost::bind(&HandlerT::setInstructionFlag, handler, ::_1)];
|
||||
geometry = (-qi::lit('&')) >> qi::lit("geometry") >> '=' >> qi::bool_[boost::bind(&HandlerT::setGeometryFlag, handler, ::_1)];
|
||||
cmp = (-qi::lit('&')) >> qi::lit("compression") >> '=' >> qi::bool_[boost::bind(&HandlerT::setCompressionFlag, handler, ::_1)];
|
||||
location = (-qi::lit('&')) >> qi::lit("loc") >> '=' >> (qi::double_ >> qi::lit(',') >> qi::double_)[boost::bind(&HandlerT::addCoordinate, handler, ::_1)];
|
||||
hint = (-qi::lit('&')) >> qi::lit("hint") >> '=' >> stringwithDot[boost::bind(&HandlerT::addHint, handler, ::_1)];
|
||||
u = (-qi::lit('&')) >> qi::lit("u") >> '=' >> qi::bool_[boost::bind(&HandlerT::setUTurn, handler, ::_1)];
|
||||
uturns = (-qi::lit('&')) >> qi::lit("uturns") >> '=' >> qi::bool_[boost::bind(&HandlerT::setAllUTurns, handler, ::_1)];
|
||||
language = (-qi::lit('&')) >> qi::lit("hl") >> '=' >> string[boost::bind(&HandlerT::setLanguage, handler, ::_1)];
|
||||
alt_route = (-qi::lit('&')) >> qi::lit("alt") >> '=' >> qi::bool_[boost::bind(&HandlerT::setAlternateRouteFlag, handler, ::_1)];
|
||||
old_API = (-qi::lit('&')) >> qi::lit("geomformat") >> '=' >> string[boost::bind(&HandlerT::setDeprecatedAPIFlag, handler, ::_1)];
|
||||
num_results = (-qi::lit('&')) >> qi::lit("num_results") >> '=' >> qi::short_[boost::bind(&HandlerT::setNumberOfResults, handler, ::_1)];
|
||||
|
||||
string = +(qi::char_("a-zA-Z"));
|
||||
stringwithDot = +(qi::char_("a-zA-Z0-9_.-"));
|
||||
stringwithPercent = +(qi::char_("a-zA-Z0-9_.-") | qi::char_('[') | qi::char_(']') | (qi::char_('%') >> qi::char_("0-9A-Z") >> qi::char_("0-9A-Z") ));
|
||||
}
|
||||
|
||||
qi::rule<Iterator> api_call, query;
|
||||
qi::rule<Iterator, std::string()> service, zoom, output, string, jsonp, checksum, location, hint,
|
||||
stringwithDot, stringwithPercent, language, instruction, geometry,
|
||||
cmp, alt_route, u, uturns, old_API, num_results;
|
||||
|
||||
HandlerT * handler;
|
||||
};
|
||||
|
||||
#endif /* APIGRAMMAR_H_ */
|
||||
@@ -1,174 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "Connection.h"
|
||||
#include "RequestHandler.h"
|
||||
#include "RequestParser.h"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/iostreams/filtering_stream.hpp>
|
||||
#include <boost/iostreams/filter/gzip.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace http
|
||||
{
|
||||
|
||||
Connection::Connection(boost::asio::io_service &io_service, RequestHandler &handler)
|
||||
: strand(io_service), TCP_socket(io_service), request_handler(handler)
|
||||
{
|
||||
}
|
||||
|
||||
boost::asio::ip::tcp::socket &Connection::socket() { return TCP_socket; }
|
||||
|
||||
/// Start the first asynchronous operation for the connection.
|
||||
void Connection::start()
|
||||
{
|
||||
TCP_socket.async_read_some(
|
||||
boost::asio::buffer(incoming_data_buffer),
|
||||
strand.wrap(boost::bind(&Connection::handle_read,
|
||||
this->shared_from_this(),
|
||||
boost::asio::placeholders::error,
|
||||
boost::asio::placeholders::bytes_transferred)));
|
||||
}
|
||||
|
||||
void Connection::handle_read(const boost::system::error_code &error, std::size_t bytes_transferred)
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// no error detected, let's parse the request
|
||||
CompressionType compression_type(noCompression);
|
||||
boost::tribool result;
|
||||
boost::tie(result, boost::tuples::ignore) =
|
||||
RequestParser().Parse(request,
|
||||
incoming_data_buffer.data(),
|
||||
incoming_data_buffer.data() + bytes_transferred,
|
||||
compression_type);
|
||||
|
||||
// the request has been parsed
|
||||
if (result)
|
||||
{
|
||||
request.endpoint = TCP_socket.remote_endpoint().address();
|
||||
request_handler.handle_request(request, reply);
|
||||
|
||||
// Header compression_header;
|
||||
std::vector<char> compressed_output;
|
||||
std::vector<boost::asio::const_buffer> output_buffer;
|
||||
|
||||
// compress the result w/ gzip/deflate if requested
|
||||
switch (compression_type)
|
||||
{
|
||||
case deflateRFC1951:
|
||||
// use deflate for compression
|
||||
reply.headers.insert(reply.headers.begin(), {"Content-Encoding", "deflate"});
|
||||
CompressBufferCollection(reply.content, compression_type, compressed_output);
|
||||
reply.SetSize(static_cast<unsigned>(compressed_output.size()));
|
||||
output_buffer = reply.HeaderstoBuffers();
|
||||
output_buffer.push_back(boost::asio::buffer(compressed_output));
|
||||
break;
|
||||
case gzipRFC1952:
|
||||
// use gzip for compression
|
||||
reply.headers.insert(reply.headers.begin(), {"Content-Encoding", "gzip"});
|
||||
CompressBufferCollection(reply.content, compression_type, compressed_output);
|
||||
reply.SetSize(static_cast<unsigned>(compressed_output.size()));
|
||||
output_buffer = reply.HeaderstoBuffers();
|
||||
output_buffer.push_back(boost::asio::buffer(compressed_output));
|
||||
break;
|
||||
case noCompression:
|
||||
// don't use any compression
|
||||
reply.SetUncompressedSize();
|
||||
output_buffer = reply.ToBuffers();
|
||||
break;
|
||||
}
|
||||
// write result to stream
|
||||
boost::asio::async_write(TCP_socket,
|
||||
output_buffer,
|
||||
strand.wrap(boost::bind(&Connection::handle_write,
|
||||
this->shared_from_this(),
|
||||
boost::asio::placeholders::error)));
|
||||
}
|
||||
else if (!result)
|
||||
{ // request is not parseable
|
||||
reply = Reply::StockReply(Reply::badRequest);
|
||||
|
||||
boost::asio::async_write(TCP_socket,
|
||||
reply.ToBuffers(),
|
||||
strand.wrap(boost::bind(&Connection::handle_write,
|
||||
this->shared_from_this(),
|
||||
boost::asio::placeholders::error)));
|
||||
}
|
||||
else
|
||||
{
|
||||
// we don't have a result yet, so continue reading
|
||||
TCP_socket.async_read_some(
|
||||
boost::asio::buffer(incoming_data_buffer),
|
||||
strand.wrap(boost::bind(&Connection::handle_read,
|
||||
this->shared_from_this(),
|
||||
boost::asio::placeholders::error,
|
||||
boost::asio::placeholders::bytes_transferred)));
|
||||
}
|
||||
}
|
||||
|
||||
/// Handle completion of a write operation.
|
||||
void Connection::handle_write(const boost::system::error_code &error)
|
||||
{
|
||||
if (!error)
|
||||
{
|
||||
// Initiate graceful connection closure.
|
||||
boost::system::error_code ignore_error;
|
||||
TCP_socket.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignore_error);
|
||||
}
|
||||
}
|
||||
|
||||
void Connection::CompressBufferCollection(std::vector<char> uncompressed_data,
|
||||
CompressionType compression_type,
|
||||
std::vector<char> &compressed_data)
|
||||
{
|
||||
boost::iostreams::gzip_params compression_parameters;
|
||||
|
||||
// there's a trade-off between speed and size. speed wins
|
||||
compression_parameters.level = boost::iostreams::zlib::best_speed;
|
||||
// check which compression flavor is used
|
||||
if (deflateRFC1951 == compression_type)
|
||||
{
|
||||
compression_parameters.noheader = true;
|
||||
}
|
||||
|
||||
BOOST_ASSERT(compressed_data.empty());
|
||||
// plug data into boost's compression stream
|
||||
boost::iostreams::filtering_ostream gzip_stream;
|
||||
gzip_stream.push(boost::iostreams::gzip_compressor(compression_parameters));
|
||||
gzip_stream.push(boost::iostreams::back_inserter(compressed_data));
|
||||
gzip_stream.write(&uncompressed_data[0], uncompressed_data.size());
|
||||
boost::iostreams::close(gzip_stream);
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef CONNECTION_H
|
||||
#define CONNECTION_H
|
||||
|
||||
// #include "RequestParser.h"
|
||||
#include "Http/CompressionType.h"
|
||||
#include "Http/Request.h"
|
||||
|
||||
#include <osrm/Reply.h>
|
||||
|
||||
#include <boost/array.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/version.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
//workaround for incomplete std::shared_ptr compatibility in old boost versions
|
||||
#if BOOST_VERSION < 105300 || defined BOOST_NO_CXX11_SMART_PTR
|
||||
|
||||
namespace boost {
|
||||
template<class T>
|
||||
const T* get_pointer(std::shared_ptr<T> const& p)
|
||||
{
|
||||
return p.get();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T* get_pointer(std::shared_ptr<T>& p)
|
||||
{
|
||||
return p.get();
|
||||
}
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
class RequestHandler;
|
||||
|
||||
namespace http
|
||||
{
|
||||
|
||||
/// Represents a single connection from a client.
|
||||
class Connection : public std::enable_shared_from_this<Connection>
|
||||
{
|
||||
public:
|
||||
explicit Connection(boost::asio::io_service &io_service, RequestHandler &handler);
|
||||
Connection(const Connection &) = delete;
|
||||
Connection() = delete;
|
||||
|
||||
boost::asio::ip::tcp::socket &socket();
|
||||
|
||||
/// Start the first asynchronous operation for the connection.
|
||||
void start();
|
||||
|
||||
private:
|
||||
void handle_read(const boost::system::error_code &e, std::size_t bytes_transferred);
|
||||
|
||||
/// Handle completion of a write operation.
|
||||
void handle_write(const boost::system::error_code &e);
|
||||
|
||||
void CompressBufferCollection(std::vector<char> uncompressed_data,
|
||||
CompressionType compression_type,
|
||||
std::vector<char> &compressed_data);
|
||||
|
||||
boost::asio::io_service::strand strand;
|
||||
boost::asio::ip::tcp::socket TCP_socket;
|
||||
RequestHandler &request_handler;
|
||||
boost::array<char, 8192> incoming_data_buffer;
|
||||
Request request;
|
||||
Reply reply;
|
||||
};
|
||||
|
||||
} // namespace http
|
||||
|
||||
#endif // CONNECTION_H
|
||||
@@ -1,126 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef BASE_DATA_FACADE_H
|
||||
#define BASE_DATA_FACADE_H
|
||||
|
||||
// Exposes all data access interfaces to the algorithms via base class ptr
|
||||
|
||||
#include "../../data_structures/edge_based_node.hpp"
|
||||
#include "../../data_structures/external_memory_node.hpp"
|
||||
#include "../../data_structures/phantom_node.hpp"
|
||||
#include "../../data_structures/turn_instructions.hpp"
|
||||
#include "../../Util/integer_range.hpp"
|
||||
#include "../../Util/osrm_exception.hpp"
|
||||
#include "../../Util/string_util.hpp"
|
||||
#include "../../typedefs.h"
|
||||
|
||||
#include <osrm/Coordinate.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
typedef osrm::range<EdgeID> EdgeRange;
|
||||
|
||||
template <class EdgeDataT> class BaseDataFacade
|
||||
{
|
||||
public:
|
||||
typedef EdgeBasedNode RTreeLeaf;
|
||||
typedef EdgeDataT EdgeData;
|
||||
BaseDataFacade() {}
|
||||
virtual ~BaseDataFacade() {}
|
||||
|
||||
// search graph access
|
||||
virtual unsigned GetNumberOfNodes() const = 0;
|
||||
|
||||
virtual unsigned GetNumberOfEdges() const = 0;
|
||||
|
||||
virtual unsigned GetOutDegree(const NodeID n) const = 0;
|
||||
|
||||
virtual NodeID GetTarget(const EdgeID e) const = 0;
|
||||
|
||||
// virtual EdgeDataT &GetEdgeData(const EdgeID e) = 0;
|
||||
|
||||
virtual const EdgeDataT &GetEdgeData(const EdgeID e) const = 0;
|
||||
|
||||
virtual EdgeID BeginEdges(const NodeID n) const = 0;
|
||||
|
||||
virtual EdgeID EndEdges(const NodeID n) const = 0;
|
||||
|
||||
virtual EdgeRange GetAdjacentEdgeRange(const NodeID node) const = 0;
|
||||
|
||||
// searches for a specific edge
|
||||
virtual EdgeID FindEdge(const NodeID from, const NodeID to) const = 0;
|
||||
|
||||
virtual EdgeID FindEdgeInEitherDirection(const NodeID from, const NodeID to) const = 0;
|
||||
|
||||
virtual EdgeID
|
||||
FindEdgeIndicateIfReverse(const NodeID from, const NodeID to, bool &result) const = 0;
|
||||
|
||||
// node and edge information access
|
||||
virtual FixedPointCoordinate GetCoordinateOfNode(const unsigned id) const = 0;
|
||||
|
||||
virtual bool EdgeIsCompressed(const unsigned id) const = 0;
|
||||
|
||||
virtual unsigned GetGeometryIndexForEdgeID(const unsigned id) const = 0;
|
||||
|
||||
virtual void GetUncompressedGeometry(const unsigned id,
|
||||
std::vector<unsigned> &result_nodes) const = 0;
|
||||
|
||||
virtual TurnInstruction GetTurnInstructionForEdgeID(const unsigned id) const = 0;
|
||||
|
||||
virtual TravelMode GetTravelModeForEdgeID(const unsigned id) const = 0;
|
||||
|
||||
virtual bool LocateClosestEndPointForCoordinate(const FixedPointCoordinate &input_coordinate,
|
||||
FixedPointCoordinate &result,
|
||||
const unsigned zoom_level = 18) = 0;
|
||||
|
||||
virtual bool
|
||||
IncrementalFindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate,
|
||||
std::vector<PhantomNode> &resulting_phantom_node_vector,
|
||||
const unsigned number_of_results) = 0;
|
||||
|
||||
virtual bool
|
||||
IncrementalFindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate,
|
||||
PhantomNode &resulting_phantom_node) = 0;
|
||||
|
||||
virtual unsigned GetCheckSum() const = 0;
|
||||
|
||||
virtual unsigned GetNameIndexFromEdgeID(const unsigned id) const = 0;
|
||||
|
||||
virtual void GetName(const unsigned name_id, std::string &result) const = 0;
|
||||
|
||||
std::string GetEscapedNameForNameID(const unsigned name_id) const
|
||||
{
|
||||
std::string temporary_string;
|
||||
GetName(name_id, temporary_string);
|
||||
return EscapeJSONString(temporary_string);
|
||||
}
|
||||
|
||||
virtual std::string GetTimestamp() const = 0;
|
||||
};
|
||||
|
||||
#endif // BASE_DATA_FACADE_H
|
||||
@@ -1,455 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef INTERNAL_DATA_FACADE
|
||||
#define INTERNAL_DATA_FACADE
|
||||
|
||||
// implements all data storage when shared memory is _NOT_ used
|
||||
|
||||
#include "BaseDataFacade.h"
|
||||
|
||||
#include "../../data_structures/original_edge_data.hpp"
|
||||
#include "../../data_structures/query_node.hpp"
|
||||
#include "../../data_structures/query_edge.hpp"
|
||||
#include "../../data_structures/shared_memory_vector_wrapper.hpp"
|
||||
#include "../../data_structures/static_graph.hpp"
|
||||
#include "../../data_structures/static_rtree.hpp"
|
||||
#include "../../data_structures/range_table.hpp"
|
||||
#include "../../Util/BoostFileSystemFix.h"
|
||||
#include "../../Util/graph_loader.hpp"
|
||||
#include "../../Util/simple_logger.hpp"
|
||||
|
||||
#include <osrm/Coordinate.h>
|
||||
#include <osrm/ServerPaths.h>
|
||||
|
||||
template <class EdgeDataT> class InternalDataFacade : public BaseDataFacade<EdgeDataT>
|
||||
{
|
||||
|
||||
private:
|
||||
typedef BaseDataFacade<EdgeDataT> super;
|
||||
typedef StaticGraph<typename super::EdgeData> QueryGraph;
|
||||
typedef typename QueryGraph::InputEdge InputEdge;
|
||||
typedef typename super::RTreeLeaf RTreeLeaf;
|
||||
|
||||
InternalDataFacade() {}
|
||||
|
||||
unsigned m_check_sum;
|
||||
unsigned m_number_of_nodes;
|
||||
QueryGraph *m_query_graph;
|
||||
std::string m_timestamp;
|
||||
|
||||
std::shared_ptr<ShM<FixedPointCoordinate, false>::vector> m_coordinate_list;
|
||||
ShM<NodeID, false>::vector m_via_node_list;
|
||||
ShM<unsigned, false>::vector m_name_ID_list;
|
||||
ShM<TurnInstruction, false>::vector m_turn_instruction_list;
|
||||
ShM<TravelMode, false>::vector m_travel_mode_list;
|
||||
ShM<char, false>::vector m_names_char_list;
|
||||
ShM<bool, false>::vector m_edge_is_compressed;
|
||||
ShM<unsigned, false>::vector m_geometry_indices;
|
||||
ShM<unsigned, false>::vector m_geometry_list;
|
||||
|
||||
boost::thread_specific_ptr<
|
||||
StaticRTree<RTreeLeaf, ShM<FixedPointCoordinate, false>::vector, false>> m_static_rtree;
|
||||
boost::filesystem::path ram_index_path;
|
||||
boost::filesystem::path file_index_path;
|
||||
RangeTable<16, false> m_name_table;
|
||||
|
||||
void LoadTimestamp(const boost::filesystem::path ×tamp_path)
|
||||
{
|
||||
if (boost::filesystem::exists(timestamp_path))
|
||||
{
|
||||
SimpleLogger().Write() << "Loading Timestamp";
|
||||
boost::filesystem::ifstream timestamp_stream(timestamp_path);
|
||||
if (!timestamp_stream)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << timestamp_path << " not found";
|
||||
}
|
||||
getline(timestamp_stream, m_timestamp);
|
||||
timestamp_stream.close();
|
||||
}
|
||||
if (m_timestamp.empty())
|
||||
{
|
||||
m_timestamp = "n/a";
|
||||
}
|
||||
if (25 < m_timestamp.length())
|
||||
{
|
||||
m_timestamp.resize(25);
|
||||
}
|
||||
}
|
||||
|
||||
void LoadGraph(const boost::filesystem::path &hsgr_path)
|
||||
{
|
||||
typename ShM<typename QueryGraph::NodeArrayEntry, false>::vector node_list;
|
||||
typename ShM<typename QueryGraph::EdgeArrayEntry, false>::vector edge_list;
|
||||
|
||||
SimpleLogger().Write() << "loading graph from " << hsgr_path.string();
|
||||
|
||||
m_number_of_nodes = readHSGRFromStream(hsgr_path, node_list, edge_list, &m_check_sum);
|
||||
|
||||
BOOST_ASSERT_MSG(0 != node_list.size(), "node list empty");
|
||||
// BOOST_ASSERT_MSG(0 != edge_list.size(), "edge list empty");
|
||||
SimpleLogger().Write() << "loaded " << node_list.size() << " nodes and " << edge_list.size()
|
||||
<< " edges";
|
||||
m_query_graph = new QueryGraph(node_list, edge_list);
|
||||
|
||||
BOOST_ASSERT_MSG(0 == node_list.size(), "node list not flushed");
|
||||
BOOST_ASSERT_MSG(0 == edge_list.size(), "edge list not flushed");
|
||||
SimpleLogger().Write() << "Data checksum is " << m_check_sum;
|
||||
}
|
||||
|
||||
void LoadNodeAndEdgeInformation(const boost::filesystem::path &nodes_file,
|
||||
const boost::filesystem::path &edges_file)
|
||||
{
|
||||
boost::filesystem::ifstream nodes_input_stream(nodes_file, std::ios::binary);
|
||||
|
||||
QueryNode current_node;
|
||||
unsigned number_of_coordinates = 0;
|
||||
nodes_input_stream.read((char *)&number_of_coordinates, sizeof(unsigned));
|
||||
m_coordinate_list =
|
||||
std::make_shared<std::vector<FixedPointCoordinate>>(number_of_coordinates);
|
||||
for (unsigned i = 0; i < number_of_coordinates; ++i)
|
||||
{
|
||||
nodes_input_stream.read((char *)¤t_node, sizeof(QueryNode));
|
||||
m_coordinate_list->at(i) = FixedPointCoordinate(current_node.lat, current_node.lon);
|
||||
BOOST_ASSERT((std::abs(m_coordinate_list->at(i).lat) >> 30) == 0);
|
||||
BOOST_ASSERT((std::abs(m_coordinate_list->at(i).lon) >> 30) == 0);
|
||||
}
|
||||
nodes_input_stream.close();
|
||||
|
||||
boost::filesystem::ifstream edges_input_stream(edges_file, std::ios::binary);
|
||||
unsigned number_of_edges = 0;
|
||||
edges_input_stream.read((char *)&number_of_edges, sizeof(unsigned));
|
||||
m_via_node_list.resize(number_of_edges);
|
||||
m_name_ID_list.resize(number_of_edges);
|
||||
m_turn_instruction_list.resize(number_of_edges);
|
||||
m_travel_mode_list.resize(number_of_edges);
|
||||
m_edge_is_compressed.resize(number_of_edges);
|
||||
|
||||
unsigned compressed = 0;
|
||||
|
||||
OriginalEdgeData current_edge_data;
|
||||
for (unsigned i = 0; i < number_of_edges; ++i)
|
||||
{
|
||||
edges_input_stream.read((char *)&(current_edge_data), sizeof(OriginalEdgeData));
|
||||
m_via_node_list[i] = current_edge_data.via_node;
|
||||
m_name_ID_list[i] = current_edge_data.name_id;
|
||||
m_turn_instruction_list[i] = current_edge_data.turn_instruction;
|
||||
m_travel_mode_list[i] = current_edge_data.travel_mode;
|
||||
m_edge_is_compressed[i] = current_edge_data.compressed_geometry;
|
||||
if (m_edge_is_compressed[i])
|
||||
{
|
||||
++compressed;
|
||||
}
|
||||
}
|
||||
|
||||
edges_input_stream.close();
|
||||
}
|
||||
|
||||
void LoadGeometries(const boost::filesystem::path &geometry_file)
|
||||
{
|
||||
std::ifstream geometry_stream(geometry_file.string().c_str(), std::ios::binary);
|
||||
unsigned number_of_indices = 0;
|
||||
unsigned number_of_compressed_geometries = 0;
|
||||
|
||||
geometry_stream.read((char *)&number_of_indices, sizeof(unsigned));
|
||||
|
||||
m_geometry_indices.resize(number_of_indices);
|
||||
if (number_of_indices > 0)
|
||||
{
|
||||
geometry_stream.read((char *)&(m_geometry_indices[0]),
|
||||
number_of_indices * sizeof(unsigned));
|
||||
}
|
||||
|
||||
geometry_stream.read((char *)&number_of_compressed_geometries, sizeof(unsigned));
|
||||
|
||||
BOOST_ASSERT(m_geometry_indices.back() == number_of_compressed_geometries);
|
||||
m_geometry_list.resize(number_of_compressed_geometries);
|
||||
|
||||
if (number_of_compressed_geometries > 0)
|
||||
{
|
||||
geometry_stream.read((char *)&(m_geometry_list[0]),
|
||||
number_of_compressed_geometries * sizeof(unsigned));
|
||||
}
|
||||
geometry_stream.close();
|
||||
}
|
||||
|
||||
void LoadRTree()
|
||||
{
|
||||
BOOST_ASSERT_MSG(!m_coordinate_list->empty(), "coordinates must be loaded before r-tree");
|
||||
|
||||
m_static_rtree.reset(
|
||||
new StaticRTree<RTreeLeaf>(ram_index_path, file_index_path, m_coordinate_list));
|
||||
}
|
||||
|
||||
void LoadStreetNames(const boost::filesystem::path &names_file)
|
||||
{
|
||||
boost::filesystem::ifstream name_stream(names_file, std::ios::binary);
|
||||
|
||||
name_stream >> m_name_table;
|
||||
|
||||
unsigned number_of_chars = 0;
|
||||
name_stream.read((char *)&number_of_chars, sizeof(unsigned));
|
||||
BOOST_ASSERT_MSG(0 != number_of_chars, "name file broken");
|
||||
m_names_char_list.resize(number_of_chars + 1); //+1 gives sentinel element
|
||||
name_stream.read((char *)&m_names_char_list[0], number_of_chars * sizeof(char));
|
||||
if (0 == m_names_char_list.size())
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "list of street names is empty";
|
||||
}
|
||||
name_stream.close();
|
||||
}
|
||||
|
||||
public:
|
||||
virtual ~InternalDataFacade()
|
||||
{
|
||||
delete m_query_graph;
|
||||
m_static_rtree.reset();
|
||||
}
|
||||
|
||||
explicit InternalDataFacade(const ServerPaths &server_paths)
|
||||
{
|
||||
// generate paths of data files
|
||||
if (server_paths.find("hsgrdata") == server_paths.end())
|
||||
{
|
||||
throw osrm::exception("no hsgr file given in ini file");
|
||||
}
|
||||
if (server_paths.find("ramindex") == server_paths.end())
|
||||
{
|
||||
throw osrm::exception("no ram index file given in ini file");
|
||||
}
|
||||
if (server_paths.find("fileindex") == server_paths.end())
|
||||
{
|
||||
throw osrm::exception("no leaf index file given in ini file");
|
||||
}
|
||||
if (server_paths.find("geometries") == server_paths.end())
|
||||
{
|
||||
throw osrm::exception("no geometries file given in ini file");
|
||||
}
|
||||
if (server_paths.find("nodesdata") == server_paths.end())
|
||||
{
|
||||
throw osrm::exception("no nodes file given in ini file");
|
||||
}
|
||||
if (server_paths.find("edgesdata") == server_paths.end())
|
||||
{
|
||||
throw osrm::exception("no edges file given in ini file");
|
||||
}
|
||||
if (server_paths.find("namesdata") == server_paths.end())
|
||||
{
|
||||
throw osrm::exception("no names file given in ini file");
|
||||
}
|
||||
|
||||
ServerPaths::const_iterator paths_iterator = server_paths.find("hsgrdata");
|
||||
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
||||
const boost::filesystem::path &hsgr_path = paths_iterator->second;
|
||||
paths_iterator = server_paths.find("timestamp");
|
||||
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
||||
const boost::filesystem::path ×tamp_path = paths_iterator->second;
|
||||
paths_iterator = server_paths.find("ramindex");
|
||||
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
||||
ram_index_path = paths_iterator->second;
|
||||
paths_iterator = server_paths.find("fileindex");
|
||||
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
||||
file_index_path = paths_iterator->second;
|
||||
paths_iterator = server_paths.find("nodesdata");
|
||||
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
||||
const boost::filesystem::path &nodes_data_path = paths_iterator->second;
|
||||
paths_iterator = server_paths.find("edgesdata");
|
||||
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
||||
const boost::filesystem::path &edges_data_path = paths_iterator->second;
|
||||
paths_iterator = server_paths.find("namesdata");
|
||||
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
||||
const boost::filesystem::path &names_data_path = paths_iterator->second;
|
||||
paths_iterator = server_paths.find("geometries");
|
||||
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
||||
const boost::filesystem::path &geometries_path = paths_iterator->second;
|
||||
|
||||
// load data
|
||||
SimpleLogger().Write() << "loading graph data";
|
||||
AssertPathExists(hsgr_path);
|
||||
LoadGraph(hsgr_path);
|
||||
SimpleLogger().Write() << "loading edge information";
|
||||
AssertPathExists(nodes_data_path);
|
||||
AssertPathExists(edges_data_path);
|
||||
LoadNodeAndEdgeInformation(nodes_data_path, edges_data_path);
|
||||
SimpleLogger().Write() << "loading geometries";
|
||||
AssertPathExists(geometries_path);
|
||||
LoadGeometries(geometries_path);
|
||||
SimpleLogger().Write() << "loading r-tree";
|
||||
AssertPathExists(ram_index_path);
|
||||
AssertPathExists(file_index_path);
|
||||
SimpleLogger().Write() << "loading timestamp";
|
||||
LoadTimestamp(timestamp_path);
|
||||
SimpleLogger().Write() << "loading street names";
|
||||
AssertPathExists(names_data_path);
|
||||
LoadStreetNames(names_data_path);
|
||||
}
|
||||
|
||||
// search graph access
|
||||
unsigned GetNumberOfNodes() const final { return m_query_graph->GetNumberOfNodes(); }
|
||||
|
||||
unsigned GetNumberOfEdges() const final { return m_query_graph->GetNumberOfEdges(); }
|
||||
|
||||
unsigned GetOutDegree(const NodeID n) const final { return m_query_graph->GetOutDegree(n); }
|
||||
|
||||
NodeID GetTarget(const EdgeID e) const final { return m_query_graph->GetTarget(e); }
|
||||
|
||||
// EdgeDataT &GetEdgeData(const EdgeID e) final { return m_query_graph->GetEdgeData(e); }
|
||||
|
||||
EdgeDataT &GetEdgeData(const EdgeID e) const final { return m_query_graph->GetEdgeData(e); }
|
||||
|
||||
EdgeID BeginEdges(const NodeID n) const final { return m_query_graph->BeginEdges(n); }
|
||||
|
||||
EdgeID EndEdges(const NodeID n) const final { return m_query_graph->EndEdges(n); }
|
||||
|
||||
EdgeRange GetAdjacentEdgeRange(const NodeID node) const final
|
||||
{
|
||||
return m_query_graph->GetAdjacentEdgeRange(node);
|
||||
};
|
||||
|
||||
// searches for a specific edge
|
||||
EdgeID FindEdge(const NodeID from, const NodeID to) const final
|
||||
{
|
||||
return m_query_graph->FindEdge(from, to);
|
||||
}
|
||||
|
||||
EdgeID FindEdgeInEitherDirection(const NodeID from, const NodeID to) const final
|
||||
{
|
||||
return m_query_graph->FindEdgeInEitherDirection(from, to);
|
||||
}
|
||||
|
||||
EdgeID FindEdgeIndicateIfReverse(const NodeID from, const NodeID to, bool &result) const final
|
||||
{
|
||||
return m_query_graph->FindEdgeIndicateIfReverse(from, to, result);
|
||||
}
|
||||
|
||||
// node and edge information access
|
||||
FixedPointCoordinate GetCoordinateOfNode(const unsigned id) const final
|
||||
{
|
||||
return m_coordinate_list->at(id);
|
||||
};
|
||||
|
||||
bool EdgeIsCompressed(const unsigned id) const { return m_edge_is_compressed.at(id); }
|
||||
|
||||
TurnInstruction GetTurnInstructionForEdgeID(const unsigned id) const final
|
||||
{
|
||||
return m_turn_instruction_list.at(id);
|
||||
}
|
||||
|
||||
TravelMode GetTravelModeForEdgeID(const unsigned id) const
|
||||
{
|
||||
return m_travel_mode_list.at(id);
|
||||
}
|
||||
|
||||
bool LocateClosestEndPointForCoordinate(const FixedPointCoordinate &input_coordinate,
|
||||
FixedPointCoordinate &result,
|
||||
const unsigned zoom_level = 18) final
|
||||
{
|
||||
if (!m_static_rtree.get())
|
||||
{
|
||||
LoadRTree();
|
||||
}
|
||||
|
||||
return m_static_rtree->LocateClosestEndPointForCoordinate(
|
||||
input_coordinate, result, zoom_level);
|
||||
}
|
||||
|
||||
bool
|
||||
IncrementalFindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate,
|
||||
PhantomNode &resulting_phantom_node) final
|
||||
{
|
||||
std::vector<PhantomNode> resulting_phantom_node_vector;
|
||||
auto result = IncrementalFindPhantomNodeForCoordinate(input_coordinate,
|
||||
resulting_phantom_node_vector,
|
||||
1);
|
||||
if (result)
|
||||
{
|
||||
BOOST_ASSERT(!resulting_phantom_node_vector.empty());
|
||||
resulting_phantom_node = resulting_phantom_node_vector.front();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool
|
||||
IncrementalFindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate,
|
||||
std::vector<PhantomNode> &resulting_phantom_node_vector,
|
||||
const unsigned number_of_results) final
|
||||
{
|
||||
if (!m_static_rtree.get())
|
||||
{
|
||||
LoadRTree();
|
||||
}
|
||||
|
||||
return m_static_rtree->IncrementalFindPhantomNodeForCoordinate(
|
||||
input_coordinate, resulting_phantom_node_vector, number_of_results);
|
||||
}
|
||||
|
||||
unsigned GetCheckSum() const final { return m_check_sum; }
|
||||
|
||||
unsigned GetNameIndexFromEdgeID(const unsigned id) const final
|
||||
{
|
||||
return m_name_ID_list.at(id);
|
||||
};
|
||||
|
||||
void GetName(const unsigned name_id, std::string &result) const final
|
||||
{
|
||||
if (UINT_MAX == name_id)
|
||||
{
|
||||
result = "";
|
||||
return;
|
||||
}
|
||||
auto range = m_name_table.GetRange(name_id);
|
||||
|
||||
result.clear();
|
||||
if (range.begin() != range.end())
|
||||
{
|
||||
result.resize(range.back() - range.front() + 1);
|
||||
std::copy(m_names_char_list.begin() + range.front(),
|
||||
m_names_char_list.begin() + range.back() + 1,
|
||||
result.begin());
|
||||
}
|
||||
}
|
||||
|
||||
virtual unsigned GetGeometryIndexForEdgeID(const unsigned id) const final
|
||||
{
|
||||
return m_via_node_list.at(id);
|
||||
}
|
||||
|
||||
virtual void GetUncompressedGeometry(const unsigned id,
|
||||
std::vector<unsigned> &result_nodes) const final
|
||||
{
|
||||
const unsigned begin = m_geometry_indices.at(id);
|
||||
const unsigned end = m_geometry_indices.at(id + 1);
|
||||
|
||||
result_nodes.clear();
|
||||
result_nodes.insert(
|
||||
result_nodes.begin(), m_geometry_list.begin() + begin, m_geometry_list.begin() + end);
|
||||
}
|
||||
|
||||
std::string GetTimestamp() const final { return m_timestamp; }
|
||||
};
|
||||
|
||||
#endif // INTERNAL_DATA_FACADE
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef SHARED_BARRIER_H
|
||||
#define SHARED_BARRIER_H
|
||||
|
||||
#include <boost/interprocess/sync/named_mutex.hpp>
|
||||
#include <boost/interprocess/sync/named_condition.hpp>
|
||||
|
||||
struct SharedBarriers
|
||||
{
|
||||
|
||||
SharedBarriers()
|
||||
: pending_update_mutex(boost::interprocess::open_or_create, "pending_update"),
|
||||
update_mutex(boost::interprocess::open_or_create, "update"),
|
||||
query_mutex(boost::interprocess::open_or_create, "query"),
|
||||
no_running_queries_condition(boost::interprocess::open_or_create, "no_running_queries"),
|
||||
update_ongoing(false), number_of_queries(0)
|
||||
{
|
||||
}
|
||||
|
||||
// Mutex to protect access to the boolean variable
|
||||
boost::interprocess::named_mutex pending_update_mutex;
|
||||
boost::interprocess::named_mutex update_mutex;
|
||||
boost::interprocess::named_mutex query_mutex;
|
||||
|
||||
// Condition that no update is running
|
||||
boost::interprocess::named_condition no_running_queries_condition;
|
||||
|
||||
// Is there an ongoing update?
|
||||
bool update_ongoing;
|
||||
// Is there any query?
|
||||
int number_of_queries;
|
||||
};
|
||||
|
||||
#endif // SHARED_BARRIER_H
|
||||
@@ -1,431 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef SHARED_DATA_FACADE_H
|
||||
#define SHARED_DATA_FACADE_H
|
||||
|
||||
// implements all data storage when shared memory _IS_ used
|
||||
|
||||
#include "BaseDataFacade.h"
|
||||
#include "SharedDataType.h"
|
||||
|
||||
#include "../../data_structures/range_table.hpp"
|
||||
#include "../../data_structures/static_graph.hpp"
|
||||
#include "../../data_structures/static_rtree.hpp"
|
||||
#include "../../Util/BoostFileSystemFix.h"
|
||||
#include "../../Util/make_unique.hpp"
|
||||
#include "../../Util/simple_logger.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
|
||||
template <class EdgeDataT> class SharedDataFacade : public BaseDataFacade<EdgeDataT>
|
||||
{
|
||||
|
||||
private:
|
||||
typedef EdgeDataT EdgeData;
|
||||
typedef BaseDataFacade<EdgeData> super;
|
||||
typedef StaticGraph<EdgeData, true> QueryGraph;
|
||||
typedef typename StaticGraph<EdgeData, true>::NodeArrayEntry GraphNode;
|
||||
typedef typename StaticGraph<EdgeData, true>::EdgeArrayEntry GraphEdge;
|
||||
typedef typename RangeTable<16, true>::BlockT NameIndexBlock;
|
||||
typedef typename QueryGraph::InputEdge InputEdge;
|
||||
typedef typename super::RTreeLeaf RTreeLeaf;
|
||||
using SharedRTree = StaticRTree<RTreeLeaf, ShM<FixedPointCoordinate, true>::vector, true>;
|
||||
using TimeStampedRTreePair = std::pair<unsigned, std::shared_ptr<SharedRTree>>;
|
||||
using RTreeNode = typename SharedRTree::TreeNode;
|
||||
|
||||
SharedDataLayout *data_layout;
|
||||
char *shared_memory;
|
||||
SharedDataTimestamp *data_timestamp_ptr;
|
||||
|
||||
SharedDataType CURRENT_LAYOUT;
|
||||
SharedDataType CURRENT_DATA;
|
||||
unsigned CURRENT_TIMESTAMP;
|
||||
|
||||
unsigned m_check_sum;
|
||||
std::unique_ptr<QueryGraph> m_query_graph;
|
||||
std::unique_ptr<SharedMemory> m_layout_memory;
|
||||
std::unique_ptr<SharedMemory> m_large_memory;
|
||||
std::string m_timestamp;
|
||||
|
||||
std::shared_ptr<ShM<FixedPointCoordinate, true>::vector> m_coordinate_list;
|
||||
ShM<NodeID, true>::vector m_via_node_list;
|
||||
ShM<unsigned, true>::vector m_name_ID_list;
|
||||
ShM<TurnInstruction, true>::vector m_turn_instruction_list;
|
||||
ShM<TravelMode, true>::vector m_travel_mode_list;
|
||||
ShM<char, true>::vector m_names_char_list;
|
||||
ShM<unsigned, true>::vector m_name_begin_indices;
|
||||
ShM<bool, true>::vector m_edge_is_compressed;
|
||||
ShM<unsigned, true>::vector m_geometry_indices;
|
||||
ShM<unsigned, true>::vector m_geometry_list;
|
||||
|
||||
boost::thread_specific_ptr<std::pair<unsigned, std::shared_ptr<SharedRTree>>> m_static_rtree;
|
||||
boost::filesystem::path file_index_path;
|
||||
|
||||
std::shared_ptr<RangeTable<16, true>> m_name_table;
|
||||
|
||||
void LoadChecksum()
|
||||
{
|
||||
m_check_sum =
|
||||
*data_layout->GetBlockPtr<unsigned>(shared_memory, SharedDataLayout::HSGR_CHECKSUM);
|
||||
SimpleLogger().Write() << "set checksum: " << m_check_sum;
|
||||
}
|
||||
|
||||
void LoadTimestamp()
|
||||
{
|
||||
char *timestamp_ptr =
|
||||
data_layout->GetBlockPtr<char>(shared_memory, SharedDataLayout::TIMESTAMP);
|
||||
m_timestamp.resize(data_layout->GetBlockSize(SharedDataLayout::TIMESTAMP));
|
||||
std::copy(timestamp_ptr,
|
||||
timestamp_ptr + data_layout->GetBlockSize(SharedDataLayout::TIMESTAMP),
|
||||
m_timestamp.begin());
|
||||
}
|
||||
|
||||
void LoadRTree()
|
||||
{
|
||||
BOOST_ASSERT_MSG(!m_coordinate_list->empty(), "coordinates must be loaded before r-tree");
|
||||
|
||||
RTreeNode *tree_ptr =
|
||||
data_layout->GetBlockPtr<RTreeNode>(shared_memory, SharedDataLayout::R_SEARCH_TREE);
|
||||
m_static_rtree.reset(new TimeStampedRTreePair(CURRENT_TIMESTAMP,
|
||||
osrm::make_unique<SharedRTree>(
|
||||
tree_ptr,
|
||||
data_layout->num_entries[SharedDataLayout::R_SEARCH_TREE],
|
||||
file_index_path,
|
||||
m_coordinate_list)));
|
||||
}
|
||||
|
||||
void LoadGraph()
|
||||
{
|
||||
GraphNode *graph_nodes_ptr =
|
||||
data_layout->GetBlockPtr<GraphNode>(shared_memory, SharedDataLayout::GRAPH_NODE_LIST);
|
||||
|
||||
GraphEdge *graph_edges_ptr =
|
||||
data_layout->GetBlockPtr<GraphEdge>(shared_memory, SharedDataLayout::GRAPH_EDGE_LIST);
|
||||
|
||||
typename ShM<GraphNode, true>::vector node_list(
|
||||
graph_nodes_ptr, data_layout->num_entries[SharedDataLayout::GRAPH_NODE_LIST]);
|
||||
typename ShM<GraphEdge, true>::vector edge_list(
|
||||
graph_edges_ptr, data_layout->num_entries[SharedDataLayout::GRAPH_EDGE_LIST]);
|
||||
m_query_graph.reset(new QueryGraph(node_list, edge_list));
|
||||
}
|
||||
|
||||
void LoadNodeAndEdgeInformation()
|
||||
{
|
||||
|
||||
FixedPointCoordinate *coordinate_list_ptr = data_layout->GetBlockPtr<FixedPointCoordinate>(
|
||||
shared_memory, SharedDataLayout::COORDINATE_LIST);
|
||||
m_coordinate_list = osrm::make_unique<ShM<FixedPointCoordinate, true>::vector>(
|
||||
coordinate_list_ptr, data_layout->num_entries[SharedDataLayout::COORDINATE_LIST]);
|
||||
|
||||
TravelMode *travel_mode_list_ptr = data_layout->GetBlockPtr<TravelMode>(
|
||||
shared_memory, SharedDataLayout::TRAVEL_MODE);
|
||||
typename ShM<TravelMode, true>::vector travel_mode_list(
|
||||
travel_mode_list_ptr,
|
||||
data_layout->num_entries[SharedDataLayout::TRAVEL_MODE]);
|
||||
m_travel_mode_list.swap(travel_mode_list);
|
||||
|
||||
TurnInstruction *turn_instruction_list_ptr = data_layout->GetBlockPtr<TurnInstruction>(
|
||||
shared_memory, SharedDataLayout::TURN_INSTRUCTION);
|
||||
typename ShM<TurnInstruction, true>::vector turn_instruction_list(
|
||||
turn_instruction_list_ptr,
|
||||
data_layout->num_entries[SharedDataLayout::TURN_INSTRUCTION]);
|
||||
m_turn_instruction_list.swap(turn_instruction_list);
|
||||
|
||||
unsigned *name_id_list_ptr =
|
||||
data_layout->GetBlockPtr<unsigned>(shared_memory, SharedDataLayout::NAME_ID_LIST);
|
||||
typename ShM<unsigned, true>::vector name_id_list(
|
||||
name_id_list_ptr, data_layout->num_entries[SharedDataLayout::NAME_ID_LIST]);
|
||||
m_name_ID_list.swap(name_id_list);
|
||||
}
|
||||
|
||||
void LoadViaNodeList()
|
||||
{
|
||||
NodeID *via_node_list_ptr =
|
||||
data_layout->GetBlockPtr<NodeID>(shared_memory, SharedDataLayout::VIA_NODE_LIST);
|
||||
typename ShM<NodeID, true>::vector via_node_list(
|
||||
via_node_list_ptr, data_layout->num_entries[SharedDataLayout::VIA_NODE_LIST]);
|
||||
m_via_node_list.swap(via_node_list);
|
||||
}
|
||||
|
||||
void LoadNames()
|
||||
{
|
||||
unsigned *offsets_ptr =
|
||||
data_layout->GetBlockPtr<unsigned>(shared_memory, SharedDataLayout::NAME_OFFSETS);
|
||||
NameIndexBlock *blocks_ptr =
|
||||
data_layout->GetBlockPtr<NameIndexBlock>(shared_memory, SharedDataLayout::NAME_BLOCKS);
|
||||
typename ShM<unsigned, true>::vector name_offsets(
|
||||
offsets_ptr, data_layout->num_entries[SharedDataLayout::NAME_OFFSETS]);
|
||||
typename ShM<NameIndexBlock, true>::vector name_blocks(
|
||||
blocks_ptr, data_layout->num_entries[SharedDataLayout::NAME_BLOCKS]);
|
||||
|
||||
char *names_list_ptr =
|
||||
data_layout->GetBlockPtr<char>(shared_memory, SharedDataLayout::NAME_CHAR_LIST);
|
||||
typename ShM<char, true>::vector names_char_list(
|
||||
names_list_ptr, data_layout->num_entries[SharedDataLayout::NAME_CHAR_LIST]);
|
||||
m_name_table = osrm::make_unique<RangeTable<16, true>>(
|
||||
name_offsets, name_blocks, static_cast<unsigned>(names_char_list.size()));
|
||||
|
||||
m_names_char_list.swap(names_char_list);
|
||||
}
|
||||
|
||||
void LoadGeometries()
|
||||
{
|
||||
unsigned *geometries_compressed_ptr = data_layout->GetBlockPtr<unsigned>(
|
||||
shared_memory, SharedDataLayout::GEOMETRIES_INDICATORS);
|
||||
typename ShM<bool, true>::vector edge_is_compressed(
|
||||
geometries_compressed_ptr,
|
||||
data_layout->num_entries[SharedDataLayout::GEOMETRIES_INDICATORS]);
|
||||
m_edge_is_compressed.swap(edge_is_compressed);
|
||||
|
||||
unsigned *geometries_index_ptr =
|
||||
data_layout->GetBlockPtr<unsigned>(shared_memory, SharedDataLayout::GEOMETRIES_INDEX);
|
||||
typename ShM<unsigned, true>::vector geometry_begin_indices(
|
||||
geometries_index_ptr, data_layout->num_entries[SharedDataLayout::GEOMETRIES_INDEX]);
|
||||
m_geometry_indices.swap(geometry_begin_indices);
|
||||
|
||||
unsigned *geometries_list_ptr =
|
||||
data_layout->GetBlockPtr<unsigned>(shared_memory, SharedDataLayout::GEOMETRIES_LIST);
|
||||
typename ShM<unsigned, true>::vector geometry_list(
|
||||
geometries_list_ptr, data_layout->num_entries[SharedDataLayout::GEOMETRIES_LIST]);
|
||||
m_geometry_list.swap(geometry_list);
|
||||
}
|
||||
|
||||
public:
|
||||
virtual ~SharedDataFacade() {}
|
||||
|
||||
SharedDataFacade()
|
||||
{
|
||||
data_timestamp_ptr = (SharedDataTimestamp *)SharedMemoryFactory::Get(
|
||||
CURRENT_REGIONS, sizeof(SharedDataTimestamp), false, false)->Ptr();
|
||||
CURRENT_LAYOUT = LAYOUT_NONE;
|
||||
CURRENT_DATA = DATA_NONE;
|
||||
CURRENT_TIMESTAMP = 0;
|
||||
|
||||
// load data
|
||||
CheckAndReloadFacade();
|
||||
}
|
||||
|
||||
void CheckAndReloadFacade()
|
||||
{
|
||||
if (CURRENT_LAYOUT != data_timestamp_ptr->layout ||
|
||||
CURRENT_DATA != data_timestamp_ptr->data ||
|
||||
CURRENT_TIMESTAMP != data_timestamp_ptr->timestamp)
|
||||
{
|
||||
// release the previous shared memory segments
|
||||
SharedMemory::Remove(CURRENT_LAYOUT);
|
||||
SharedMemory::Remove(CURRENT_DATA);
|
||||
|
||||
CURRENT_LAYOUT = data_timestamp_ptr->layout;
|
||||
CURRENT_DATA = data_timestamp_ptr->data;
|
||||
CURRENT_TIMESTAMP = data_timestamp_ptr->timestamp;
|
||||
|
||||
m_layout_memory.reset(SharedMemoryFactory::Get(CURRENT_LAYOUT));
|
||||
|
||||
data_layout = (SharedDataLayout *)(m_layout_memory->Ptr());
|
||||
|
||||
m_large_memory.reset(SharedMemoryFactory::Get(CURRENT_DATA));
|
||||
shared_memory = (char *)(m_large_memory->Ptr());
|
||||
|
||||
const char *file_index_ptr =
|
||||
data_layout->GetBlockPtr<char>(shared_memory, SharedDataLayout::FILE_INDEX_PATH);
|
||||
file_index_path = boost::filesystem::path(file_index_ptr);
|
||||
if (!boost::filesystem::exists(file_index_path))
|
||||
{
|
||||
SimpleLogger().Write(logDEBUG) << "Leaf file name " << file_index_path.string();
|
||||
throw osrm::exception("Could not load leaf index file."
|
||||
"Is any data loaded into shared memory?");
|
||||
}
|
||||
|
||||
LoadGraph();
|
||||
LoadChecksum();
|
||||
LoadNodeAndEdgeInformation();
|
||||
LoadGeometries();
|
||||
LoadTimestamp();
|
||||
LoadViaNodeList();
|
||||
LoadNames();
|
||||
|
||||
data_layout->PrintInformation();
|
||||
|
||||
SimpleLogger().Write() << "number of geometries: " << m_coordinate_list->size();
|
||||
for (unsigned i = 0; i < m_coordinate_list->size(); ++i)
|
||||
{
|
||||
if (!GetCoordinateOfNode(i).is_valid())
|
||||
{
|
||||
SimpleLogger().Write() << "coordinate " << i << " not valid";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// search graph access
|
||||
unsigned GetNumberOfNodes() const final { return m_query_graph->GetNumberOfNodes(); }
|
||||
|
||||
unsigned GetNumberOfEdges() const final { return m_query_graph->GetNumberOfEdges(); }
|
||||
|
||||
unsigned GetOutDegree(const NodeID n) const final { return m_query_graph->GetOutDegree(n); }
|
||||
|
||||
NodeID GetTarget(const EdgeID e) const final { return m_query_graph->GetTarget(e); }
|
||||
|
||||
EdgeDataT &GetEdgeData(const EdgeID e) const final { return m_query_graph->GetEdgeData(e); }
|
||||
|
||||
EdgeID BeginEdges(const NodeID n) const final { return m_query_graph->BeginEdges(n); }
|
||||
|
||||
EdgeID EndEdges(const NodeID n) const final { return m_query_graph->EndEdges(n); }
|
||||
|
||||
EdgeRange GetAdjacentEdgeRange(const NodeID node) const final
|
||||
{
|
||||
return m_query_graph->GetAdjacentEdgeRange(node);
|
||||
};
|
||||
|
||||
// searches for a specific edge
|
||||
EdgeID FindEdge(const NodeID from, const NodeID to) const final
|
||||
{
|
||||
return m_query_graph->FindEdge(from, to);
|
||||
}
|
||||
|
||||
EdgeID FindEdgeInEitherDirection(const NodeID from, const NodeID to) const final
|
||||
{
|
||||
return m_query_graph->FindEdgeInEitherDirection(from, to);
|
||||
}
|
||||
|
||||
EdgeID FindEdgeIndicateIfReverse(const NodeID from, const NodeID to, bool &result) const final
|
||||
{
|
||||
return m_query_graph->FindEdgeIndicateIfReverse(from, to, result);
|
||||
}
|
||||
|
||||
// node and edge information access
|
||||
FixedPointCoordinate GetCoordinateOfNode(const NodeID id) const final
|
||||
{
|
||||
return m_coordinate_list->at(id);
|
||||
};
|
||||
|
||||
virtual bool EdgeIsCompressed(const unsigned id) const final
|
||||
{
|
||||
return m_edge_is_compressed.at(id);
|
||||
}
|
||||
|
||||
virtual void GetUncompressedGeometry(const unsigned id,
|
||||
std::vector<unsigned> &result_nodes) const final
|
||||
{
|
||||
const unsigned begin = m_geometry_indices.at(id);
|
||||
const unsigned end = m_geometry_indices.at(id + 1);
|
||||
|
||||
result_nodes.clear();
|
||||
result_nodes.insert(
|
||||
result_nodes.begin(), m_geometry_list.begin() + begin, m_geometry_list.begin() + end);
|
||||
}
|
||||
|
||||
virtual unsigned GetGeometryIndexForEdgeID(const unsigned id) const final
|
||||
{
|
||||
return m_via_node_list.at(id);
|
||||
}
|
||||
|
||||
TurnInstruction GetTurnInstructionForEdgeID(const unsigned id) const final
|
||||
{
|
||||
return m_turn_instruction_list.at(id);
|
||||
}
|
||||
|
||||
TravelMode GetTravelModeForEdgeID(const unsigned id) const
|
||||
{
|
||||
return m_travel_mode_list.at(id);
|
||||
}
|
||||
|
||||
bool LocateClosestEndPointForCoordinate(const FixedPointCoordinate &input_coordinate,
|
||||
FixedPointCoordinate &result,
|
||||
const unsigned zoom_level = 18) final
|
||||
{
|
||||
if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
|
||||
{
|
||||
LoadRTree();
|
||||
}
|
||||
|
||||
return m_static_rtree->second->LocateClosestEndPointForCoordinate(
|
||||
input_coordinate, result, zoom_level);
|
||||
}
|
||||
|
||||
bool
|
||||
IncrementalFindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate,
|
||||
PhantomNode &resulting_phantom_node) final
|
||||
{
|
||||
std::vector<PhantomNode> resulting_phantom_node_vector;
|
||||
auto result = IncrementalFindPhantomNodeForCoordinate(input_coordinate,
|
||||
resulting_phantom_node_vector,
|
||||
1);
|
||||
if (result)
|
||||
{
|
||||
BOOST_ASSERT(!resulting_phantom_node_vector.empty());
|
||||
resulting_phantom_node = resulting_phantom_node_vector.front();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool
|
||||
IncrementalFindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate,
|
||||
std::vector<PhantomNode> &resulting_phantom_node_vector,
|
||||
const unsigned number_of_results) final
|
||||
{
|
||||
if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
|
||||
{
|
||||
LoadRTree();
|
||||
}
|
||||
|
||||
return m_static_rtree->second->IncrementalFindPhantomNodeForCoordinate(
|
||||
input_coordinate, resulting_phantom_node_vector, number_of_results);
|
||||
}
|
||||
|
||||
unsigned GetCheckSum() const final { return m_check_sum; }
|
||||
|
||||
unsigned GetNameIndexFromEdgeID(const unsigned id) const final
|
||||
{
|
||||
return m_name_ID_list.at(id);
|
||||
};
|
||||
|
||||
void GetName(const unsigned name_id, std::string &result) const final
|
||||
{
|
||||
if (UINT_MAX == name_id)
|
||||
{
|
||||
result = "";
|
||||
return;
|
||||
}
|
||||
auto range = m_name_table->GetRange(name_id);
|
||||
|
||||
result.clear();
|
||||
if (range.begin() != range.end())
|
||||
{
|
||||
result.resize(range.back() - range.front() + 1);
|
||||
std::copy(m_names_char_list.begin() + range.front(),
|
||||
m_names_char_list.begin() + range.back() + 1,
|
||||
result.begin());
|
||||
}
|
||||
}
|
||||
|
||||
std::string GetTimestamp() const final { return m_timestamp; }
|
||||
};
|
||||
|
||||
#endif // SHARED_DATA_FACADE_H
|
||||
@@ -1,193 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef SHARED_DATA_TYPE_H_
|
||||
#define SHARED_DATA_TYPE_H_
|
||||
|
||||
#include "../../Util/osrm_exception.hpp"
|
||||
#include "../../Util/simple_logger.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include <array>
|
||||
|
||||
// Added at the start and end of each block as sanity check
|
||||
static const char CANARY[] = "OSRM";
|
||||
|
||||
struct SharedDataLayout
|
||||
{
|
||||
enum BlockID {
|
||||
NAME_OFFSETS = 0,
|
||||
NAME_BLOCKS,
|
||||
NAME_CHAR_LIST,
|
||||
NAME_ID_LIST,
|
||||
VIA_NODE_LIST,
|
||||
GRAPH_NODE_LIST,
|
||||
GRAPH_EDGE_LIST,
|
||||
COORDINATE_LIST,
|
||||
TURN_INSTRUCTION,
|
||||
TRAVEL_MODE,
|
||||
R_SEARCH_TREE,
|
||||
GEOMETRIES_INDEX,
|
||||
GEOMETRIES_LIST,
|
||||
GEOMETRIES_INDICATORS,
|
||||
HSGR_CHECKSUM,
|
||||
TIMESTAMP,
|
||||
FILE_INDEX_PATH,
|
||||
NUM_BLOCKS
|
||||
};
|
||||
|
||||
std::array<uint64_t, NUM_BLOCKS> num_entries;
|
||||
std::array<uint64_t, NUM_BLOCKS> entry_size;
|
||||
|
||||
SharedDataLayout()
|
||||
: num_entries()
|
||||
, entry_size()
|
||||
{
|
||||
}
|
||||
|
||||
void PrintInformation() const
|
||||
{
|
||||
SimpleLogger().Write(logDEBUG) << "-";
|
||||
SimpleLogger().Write(logDEBUG) << "name_offsets_size: " << num_entries[NAME_OFFSETS];
|
||||
SimpleLogger().Write(logDEBUG) << "name_blocks_size: " << num_entries[NAME_BLOCKS];
|
||||
SimpleLogger().Write(logDEBUG) << "name_char_list_size: " << num_entries[NAME_CHAR_LIST];
|
||||
SimpleLogger().Write(logDEBUG) << "name_id_list_size: " << num_entries[NAME_ID_LIST];
|
||||
SimpleLogger().Write(logDEBUG) << "via_node_list_size: " << num_entries[VIA_NODE_LIST];
|
||||
SimpleLogger().Write(logDEBUG) << "graph_node_list_size: " << num_entries[GRAPH_NODE_LIST];
|
||||
SimpleLogger().Write(logDEBUG) << "graph_edge_list_size: " << num_entries[GRAPH_EDGE_LIST];
|
||||
SimpleLogger().Write(logDEBUG) << "timestamp_length: " << num_entries[TIMESTAMP];
|
||||
SimpleLogger().Write(logDEBUG) << "coordinate_list_size: " << num_entries[COORDINATE_LIST];
|
||||
SimpleLogger().Write(logDEBUG) << "turn_instruction_list_size: " << num_entries[TURN_INSTRUCTION];
|
||||
SimpleLogger().Write(logDEBUG) << "travel_mode_list_size: " << num_entries[TRAVEL_MODE];
|
||||
SimpleLogger().Write(logDEBUG) << "r_search_tree_size: " << num_entries[R_SEARCH_TREE];
|
||||
SimpleLogger().Write(logDEBUG) << "geometries_indicators: " << num_entries[GEOMETRIES_INDICATORS]
|
||||
<< "/" << ((num_entries[GEOMETRIES_INDICATORS] / 8) + 1);
|
||||
SimpleLogger().Write(logDEBUG) << "geometries_index_list_size: " << num_entries[GEOMETRIES_INDEX];
|
||||
SimpleLogger().Write(logDEBUG) << "geometries_list_size: " << num_entries[GEOMETRIES_LIST];
|
||||
SimpleLogger().Write(logDEBUG) << "sizeof(checksum): " << entry_size[HSGR_CHECKSUM];
|
||||
|
||||
SimpleLogger().Write(logDEBUG) << "NAME_OFFSETS " << ": " << GetBlockSize(NAME_OFFSETS );
|
||||
SimpleLogger().Write(logDEBUG) << "NAME_BLOCKS " << ": " << GetBlockSize(NAME_BLOCKS );
|
||||
SimpleLogger().Write(logDEBUG) << "NAME_CHAR_LIST " << ": " << GetBlockSize(NAME_CHAR_LIST );
|
||||
SimpleLogger().Write(logDEBUG) << "NAME_ID_LIST " << ": " << GetBlockSize(NAME_ID_LIST );
|
||||
SimpleLogger().Write(logDEBUG) << "VIA_NODE_LIST " << ": " << GetBlockSize(VIA_NODE_LIST );
|
||||
SimpleLogger().Write(logDEBUG) << "GRAPH_NODE_LIST " << ": " << GetBlockSize(GRAPH_NODE_LIST );
|
||||
SimpleLogger().Write(logDEBUG) << "GRAPH_EDGE_LIST " << ": " << GetBlockSize(GRAPH_EDGE_LIST );
|
||||
SimpleLogger().Write(logDEBUG) << "COORDINATE_LIST " << ": " << GetBlockSize(COORDINATE_LIST );
|
||||
SimpleLogger().Write(logDEBUG) << "TURN_INSTRUCTION " << ": " << GetBlockSize(TURN_INSTRUCTION );
|
||||
SimpleLogger().Write(logDEBUG) << "TRAVEL_MODE " << ": " << GetBlockSize(TRAVEL_MODE );
|
||||
SimpleLogger().Write(logDEBUG) << "R_SEARCH_TREE " << ": " << GetBlockSize(R_SEARCH_TREE );
|
||||
SimpleLogger().Write(logDEBUG) << "GEOMETRIES_INDEX " << ": " << GetBlockSize(GEOMETRIES_INDEX );
|
||||
SimpleLogger().Write(logDEBUG) << "GEOMETRIES_LIST " << ": " << GetBlockSize(GEOMETRIES_LIST );
|
||||
SimpleLogger().Write(logDEBUG) << "GEOMETRIES_INDICATORS" << ": " << GetBlockSize(GEOMETRIES_INDICATORS);
|
||||
SimpleLogger().Write(logDEBUG) << "HSGR_CHECKSUM " << ": " << GetBlockSize(HSGR_CHECKSUM );
|
||||
SimpleLogger().Write(logDEBUG) << "TIMESTAMP " << ": " << GetBlockSize(TIMESTAMP );
|
||||
SimpleLogger().Write(logDEBUG) << "FILE_INDEX_PATH " << ": " << GetBlockSize(FILE_INDEX_PATH );
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void SetBlockSize(BlockID bid, uint64_t entries)
|
||||
{
|
||||
num_entries[bid] = entries;
|
||||
entry_size[bid] = sizeof(T);
|
||||
}
|
||||
|
||||
inline uint64_t GetBlockSize(BlockID bid) const
|
||||
{
|
||||
// special encoding
|
||||
if (bid == GEOMETRIES_INDICATORS)
|
||||
{
|
||||
return (num_entries[GEOMETRIES_INDICATORS]/32 + 1) * entry_size[GEOMETRIES_INDICATORS];
|
||||
}
|
||||
|
||||
return num_entries[bid] * entry_size[bid];
|
||||
}
|
||||
|
||||
inline uint64_t GetSizeOfLayout() const
|
||||
{
|
||||
return GetBlockOffset(NUM_BLOCKS) + NUM_BLOCKS*2*sizeof(CANARY);
|
||||
}
|
||||
|
||||
inline uint64_t GetBlockOffset(BlockID bid) const
|
||||
{
|
||||
uint64_t result = sizeof(CANARY);
|
||||
for (auto i = 0; i < bid; i++)
|
||||
{
|
||||
result += GetBlockSize((BlockID) i) + 2*sizeof(CANARY);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T, bool WRITE_CANARY=false>
|
||||
inline T* GetBlockPtr(char* shared_memory, BlockID bid)
|
||||
{
|
||||
T* ptr = (T*)(shared_memory + GetBlockOffset(bid));
|
||||
if (WRITE_CANARY)
|
||||
{
|
||||
char* start_canary_ptr = shared_memory + GetBlockOffset(bid) - sizeof(CANARY);
|
||||
char* end_canary_ptr = shared_memory + GetBlockOffset(bid) + GetBlockSize(bid);
|
||||
std::copy(CANARY, CANARY + sizeof(CANARY), start_canary_ptr);
|
||||
std::copy(CANARY, CANARY + sizeof(CANARY), end_canary_ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
char* start_canary_ptr = shared_memory + GetBlockOffset(bid) - sizeof(CANARY);
|
||||
char* end_canary_ptr = shared_memory + GetBlockOffset(bid) + GetBlockSize(bid);
|
||||
bool start_canary_alive = std::equal(CANARY, CANARY + sizeof(CANARY), start_canary_ptr);
|
||||
bool end_canary_alive = std::equal(CANARY, CANARY + sizeof(CANARY), end_canary_ptr);
|
||||
if (!start_canary_alive)
|
||||
{
|
||||
throw osrm::exception("Start canary of block corrupted.");
|
||||
}
|
||||
if (!end_canary_alive)
|
||||
{
|
||||
throw osrm::exception("End canary of block corrupted.");
|
||||
}
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
||||
};
|
||||
|
||||
enum SharedDataType
|
||||
{ CURRENT_REGIONS,
|
||||
LAYOUT_1,
|
||||
DATA_1,
|
||||
LAYOUT_2,
|
||||
DATA_2,
|
||||
LAYOUT_NONE,
|
||||
DATA_NONE };
|
||||
|
||||
struct SharedDataTimestamp
|
||||
{
|
||||
SharedDataType layout;
|
||||
SharedDataType data;
|
||||
unsigned timestamp;
|
||||
};
|
||||
|
||||
#endif /* SHARED_DATA_TYPE_H_ */
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef COMPRESSION_TYPE_H
|
||||
#define COMPRESSION_TYPE_H
|
||||
|
||||
namespace http
|
||||
{
|
||||
|
||||
enum CompressionType
|
||||
{ noCompression,
|
||||
gzipRFC1952,
|
||||
deflateRFC1951 };
|
||||
|
||||
}
|
||||
|
||||
#endif // COMPRESSION_TYPE_H
|
||||
@@ -1,122 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include <osrm/Reply.h>
|
||||
|
||||
#include "../../Util/cast.hpp"
|
||||
|
||||
namespace http
|
||||
{
|
||||
|
||||
void Reply::SetSize(const unsigned size)
|
||||
{
|
||||
for (Header &h : headers)
|
||||
{
|
||||
if ("Content-Length" == h.name)
|
||||
{
|
||||
h.value = cast::integral_to_string(size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sets the size of the uncompressed output.
|
||||
void Reply::SetUncompressedSize() { SetSize(static_cast<unsigned>(content.size())); }
|
||||
|
||||
std::vector<boost::asio::const_buffer> Reply::ToBuffers()
|
||||
{
|
||||
std::vector<boost::asio::const_buffer> buffers;
|
||||
buffers.push_back(ToBuffer(status));
|
||||
for (const Header &h : headers)
|
||||
{
|
||||
buffers.push_back(boost::asio::buffer(h.name));
|
||||
buffers.push_back(boost::asio::buffer(seperators));
|
||||
buffers.push_back(boost::asio::buffer(h.value));
|
||||
buffers.push_back(boost::asio::buffer(crlf));
|
||||
}
|
||||
buffers.push_back(boost::asio::buffer(crlf));
|
||||
buffers.push_back(boost::asio::buffer(content));
|
||||
return buffers;
|
||||
}
|
||||
|
||||
std::vector<boost::asio::const_buffer> Reply::HeaderstoBuffers()
|
||||
{
|
||||
std::vector<boost::asio::const_buffer> buffers;
|
||||
buffers.push_back(ToBuffer(status));
|
||||
for (std::size_t i = 0; i < headers.size(); ++i)
|
||||
{
|
||||
Header ¤t_header = headers[i];
|
||||
buffers.push_back(boost::asio::buffer(current_header.name));
|
||||
buffers.push_back(boost::asio::buffer(seperators));
|
||||
buffers.push_back(boost::asio::buffer(current_header.value));
|
||||
buffers.push_back(boost::asio::buffer(crlf));
|
||||
}
|
||||
buffers.push_back(boost::asio::buffer(crlf));
|
||||
return buffers;
|
||||
}
|
||||
|
||||
Reply Reply::StockReply(Reply::status_type status)
|
||||
{
|
||||
Reply reply;
|
||||
reply.status = status;
|
||||
reply.content.clear();
|
||||
|
||||
const std::string status_string = reply.ToString(status);
|
||||
reply.content.insert(reply.content.end(), status_string.begin(), status_string.end());
|
||||
reply.headers.emplace_back("Access-Control-Allow-Origin", "*");
|
||||
reply.headers.emplace_back("Content-Length", cast::integral_to_string(reply.content.size()));
|
||||
reply.headers.emplace_back("Content-Type", "text/html");
|
||||
return reply;
|
||||
}
|
||||
|
||||
std::string Reply::ToString(Reply::status_type status)
|
||||
{
|
||||
if (Reply::ok == status)
|
||||
{
|
||||
return okHTML;
|
||||
}
|
||||
if (Reply::badRequest == status)
|
||||
{
|
||||
return badRequestHTML;
|
||||
}
|
||||
return internalServerErrorHTML;
|
||||
}
|
||||
|
||||
boost::asio::const_buffer Reply::ToBuffer(Reply::status_type status)
|
||||
{
|
||||
if (Reply::ok == status)
|
||||
{
|
||||
return boost::asio::buffer(okString);
|
||||
}
|
||||
if (Reply::internalServerError == status)
|
||||
{
|
||||
return boost::asio::buffer(internalServerErrorString);
|
||||
}
|
||||
return boost::asio::buffer(badRequestString);
|
||||
}
|
||||
|
||||
Reply::Reply() : status(ok) {}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef REQUEST_H
|
||||
#define REQUEST_H
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace http
|
||||
{
|
||||
|
||||
struct Request
|
||||
{
|
||||
std::string uri;
|
||||
std::string referrer;
|
||||
std::string agent;
|
||||
boost::asio::ip::address endpoint;
|
||||
};
|
||||
|
||||
} // namespace http
|
||||
|
||||
#endif // REQUEST_H
|
||||
@@ -1,143 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "RequestHandler.h"
|
||||
|
||||
#include "APIGrammar.h"
|
||||
#include "Http/Request.h"
|
||||
|
||||
#include "../data_structures/json_container.hpp"
|
||||
#include "../Library/OSRM.h"
|
||||
#include "../Util/json_renderer.hpp"
|
||||
#include "../Util/simple_logger.hpp"
|
||||
#include "../Util/string_util.hpp"
|
||||
#include "../typedefs.h"
|
||||
|
||||
#include <osrm/Reply.h>
|
||||
#include <osrm/RouteParameters.h>
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
RequestHandler::RequestHandler() : routing_machine(nullptr) {}
|
||||
|
||||
void RequestHandler::handle_request(const http::Request &req, http::Reply &reply)
|
||||
{
|
||||
// parse command
|
||||
try
|
||||
{
|
||||
std::string request;
|
||||
URIDecode(req.uri, request);
|
||||
|
||||
// deactivated as GCC apparently does not implement that, not even in 4.9
|
||||
// std::time_t t = std::time(nullptr);
|
||||
// SimpleLogger().Write() << std::put_time(std::localtime(&t), "%m-%d-%Y %H:%M:%S") <<
|
||||
// " " << req.endpoint.to_string() << " " <<
|
||||
// req.referrer << ( 0 == req.referrer.length() ? "- " :" ") <<
|
||||
// req.agent << ( 0 == req.agent.length() ? "- " :" ") << request;
|
||||
|
||||
time_t ltime;
|
||||
struct tm *time_stamp;
|
||||
|
||||
ltime = time(nullptr);
|
||||
time_stamp = localtime(<ime);
|
||||
|
||||
// log timestamp
|
||||
SimpleLogger().Write() << (time_stamp->tm_mday < 10 ? "0" : "") << time_stamp->tm_mday << "-"
|
||||
<< (time_stamp->tm_mon + 1 < 10 ? "0" : "") << (time_stamp->tm_mon + 1) << "-"
|
||||
<< 1900 + time_stamp->tm_year << " " << (time_stamp->tm_hour < 10 ? "0" : "")
|
||||
<< time_stamp->tm_hour << ":" << (time_stamp->tm_min < 10 ? "0" : "") << time_stamp->tm_min
|
||||
<< ":" << (time_stamp->tm_sec < 10 ? "0" : "") << time_stamp->tm_sec << " "
|
||||
<< req.endpoint.to_string() << " " << req.referrer
|
||||
<< (0 == req.referrer.length() ? "- " : " ") << req.agent
|
||||
<< (0 == req.agent.length() ? "- " : " ") << request;
|
||||
|
||||
RouteParameters route_parameters;
|
||||
APIGrammarParser api_parser(&route_parameters);
|
||||
|
||||
auto iter = request.begin();
|
||||
const bool result = boost::spirit::qi::parse(iter, request.end(), api_parser);
|
||||
|
||||
// check if the was an error with the request
|
||||
if (!result || (iter != request.end()))
|
||||
{
|
||||
reply = http::Reply::StockReply(http::Reply::badRequest);
|
||||
reply.content.clear();
|
||||
const auto position = std::distance(request.begin(), iter);
|
||||
JSON::Object json_result;
|
||||
json_result.values["status"] = 400;
|
||||
std::string message = "Query string malformed close to position ";
|
||||
message += cast::integral_to_string(position);
|
||||
json_result.values["status_message"] = message;
|
||||
JSON::render(reply.content, json_result);
|
||||
return;
|
||||
}
|
||||
|
||||
// parsing done, lets call the right plugin to handle the request
|
||||
BOOST_ASSERT_MSG(routing_machine != nullptr, "pointer not init'ed");
|
||||
|
||||
if (!route_parameters.jsonp_parameter.empty())
|
||||
{ // prepend response with jsonp parameter
|
||||
const std::string json_p = (route_parameters.jsonp_parameter + "(");
|
||||
reply.content.insert(reply.content.end(), json_p.begin(), json_p.end());
|
||||
}
|
||||
routing_machine->RunQuery(route_parameters, reply);
|
||||
if (!route_parameters.jsonp_parameter.empty())
|
||||
{ // append brace to jsonp response
|
||||
reply.content.push_back(')');
|
||||
}
|
||||
|
||||
// set headers
|
||||
reply.headers.emplace_back("Content-Length", cast::integral_to_string(reply.content.size()));
|
||||
if ("gpx" == route_parameters.output_format)
|
||||
{ // gpx file
|
||||
reply.headers.emplace_back("Content-Type", "application/gpx+xml; charset=UTF-8");
|
||||
reply.headers.emplace_back("Content-Disposition", "attachment; filename=\"route.gpx\"");
|
||||
}
|
||||
else if (route_parameters.jsonp_parameter.empty())
|
||||
{ // json file
|
||||
reply.headers.emplace_back("Content-Type", "application/json; charset=UTF-8");
|
||||
reply.headers.emplace_back("Content-Disposition", "inline; filename=\"response.json\"");
|
||||
}
|
||||
else
|
||||
{ // jsonp
|
||||
reply.headers.emplace_back("Content-Type", "text/javascript; charset=UTF-8");
|
||||
reply.headers.emplace_back("Content-Disposition", "inline; filename=\"response.js\"");
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
reply = http::Reply::StockReply(http::Reply::internalServerError);
|
||||
SimpleLogger().Write(logWARNING) << "[server error] code: " << e.what()
|
||||
<< ", uri: " << req.uri;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void RequestHandler::RegisterRoutingMachine(OSRM *osrm) { routing_machine = osrm; }
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef REQUEST_HANDLER_H
|
||||
#define REQUEST_HANDLER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
template <typename Iterator, class HandlerT> struct APIGrammar;
|
||||
struct RouteParameters;
|
||||
class OSRM;
|
||||
|
||||
namespace http
|
||||
{
|
||||
class Reply;
|
||||
struct Request;
|
||||
}
|
||||
|
||||
class RequestHandler
|
||||
{
|
||||
|
||||
public:
|
||||
using APIGrammarParser = APIGrammar<std::string::iterator, RouteParameters>;
|
||||
|
||||
RequestHandler();
|
||||
RequestHandler(const RequestHandler &) = delete;
|
||||
|
||||
void handle_request(const http::Request &req, http::Reply &rep);
|
||||
void RegisterRoutingMachine(OSRM *osrm);
|
||||
|
||||
private:
|
||||
OSRM *routing_machine;
|
||||
};
|
||||
|
||||
#endif // REQUEST_HANDLER_H
|
||||
@@ -1,310 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "RequestParser.h"
|
||||
|
||||
#include "Http/Request.h"
|
||||
|
||||
namespace http
|
||||
{
|
||||
|
||||
RequestParser::RequestParser() : state_(method_start), header({"", ""}) {}
|
||||
|
||||
void RequestParser::Reset() { state_ = method_start; }
|
||||
|
||||
boost::tuple<boost::tribool, char *>
|
||||
RequestParser::Parse(Request &req, char *begin, char *end, http::CompressionType &compression_type)
|
||||
{
|
||||
while (begin != end)
|
||||
{
|
||||
boost::tribool result = consume(req, *begin++, compression_type);
|
||||
if (result || !result)
|
||||
{
|
||||
return boost::make_tuple(result, begin);
|
||||
}
|
||||
}
|
||||
boost::tribool result = boost::indeterminate;
|
||||
return boost::make_tuple(result, begin);
|
||||
}
|
||||
|
||||
boost::tribool
|
||||
RequestParser::consume(Request &req, char input, http::CompressionType &compression_type)
|
||||
{
|
||||
switch (state_)
|
||||
{
|
||||
case method_start:
|
||||
if (!isChar(input) || isCTL(input) || isTSpecial(input))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
state_ = method;
|
||||
return boost::indeterminate;
|
||||
case method:
|
||||
if (input == ' ')
|
||||
{
|
||||
state_ = uri;
|
||||
return boost::indeterminate;
|
||||
}
|
||||
if (!isChar(input) || isCTL(input) || isTSpecial(input))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return boost::indeterminate;
|
||||
case uri_start:
|
||||
if (isCTL(input))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
state_ = uri;
|
||||
req.uri.push_back(input);
|
||||
return boost::indeterminate;
|
||||
case uri:
|
||||
if (input == ' ')
|
||||
{
|
||||
state_ = http_version_h;
|
||||
return boost::indeterminate;
|
||||
}
|
||||
if (isCTL(input))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
req.uri.push_back(input);
|
||||
return boost::indeterminate;
|
||||
case http_version_h:
|
||||
if (input == 'H')
|
||||
{
|
||||
state_ = http_version_t_1;
|
||||
return boost::indeterminate;
|
||||
}
|
||||
return false;
|
||||
case http_version_t_1:
|
||||
if (input == 'T')
|
||||
{
|
||||
state_ = http_version_t_2;
|
||||
return boost::indeterminate;
|
||||
}
|
||||
return false;
|
||||
case http_version_t_2:
|
||||
if (input == 'T')
|
||||
{
|
||||
state_ = http_version_p;
|
||||
return boost::indeterminate;
|
||||
}
|
||||
return false;
|
||||
case http_version_p:
|
||||
if (input == 'P')
|
||||
{
|
||||
state_ = http_version_slash;
|
||||
return boost::indeterminate;
|
||||
}
|
||||
return false;
|
||||
case http_version_slash:
|
||||
if (input == '/')
|
||||
{
|
||||
state_ = http_version_major_start;
|
||||
return boost::indeterminate;
|
||||
}
|
||||
return false;
|
||||
case http_version_major_start:
|
||||
if (isDigit(input))
|
||||
{
|
||||
state_ = http_version_major;
|
||||
return boost::indeterminate;
|
||||
}
|
||||
return false;
|
||||
case http_version_major:
|
||||
if (input == '.')
|
||||
{
|
||||
state_ = http_version_minor_start;
|
||||
return boost::indeterminate;
|
||||
}
|
||||
if (isDigit(input))
|
||||
{
|
||||
return boost::indeterminate;
|
||||
}
|
||||
return false;
|
||||
case http_version_minor_start:
|
||||
if (isDigit(input))
|
||||
{
|
||||
state_ = http_version_minor;
|
||||
return boost::indeterminate;
|
||||
}
|
||||
return false;
|
||||
case http_version_minor:
|
||||
if (input == '\r')
|
||||
{
|
||||
state_ = expecting_newline_1;
|
||||
return boost::indeterminate;
|
||||
}
|
||||
if (isDigit(input))
|
||||
{
|
||||
return boost::indeterminate;
|
||||
}
|
||||
return false;
|
||||
case expecting_newline_1:
|
||||
if (input == '\n')
|
||||
{
|
||||
state_ = header_line_start;
|
||||
return boost::indeterminate;
|
||||
}
|
||||
return false;
|
||||
case header_line_start:
|
||||
if (header.name == "Accept-Encoding")
|
||||
{
|
||||
/* giving gzip precedence over deflate */
|
||||
if (header.value.find("deflate") != std::string::npos)
|
||||
{
|
||||
compression_type = deflateRFC1951;
|
||||
}
|
||||
if (header.value.find("gzip") != std::string::npos)
|
||||
{
|
||||
compression_type = gzipRFC1952;
|
||||
}
|
||||
}
|
||||
|
||||
if ("Referer" == header.name)
|
||||
{
|
||||
req.referrer = header.value;
|
||||
}
|
||||
|
||||
if ("User-Agent" == header.name)
|
||||
{
|
||||
req.agent = header.value;
|
||||
}
|
||||
|
||||
if (input == '\r')
|
||||
{
|
||||
state_ = expecting_newline_3;
|
||||
return boost::indeterminate;
|
||||
}
|
||||
if (!isChar(input) || isCTL(input) || isTSpecial(input))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
state_ = header_name;
|
||||
header.Clear();
|
||||
header.name.push_back(input);
|
||||
return boost::indeterminate;
|
||||
case header_lws:
|
||||
if (input == '\r')
|
||||
{
|
||||
state_ = expecting_newline_2;
|
||||
return boost::indeterminate;
|
||||
}
|
||||
if (input == ' ' || input == '\t')
|
||||
{
|
||||
return boost::indeterminate;
|
||||
}
|
||||
if (isCTL(input))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
state_ = header_value;
|
||||
return boost::indeterminate;
|
||||
case header_name:
|
||||
if (input == ':')
|
||||
{
|
||||
state_ = space_before_header_value;
|
||||
return boost::indeterminate;
|
||||
}
|
||||
if (!isChar(input) || isCTL(input) || isTSpecial(input))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
header.name.push_back(input);
|
||||
return boost::indeterminate;
|
||||
case space_before_header_value:
|
||||
if (input == ' ')
|
||||
{
|
||||
state_ = header_value;
|
||||
return boost::indeterminate;
|
||||
}
|
||||
return false;
|
||||
case header_value:
|
||||
if (input == '\r')
|
||||
{
|
||||
state_ = expecting_newline_2;
|
||||
return boost::indeterminate;
|
||||
}
|
||||
if (isCTL(input))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
header.value.push_back(input);
|
||||
return boost::indeterminate;
|
||||
case expecting_newline_2:
|
||||
if (input == '\n')
|
||||
{
|
||||
state_ = header_line_start;
|
||||
return boost::indeterminate;
|
||||
}
|
||||
return false;
|
||||
default: // expecting_newline_3:
|
||||
return (input == '\n');
|
||||
// default:
|
||||
// return false;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool RequestParser::isChar(int character) { return character >= 0 && character <= 127; }
|
||||
|
||||
inline bool RequestParser::isCTL(int character)
|
||||
{
|
||||
return (character >= 0 && character <= 31) || (character == 127);
|
||||
}
|
||||
|
||||
inline bool RequestParser::isTSpecial(int character)
|
||||
{
|
||||
switch (character)
|
||||
{
|
||||
case '(':
|
||||
case ')':
|
||||
case '<':
|
||||
case '>':
|
||||
case '@':
|
||||
case ',':
|
||||
case ';':
|
||||
case ':':
|
||||
case '\\':
|
||||
case '"':
|
||||
case '/':
|
||||
case '[':
|
||||
case ']':
|
||||
case '?':
|
||||
case '=':
|
||||
case '{':
|
||||
case '}':
|
||||
case ' ':
|
||||
case '\t':
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool RequestParser::isDigit(int character) { return character >= '0' && character <= '9'; }
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef REQUEST_PARSER_H
|
||||
#define REQUEST_PARSER_H
|
||||
|
||||
#include "Http/CompressionType.h"
|
||||
#include <osrm/Header.h>
|
||||
|
||||
#include <boost/logic/tribool.hpp>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
|
||||
namespace http
|
||||
{
|
||||
|
||||
struct Request;
|
||||
|
||||
class RequestParser
|
||||
{
|
||||
public:
|
||||
RequestParser();
|
||||
void Reset();
|
||||
|
||||
boost::tuple<boost::tribool, char *>
|
||||
Parse(Request &req, char *begin, char *end, CompressionType &compression_type);
|
||||
|
||||
private:
|
||||
boost::tribool consume(Request &req, char input, CompressionType &compression_type);
|
||||
|
||||
inline bool isChar(int c);
|
||||
|
||||
inline bool isCTL(int c);
|
||||
|
||||
inline bool isTSpecial(int c);
|
||||
|
||||
inline bool isDigit(int c);
|
||||
|
||||
enum state
|
||||
{ method_start,
|
||||
method,
|
||||
uri_start,
|
||||
uri,
|
||||
http_version_h,
|
||||
http_version_t_1,
|
||||
http_version_t_2,
|
||||
http_version_p,
|
||||
http_version_slash,
|
||||
http_version_major_start,
|
||||
http_version_major,
|
||||
http_version_minor_start,
|
||||
http_version_minor,
|
||||
expecting_newline_1,
|
||||
header_line_start,
|
||||
header_lws,
|
||||
header_name,
|
||||
space_before_header_value,
|
||||
header_value,
|
||||
expecting_newline_2,
|
||||
expecting_newline_3 } state_;
|
||||
|
||||
Header header;
|
||||
};
|
||||
|
||||
} // namespace http
|
||||
|
||||
#endif // REQUEST_PARSER_H
|
||||
-119
@@ -1,119 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef SERVER_H
|
||||
#define SERVER_H
|
||||
|
||||
#include "Connection.h"
|
||||
#include "RequestHandler.h"
|
||||
|
||||
#include "../Util/cast.hpp"
|
||||
#include "../Util/make_unique.hpp"
|
||||
#include "../Util/simple_logger.hpp"
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
class Server
|
||||
{
|
||||
public:
|
||||
|
||||
// Note: returns a shared instead of a unique ptr as it is captured in a lambda somewhere else
|
||||
static std::shared_ptr<Server> CreateServer(std::string &ip_address, int ip_port, unsigned requested_num_threads)
|
||||
{
|
||||
SimpleLogger().Write() << "http 1.1 compression handled by zlib version " << zlibVersion();
|
||||
const unsigned hardware_threads = std::max(1u, std::thread::hardware_concurrency());
|
||||
const unsigned real_num_threads = std::min(hardware_threads, requested_num_threads);
|
||||
return std::make_shared<Server>(ip_address, ip_port, real_num_threads);
|
||||
}
|
||||
|
||||
explicit Server(const std::string &address, const int port, const unsigned thread_pool_size)
|
||||
: thread_pool_size(thread_pool_size), acceptor(io_service),
|
||||
new_connection(std::make_shared<http::Connection>(io_service, request_handler)), request_handler()
|
||||
{
|
||||
const std::string port_string = cast::integral_to_string(port);
|
||||
|
||||
boost::asio::ip::tcp::resolver resolver(io_service);
|
||||
boost::asio::ip::tcp::resolver::query query(address, port_string);
|
||||
boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve(query);
|
||||
|
||||
acceptor.open(endpoint.protocol());
|
||||
acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
|
||||
acceptor.bind(endpoint);
|
||||
acceptor.listen();
|
||||
acceptor.async_accept(
|
||||
new_connection->socket(),
|
||||
boost::bind(&Server::HandleAccept, this, boost::asio::placeholders::error));
|
||||
}
|
||||
|
||||
void Run()
|
||||
{
|
||||
std::vector<std::shared_ptr<std::thread>> threads;
|
||||
for (unsigned i = 0; i < thread_pool_size; ++i)
|
||||
{
|
||||
std::shared_ptr<std::thread> thread = std::make_shared<std::thread>(
|
||||
boost::bind(&boost::asio::io_service::run, &io_service));
|
||||
threads.push_back(thread);
|
||||
}
|
||||
for (auto thread : threads)
|
||||
{
|
||||
thread->join();
|
||||
}
|
||||
}
|
||||
|
||||
void Stop() { io_service.stop(); }
|
||||
|
||||
RequestHandler &GetRequestHandlerPtr() { return request_handler; }
|
||||
|
||||
private:
|
||||
void HandleAccept(const boost::system::error_code &e)
|
||||
{
|
||||
if (!e)
|
||||
{
|
||||
new_connection->start();
|
||||
new_connection = std::make_shared<http::Connection>(io_service, request_handler);
|
||||
acceptor.async_accept(
|
||||
new_connection->socket(),
|
||||
boost::bind(&Server::HandleAccept, this, boost::asio::placeholders::error));
|
||||
}
|
||||
}
|
||||
|
||||
unsigned thread_pool_size;
|
||||
boost::asio::io_service io_service;
|
||||
boost::asio::ip::tcp::acceptor acceptor;
|
||||
std::shared_ptr<http::Connection> new_connection;
|
||||
RequestHandler request_handler;
|
||||
};
|
||||
|
||||
#endif // SERVER_H
|
||||
@@ -1,109 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "../../algorithms/douglas_peucker.hpp"
|
||||
#include "../../data_structures/segment_information.hpp"
|
||||
#include "../../Include/osrm/Coordinate.h"
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/test_case_template.hpp>
|
||||
#include <boost/mpl/list.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(douglas_peucker)
|
||||
|
||||
SegmentInformation getTestInfo(int lat, int lon, bool necessary)
|
||||
{
|
||||
return SegmentInformation(FixedPointCoordinate(lat, lon),
|
||||
0, 0, 0, TurnInstruction::HeadOn, necessary, false, 0);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(all_necessary_test)
|
||||
{
|
||||
/*
|
||||
* x
|
||||
* / \
|
||||
* x \
|
||||
* / \
|
||||
* x x
|
||||
*/
|
||||
std::vector<SegmentInformation> info = {
|
||||
getTestInfo(5, 5, true),
|
||||
getTestInfo(6, 6, true),
|
||||
getTestInfo(10, 10, true),
|
||||
getTestInfo(5, 15, true)
|
||||
};
|
||||
DouglasPeucker dp;
|
||||
for (unsigned z = 0; z < DOUGLAS_PEUCKER_THRESHOLDS.size(); z++)
|
||||
{
|
||||
dp.Run(info, z);
|
||||
for (const auto& i : info)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(i.necessary, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(remove_second_node_test)
|
||||
{
|
||||
DouglasPeucker dp;
|
||||
for (unsigned z = 0; z < DOUGLAS_PEUCKER_THRESHOLDS.size(); z++)
|
||||
{
|
||||
/*
|
||||
* x--x
|
||||
* | \
|
||||
* x-x x
|
||||
* |
|
||||
* x
|
||||
*/
|
||||
std::vector<SegmentInformation> info = {
|
||||
getTestInfo(5 * COORDINATE_PRECISION,
|
||||
5 * COORDINATE_PRECISION, true),
|
||||
getTestInfo(5 * COORDINATE_PRECISION,
|
||||
5 * COORDINATE_PRECISION + DOUGLAS_PEUCKER_THRESHOLDS[z], false),
|
||||
getTestInfo(10 * COORDINATE_PRECISION,
|
||||
10 * COORDINATE_PRECISION, false),
|
||||
getTestInfo(10 * COORDINATE_PRECISION,
|
||||
10 + COORDINATE_PRECISION + DOUGLAS_PEUCKER_THRESHOLDS[z] * 2, false),
|
||||
getTestInfo(5 * COORDINATE_PRECISION,
|
||||
15 * COORDINATE_PRECISION, false),
|
||||
getTestInfo(5 * COORDINATE_PRECISION + DOUGLAS_PEUCKER_THRESHOLDS[z],
|
||||
15 * COORDINATE_PRECISION, true),
|
||||
};
|
||||
BOOST_TEST_MESSAGE("Threshold (" << z << "): " << DOUGLAS_PEUCKER_THRESHOLDS[z]);
|
||||
dp.Run(info, z);
|
||||
BOOST_CHECK_EQUAL(info[0].necessary, true);
|
||||
BOOST_CHECK_EQUAL(info[1].necessary, false);
|
||||
BOOST_CHECK_EQUAL(info[2].necessary, true);
|
||||
BOOST_CHECK_EQUAL(info[3].necessary, true);
|
||||
BOOST_CHECK_EQUAL(info[4].necessary, false);
|
||||
BOOST_CHECK_EQUAL(info[5].necessary, true);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#define BOOST_TEST_MODULE algorithm tests
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
/*
|
||||
* This file will contain an automatically generated main function.
|
||||
*/
|
||||
|
||||
@@ -1,178 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "../../data_structures/binary_heap.hpp"
|
||||
#include "../../typedefs.h"
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/test_case_template.hpp>
|
||||
#include <boost/mpl/list.hpp>
|
||||
|
||||
#include <random>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(binary_heap)
|
||||
|
||||
struct TestData
|
||||
{
|
||||
unsigned value;
|
||||
};
|
||||
|
||||
typedef NodeID TestNodeID;
|
||||
typedef int TestKey;
|
||||
typedef int TestWeight;
|
||||
typedef boost::mpl::list<ArrayStorage<TestNodeID, TestKey>,
|
||||
MapStorage<TestNodeID, TestKey>,
|
||||
UnorderedMapStorage<TestNodeID, TestKey>> storage_types;
|
||||
|
||||
template <unsigned NUM_ELEM> struct RandomDataFixture
|
||||
{
|
||||
RandomDataFixture()
|
||||
{
|
||||
for (unsigned i = 0; i < NUM_ELEM; i++)
|
||||
{
|
||||
data.push_back(TestData{i * 3});
|
||||
weights.push_back((i + 1) * 100);
|
||||
ids.push_back(i);
|
||||
order.push_back(i);
|
||||
}
|
||||
|
||||
// Choosen by a fair W20 dice roll
|
||||
std::mt19937 g(15);
|
||||
|
||||
std::shuffle(order.begin(), order.end(), g);
|
||||
}
|
||||
|
||||
std::vector<TestData> data;
|
||||
std::vector<TestWeight> weights;
|
||||
std::vector<TestNodeID> ids;
|
||||
std::vector<unsigned> order;
|
||||
};
|
||||
|
||||
constexpr unsigned NUM_NODES = 100;
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE_TEMPLATE(insert_test, T, storage_types, RandomDataFixture<NUM_NODES>)
|
||||
{
|
||||
BinaryHeap<TestNodeID, TestKey, TestWeight, TestData, T> heap(NUM_NODES);
|
||||
|
||||
TestWeight min_weight = std::numeric_limits<TestWeight>::max();
|
||||
TestNodeID min_id;
|
||||
|
||||
for (unsigned idx : order)
|
||||
{
|
||||
BOOST_CHECK(!heap.WasInserted(ids[idx]));
|
||||
|
||||
heap.Insert(ids[idx], weights[idx], data[idx]);
|
||||
|
||||
BOOST_CHECK(heap.WasInserted(ids[idx]));
|
||||
|
||||
if (weights[idx] < min_weight)
|
||||
{
|
||||
min_weight = weights[idx];
|
||||
min_id = ids[idx];
|
||||
}
|
||||
BOOST_CHECK_EQUAL(min_id, heap.Min());
|
||||
}
|
||||
|
||||
for (auto id : ids)
|
||||
{
|
||||
const auto &d = heap.GetData(id);
|
||||
BOOST_CHECK_EQUAL(d.value, data[id].value);
|
||||
|
||||
const auto &w = heap.GetKey(id);
|
||||
BOOST_CHECK_EQUAL(w, weights[id]);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE_TEMPLATE(delete_min_test, T, storage_types, RandomDataFixture<NUM_NODES>)
|
||||
{
|
||||
BinaryHeap<TestNodeID, TestKey, TestWeight, TestData, T> heap(NUM_NODES);
|
||||
|
||||
for (unsigned idx : order)
|
||||
{
|
||||
heap.Insert(ids[idx], weights[idx], data[idx]);
|
||||
}
|
||||
|
||||
for (auto id : ids)
|
||||
{
|
||||
BOOST_CHECK(!heap.WasRemoved(id));
|
||||
|
||||
BOOST_CHECK_EQUAL(heap.Min(), id);
|
||||
BOOST_CHECK_EQUAL(id, heap.DeleteMin());
|
||||
if (id + 1 < NUM_NODES)
|
||||
BOOST_CHECK_EQUAL(heap.Min(), id + 1);
|
||||
|
||||
BOOST_CHECK(heap.WasRemoved(id));
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE_TEMPLATE(delete_all_test, T, storage_types, RandomDataFixture<NUM_NODES>)
|
||||
{
|
||||
BinaryHeap<TestNodeID, TestKey, TestWeight, TestData, T> heap(NUM_NODES);
|
||||
|
||||
for (unsigned idx : order)
|
||||
{
|
||||
heap.Insert(ids[idx], weights[idx], data[idx]);
|
||||
}
|
||||
|
||||
heap.DeleteAll();
|
||||
|
||||
BOOST_CHECK(heap.Empty());
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE_TEMPLATE(decrease_key_test, T, storage_types, RandomDataFixture<10>)
|
||||
{
|
||||
BinaryHeap<TestNodeID, TestKey, TestWeight, TestData, T> heap(10);
|
||||
|
||||
for (unsigned idx : order)
|
||||
{
|
||||
heap.Insert(ids[idx], weights[idx], data[idx]);
|
||||
}
|
||||
|
||||
std::vector<TestNodeID> rids(ids);
|
||||
std::reverse(rids.begin(), rids.end());
|
||||
|
||||
for (auto id : rids)
|
||||
{
|
||||
TestNodeID min_id = heap.Min();
|
||||
TestWeight min_weight = heap.GetKey(min_id);
|
||||
|
||||
// decrease weight until we reach min weight
|
||||
while (weights[id] > min_weight)
|
||||
{
|
||||
heap.DecreaseKey(id, weights[id]);
|
||||
BOOST_CHECK_EQUAL(heap.Min(), min_id);
|
||||
weights[id]--;
|
||||
}
|
||||
|
||||
// make weight smaller than min
|
||||
weights[id] -= 2;
|
||||
heap.DecreaseKey(id, weights[id]);
|
||||
BOOST_CHECK_EQUAL(heap.Min(), id);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
@@ -1,131 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "../../data_structures/range_table.hpp"
|
||||
#include "../../typedefs.h"
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/test_case_template.hpp>
|
||||
|
||||
#include <numeric>
|
||||
|
||||
constexpr unsigned BLOCK_SIZE = 16;
|
||||
typedef RangeTable<BLOCK_SIZE, false> TestRangeTable;
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(range_table)
|
||||
|
||||
void ConstructionTest(std::vector<unsigned> lengths, std::vector<unsigned> offsets)
|
||||
{
|
||||
BOOST_ASSERT(lengths.size() == offsets.size() - 1);
|
||||
|
||||
TestRangeTable table(lengths);
|
||||
|
||||
for (unsigned i = 0; i < lengths.size(); i++)
|
||||
{
|
||||
auto range = table.GetRange(i);
|
||||
BOOST_CHECK_EQUAL(range.front(), offsets[i]);
|
||||
BOOST_CHECK_EQUAL(range.back() + 1, offsets[i + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ComputeLengthsOffsets(std::vector<unsigned> &lengths, std::vector<unsigned> &offsets, unsigned num)
|
||||
{
|
||||
lengths.resize(num);
|
||||
offsets.resize(num + 1);
|
||||
std::iota(lengths.begin(), lengths.end(), 1);
|
||||
offsets[0] = 0;
|
||||
std::partial_sum(lengths.begin(), lengths.end(), offsets.begin() + 1);
|
||||
|
||||
std::stringstream l_ss;
|
||||
l_ss << "Lengths: ";
|
||||
for (auto l : lengths)
|
||||
l_ss << l << ", ";
|
||||
BOOST_TEST_MESSAGE(l_ss.str());
|
||||
std::stringstream o_ss;
|
||||
o_ss << "Offsets: ";
|
||||
for (auto o : offsets)
|
||||
o_ss << o << ", ";
|
||||
BOOST_TEST_MESSAGE(o_ss.str());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(serialization_test)
|
||||
{
|
||||
std::vector<unsigned> lengths;
|
||||
std::vector<unsigned> offsets;
|
||||
ComputeLengthsOffsets(lengths, offsets, (BLOCK_SIZE + 1) * 10);
|
||||
|
||||
TestRangeTable in_table(lengths);
|
||||
TestRangeTable out_table;
|
||||
|
||||
std::stringstream ss;
|
||||
ss << in_table;
|
||||
ss >> out_table;
|
||||
|
||||
for (unsigned i = 0; i < lengths.size(); i++)
|
||||
{
|
||||
auto range = out_table.GetRange(i);
|
||||
BOOST_CHECK_EQUAL(range.front(), offsets[i]);
|
||||
BOOST_CHECK_EQUAL(range.back() + 1, offsets[i + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(construction_test)
|
||||
{
|
||||
// only offset empty block
|
||||
ConstructionTest({1}, {0, 1});
|
||||
// first block almost full => sentinel is last element of block
|
||||
// [0] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, (16)}
|
||||
std::vector<unsigned> almost_full_lengths;
|
||||
std::vector<unsigned> almost_full_offsets;
|
||||
ComputeLengthsOffsets(almost_full_lengths, almost_full_offsets, BLOCK_SIZE);
|
||||
ConstructionTest(almost_full_lengths, almost_full_offsets);
|
||||
|
||||
// first block full => sentinel is offset of new block, next block empty
|
||||
// [0] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
|
||||
// [(153)] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
||||
std::vector<unsigned> full_lengths;
|
||||
std::vector<unsigned> full_offsets;
|
||||
ComputeLengthsOffsets(full_lengths, full_offsets, BLOCK_SIZE + 1);
|
||||
ConstructionTest(full_lengths, full_offsets);
|
||||
|
||||
// first block full and offset of next block not sentinel, but the first differential value
|
||||
// [0] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
|
||||
// [153] {(17), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
||||
std::vector<unsigned> over_full_lengths;
|
||||
std::vector<unsigned> over_full_offsets;
|
||||
ComputeLengthsOffsets(over_full_lengths, over_full_offsets, BLOCK_SIZE + 2);
|
||||
ConstructionTest(over_full_lengths, over_full_offsets);
|
||||
|
||||
// test multiple blocks
|
||||
std::vector<unsigned> multiple_lengths;
|
||||
std::vector<unsigned> multiple_offsets;
|
||||
ComputeLengthsOffsets(multiple_lengths, multiple_offsets, (BLOCK_SIZE + 1) * 10);
|
||||
ConstructionTest(multiple_lengths, multiple_offsets);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
@@ -1,191 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "../../data_structures/static_graph.hpp"
|
||||
#include "../../typedefs.h"
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/test_case_template.hpp>
|
||||
#include <boost/mpl/list.hpp>
|
||||
|
||||
#include <random>
|
||||
#include <unordered_map>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(static_graph)
|
||||
|
||||
struct TestData
|
||||
{
|
||||
EdgeID id;
|
||||
bool shortcut;
|
||||
unsigned distance;
|
||||
};
|
||||
|
||||
struct TestEdge
|
||||
{
|
||||
unsigned source;
|
||||
unsigned target;
|
||||
unsigned distance;
|
||||
};
|
||||
|
||||
typedef StaticGraph<TestData> TestStaticGraph;
|
||||
typedef TestStaticGraph::NodeArrayEntry TestNodeArrayEntry;
|
||||
typedef TestStaticGraph::EdgeArrayEntry TestEdgeArrayEntry;
|
||||
typedef TestStaticGraph::InputEdge TestInputEdge;
|
||||
|
||||
constexpr unsigned TEST_NUM_NODES = 100;
|
||||
constexpr unsigned TEST_NUM_EDGES = 500;
|
||||
// Choosen by a fair W20 dice roll (this value is completely arbitrary)
|
||||
constexpr unsigned RANDOM_SEED = 15;
|
||||
|
||||
template <unsigned NUM_NODES, unsigned NUM_EDGES> struct RandomArrayEntryFixture
|
||||
{
|
||||
RandomArrayEntryFixture()
|
||||
{
|
||||
std::mt19937 g(RANDOM_SEED);
|
||||
|
||||
std::uniform_int_distribution<> edge_udist(0, NUM_EDGES - 1);
|
||||
std::vector<unsigned> offsets;
|
||||
for (unsigned i = 0; i < NUM_NODES; i++)
|
||||
{
|
||||
offsets.push_back(edge_udist(g));
|
||||
}
|
||||
std::sort(offsets.begin(), offsets.end());
|
||||
// add sentinel
|
||||
offsets.push_back(offsets.back());
|
||||
|
||||
// extract interval lengths
|
||||
for (unsigned i = 0; i < offsets.size() - 1; i++)
|
||||
{
|
||||
lengths.push_back(offsets[i + 1] - offsets[i]);
|
||||
}
|
||||
lengths.push_back(NUM_EDGES - offsets[NUM_NODES - 1]);
|
||||
|
||||
for (auto offset : offsets)
|
||||
{
|
||||
nodes.emplace_back(TestNodeArrayEntry{offset});
|
||||
}
|
||||
|
||||
std::uniform_int_distribution<> lengths_udist(0, 100000);
|
||||
std::uniform_int_distribution<> node_udist(0, NUM_NODES - 1);
|
||||
for (unsigned i = 0; i < NUM_EDGES; i++)
|
||||
{
|
||||
edges.emplace_back(
|
||||
TestEdgeArrayEntry{static_cast<unsigned>(node_udist(g)),
|
||||
TestData{i, false, static_cast<unsigned>(lengths_udist(g))}});
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < NUM_NODES; i++)
|
||||
order.push_back(i);
|
||||
std::shuffle(order.begin(), order.end(), g);
|
||||
}
|
||||
|
||||
typename ShM<TestNodeArrayEntry, false>::vector nodes;
|
||||
typename ShM<TestEdgeArrayEntry, false>::vector edges;
|
||||
std::vector<unsigned> lengths;
|
||||
std::vector<unsigned> order;
|
||||
};
|
||||
|
||||
typedef RandomArrayEntryFixture<TEST_NUM_NODES, TEST_NUM_EDGES> TestRandomArrayEntryFixture;
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(array_test, TestRandomArrayEntryFixture)
|
||||
{
|
||||
auto nodes_copy = nodes;
|
||||
|
||||
TestStaticGraph graph(nodes, edges);
|
||||
|
||||
BOOST_CHECK_EQUAL(graph.GetNumberOfEdges(), TEST_NUM_EDGES);
|
||||
BOOST_CHECK_EQUAL(graph.GetNumberOfNodes(), TEST_NUM_NODES);
|
||||
|
||||
for (auto idx : order)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(graph.BeginEdges((NodeID)idx), nodes_copy[idx].first_edge);
|
||||
BOOST_CHECK_EQUAL(graph.EndEdges((NodeID)idx), nodes_copy[idx + 1].first_edge);
|
||||
BOOST_CHECK_EQUAL(graph.GetOutDegree((NodeID)idx), lengths[idx]);
|
||||
}
|
||||
}
|
||||
|
||||
TestStaticGraph GraphFromEdgeList(const std::vector<TestEdge> &edges)
|
||||
{
|
||||
std::vector<TestInputEdge> input_edges;
|
||||
unsigned i = 0;
|
||||
unsigned num_nodes = 0;
|
||||
for (const auto &e : edges)
|
||||
{
|
||||
input_edges.push_back(TestInputEdge{e.source, e.target, TestData{i++, false, e.distance}});
|
||||
|
||||
num_nodes = std::max(num_nodes, std::max(e.source, e.target));
|
||||
}
|
||||
|
||||
return TestStaticGraph(num_nodes, input_edges);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(find_test)
|
||||
{
|
||||
/*
|
||||
* (0) -1-> (1)
|
||||
* ^ ^
|
||||
* 2 1
|
||||
* | |
|
||||
* (3) -4-> (4)
|
||||
* <-3-
|
||||
*/
|
||||
TestStaticGraph simple_graph = GraphFromEdgeList({TestEdge{0, 1, 1},
|
||||
TestEdge{3, 0, 2},
|
||||
TestEdge{3, 4, 4},
|
||||
TestEdge{4, 3, 3},
|
||||
TestEdge{3, 0, 1}});
|
||||
|
||||
auto eit = simple_graph.FindEdge(0, 1);
|
||||
BOOST_CHECK_EQUAL(simple_graph.GetEdgeData(eit).id, 0);
|
||||
|
||||
eit = simple_graph.FindEdge(1, 0);
|
||||
BOOST_CHECK_EQUAL(eit, SPECIAL_EDGEID);
|
||||
|
||||
eit = simple_graph.FindEdgeInEitherDirection(1, 0);
|
||||
BOOST_CHECK_EQUAL(simple_graph.GetEdgeData(eit).id, 0);
|
||||
|
||||
bool reverse = false;
|
||||
eit = simple_graph.FindEdgeIndicateIfReverse(1, 0, reverse);
|
||||
BOOST_CHECK_EQUAL(simple_graph.GetEdgeData(eit).id, 0);
|
||||
BOOST_CHECK(reverse);
|
||||
|
||||
eit = simple_graph.FindEdge(3, 1);
|
||||
BOOST_CHECK_EQUAL(eit, SPECIAL_EDGEID);
|
||||
eit = simple_graph.FindEdge(0, 4);
|
||||
BOOST_CHECK_EQUAL(eit, SPECIAL_EDGEID);
|
||||
|
||||
eit = simple_graph.FindEdge(3, 4);
|
||||
BOOST_CHECK_EQUAL(simple_graph.GetEdgeData(eit).id, 2);
|
||||
eit = simple_graph.FindEdgeInEitherDirection(3, 4);
|
||||
// I think this is wrong behaviour! Should be 3.
|
||||
BOOST_CHECK_EQUAL(simple_graph.GetEdgeData(eit).id, 2);
|
||||
|
||||
eit = simple_graph.FindEdge(3, 0);
|
||||
BOOST_CHECK_EQUAL(simple_graph.GetEdgeData(eit).id, 4);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
@@ -1,488 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "../../data_structures/static_rtree.hpp"
|
||||
#include "../../data_structures/query_node.hpp"
|
||||
#include "../../data_structures/edge_based_node.hpp"
|
||||
#include "../../Util/floating_point.hpp"
|
||||
#include "../../typedefs.h"
|
||||
|
||||
#include <osrm/Coordinate.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/test_case_template.hpp>
|
||||
#include <boost/mpl/list.hpp>
|
||||
|
||||
#include <random>
|
||||
#include <unordered_set>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(static_rtree)
|
||||
|
||||
constexpr uint32_t TEST_BRANCHING_FACTOR = 8;
|
||||
constexpr uint32_t TEST_LEAF_NODE_SIZE = 64;
|
||||
|
||||
typedef EdgeBasedNode TestData;
|
||||
typedef StaticRTree<TestData,
|
||||
std::vector<FixedPointCoordinate>,
|
||||
false,
|
||||
TEST_BRANCHING_FACTOR,
|
||||
TEST_LEAF_NODE_SIZE> TestStaticRTree;
|
||||
|
||||
// Choosen by a fair W20 dice roll (this value is completely arbitrary)
|
||||
constexpr unsigned RANDOM_SEED = 42;
|
||||
static const int32_t WORLD_MIN_LAT = -90 * COORDINATE_PRECISION;
|
||||
static const int32_t WORLD_MAX_LAT = 90 * COORDINATE_PRECISION;
|
||||
static const int32_t WORLD_MIN_LON = -180 * COORDINATE_PRECISION;
|
||||
static const int32_t WORLD_MAX_LON = 180 * COORDINATE_PRECISION;
|
||||
|
||||
class LinearSearchNN
|
||||
{
|
||||
public:
|
||||
LinearSearchNN(const std::shared_ptr<std::vector<FixedPointCoordinate>> &coords,
|
||||
const std::vector<TestData> &edges)
|
||||
: coords(coords), edges(edges)
|
||||
{
|
||||
}
|
||||
|
||||
bool LocateClosestEndPointForCoordinate(const FixedPointCoordinate &input_coordinate,
|
||||
FixedPointCoordinate &result_coordinate)
|
||||
{
|
||||
float min_dist = std::numeric_limits<float>::max();
|
||||
FixedPointCoordinate min_coord;
|
||||
for (const TestData &e : edges)
|
||||
{
|
||||
const FixedPointCoordinate &start = coords->at(e.u);
|
||||
const FixedPointCoordinate &end = coords->at(e.v);
|
||||
float distance = FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
input_coordinate.lat, input_coordinate.lon, start.lat, start.lon);
|
||||
if (distance < min_dist)
|
||||
{
|
||||
min_coord = start;
|
||||
min_dist = distance;
|
||||
}
|
||||
|
||||
distance = FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
input_coordinate.lat, input_coordinate.lon, end.lat, end.lon);
|
||||
if (distance < min_dist)
|
||||
{
|
||||
min_coord = end;
|
||||
min_dist = distance;
|
||||
}
|
||||
}
|
||||
|
||||
result_coordinate = min_coord;
|
||||
return result_coordinate.is_valid();
|
||||
}
|
||||
|
||||
bool FindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate,
|
||||
PhantomNode &result_phantom_node,
|
||||
const unsigned zoom_level)
|
||||
{
|
||||
float min_dist = std::numeric_limits<float>::max();
|
||||
TestData nearest_edge;
|
||||
for (const TestData &e : edges)
|
||||
{
|
||||
if (e.component_id != 0)
|
||||
continue;
|
||||
|
||||
float current_ratio = 0.;
|
||||
FixedPointCoordinate nearest;
|
||||
const float current_perpendicular_distance =
|
||||
FixedPointCoordinate::ComputePerpendicularDistance(
|
||||
coords->at(e.u), coords->at(e.v), input_coordinate, nearest, current_ratio);
|
||||
|
||||
if ((current_perpendicular_distance < min_dist) &&
|
||||
!osrm::epsilon_compare(current_perpendicular_distance, min_dist))
|
||||
{ // found a new minimum
|
||||
min_dist = current_perpendicular_distance;
|
||||
result_phantom_node = {e.forward_edge_based_node_id,
|
||||
e.reverse_edge_based_node_id,
|
||||
e.name_id,
|
||||
e.forward_weight,
|
||||
e.reverse_weight,
|
||||
e.forward_offset,
|
||||
e.reverse_offset,
|
||||
e.packed_geometry_id,
|
||||
e.component_id,
|
||||
nearest,
|
||||
e.fwd_segment_position,
|
||||
e.forward_travel_mode,
|
||||
e.backward_travel_mode};
|
||||
nearest_edge = e;
|
||||
}
|
||||
}
|
||||
|
||||
if (result_phantom_node.location.is_valid())
|
||||
{
|
||||
// Hack to fix rounding errors and wandering via nodes.
|
||||
if (1 == std::abs(input_coordinate.lon - result_phantom_node.location.lon))
|
||||
{
|
||||
result_phantom_node.location.lon = input_coordinate.lon;
|
||||
}
|
||||
if (1 == std::abs(input_coordinate.lat - result_phantom_node.location.lat))
|
||||
{
|
||||
result_phantom_node.location.lat = input_coordinate.lat;
|
||||
}
|
||||
|
||||
const float distance_1 = FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
coords->at(nearest_edge.u), result_phantom_node.location);
|
||||
const float distance_2 = FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
coords->at(nearest_edge.u), coords->at(nearest_edge.v));
|
||||
const float ratio = std::min(1.f, distance_1 / distance_2);
|
||||
|
||||
if (SPECIAL_NODEID != result_phantom_node.forward_node_id)
|
||||
{
|
||||
result_phantom_node.forward_weight *= ratio;
|
||||
}
|
||||
if (SPECIAL_NODEID != result_phantom_node.reverse_node_id)
|
||||
{
|
||||
result_phantom_node.reverse_weight *= (1. - ratio);
|
||||
}
|
||||
}
|
||||
|
||||
return result_phantom_node.location.is_valid();
|
||||
}
|
||||
|
||||
private:
|
||||
const std::shared_ptr<std::vector<FixedPointCoordinate>> &coords;
|
||||
const std::vector<TestData> &edges;
|
||||
};
|
||||
|
||||
template <unsigned NUM_NODES, unsigned NUM_EDGES> struct RandomGraphFixture
|
||||
{
|
||||
struct TupleHash
|
||||
{
|
||||
typedef std::pair<unsigned, unsigned> argument_type;
|
||||
typedef std::size_t result_type;
|
||||
|
||||
result_type operator()(const argument_type &t) const
|
||||
{
|
||||
std::size_t val{0};
|
||||
boost::hash_combine(val, t.first);
|
||||
boost::hash_combine(val, t.second);
|
||||
return val;
|
||||
}
|
||||
};
|
||||
|
||||
RandomGraphFixture() : coords(std::make_shared<std::vector<FixedPointCoordinate>>())
|
||||
{
|
||||
BOOST_TEST_MESSAGE("Constructing " << NUM_NODES << " nodes and " << NUM_EDGES << " edges.");
|
||||
|
||||
std::mt19937 g(RANDOM_SEED);
|
||||
|
||||
std::uniform_int_distribution<> lat_udist(WORLD_MIN_LAT, WORLD_MAX_LAT);
|
||||
std::uniform_int_distribution<> lon_udist(WORLD_MIN_LON, WORLD_MAX_LON);
|
||||
|
||||
for (unsigned i = 0; i < NUM_NODES; i++)
|
||||
{
|
||||
int lat = lat_udist(g);
|
||||
int lon = lon_udist(g);
|
||||
nodes.emplace_back(QueryNode(lat, lon, i));
|
||||
coords->emplace_back(FixedPointCoordinate(lat, lon));
|
||||
}
|
||||
|
||||
std::uniform_int_distribution<> edge_udist(0, nodes.size() - 1);
|
||||
|
||||
std::unordered_set<std::pair<unsigned, unsigned>, TupleHash> used_edges;
|
||||
|
||||
while (edges.size() < NUM_EDGES)
|
||||
{
|
||||
TestData data;
|
||||
data.u = edge_udist(g);
|
||||
data.v = edge_udist(g);
|
||||
if (used_edges.find(std::pair<unsigned, unsigned>(
|
||||
std::min(data.u, data.v), std::max(data.u, data.v))) == used_edges.end())
|
||||
{
|
||||
data.component_id = 0;
|
||||
edges.emplace_back(data);
|
||||
used_edges.emplace(std::min(data.u, data.v), std::max(data.u, data.v));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<QueryNode> nodes;
|
||||
std::shared_ptr<std::vector<FixedPointCoordinate>> coords;
|
||||
std::vector<TestData> edges;
|
||||
};
|
||||
|
||||
struct GraphFixture
|
||||
{
|
||||
GraphFixture(const std::vector<std::pair<float, float>> &input_coords,
|
||||
const std::vector<std::pair<unsigned, unsigned>> &input_edges)
|
||||
: coords(std::make_shared<std::vector<FixedPointCoordinate>>())
|
||||
{
|
||||
|
||||
for (unsigned i = 0; i < input_coords.size(); i++)
|
||||
{
|
||||
FixedPointCoordinate c(input_coords[i].first * COORDINATE_PRECISION,
|
||||
input_coords[i].second * COORDINATE_PRECISION);
|
||||
coords->emplace_back(c);
|
||||
nodes.emplace_back(QueryNode(c.lat, c.lon, i));
|
||||
}
|
||||
|
||||
for (const auto &pair : input_edges)
|
||||
{
|
||||
TestData d;
|
||||
d.u = pair.first;
|
||||
d.v = pair.second;
|
||||
edges.emplace_back(d);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<QueryNode> nodes;
|
||||
std::shared_ptr<std::vector<FixedPointCoordinate>> coords;
|
||||
std::vector<TestData> edges;
|
||||
};
|
||||
|
||||
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE * 3, TEST_LEAF_NODE_SIZE / 2>
|
||||
TestRandomGraphFixture_LeafHalfFull;
|
||||
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE * 5, TEST_LEAF_NODE_SIZE>
|
||||
TestRandomGraphFixture_LeafFull;
|
||||
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE * 10, TEST_LEAF_NODE_SIZE * 2>
|
||||
TestRandomGraphFixture_TwoLeaves;
|
||||
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE * TEST_BRANCHING_FACTOR * 3,
|
||||
TEST_LEAF_NODE_SIZE * TEST_BRANCHING_FACTOR>
|
||||
TestRandomGraphFixture_Branch;
|
||||
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE * TEST_BRANCHING_FACTOR * 3,
|
||||
TEST_LEAF_NODE_SIZE * TEST_BRANCHING_FACTOR * 2>
|
||||
TestRandomGraphFixture_MultipleLevels;
|
||||
|
||||
template <typename RTreeT>
|
||||
void simple_verify_rtree(RTreeT &rtree,
|
||||
const std::shared_ptr<std::vector<FixedPointCoordinate>> &coords,
|
||||
const std::vector<TestData> &edges)
|
||||
{
|
||||
BOOST_TEST_MESSAGE("Verify end points");
|
||||
for (const auto &e : edges)
|
||||
{
|
||||
FixedPointCoordinate result_u, result_v;
|
||||
const FixedPointCoordinate &pu = coords->at(e.u);
|
||||
const FixedPointCoordinate &pv = coords->at(e.v);
|
||||
bool found_u = rtree.LocateClosestEndPointForCoordinate(pu, result_u, 1);
|
||||
bool found_v = rtree.LocateClosestEndPointForCoordinate(pv, result_v, 1);
|
||||
BOOST_CHECK(found_u && found_v);
|
||||
float dist_u = FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
result_u.lat, result_u.lon, pu.lat, pu.lon);
|
||||
BOOST_CHECK_LE(dist_u, std::numeric_limits<float>::epsilon());
|
||||
float dist_v = FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
result_v.lat, result_v.lon, pv.lat, pv.lon);
|
||||
BOOST_CHECK_LE(dist_v, std::numeric_limits<float>::epsilon());
|
||||
}
|
||||
}
|
||||
|
||||
template <typename RTreeT>
|
||||
void sampling_verify_rtree(RTreeT &rtree, LinearSearchNN &lsnn, unsigned num_samples)
|
||||
{
|
||||
std::mt19937 g(RANDOM_SEED);
|
||||
std::uniform_int_distribution<> lat_udist(WORLD_MIN_LAT, WORLD_MAX_LAT);
|
||||
std::uniform_int_distribution<> lon_udist(WORLD_MIN_LON, WORLD_MAX_LON);
|
||||
std::vector<FixedPointCoordinate> queries;
|
||||
for (unsigned i = 0; i < num_samples; i++)
|
||||
{
|
||||
queries.emplace_back(FixedPointCoordinate(lat_udist(g), lon_udist(g)));
|
||||
}
|
||||
|
||||
BOOST_TEST_MESSAGE("Sampling queries");
|
||||
for (const auto &q : queries)
|
||||
{
|
||||
FixedPointCoordinate result_rtree;
|
||||
rtree.LocateClosestEndPointForCoordinate(q, result_rtree, 1);
|
||||
FixedPointCoordinate result_ln;
|
||||
lsnn.LocateClosestEndPointForCoordinate(q, result_ln);
|
||||
BOOST_CHECK_EQUAL(result_ln, result_rtree);
|
||||
|
||||
PhantomNode phantom_rtree;
|
||||
rtree.FindPhantomNodeForCoordinate(q, phantom_rtree, 1);
|
||||
PhantomNode phantom_ln;
|
||||
lsnn.FindPhantomNodeForCoordinate(q, phantom_ln, 1);
|
||||
BOOST_CHECK_EQUAL(phantom_rtree, phantom_ln);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename FixtureT, typename RTreeT = TestStaticRTree>
|
||||
void build_rtree(const std::string &prefix,
|
||||
FixtureT *fixture,
|
||||
std::string &leaves_path,
|
||||
std::string &nodes_path)
|
||||
{
|
||||
nodes_path = prefix + ".ramIndex";
|
||||
leaves_path = prefix + ".fileIndex";
|
||||
const std::string coords_path = prefix + ".nodes";
|
||||
|
||||
boost::filesystem::ofstream node_stream(coords_path, std::ios::binary);
|
||||
const unsigned num_nodes = fixture->nodes.size();
|
||||
node_stream.write((char *)&num_nodes, sizeof(unsigned));
|
||||
node_stream.write((char *)&(fixture->nodes[0]), num_nodes * sizeof(QueryNode));
|
||||
node_stream.close();
|
||||
|
||||
RTreeT r(fixture->edges, nodes_path, leaves_path, fixture->nodes);
|
||||
}
|
||||
|
||||
template <typename FixtureT, typename RTreeT = TestStaticRTree>
|
||||
void construction_test(const std::string &prefix, FixtureT *fixture)
|
||||
{
|
||||
std::string leaves_path;
|
||||
std::string nodes_path;
|
||||
build_rtree<FixtureT, RTreeT>(prefix, fixture, leaves_path, nodes_path);
|
||||
RTreeT rtree(nodes_path, leaves_path, fixture->coords);
|
||||
LinearSearchNN lsnn(fixture->coords, fixture->edges);
|
||||
|
||||
simple_verify_rtree(rtree, fixture->coords, fixture->edges);
|
||||
sampling_verify_rtree(rtree, lsnn, 100);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(construct_half_leaf_test, TestRandomGraphFixture_LeafHalfFull)
|
||||
{
|
||||
construction_test("test_1", this);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(construct_full_leaf_test, TestRandomGraphFixture_LeafFull)
|
||||
{
|
||||
construction_test("test_2", this);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(construct_two_leaves_test, TestRandomGraphFixture_TwoLeaves)
|
||||
{
|
||||
construction_test("test_3", this);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(construct_branch_test, TestRandomGraphFixture_Branch)
|
||||
{
|
||||
construction_test("test_4", this);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(construct_multiple_levels_test, TestRandomGraphFixture_MultipleLevels)
|
||||
{
|
||||
construction_test("test_5", this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Bug: If you querry a point that lies between two BBs that have a gap,
|
||||
* one BB will be pruned, even if it could contain a nearer match.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(regression_test)
|
||||
{
|
||||
typedef std::pair<float, float> Coord;
|
||||
typedef std::pair<unsigned, unsigned> Edge;
|
||||
GraphFixture fixture({
|
||||
Coord(40.0, 0.0),
|
||||
Coord(35.0, 5.0),
|
||||
|
||||
Coord(5.0, 5.0),
|
||||
Coord(0.0, 10.0),
|
||||
|
||||
Coord(20.0, 10.0),
|
||||
Coord(20.0, 5.0),
|
||||
|
||||
Coord(40.0, 100.0),
|
||||
Coord(35.0, 105.0),
|
||||
|
||||
Coord(5.0, 105.0),
|
||||
Coord(0.0, 110.0),
|
||||
},
|
||||
{Edge(0, 1), Edge(2, 3), Edge(4, 5), Edge(6, 7), Edge(8, 9)});
|
||||
|
||||
typedef StaticRTree<TestData, std::vector<FixedPointCoordinate>, false, 2, 3> MiniStaticRTree;
|
||||
|
||||
std::string leaves_path;
|
||||
std::string nodes_path;
|
||||
build_rtree<GraphFixture, MiniStaticRTree>(
|
||||
"test_regression", &fixture, leaves_path, nodes_path);
|
||||
MiniStaticRTree rtree(nodes_path, leaves_path, fixture.coords);
|
||||
|
||||
// query a node just right of the center of the gap
|
||||
FixedPointCoordinate input(20.0 * COORDINATE_PRECISION, 55.1 * COORDINATE_PRECISION);
|
||||
FixedPointCoordinate result;
|
||||
rtree.LocateClosestEndPointForCoordinate(input, result, 1);
|
||||
FixedPointCoordinate result_ln;
|
||||
LinearSearchNN lsnn(fixture.coords, fixture.edges);
|
||||
lsnn.LocateClosestEndPointForCoordinate(input, result_ln);
|
||||
|
||||
// TODO: reactivate
|
||||
// BOOST_CHECK_EQUAL(result_ln, result);
|
||||
}
|
||||
|
||||
void TestRectangle(double width, double height, double center_lat, double center_lon)
|
||||
{
|
||||
FixedPointCoordinate center(center_lat * COORDINATE_PRECISION,
|
||||
center_lon * COORDINATE_PRECISION);
|
||||
|
||||
TestStaticRTree::RectangleT rect;
|
||||
rect.min_lat = center.lat - height / 2.0 * COORDINATE_PRECISION;
|
||||
rect.max_lat = center.lat + height / 2.0 * COORDINATE_PRECISION;
|
||||
rect.min_lon = center.lon - width / 2.0 * COORDINATE_PRECISION;
|
||||
rect.max_lon = center.lon + width / 2.0 * COORDINATE_PRECISION;
|
||||
|
||||
unsigned offset = 5 * COORDINATE_PRECISION;
|
||||
FixedPointCoordinate north(rect.max_lat + offset, center.lon);
|
||||
FixedPointCoordinate south(rect.min_lat - offset, center.lon);
|
||||
FixedPointCoordinate west(center.lat, rect.min_lon - offset);
|
||||
FixedPointCoordinate east(center.lat, rect.max_lon + offset);
|
||||
FixedPointCoordinate north_east(rect.max_lat + offset, rect.max_lon + offset);
|
||||
FixedPointCoordinate north_west(rect.max_lat + offset, rect.min_lon - offset);
|
||||
FixedPointCoordinate south_east(rect.min_lat - offset, rect.max_lon + offset);
|
||||
FixedPointCoordinate south_west(rect.min_lat - offset, rect.min_lon - offset);
|
||||
|
||||
/* Distance to line segments of rectangle */
|
||||
BOOST_CHECK_EQUAL(rect.GetMinDist(north),
|
||||
FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
north, FixedPointCoordinate(rect.max_lat, north.lon)));
|
||||
BOOST_CHECK_EQUAL(rect.GetMinDist(south),
|
||||
FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
south, FixedPointCoordinate(rect.min_lat, south.lon)));
|
||||
BOOST_CHECK_EQUAL(rect.GetMinDist(west),
|
||||
FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
west, FixedPointCoordinate(west.lat, rect.min_lon)));
|
||||
BOOST_CHECK_EQUAL(rect.GetMinDist(east),
|
||||
FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
east, FixedPointCoordinate(east.lat, rect.max_lon)));
|
||||
|
||||
/* Distance to corner points */
|
||||
BOOST_CHECK_EQUAL(rect.GetMinDist(north_east),
|
||||
FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
north_east, FixedPointCoordinate(rect.max_lat, rect.max_lon)));
|
||||
BOOST_CHECK_EQUAL(rect.GetMinDist(north_west),
|
||||
FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
north_west, FixedPointCoordinate(rect.max_lat, rect.min_lon)));
|
||||
BOOST_CHECK_EQUAL(rect.GetMinDist(south_east),
|
||||
FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
south_east, FixedPointCoordinate(rect.min_lat, rect.max_lon)));
|
||||
BOOST_CHECK_EQUAL(rect.GetMinDist(south_west),
|
||||
FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
south_west, FixedPointCoordinate(rect.min_lat, rect.min_lon)));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(rectangle_test)
|
||||
{
|
||||
TestRectangle(10, 10, 5, 5);
|
||||
TestRectangle(10, 10, -5, 5);
|
||||
TestRectangle(10, 10, 5, -5);
|
||||
TestRectangle(10, 10, -5, -5);
|
||||
TestRectangle(10, 10, 0, 0);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#define BOOST_TEST_MODULE datastructure tests
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
/*
|
||||
* This file will contain an automatically generated main function.
|
||||
*/
|
||||
@@ -1,144 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef BOOST_FILE_SYSTEM_FIX_H
|
||||
#define BOOST_FILE_SYSTEM_FIX_H
|
||||
|
||||
#include "osrm_exception.hpp"
|
||||
|
||||
// #include <boost/any.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
// #include <boost/program_options.hpp>
|
||||
|
||||
// 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
|
||||
{
|
||||
|
||||
// Validator for boost::filesystem::path, that verifies that the file
|
||||
// exists. The validate() function must be defined in the same namespace
|
||||
// as the target type, (boost::filesystem::path in this case), otherwise
|
||||
// it is not called
|
||||
// inline void validate(
|
||||
// boost::any & v,
|
||||
// const std::vector<std::string> & values,
|
||||
// boost::filesystem::path *,
|
||||
// int
|
||||
// ) {
|
||||
// boost::program_options::validators::check_first_occurrence(v);
|
||||
// const std::string & input_string =
|
||||
// boost::program_options::validators::get_single_string(values);
|
||||
// if(boost::filesystem::is_regular_file(input_string)) {
|
||||
// v = boost::any(boost::filesystem::path(input_string));
|
||||
// } else {
|
||||
// throw osrm::exception(input_string + " not found");
|
||||
// }
|
||||
// }
|
||||
|
||||
// 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);
|
||||
|
||||
boost::filesystem::path canonical_path;
|
||||
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))
|
||||
{
|
||||
canonical_path /= *path_iterator;
|
||||
}
|
||||
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
|
||||
{
|
||||
// Otherwise it should be safe to resolve the parent
|
||||
canonical_path = canonical_path.parent_path();
|
||||
}
|
||||
}
|
||||
else if ("." == path_iterator->string())
|
||||
{
|
||||
// Ignore
|
||||
}
|
||||
else
|
||||
{
|
||||
// Just cat other path entries
|
||||
canonical_path /= *path_iterator;
|
||||
}
|
||||
}
|
||||
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(nullptr);
|
||||
|
||||
return path(buffer);
|
||||
}
|
||||
|
||||
inline path unique_path(const path &) { return temp_directory_path(); }
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef BOOST_FILESYSTEM_VERSION
|
||||
#define BOOST_FILESYSTEM_VERSION 3
|
||||
#endif
|
||||
|
||||
inline void AssertPathExists(const boost::filesystem::path &path)
|
||||
{
|
||||
if (!boost::filesystem::is_regular_file(path))
|
||||
{
|
||||
throw osrm::exception(path.string() + " not found.");
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* BOOST_FILE_SYSTEM_FIX_H */
|
||||
@@ -1,279 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef DATA_STORE_OPTIONS_H
|
||||
#define DATA_STORE_OPTIONS_H
|
||||
|
||||
#include "BoostFileSystemFix.h"
|
||||
#include "git_sha.hpp"
|
||||
#include "IniFileUtil.h"
|
||||
#include "osrm_exception.hpp"
|
||||
#include "simple_logger.hpp"
|
||||
|
||||
#include <osrm/ServerPaths.h>
|
||||
|
||||
#include <boost/any.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
// generate boost::program_options object for the routing part
|
||||
bool GenerateDataStoreOptions(const int argc, const char *argv[], ServerPaths &paths)
|
||||
{
|
||||
// declare a group of options that will be allowed only on command line
|
||||
boost::program_options::options_description generic_options("Options");
|
||||
generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message")
|
||||
("springclean,s", "Remove all regions in shared memory")("config,c",
|
||||
boost::program_options::value<boost::filesystem::path>(&paths["config"])
|
||||
->default_value("server.ini"),
|
||||
"Path to a configuration file");
|
||||
|
||||
// declare a group of options that will be allowed both on command line
|
||||
// as well as in a config file
|
||||
boost::program_options::options_description config_options("Configuration");
|
||||
config_options.add_options()(
|
||||
"hsgrdata",
|
||||
boost::program_options::value<boost::filesystem::path>(&paths["hsgrdata"]),
|
||||
".hsgr file")("nodesdata",
|
||||
boost::program_options::value<boost::filesystem::path>(&paths["nodesdata"]),
|
||||
".nodes file")(
|
||||
"edgesdata",
|
||||
boost::program_options::value<boost::filesystem::path>(&paths["edgesdata"]),
|
||||
".edges file")("geometry",
|
||||
boost::program_options::value<boost::filesystem::path>(&paths["geometry"]),
|
||||
".geometry file")(
|
||||
"ramindex",
|
||||
boost::program_options::value<boost::filesystem::path>(&paths["ramindex"]),
|
||||
".ramIndex file")(
|
||||
"fileindex",
|
||||
boost::program_options::value<boost::filesystem::path>(&paths["fileindex"]),
|
||||
".fileIndex file")(
|
||||
"namesdata",
|
||||
boost::program_options::value<boost::filesystem::path>(&paths["namesdata"]),
|
||||
".names file")("timestamp",
|
||||
boost::program_options::value<boost::filesystem::path>(&paths["timestamp"]),
|
||||
".timestamp file");
|
||||
|
||||
// hidden options, will be allowed both on command line and in config
|
||||
// file, but will not be shown to the user
|
||||
boost::program_options::options_description hidden_options("Hidden options");
|
||||
hidden_options.add_options()(
|
||||
"base,b",
|
||||
boost::program_options::value<boost::filesystem::path>(&paths["base"]),
|
||||
"base path to .osrm file");
|
||||
|
||||
// positional option
|
||||
boost::program_options::positional_options_description positional_options;
|
||||
positional_options.add("base", 1);
|
||||
|
||||
// combine above options for parsing
|
||||
boost::program_options::options_description cmdline_options;
|
||||
cmdline_options.add(generic_options).add(config_options).add(hidden_options);
|
||||
|
||||
boost::program_options::options_description config_file_options;
|
||||
config_file_options.add(config_options).add(hidden_options);
|
||||
|
||||
boost::program_options::options_description visible_options(
|
||||
boost::filesystem::basename(argv[0]) + " [<options>] <configuration>");
|
||||
visible_options.add(generic_options).add(config_options);
|
||||
|
||||
// parse command line options
|
||||
boost::program_options::variables_map option_variables;
|
||||
boost::program_options::store(boost::program_options::command_line_parser(argc, argv)
|
||||
.options(cmdline_options)
|
||||
.positional(positional_options)
|
||||
.run(),
|
||||
option_variables);
|
||||
|
||||
if (option_variables.count("version"))
|
||||
{
|
||||
SimpleLogger().Write() << g_GIT_DESCRIPTION;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (option_variables.count("help"))
|
||||
{
|
||||
SimpleLogger().Write() << visible_options;
|
||||
return false;
|
||||
}
|
||||
|
||||
boost::program_options::notify(option_variables);
|
||||
|
||||
const bool parameter_present = (paths.find("hsgrdata") != paths.end() &&
|
||||
!paths.find("hsgrdata")->second.string().empty()) ||
|
||||
(paths.find("nodesdata") != paths.end() &&
|
||||
!paths.find("nodesdata")->second.string().empty()) ||
|
||||
(paths.find("edgesdata") != paths.end() &&
|
||||
!paths.find("edgesdata")->second.string().empty()) ||
|
||||
(paths.find("geometry") != paths.end() &&
|
||||
!paths.find("geometry")->second.string().empty()) ||
|
||||
(paths.find("ramindex") != paths.end() &&
|
||||
!paths.find("ramindex")->second.string().empty()) ||
|
||||
(paths.find("fileindex") != paths.end() &&
|
||||
!paths.find("fileindex")->second.string().empty()) ||
|
||||
(paths.find("timestamp") != paths.end() &&
|
||||
!paths.find("timestamp")->second.string().empty());
|
||||
|
||||
if (parameter_present)
|
||||
{
|
||||
if ((paths.find("config") != paths.end() &&
|
||||
boost::filesystem::is_regular_file(paths.find("config")->second)) ||
|
||||
option_variables.count("base"))
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "conflicting parameters";
|
||||
SimpleLogger().Write() << visible_options;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// parse config file
|
||||
ServerPaths::iterator path_iterator = paths.find("config");
|
||||
if (path_iterator != paths.end() && boost::filesystem::is_regular_file(path_iterator->second) &&
|
||||
!option_variables.count("base"))
|
||||
{
|
||||
SimpleLogger().Write() << "Reading options from: " << path_iterator->second.string();
|
||||
std::string ini_file_contents = ReadIniFileAndLowerContents(path_iterator->second);
|
||||
std::stringstream config_stream(ini_file_contents);
|
||||
boost::program_options::store(parse_config_file(config_stream, config_file_options),
|
||||
option_variables);
|
||||
boost::program_options::notify(option_variables);
|
||||
}
|
||||
else if (option_variables.count("base"))
|
||||
{
|
||||
path_iterator = paths.find("base");
|
||||
BOOST_ASSERT(paths.end() != path_iterator);
|
||||
std::string base_string = path_iterator->second.string();
|
||||
|
||||
path_iterator = paths.find("hsgrdata");
|
||||
if (path_iterator != paths.end())
|
||||
{
|
||||
path_iterator->second = base_string + ".hsgr";
|
||||
}
|
||||
|
||||
path_iterator = paths.find("nodesdata");
|
||||
if (path_iterator != paths.end())
|
||||
{
|
||||
path_iterator->second = base_string + ".nodes";
|
||||
}
|
||||
|
||||
path_iterator = paths.find("edgesdata");
|
||||
if (path_iterator != paths.end())
|
||||
{
|
||||
path_iterator->second = base_string + ".edges";
|
||||
}
|
||||
|
||||
path_iterator = paths.find("geometry");
|
||||
if (path_iterator != paths.end())
|
||||
{
|
||||
path_iterator->second = base_string + ".geometry";
|
||||
}
|
||||
|
||||
path_iterator = paths.find("ramindex");
|
||||
if (path_iterator != paths.end())
|
||||
{
|
||||
path_iterator->second = base_string + ".ramIndex";
|
||||
}
|
||||
|
||||
path_iterator = paths.find("fileindex");
|
||||
if (path_iterator != paths.end())
|
||||
{
|
||||
path_iterator->second = base_string + ".fileIndex";
|
||||
}
|
||||
|
||||
path_iterator = paths.find("namesdata");
|
||||
if (path_iterator != paths.end())
|
||||
{
|
||||
path_iterator->second = base_string + ".names";
|
||||
}
|
||||
|
||||
path_iterator = paths.find("timestamp");
|
||||
if (path_iterator != paths.end())
|
||||
{
|
||||
path_iterator->second = base_string + ".timestamp";
|
||||
}
|
||||
}
|
||||
|
||||
path_iterator = paths.find("hsgrdata");
|
||||
if (path_iterator == paths.end() || path_iterator->second.string().empty())
|
||||
{
|
||||
throw osrm::exception(".hsgr file must be specified");
|
||||
}
|
||||
AssertPathExists(path_iterator->second);
|
||||
|
||||
path_iterator = paths.find("nodesdata");
|
||||
if (path_iterator == paths.end() || path_iterator->second.string().empty())
|
||||
{
|
||||
throw osrm::exception(".nodes file must be specified");
|
||||
}
|
||||
AssertPathExists(path_iterator->second);
|
||||
|
||||
path_iterator = paths.find("edgesdata");
|
||||
if (path_iterator == paths.end() || path_iterator->second.string().empty())
|
||||
{
|
||||
throw osrm::exception(".edges file must be specified");
|
||||
}
|
||||
AssertPathExists(path_iterator->second);
|
||||
|
||||
path_iterator = paths.find("geometry");
|
||||
if (path_iterator == paths.end() || path_iterator->second.string().empty())
|
||||
{
|
||||
throw osrm::exception(".geometry file must be specified");
|
||||
}
|
||||
AssertPathExists(path_iterator->second);
|
||||
|
||||
path_iterator = paths.find("ramindex");
|
||||
if (path_iterator == paths.end() || path_iterator->second.string().empty())
|
||||
{
|
||||
throw osrm::exception(".ramindex file must be specified");
|
||||
}
|
||||
AssertPathExists(path_iterator->second);
|
||||
|
||||
path_iterator = paths.find("fileindex");
|
||||
if (path_iterator == paths.end() || path_iterator->second.string().empty())
|
||||
{
|
||||
throw osrm::exception(".fileindex file must be specified");
|
||||
}
|
||||
AssertPathExists(path_iterator->second);
|
||||
|
||||
path_iterator = paths.find("namesdata");
|
||||
if (path_iterator == paths.end() || path_iterator->second.string().empty())
|
||||
{
|
||||
throw osrm::exception(".names file must be specified");
|
||||
}
|
||||
AssertPathExists(path_iterator->second);
|
||||
|
||||
path_iterator = paths.find("timestamp");
|
||||
if (path_iterator == paths.end() || path_iterator->second.string().empty())
|
||||
{
|
||||
throw osrm::exception(".timestamp file must be specified");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif /* DATA_STORE_OPTIONS_H */
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef FINGERPRINT_H
|
||||
#define FINGERPRINT_H
|
||||
|
||||
#include <boost/uuid/uuid.hpp>
|
||||
|
||||
// implements a singleton, i.e. there is one and only one conviguration object
|
||||
class FingerPrint
|
||||
{
|
||||
public:
|
||||
FingerPrint();
|
||||
FingerPrint(const FingerPrint&) = delete;
|
||||
~FingerPrint();
|
||||
const boost::uuids::uuid &GetFingerPrint() const;
|
||||
bool IsMagicNumberOK() const;
|
||||
bool TestGraphUtil(const FingerPrint &other) const;
|
||||
bool TestPrepare(const FingerPrint &other) const;
|
||||
bool TestRTree(const FingerPrint &other) const;
|
||||
bool TestQueryObjects(const FingerPrint &other) const;
|
||||
|
||||
private:
|
||||
const unsigned magic_number;
|
||||
char md5_prepare[33];
|
||||
char md5_tree[33];
|
||||
char md5_graph[33];
|
||||
char md5_objects[33];
|
||||
|
||||
// initialize to {6ba7b810-9dad-11d1-80b4-00c04fd430c8}
|
||||
boost::uuids::uuid named_uuid;
|
||||
bool has_64_bits;
|
||||
};
|
||||
|
||||
#endif /* FingerPrint_H */
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef INI_FILE_UTIL_H
|
||||
#define INI_FILE_UTIL_H
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
#include <regex>
|
||||
#include <string>
|
||||
|
||||
// support old capitalized option names by down-casing them with a regex replace
|
||||
inline std::string ReadIniFileAndLowerContents(const boost::filesystem::path &path)
|
||||
{
|
||||
boost::filesystem::fstream config_stream(path);
|
||||
std::string ini_file_content((std::istreambuf_iterator<char>(config_stream)),
|
||||
std::istreambuf_iterator<char>());
|
||||
boost::regex regex( "^([^=]*)" ); //match from start of line to '='
|
||||
std::string format( "\\L$1\\E" ); //replace with downcased substring
|
||||
return boost::regex_replace( ini_file_content, regex, format );
|
||||
}
|
||||
|
||||
#endif // INI_FILE_UTIL_H
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef MERCATOR_UTIL_H
|
||||
#define MERCATOR_UTIL_H
|
||||
|
||||
#include <cmath>
|
||||
|
||||
inline double y2lat(const double a)
|
||||
{
|
||||
return 180. * M_1_PI * (2. * std::atan(std::exp(a * M_PI / 180.)) - M_PI_2);
|
||||
}
|
||||
|
||||
inline double lat2y(const double a)
|
||||
{
|
||||
return 180. * M_1_PI * std::log(std::tan(M_PI_4 + a * (M_PI / 180.) / 2.));
|
||||
}
|
||||
|
||||
#endif // MERCATOR_UTIL_H
|
||||
@@ -1,279 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef PROGAM_OPTIONS_H
|
||||
#define PROGAM_OPTIONS_H
|
||||
|
||||
#include "git_sha.hpp"
|
||||
#include "IniFileUtil.h"
|
||||
#include "osrm_exception.hpp"
|
||||
#include "simple_logger.hpp"
|
||||
|
||||
#include <osrm/ServerPaths.h>
|
||||
|
||||
#include <boost/any.hpp>
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
const static unsigned INIT_OK_START_ENGINE = 0;
|
||||
const static unsigned INIT_OK_DO_NOT_START_ENGINE = 1;
|
||||
const static unsigned INIT_FAILED = -1;
|
||||
|
||||
inline void populate_base_path(ServerPaths &server_paths)
|
||||
{
|
||||
// populate the server_path object
|
||||
auto path_iterator = server_paths.find("base");
|
||||
|
||||
// if a base path has been set, we populate it.
|
||||
if (path_iterator != server_paths.end())
|
||||
{
|
||||
const std::string base_string = path_iterator->second.string();
|
||||
SimpleLogger().Write() << "populating base path: " << base_string;
|
||||
|
||||
server_paths["hsgrdata"] = base_string + ".hsgr";
|
||||
BOOST_ASSERT(server_paths.find("hsgrdata") != server_paths.end());
|
||||
server_paths["nodesdata"] = base_string + ".nodes";
|
||||
BOOST_ASSERT(server_paths.find("nodesdata") != server_paths.end());
|
||||
server_paths["edgesdata"] = base_string + ".edges";
|
||||
BOOST_ASSERT(server_paths.find("edgesdata") != server_paths.end());
|
||||
server_paths["geometries"] = base_string + ".geometry";
|
||||
BOOST_ASSERT(server_paths.find("geometries") != server_paths.end());
|
||||
server_paths["ramindex"] = base_string + ".ramIndex";
|
||||
BOOST_ASSERT(server_paths.find("ramindex") != server_paths.end());
|
||||
server_paths["fileindex"] = base_string + ".fileIndex";
|
||||
BOOST_ASSERT(server_paths.find("fileindex") != server_paths.end());
|
||||
server_paths["namesdata"] = base_string + ".names";
|
||||
BOOST_ASSERT(server_paths.find("namesdata") != server_paths.end());
|
||||
server_paths["timestamp"] = base_string + ".timestamp";
|
||||
BOOST_ASSERT(server_paths.find("timestamp") != server_paths.end());
|
||||
}
|
||||
|
||||
// check if files are give and whether they exist at all
|
||||
path_iterator = server_paths.find("hsgrdata");
|
||||
if (path_iterator == server_paths.end() ||
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
if (path_iterator == server_paths.end())
|
||||
{
|
||||
SimpleLogger().Write() << "hsgrdata unset";
|
||||
}
|
||||
if (!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
SimpleLogger().Write() << "not a regular file";
|
||||
}
|
||||
|
||||
throw osrm::exception(".hsgr not found: " + path_iterator->second.string());
|
||||
}
|
||||
|
||||
path_iterator = server_paths.find("nodesdata");
|
||||
if (path_iterator == server_paths.end() ||
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
throw osrm::exception(".nodes not found");
|
||||
}
|
||||
|
||||
path_iterator = server_paths.find("edgesdata");
|
||||
if (path_iterator == server_paths.end() ||
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
throw osrm::exception(".edges not found");
|
||||
}
|
||||
|
||||
path_iterator = server_paths.find("geometries");
|
||||
if (path_iterator == server_paths.end() ||
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
throw osrm::exception(".geometry not found");
|
||||
}
|
||||
|
||||
path_iterator = server_paths.find("ramindex");
|
||||
if (path_iterator == server_paths.end() ||
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
throw osrm::exception(".ramIndex not found");
|
||||
}
|
||||
|
||||
path_iterator = server_paths.find("fileindex");
|
||||
if (path_iterator == server_paths.end() ||
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
throw osrm::exception(".fileIndex not found");
|
||||
}
|
||||
|
||||
path_iterator = server_paths.find("namesdata");
|
||||
if (path_iterator == server_paths.end() ||
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
throw osrm::exception(".namesIndex not found");
|
||||
}
|
||||
|
||||
SimpleLogger().Write() << "HSGR file:\t" << server_paths["hsgrdata"];
|
||||
SimpleLogger().Write(logDEBUG) << "Nodes file:\t" << server_paths["nodesdata"];
|
||||
SimpleLogger().Write(logDEBUG) << "Edges file:\t" << server_paths["edgesdata"];
|
||||
SimpleLogger().Write(logDEBUG) << "Geometry file:\t" << server_paths["geometries"];
|
||||
SimpleLogger().Write(logDEBUG) << "RAM file:\t" << server_paths["ramindex"];
|
||||
SimpleLogger().Write(logDEBUG) << "Index file:\t" << server_paths["fileindex"];
|
||||
SimpleLogger().Write(logDEBUG) << "Names file:\t" << server_paths["namesdata"];
|
||||
SimpleLogger().Write(logDEBUG) << "Timestamp file:\t" << server_paths["timestamp"];
|
||||
}
|
||||
|
||||
// generate boost::program_options object for the routing part
|
||||
inline unsigned GenerateServerProgramOptions(const int argc,
|
||||
const char *argv[],
|
||||
ServerPaths &paths,
|
||||
std::string &ip_address,
|
||||
int &ip_port,
|
||||
int &requested_num_threads,
|
||||
bool &use_shared_memory,
|
||||
bool &trial)
|
||||
{
|
||||
// declare a group of options that will be allowed only on command line
|
||||
boost::program_options::options_description generic_options("Options");
|
||||
generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message")(
|
||||
"config,c",
|
||||
boost::program_options::value<boost::filesystem::path>(&paths["config"])
|
||||
->default_value("server.ini"),
|
||||
"Path to a configuration file")(
|
||||
"trial",
|
||||
boost::program_options::value<bool>(&trial)->implicit_value(true),
|
||||
"Quit after initialization");
|
||||
|
||||
// declare a group of options that will be allowed both on command line
|
||||
// as well as in a config file
|
||||
boost::program_options::options_description config_options("Configuration");
|
||||
config_options.add_options()(
|
||||
"hsgrdata",
|
||||
boost::program_options::value<boost::filesystem::path>(&paths["hsgrdata"]),
|
||||
".hsgr file")("nodesdata",
|
||||
boost::program_options::value<boost::filesystem::path>(&paths["nodesdata"]),
|
||||
".nodes file")(
|
||||
"edgesdata",
|
||||
boost::program_options::value<boost::filesystem::path>(&paths["edgesdata"]),
|
||||
".edges file")("geometry",
|
||||
boost::program_options::value<boost::filesystem::path>(&paths["geometries"]),
|
||||
".geometry file")(
|
||||
"ramindex",
|
||||
boost::program_options::value<boost::filesystem::path>(&paths["ramindex"]),
|
||||
".ramIndex file")(
|
||||
"fileindex",
|
||||
boost::program_options::value<boost::filesystem::path>(&paths["fileindex"]),
|
||||
"File index file")(
|
||||
"namesdata",
|
||||
boost::program_options::value<boost::filesystem::path>(&paths["namesdata"]),
|
||||
".names file")("timestamp",
|
||||
boost::program_options::value<boost::filesystem::path>(&paths["timestamp"]),
|
||||
".timestamp file")(
|
||||
"ip,i",
|
||||
boost::program_options::value<std::string>(&ip_address)->default_value("0.0.0.0"),
|
||||
"IP address")(
|
||||
"port,p", boost::program_options::value<int>(&ip_port)->default_value(5000), "TCP/IP port")(
|
||||
"threads,t",
|
||||
boost::program_options::value<int>(&requested_num_threads)->default_value(8),
|
||||
"Number of threads to use")(
|
||||
"sharedmemory,s",
|
||||
boost::program_options::value<bool>(&use_shared_memory)->implicit_value(true),
|
||||
"Load data from shared memory");
|
||||
|
||||
// hidden options, will be allowed both on command line and in config
|
||||
// file, but will not be shown to the user
|
||||
boost::program_options::options_description hidden_options("Hidden options");
|
||||
hidden_options.add_options()(
|
||||
"base,b",
|
||||
boost::program_options::value<boost::filesystem::path>(&paths["base"]),
|
||||
"base path to .osrm file");
|
||||
|
||||
// positional option
|
||||
boost::program_options::positional_options_description positional_options;
|
||||
positional_options.add("base", 1);
|
||||
|
||||
// combine above options for parsing
|
||||
boost::program_options::options_description cmdline_options;
|
||||
cmdline_options.add(generic_options).add(config_options).add(hidden_options);
|
||||
|
||||
boost::program_options::options_description config_file_options;
|
||||
config_file_options.add(config_options).add(hidden_options);
|
||||
|
||||
boost::program_options::options_description visible_options(
|
||||
boost::filesystem::basename(argv[0]) + " <base.osrm> [<options>]");
|
||||
visible_options.add(generic_options).add(config_options);
|
||||
|
||||
// parse command line options
|
||||
boost::program_options::variables_map option_variables;
|
||||
boost::program_options::store(boost::program_options::command_line_parser(argc, argv)
|
||||
.options(cmdline_options)
|
||||
.positional(positional_options)
|
||||
.run(),
|
||||
option_variables);
|
||||
|
||||
if (option_variables.count("version"))
|
||||
{
|
||||
SimpleLogger().Write() << g_GIT_DESCRIPTION;
|
||||
return INIT_OK_DO_NOT_START_ENGINE;
|
||||
}
|
||||
|
||||
if (option_variables.count("help"))
|
||||
{
|
||||
SimpleLogger().Write() << visible_options;
|
||||
return INIT_OK_DO_NOT_START_ENGINE;
|
||||
}
|
||||
|
||||
boost::program_options::notify(option_variables);
|
||||
|
||||
// parse config file
|
||||
ServerPaths::iterator path_iterator = paths.find("config");
|
||||
if (path_iterator != paths.end() && boost::filesystem::is_regular_file(path_iterator->second) &&
|
||||
!option_variables.count("base"))
|
||||
{
|
||||
SimpleLogger().Write() << "Reading options from: " << path_iterator->second.string();
|
||||
std::string ini_file_contents = ReadIniFileAndLowerContents(path_iterator->second);
|
||||
std::stringstream config_stream(ini_file_contents);
|
||||
boost::program_options::store(parse_config_file(config_stream, config_file_options),
|
||||
option_variables);
|
||||
boost::program_options::notify(option_variables);
|
||||
return INIT_OK_START_ENGINE;
|
||||
}
|
||||
|
||||
if (1 > requested_num_threads)
|
||||
{
|
||||
throw osrm::exception("Number of threads must be a positive number");
|
||||
}
|
||||
|
||||
if (!use_shared_memory && option_variables.count("base"))
|
||||
{
|
||||
return INIT_OK_START_ENGINE;
|
||||
}
|
||||
if (use_shared_memory && !option_variables.count("base"))
|
||||
{
|
||||
return INIT_OK_START_ENGINE;
|
||||
}
|
||||
SimpleLogger().Write() << visible_options;
|
||||
return INIT_OK_DO_NOT_START_ENGINE;
|
||||
}
|
||||
|
||||
#endif /* PROGRAM_OPTIONS_H */
|
||||
@@ -1,790 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef TRIGONOMETRY_TABLES_H
|
||||
#define TRIGONOMETRY_TABLES_H
|
||||
|
||||
#include "../typedefs.h"
|
||||
#include <cmath>
|
||||
|
||||
#include <limits>
|
||||
|
||||
constexpr unsigned short atan_table[4096] = {
|
||||
0x0000, 0x0014, 0x0028, 0x003d, 0x0051, 0x0065,
|
||||
0x007a, 0x008e, 0x00a3, 0x00b7, 0x00cb, 0x00e0,
|
||||
0x00f4, 0x0108, 0x011d, 0x0131, 0x0146, 0x015a,
|
||||
0x016e, 0x0183, 0x0197, 0x01ab, 0x01c0, 0x01d4,
|
||||
0x01e9, 0x01fd, 0x0211, 0x0226, 0x023a, 0x024e,
|
||||
0x0263, 0x0277, 0x028c, 0x02a0, 0x02b4, 0x02c9,
|
||||
0x02dd, 0x02f1, 0x0306, 0x031a, 0x032f, 0x0343,
|
||||
0x0357, 0x036c, 0x0380, 0x0394, 0x03a9, 0x03bd,
|
||||
0x03d2, 0x03e6, 0x03fa, 0x040f, 0x0423, 0x0437,
|
||||
0x044c, 0x0460, 0x0475, 0x0489, 0x049d, 0x04b2,
|
||||
0x04c6, 0x04da, 0x04ef, 0x0503, 0x0517, 0x052c,
|
||||
0x0540, 0x0555, 0x0569, 0x057d, 0x0592, 0x05a6,
|
||||
0x05ba, 0x05cf, 0x05e3, 0x05f8, 0x060c, 0x0620,
|
||||
0x0635, 0x0649, 0x065d, 0x0672, 0x0686, 0x069b,
|
||||
0x06af, 0x06c3, 0x06d8, 0x06ec, 0x0700, 0x0715,
|
||||
0x0729, 0x073d, 0x0752, 0x0766, 0x077b, 0x078f,
|
||||
0x07a3, 0x07b8, 0x07cc, 0x07e0, 0x07f5, 0x0809,
|
||||
0x081d, 0x0832, 0x0846, 0x085b, 0x086f, 0x0883,
|
||||
0x0898, 0x08ac, 0x08c0, 0x08d5, 0x08e9, 0x08fd,
|
||||
0x0912, 0x0926, 0x093b, 0x094f, 0x0963, 0x0978,
|
||||
0x098c, 0x09a0, 0x09b5, 0x09c9, 0x09dd, 0x09f2,
|
||||
0x0a06, 0x0a1a, 0x0a2f, 0x0a43, 0x0a58, 0x0a6c,
|
||||
0x0a80, 0x0a95, 0x0aa9, 0x0abd, 0x0ad2, 0x0ae6,
|
||||
0x0afa, 0x0b0f, 0x0b23, 0x0b37, 0x0b4c, 0x0b60,
|
||||
0x0b75, 0x0b89, 0x0b9d, 0x0bb2, 0x0bc6, 0x0bda,
|
||||
0x0bef, 0x0c03, 0x0c17, 0x0c2c, 0x0c40, 0x0c54,
|
||||
0x0c69, 0x0c7d, 0x0c91, 0x0ca6, 0x0cba, 0x0cce,
|
||||
0x0ce3, 0x0cf7, 0x0d0b, 0x0d20, 0x0d34, 0x0d48,
|
||||
0x0d5d, 0x0d71, 0x0d86, 0x0d9a, 0x0dae, 0x0dc3,
|
||||
0x0dd7, 0x0deb, 0x0e00, 0x0e14, 0x0e28, 0x0e3d,
|
||||
0x0e51, 0x0e65, 0x0e7a, 0x0e8e, 0x0ea2, 0x0eb7,
|
||||
0x0ecb, 0x0edf, 0x0ef4, 0x0f08, 0x0f1c, 0x0f31,
|
||||
0x0f45, 0x0f59, 0x0f6e, 0x0f82, 0x0f96, 0x0fab,
|
||||
0x0fbf, 0x0fd3, 0x0fe8, 0x0ffc, 0x1010, 0x1025,
|
||||
0x1039, 0x104d, 0x1062, 0x1076, 0x108a, 0x109e,
|
||||
0x10b3, 0x10c7, 0x10db, 0x10f0, 0x1104, 0x1118,
|
||||
0x112d, 0x1141, 0x1155, 0x116a, 0x117e, 0x1192,
|
||||
0x11a7, 0x11bb, 0x11cf, 0x11e4, 0x11f8, 0x120c,
|
||||
0x1221, 0x1235, 0x1249, 0x125d, 0x1272, 0x1286,
|
||||
0x129a, 0x12af, 0x12c3, 0x12d7, 0x12ec, 0x1300,
|
||||
0x1314, 0x1329, 0x133d, 0x1351, 0x1365, 0x137a,
|
||||
0x138e, 0x13a2, 0x13b7, 0x13cb, 0x13df, 0x13f4,
|
||||
0x1408, 0x141c, 0x1431, 0x1445, 0x1459, 0x146d,
|
||||
0x1482, 0x1496, 0x14aa, 0x14bf, 0x14d3, 0x14e7,
|
||||
0x14fb, 0x1510, 0x1524, 0x1538, 0x154d, 0x1561,
|
||||
0x1575, 0x1589, 0x159e, 0x15b2, 0x15c6, 0x15db,
|
||||
0x15ef, 0x1603, 0x1617, 0x162c, 0x1640, 0x1654,
|
||||
0x1669, 0x167d, 0x1691, 0x16a5, 0x16ba, 0x16ce,
|
||||
0x16e2, 0x16f7, 0x170b, 0x171f, 0x1733, 0x1748,
|
||||
0x175c, 0x1770, 0x1784, 0x1799, 0x17ad, 0x17c1,
|
||||
0x17d6, 0x17ea, 0x17fe, 0x1812, 0x1827, 0x183b,
|
||||
0x184f, 0x1863, 0x1878, 0x188c, 0x18a0, 0x18b4,
|
||||
0x18c9, 0x18dd, 0x18f1, 0x1905, 0x191a, 0x192e,
|
||||
0x1942, 0x1957, 0x196b, 0x197f, 0x1993, 0x19a8,
|
||||
0x19bc, 0x19d0, 0x19e4, 0x19f9, 0x1a0d, 0x1a21,
|
||||
0x1a35, 0x1a49, 0x1a5e, 0x1a72, 0x1a86, 0x1a9a,
|
||||
0x1aaf, 0x1ac3, 0x1ad7, 0x1aeb, 0x1b00, 0x1b14,
|
||||
0x1b28, 0x1b3c, 0x1b51, 0x1b65, 0x1b79, 0x1b8d,
|
||||
0x1ba2, 0x1bb6, 0x1bca, 0x1bde, 0x1bf2, 0x1c07,
|
||||
0x1c1b, 0x1c2f, 0x1c43, 0x1c58, 0x1c6c, 0x1c80,
|
||||
0x1c94, 0x1ca8, 0x1cbd, 0x1cd1, 0x1ce5, 0x1cf9,
|
||||
0x1d0e, 0x1d22, 0x1d36, 0x1d4a, 0x1d5e, 0x1d73,
|
||||
0x1d87, 0x1d9b, 0x1daf, 0x1dc3, 0x1dd8, 0x1dec,
|
||||
0x1e00, 0x1e14, 0x1e28, 0x1e3d, 0x1e51, 0x1e65,
|
||||
0x1e79, 0x1e8d, 0x1ea2, 0x1eb6, 0x1eca, 0x1ede,
|
||||
0x1ef2, 0x1f07, 0x1f1b, 0x1f2f, 0x1f43, 0x1f57,
|
||||
0x1f6c, 0x1f80, 0x1f94, 0x1fa8, 0x1fbc, 0x1fd1,
|
||||
0x1fe5, 0x1ff9, 0x200d, 0x2021, 0x2035, 0x204a,
|
||||
0x205e, 0x2072, 0x2086, 0x209a, 0x20ae, 0x20c3,
|
||||
0x20d7, 0x20eb, 0x20ff, 0x2113, 0x2127, 0x213c,
|
||||
0x2150, 0x2164, 0x2178, 0x218c, 0x21a0, 0x21b5,
|
||||
0x21c9, 0x21dd, 0x21f1, 0x2205, 0x2219, 0x222e,
|
||||
0x2242, 0x2256, 0x226a, 0x227e, 0x2292, 0x22a6,
|
||||
0x22bb, 0x22cf, 0x22e3, 0x22f7, 0x230b, 0x231f,
|
||||
0x2333, 0x2348, 0x235c, 0x2370, 0x2384, 0x2398,
|
||||
0x23ac, 0x23c0, 0x23d5, 0x23e9, 0x23fd, 0x2411,
|
||||
0x2425, 0x2439, 0x244d, 0x2461, 0x2476, 0x248a,
|
||||
0x249e, 0x24b2, 0x24c6, 0x24da, 0x24ee, 0x2502,
|
||||
0x2517, 0x252b, 0x253f, 0x2553, 0x2567, 0x257b,
|
||||
0x258f, 0x25a3, 0x25b7, 0x25cb, 0x25e0, 0x25f4,
|
||||
0x2608, 0x261c, 0x2630, 0x2644, 0x2658, 0x266c,
|
||||
0x2680, 0x2694, 0x26a9, 0x26bd, 0x26d1, 0x26e5,
|
||||
0x26f9, 0x270d, 0x2721, 0x2735, 0x2749, 0x275d,
|
||||
0x2771, 0x2785, 0x279a, 0x27ae, 0x27c2, 0x27d6,
|
||||
0x27ea, 0x27fe, 0x2812, 0x2826, 0x283a, 0x284e,
|
||||
0x2862, 0x2876, 0x288a, 0x289e, 0x28b3, 0x28c7,
|
||||
0x28db, 0x28ef, 0x2903, 0x2917, 0x292b, 0x293f,
|
||||
0x2953, 0x2967, 0x297b, 0x298f, 0x29a3, 0x29b7,
|
||||
0x29cb, 0x29df, 0x29f3, 0x2a07, 0x2a1b, 0x2a2f,
|
||||
0x2a43, 0x2a58, 0x2a6c, 0x2a80, 0x2a94, 0x2aa8,
|
||||
0x2abc, 0x2ad0, 0x2ae4, 0x2af8, 0x2b0c, 0x2b20,
|
||||
0x2b34, 0x2b48, 0x2b5c, 0x2b70, 0x2b84, 0x2b98,
|
||||
0x2bac, 0x2bc0, 0x2bd4, 0x2be8, 0x2bfc, 0x2c10,
|
||||
0x2c24, 0x2c38, 0x2c4c, 0x2c60, 0x2c74, 0x2c88,
|
||||
0x2c9c, 0x2cb0, 0x2cc4, 0x2cd8, 0x2cec, 0x2d00,
|
||||
0x2d14, 0x2d28, 0x2d3c, 0x2d50, 0x2d64, 0x2d78,
|
||||
0x2d8c, 0x2da0, 0x2db4, 0x2dc8, 0x2ddc, 0x2df0,
|
||||
0x2e04, 0x2e18, 0x2e2c, 0x2e40, 0x2e54, 0x2e68,
|
||||
0x2e7c, 0x2e90, 0x2ea3, 0x2eb7, 0x2ecb, 0x2edf,
|
||||
0x2ef3, 0x2f07, 0x2f1b, 0x2f2f, 0x2f43, 0x2f57,
|
||||
0x2f6b, 0x2f7f, 0x2f93, 0x2fa7, 0x2fbb, 0x2fcf,
|
||||
0x2fe3, 0x2ff7, 0x300b, 0x301e, 0x3032, 0x3046,
|
||||
0x305a, 0x306e, 0x3082, 0x3096, 0x30aa, 0x30be,
|
||||
0x30d2, 0x30e6, 0x30fa, 0x310e, 0x3122, 0x3135,
|
||||
0x3149, 0x315d, 0x3171, 0x3185, 0x3199, 0x31ad,
|
||||
0x31c1, 0x31d5, 0x31e9, 0x31fd, 0x3210, 0x3224,
|
||||
0x3238, 0x324c, 0x3260, 0x3274, 0x3288, 0x329c,
|
||||
0x32b0, 0x32c3, 0x32d7, 0x32eb, 0x32ff, 0x3313,
|
||||
0x3327, 0x333b, 0x334f, 0x3363, 0x3376, 0x338a,
|
||||
0x339e, 0x33b2, 0x33c6, 0x33da, 0x33ee, 0x3401,
|
||||
0x3415, 0x3429, 0x343d, 0x3451, 0x3465, 0x3479,
|
||||
0x348c, 0x34a0, 0x34b4, 0x34c8, 0x34dc, 0x34f0,
|
||||
0x3504, 0x3517, 0x352b, 0x353f, 0x3553, 0x3567,
|
||||
0x357b, 0x358e, 0x35a2, 0x35b6, 0x35ca, 0x35de,
|
||||
0x35f2, 0x3605, 0x3619, 0x362d, 0x3641, 0x3655,
|
||||
0x3668, 0x367c, 0x3690, 0x36a4, 0x36b8, 0x36cb,
|
||||
0x36df, 0x36f3, 0x3707, 0x371b, 0x372f, 0x3742,
|
||||
0x3756, 0x376a, 0x377e, 0x3791, 0x37a5, 0x37b9,
|
||||
0x37cd, 0x37e1, 0x37f4, 0x3808, 0x381c, 0x3830,
|
||||
0x3844, 0x3857, 0x386b, 0x387f, 0x3893, 0x38a6,
|
||||
0x38ba, 0x38ce, 0x38e2, 0x38f5, 0x3909, 0x391d,
|
||||
0x3931, 0x3944, 0x3958, 0x396c, 0x3980, 0x3993,
|
||||
0x39a7, 0x39bb, 0x39cf, 0x39e2, 0x39f6, 0x3a0a,
|
||||
0x3a1e, 0x3a31, 0x3a45, 0x3a59, 0x3a6d, 0x3a80,
|
||||
0x3a94, 0x3aa8, 0x3abb, 0x3acf, 0x3ae3, 0x3af7,
|
||||
0x3b0a, 0x3b1e, 0x3b32, 0x3b45, 0x3b59, 0x3b6d,
|
||||
0x3b81, 0x3b94, 0x3ba8, 0x3bbc, 0x3bcf, 0x3be3,
|
||||
0x3bf7, 0x3c0b, 0x3c1e, 0x3c32, 0x3c46, 0x3c59,
|
||||
0x3c6d, 0x3c81, 0x3c94, 0x3ca8, 0x3cbc, 0x3ccf,
|
||||
0x3ce3, 0x3cf7, 0x3d0a, 0x3d1e, 0x3d32, 0x3d45,
|
||||
0x3d59, 0x3d6d, 0x3d80, 0x3d94, 0x3da8, 0x3dbb,
|
||||
0x3dcf, 0x3de3, 0x3df6, 0x3e0a, 0x3e1e, 0x3e31,
|
||||
0x3e45, 0x3e59, 0x3e6c, 0x3e80, 0x3e93, 0x3ea7,
|
||||
0x3ebb, 0x3ece, 0x3ee2, 0x3ef6, 0x3f09, 0x3f1d,
|
||||
0x3f30, 0x3f44, 0x3f58, 0x3f6b, 0x3f7f, 0x3f93,
|
||||
0x3fa6, 0x3fba, 0x3fcd, 0x3fe1, 0x3ff5, 0x4008,
|
||||
0x401c, 0x402f, 0x4043, 0x4057, 0x406a, 0x407e,
|
||||
0x4091, 0x40a5, 0x40b8, 0x40cc, 0x40e0, 0x40f3,
|
||||
0x4107, 0x411a, 0x412e, 0x4142, 0x4155, 0x4169,
|
||||
0x417c, 0x4190, 0x41a3, 0x41b7, 0x41ca, 0x41de,
|
||||
0x41f2, 0x4205, 0x4219, 0x422c, 0x4240, 0x4253,
|
||||
0x4267, 0x427a, 0x428e, 0x42a1, 0x42b5, 0x42c9,
|
||||
0x42dc, 0x42f0, 0x4303, 0x4317, 0x432a, 0x433e,
|
||||
0x4351, 0x4365, 0x4378, 0x438c, 0x439f, 0x43b3,
|
||||
0x43c6, 0x43da, 0x43ed, 0x4401, 0x4414, 0x4428,
|
||||
0x443b, 0x444f, 0x4462, 0x4476, 0x4489, 0x449d,
|
||||
0x44b0, 0x44c4, 0x44d7, 0x44eb, 0x44fe, 0x4512,
|
||||
0x4525, 0x4539, 0x454c, 0x4560, 0x4573, 0x4586,
|
||||
0x459a, 0x45ad, 0x45c1, 0x45d4, 0x45e8, 0x45fb,
|
||||
0x460f, 0x4622, 0x4636, 0x4649, 0x465c, 0x4670,
|
||||
0x4683, 0x4697, 0x46aa, 0x46be, 0x46d1, 0x46e5,
|
||||
0x46f8, 0x470b, 0x471f, 0x4732, 0x4746, 0x4759,
|
||||
0x476c, 0x4780, 0x4793, 0x47a7, 0x47ba, 0x47cd,
|
||||
0x47e1, 0x47f4, 0x4808, 0x481b, 0x482e, 0x4842,
|
||||
0x4855, 0x4869, 0x487c, 0x488f, 0x48a3, 0x48b6,
|
||||
0x48ca, 0x48dd, 0x48f0, 0x4904, 0x4917, 0x492a,
|
||||
0x493e, 0x4951, 0x4965, 0x4978, 0x498b, 0x499f,
|
||||
0x49b2, 0x49c5, 0x49d9, 0x49ec, 0x49ff, 0x4a13,
|
||||
0x4a26, 0x4a39, 0x4a4d, 0x4a60, 0x4a73, 0x4a87,
|
||||
0x4a9a, 0x4aad, 0x4ac1, 0x4ad4, 0x4ae7, 0x4afb,
|
||||
0x4b0e, 0x4b21, 0x4b35, 0x4b48, 0x4b5b, 0x4b6f,
|
||||
0x4b82, 0x4b95, 0x4ba8, 0x4bbc, 0x4bcf, 0x4be2,
|
||||
0x4bf6, 0x4c09, 0x4c1c, 0x4c2f, 0x4c43, 0x4c56,
|
||||
0x4c69, 0x4c7d, 0x4c90, 0x4ca3, 0x4cb6, 0x4cca,
|
||||
0x4cdd, 0x4cf0, 0x4d03, 0x4d17, 0x4d2a, 0x4d3d,
|
||||
0x4d50, 0x4d64, 0x4d77, 0x4d8a, 0x4d9d, 0x4db1,
|
||||
0x4dc4, 0x4dd7, 0x4dea, 0x4dfe, 0x4e11, 0x4e24,
|
||||
0x4e37, 0x4e4b, 0x4e5e, 0x4e71, 0x4e84, 0x4e97,
|
||||
0x4eab, 0x4ebe, 0x4ed1, 0x4ee4, 0x4ef7, 0x4f0b,
|
||||
0x4f1e, 0x4f31, 0x4f44, 0x4f57, 0x4f6b, 0x4f7e,
|
||||
0x4f91, 0x4fa4, 0x4fb7, 0x4fcb, 0x4fde, 0x4ff1,
|
||||
0x5004, 0x5017, 0x502a, 0x503e, 0x5051, 0x5064,
|
||||
0x5077, 0x508a, 0x509d, 0x50b1, 0x50c4, 0x50d7,
|
||||
0x50ea, 0x50fd, 0x5110, 0x5123, 0x5137, 0x514a,
|
||||
0x515d, 0x5170, 0x5183, 0x5196, 0x51a9, 0x51bc,
|
||||
0x51d0, 0x51e3, 0x51f6, 0x5209, 0x521c, 0x522f,
|
||||
0x5242, 0x5255, 0x5268, 0x527c, 0x528f, 0x52a2,
|
||||
0x52b5, 0x52c8, 0x52db, 0x52ee, 0x5301, 0x5314,
|
||||
0x5327, 0x533a, 0x534e, 0x5361, 0x5374, 0x5387,
|
||||
0x539a, 0x53ad, 0x53c0, 0x53d3, 0x53e6, 0x53f9,
|
||||
0x540c, 0x541f, 0x5432, 0x5445, 0x5458, 0x546b,
|
||||
0x547e, 0x5491, 0x54a5, 0x54b8, 0x54cb, 0x54de,
|
||||
0x54f1, 0x5504, 0x5517, 0x552a, 0x553d, 0x5550,
|
||||
0x5563, 0x5576, 0x5589, 0x559c, 0x55af, 0x55c2,
|
||||
0x55d5, 0x55e8, 0x55fb, 0x560e, 0x5621, 0x5634,
|
||||
0x5647, 0x565a, 0x566d, 0x5680, 0x5693, 0x56a6,
|
||||
0x56b9, 0x56cb, 0x56de, 0x56f1, 0x5704, 0x5717,
|
||||
0x572a, 0x573d, 0x5750, 0x5763, 0x5776, 0x5789,
|
||||
0x579c, 0x57af, 0x57c2, 0x57d5, 0x57e8, 0x57fb,
|
||||
0x580e, 0x5820, 0x5833, 0x5846, 0x5859, 0x586c,
|
||||
0x587f, 0x5892, 0x58a5, 0x58b8, 0x58cb, 0x58de,
|
||||
0x58f0, 0x5903, 0x5916, 0x5929, 0x593c, 0x594f,
|
||||
0x5962, 0x5975, 0x5988, 0x599a, 0x59ad, 0x59c0,
|
||||
0x59d3, 0x59e6, 0x59f9, 0x5a0c, 0x5a1f, 0x5a31,
|
||||
0x5a44, 0x5a57, 0x5a6a, 0x5a7d, 0x5a90, 0x5aa2,
|
||||
0x5ab5, 0x5ac8, 0x5adb, 0x5aee, 0x5b01, 0x5b13,
|
||||
0x5b26, 0x5b39, 0x5b4c, 0x5b5f, 0x5b72, 0x5b84,
|
||||
0x5b97, 0x5baa, 0x5bbd, 0x5bd0, 0x5be2, 0x5bf5,
|
||||
0x5c08, 0x5c1b, 0x5c2e, 0x5c40, 0x5c53, 0x5c66,
|
||||
0x5c79, 0x5c8c, 0x5c9e, 0x5cb1, 0x5cc4, 0x5cd7,
|
||||
0x5ce9, 0x5cfc, 0x5d0f, 0x5d22, 0x5d34, 0x5d47,
|
||||
0x5d5a, 0x5d6d, 0x5d7f, 0x5d92, 0x5da5, 0x5db8,
|
||||
0x5dca, 0x5ddd, 0x5df0, 0x5e03, 0x5e15, 0x5e28,
|
||||
0x5e3b, 0x5e4d, 0x5e60, 0x5e73, 0x5e86, 0x5e98,
|
||||
0x5eab, 0x5ebe, 0x5ed0, 0x5ee3, 0x5ef6, 0x5f09,
|
||||
0x5f1b, 0x5f2e, 0x5f41, 0x5f53, 0x5f66, 0x5f79,
|
||||
0x5f8b, 0x5f9e, 0x5fb1, 0x5fc3, 0x5fd6, 0x5fe9,
|
||||
0x5ffb, 0x600e, 0x6021, 0x6033, 0x6046, 0x6059,
|
||||
0x606b, 0x607e, 0x6091, 0x60a3, 0x60b6, 0x60c8,
|
||||
0x60db, 0x60ee, 0x6100, 0x6113, 0x6126, 0x6138,
|
||||
0x614b, 0x615d, 0x6170, 0x6183, 0x6195, 0x61a8,
|
||||
0x61ba, 0x61cd, 0x61e0, 0x61f2, 0x6205, 0x6217,
|
||||
0x622a, 0x623d, 0x624f, 0x6262, 0x6274, 0x6287,
|
||||
0x6299, 0x62ac, 0x62bf, 0x62d1, 0x62e4, 0x62f6,
|
||||
0x6309, 0x631b, 0x632e, 0x6340, 0x6353, 0x6366,
|
||||
0x6378, 0x638b, 0x639d, 0x63b0, 0x63c2, 0x63d5,
|
||||
0x63e7, 0x63fa, 0x640c, 0x641f, 0x6431, 0x6444,
|
||||
0x6456, 0x6469, 0x647b, 0x648e, 0x64a0, 0x64b3,
|
||||
0x64c5, 0x64d8, 0x64ea, 0x64fd, 0x650f, 0x6522,
|
||||
0x6534, 0x6547, 0x6559, 0x656c, 0x657e, 0x6591,
|
||||
0x65a3, 0x65b5, 0x65c8, 0x65da, 0x65ed, 0x65ff,
|
||||
0x6612, 0x6624, 0x6637, 0x6649, 0x665b, 0x666e,
|
||||
0x6680, 0x6693, 0x66a5, 0x66b8, 0x66ca, 0x66dc,
|
||||
0x66ef, 0x6701, 0x6714, 0x6726, 0x6738, 0x674b,
|
||||
0x675d, 0x6770, 0x6782, 0x6794, 0x67a7, 0x67b9,
|
||||
0x67cc, 0x67de, 0x67f0, 0x6803, 0x6815, 0x6827,
|
||||
0x683a, 0x684c, 0x685e, 0x6871, 0x6883, 0x6896,
|
||||
0x68a8, 0x68ba, 0x68cd, 0x68df, 0x68f1, 0x6904,
|
||||
0x6916, 0x6928, 0x693b, 0x694d, 0x695f, 0x6972,
|
||||
0x6984, 0x6996, 0x69a8, 0x69bb, 0x69cd, 0x69df,
|
||||
0x69f2, 0x6a04, 0x6a16, 0x6a29, 0x6a3b, 0x6a4d,
|
||||
0x6a5f, 0x6a72, 0x6a84, 0x6a96, 0x6aa9, 0x6abb,
|
||||
0x6acd, 0x6adf, 0x6af2, 0x6b04, 0x6b16, 0x6b28,
|
||||
0x6b3b, 0x6b4d, 0x6b5f, 0x6b71, 0x6b84, 0x6b96,
|
||||
0x6ba8, 0x6bba, 0x6bcd, 0x6bdf, 0x6bf1, 0x6c03,
|
||||
0x6c15, 0x6c28, 0x6c3a, 0x6c4c, 0x6c5e, 0x6c70,
|
||||
0x6c83, 0x6c95, 0x6ca7, 0x6cb9, 0x6ccb, 0x6cde,
|
||||
0x6cf0, 0x6d02, 0x6d14, 0x6d26, 0x6d39, 0x6d4b,
|
||||
0x6d5d, 0x6d6f, 0x6d81, 0x6d93, 0x6da6, 0x6db8,
|
||||
0x6dca, 0x6ddc, 0x6dee, 0x6e00, 0x6e12, 0x6e25,
|
||||
0x6e37, 0x6e49, 0x6e5b, 0x6e6d, 0x6e7f, 0x6e91,
|
||||
0x6ea3, 0x6eb6, 0x6ec8, 0x6eda, 0x6eec, 0x6efe,
|
||||
0x6f10, 0x6f22, 0x6f34, 0x6f46, 0x6f58, 0x6f6b,
|
||||
0x6f7d, 0x6f8f, 0x6fa1, 0x6fb3, 0x6fc5, 0x6fd7,
|
||||
0x6fe9, 0x6ffb, 0x700d, 0x701f, 0x7031, 0x7043,
|
||||
0x7055, 0x7068, 0x707a, 0x708c, 0x709e, 0x70b0,
|
||||
0x70c2, 0x70d4, 0x70e6, 0x70f8, 0x710a, 0x711c,
|
||||
0x712e, 0x7140, 0x7152, 0x7164, 0x7176, 0x7188,
|
||||
0x719a, 0x71ac, 0x71be, 0x71d0, 0x71e2, 0x71f4,
|
||||
0x7206, 0x7218, 0x722a, 0x723c, 0x724e, 0x7260,
|
||||
0x7272, 0x7284, 0x7296, 0x72a8, 0x72ba, 0x72cc,
|
||||
0x72dd, 0x72ef, 0x7301, 0x7313, 0x7325, 0x7337,
|
||||
0x7349, 0x735b, 0x736d, 0x737f, 0x7391, 0x73a3,
|
||||
0x73b5, 0x73c7, 0x73d8, 0x73ea, 0x73fc, 0x740e,
|
||||
0x7420, 0x7432, 0x7444, 0x7456, 0x7468, 0x747a,
|
||||
0x748b, 0x749d, 0x74af, 0x74c1, 0x74d3, 0x74e5,
|
||||
0x74f7, 0x7509, 0x751a, 0x752c, 0x753e, 0x7550,
|
||||
0x7562, 0x7574, 0x7585, 0x7597, 0x75a9, 0x75bb,
|
||||
0x75cd, 0x75df, 0x75f0, 0x7602, 0x7614, 0x7626,
|
||||
0x7638, 0x764a, 0x765b, 0x766d, 0x767f, 0x7691,
|
||||
0x76a3, 0x76b4, 0x76c6, 0x76d8, 0x76ea, 0x76fb,
|
||||
0x770d, 0x771f, 0x7731, 0x7743, 0x7754, 0x7766,
|
||||
0x7778, 0x778a, 0x779b, 0x77ad, 0x77bf, 0x77d1,
|
||||
0x77e2, 0x77f4, 0x7806, 0x7818, 0x7829, 0x783b,
|
||||
0x784d, 0x785e, 0x7870, 0x7882, 0x7894, 0x78a5,
|
||||
0x78b7, 0x78c9, 0x78da, 0x78ec, 0x78fe, 0x7910,
|
||||
0x7921, 0x7933, 0x7945, 0x7956, 0x7968, 0x797a,
|
||||
0x798b, 0x799d, 0x79af, 0x79c0, 0x79d2, 0x79e4,
|
||||
0x79f5, 0x7a07, 0x7a19, 0x7a2a, 0x7a3c, 0x7a4e,
|
||||
0x7a5f, 0x7a71, 0x7a82, 0x7a94, 0x7aa6, 0x7ab7,
|
||||
0x7ac9, 0x7adb, 0x7aec, 0x7afe, 0x7b0f, 0x7b21,
|
||||
0x7b33, 0x7b44, 0x7b56, 0x7b67, 0x7b79, 0x7b8b,
|
||||
0x7b9c, 0x7bae, 0x7bbf, 0x7bd1, 0x7be2, 0x7bf4,
|
||||
0x7c06, 0x7c17, 0x7c29, 0x7c3a, 0x7c4c, 0x7c5d,
|
||||
0x7c6f, 0x7c81, 0x7c92, 0x7ca4, 0x7cb5, 0x7cc7,
|
||||
0x7cd8, 0x7cea, 0x7cfb, 0x7d0d, 0x7d1e, 0x7d30,
|
||||
0x7d41, 0x7d53, 0x7d64, 0x7d76, 0x7d87, 0x7d99,
|
||||
0x7daa, 0x7dbc, 0x7dcd, 0x7ddf, 0x7df0, 0x7e02,
|
||||
0x7e13, 0x7e25, 0x7e36, 0x7e48, 0x7e59, 0x7e6b,
|
||||
0x7e7c, 0x7e8e, 0x7e9f, 0x7eb0, 0x7ec2, 0x7ed3,
|
||||
0x7ee5, 0x7ef6, 0x7f08, 0x7f19, 0x7f2b, 0x7f3c,
|
||||
0x7f4d, 0x7f5f, 0x7f70, 0x7f82, 0x7f93, 0x7fa4,
|
||||
0x7fb6, 0x7fc7, 0x7fd9, 0x7fea, 0x7ffb, 0x800d,
|
||||
0x801e, 0x8030, 0x8041, 0x8052, 0x8064, 0x8075,
|
||||
0x8086, 0x8098, 0x80a9, 0x80bb, 0x80cc, 0x80dd,
|
||||
0x80ef, 0x8100, 0x8111, 0x8123, 0x8134, 0x8145,
|
||||
0x8157, 0x8168, 0x8179, 0x818b, 0x819c, 0x81ad,
|
||||
0x81bf, 0x81d0, 0x81e1, 0x81f3, 0x8204, 0x8215,
|
||||
0x8226, 0x8238, 0x8249, 0x825a, 0x826c, 0x827d,
|
||||
0x828e, 0x829f, 0x82b1, 0x82c2, 0x82d3, 0x82e5,
|
||||
0x82f6, 0x8307, 0x8318, 0x832a, 0x833b, 0x834c,
|
||||
0x835d, 0x836f, 0x8380, 0x8391, 0x83a2, 0x83b3,
|
||||
0x83c5, 0x83d6, 0x83e7, 0x83f8, 0x840a, 0x841b,
|
||||
0x842c, 0x843d, 0x844e, 0x8460, 0x8471, 0x8482,
|
||||
0x8493, 0x84a4, 0x84b6, 0x84c7, 0x84d8, 0x84e9,
|
||||
0x84fa, 0x850b, 0x851d, 0x852e, 0x853f, 0x8550,
|
||||
0x8561, 0x8572, 0x8584, 0x8595, 0x85a6, 0x85b7,
|
||||
0x85c8, 0x85d9, 0x85ea, 0x85fb, 0x860d, 0x861e,
|
||||
0x862f, 0x8640, 0x8651, 0x8662, 0x8673, 0x8684,
|
||||
0x8695, 0x86a7, 0x86b8, 0x86c9, 0x86da, 0x86eb,
|
||||
0x86fc, 0x870d, 0x871e, 0x872f, 0x8740, 0x8751,
|
||||
0x8762, 0x8773, 0x8784, 0x8796, 0x87a7, 0x87b8,
|
||||
0x87c9, 0x87da, 0x87eb, 0x87fc, 0x880d, 0x881e,
|
||||
0x882f, 0x8840, 0x8851, 0x8862, 0x8873, 0x8884,
|
||||
0x8895, 0x88a6, 0x88b7, 0x88c8, 0x88d9, 0x88ea,
|
||||
0x88fb, 0x890c, 0x891d, 0x892e, 0x893f, 0x8950,
|
||||
0x8961, 0x8972, 0x8983, 0x8994, 0x89a5, 0x89b6,
|
||||
0x89c6, 0x89d7, 0x89e8, 0x89f9, 0x8a0a, 0x8a1b,
|
||||
0x8a2c, 0x8a3d, 0x8a4e, 0x8a5f, 0x8a70, 0x8a81,
|
||||
0x8a92, 0x8aa3, 0x8ab3, 0x8ac4, 0x8ad5, 0x8ae6,
|
||||
0x8af7, 0x8b08, 0x8b19, 0x8b2a, 0x8b3b, 0x8b4b,
|
||||
0x8b5c, 0x8b6d, 0x8b7e, 0x8b8f, 0x8ba0, 0x8bb1,
|
||||
0x8bc1, 0x8bd2, 0x8be3, 0x8bf4, 0x8c05, 0x8c16,
|
||||
0x8c27, 0x8c37, 0x8c48, 0x8c59, 0x8c6a, 0x8c7b,
|
||||
0x8c8c, 0x8c9c, 0x8cad, 0x8cbe, 0x8ccf, 0x8ce0,
|
||||
0x8cf0, 0x8d01, 0x8d12, 0x8d23, 0x8d34, 0x8d44,
|
||||
0x8d55, 0x8d66, 0x8d77, 0x8d87, 0x8d98, 0x8da9,
|
||||
0x8dba, 0x8dca, 0x8ddb, 0x8dec, 0x8dfd, 0x8e0d,
|
||||
0x8e1e, 0x8e2f, 0x8e40, 0x8e50, 0x8e61, 0x8e72,
|
||||
0x8e83, 0x8e93, 0x8ea4, 0x8eb5, 0x8ec5, 0x8ed6,
|
||||
0x8ee7, 0x8ef8, 0x8f08, 0x8f19, 0x8f2a, 0x8f3a,
|
||||
0x8f4b, 0x8f5c, 0x8f6c, 0x8f7d, 0x8f8e, 0x8f9e,
|
||||
0x8faf, 0x8fc0, 0x8fd0, 0x8fe1, 0x8ff2, 0x9002,
|
||||
0x9013, 0x9024, 0x9034, 0x9045, 0x9056, 0x9066,
|
||||
0x9077, 0x9088, 0x9098, 0x90a9, 0x90b9, 0x90ca,
|
||||
0x90db, 0x90eb, 0x90fc, 0x910c, 0x911d, 0x912e,
|
||||
0x913e, 0x914f, 0x915f, 0x9170, 0x9181, 0x9191,
|
||||
0x91a2, 0x91b2, 0x91c3, 0x91d3, 0x91e4, 0x91f5,
|
||||
0x9205, 0x9216, 0x9226, 0x9237, 0x9247, 0x9258,
|
||||
0x9268, 0x9279, 0x9289, 0x929a, 0x92aa, 0x92bb,
|
||||
0x92cc, 0x92dc, 0x92ed, 0x92fd, 0x930e, 0x931e,
|
||||
0x932f, 0x933f, 0x9350, 0x9360, 0x9370, 0x9381,
|
||||
0x9391, 0x93a2, 0x93b2, 0x93c3, 0x93d3, 0x93e4,
|
||||
0x93f4, 0x9405, 0x9415, 0x9426, 0x9436, 0x9447,
|
||||
0x9457, 0x9467, 0x9478, 0x9488, 0x9499, 0x94a9,
|
||||
0x94ba, 0x94ca, 0x94da, 0x94eb, 0x94fb, 0x950c,
|
||||
0x951c, 0x952c, 0x953d, 0x954d, 0x955e, 0x956e,
|
||||
0x957e, 0x958f, 0x959f, 0x95af, 0x95c0, 0x95d0,
|
||||
0x95e1, 0x95f1, 0x9601, 0x9612, 0x9622, 0x9632,
|
||||
0x9643, 0x9653, 0x9663, 0x9674, 0x9684, 0x9694,
|
||||
0x96a5, 0x96b5, 0x96c5, 0x96d6, 0x96e6, 0x96f6,
|
||||
0x9707, 0x9717, 0x9727, 0x9738, 0x9748, 0x9758,
|
||||
0x9768, 0x9779, 0x9789, 0x9799, 0x97aa, 0x97ba,
|
||||
0x97ca, 0x97da, 0x97eb, 0x97fb, 0x980b, 0x981b,
|
||||
0x982c, 0x983c, 0x984c, 0x985c, 0x986d, 0x987d,
|
||||
0x988d, 0x989d, 0x98ad, 0x98be, 0x98ce, 0x98de,
|
||||
0x98ee, 0x98ff, 0x990f, 0x991f, 0x992f, 0x993f,
|
||||
0x9950, 0x9960, 0x9970, 0x9980, 0x9990, 0x99a0,
|
||||
0x99b1, 0x99c1, 0x99d1, 0x99e1, 0x99f1, 0x9a01,
|
||||
0x9a12, 0x9a22, 0x9a32, 0x9a42, 0x9a52, 0x9a62,
|
||||
0x9a72, 0x9a83, 0x9a93, 0x9aa3, 0x9ab3, 0x9ac3,
|
||||
0x9ad3, 0x9ae3, 0x9af3, 0x9b04, 0x9b14, 0x9b24,
|
||||
0x9b34, 0x9b44, 0x9b54, 0x9b64, 0x9b74, 0x9b84,
|
||||
0x9b94, 0x9ba4, 0x9bb5, 0x9bc5, 0x9bd5, 0x9be5,
|
||||
0x9bf5, 0x9c05, 0x9c15, 0x9c25, 0x9c35, 0x9c45,
|
||||
0x9c55, 0x9c65, 0x9c75, 0x9c85, 0x9c95, 0x9ca5,
|
||||
0x9cb5, 0x9cc5, 0x9cd5, 0x9ce5, 0x9cf5, 0x9d05,
|
||||
0x9d15, 0x9d25, 0x9d35, 0x9d45, 0x9d55, 0x9d65,
|
||||
0x9d75, 0x9d85, 0x9d95, 0x9da5, 0x9db5, 0x9dc5,
|
||||
0x9dd5, 0x9de5, 0x9df5, 0x9e05, 0x9e15, 0x9e25,
|
||||
0x9e35, 0x9e45, 0x9e55, 0x9e65, 0x9e74, 0x9e84,
|
||||
0x9e94, 0x9ea4, 0x9eb4, 0x9ec4, 0x9ed4, 0x9ee4,
|
||||
0x9ef4, 0x9f04, 0x9f14, 0x9f23, 0x9f33, 0x9f43,
|
||||
0x9f53, 0x9f63, 0x9f73, 0x9f83, 0x9f93, 0x9fa3,
|
||||
0x9fb2, 0x9fc2, 0x9fd2, 0x9fe2, 0x9ff2, 0xa002,
|
||||
0xa012, 0xa021, 0xa031, 0xa041, 0xa051, 0xa061,
|
||||
0xa071, 0xa080, 0xa090, 0xa0a0, 0xa0b0, 0xa0c0,
|
||||
0xa0cf, 0xa0df, 0xa0ef, 0xa0ff, 0xa10f, 0xa11e,
|
||||
0xa12e, 0xa13e, 0xa14e, 0xa15e, 0xa16d, 0xa17d,
|
||||
0xa18d, 0xa19d, 0xa1ac, 0xa1bc, 0xa1cc, 0xa1dc,
|
||||
0xa1eb, 0xa1fb, 0xa20b, 0xa21b, 0xa22a, 0xa23a,
|
||||
0xa24a, 0xa25a, 0xa269, 0xa279, 0xa289, 0xa298,
|
||||
0xa2a8, 0xa2b8, 0xa2c8, 0xa2d7, 0xa2e7, 0xa2f7,
|
||||
0xa306, 0xa316, 0xa326, 0xa335, 0xa345, 0xa355,
|
||||
0xa364, 0xa374, 0xa384, 0xa393, 0xa3a3, 0xa3b3,
|
||||
0xa3c2, 0xa3d2, 0xa3e2, 0xa3f1, 0xa401, 0xa411,
|
||||
0xa420, 0xa430, 0xa440, 0xa44f, 0xa45f, 0xa46e,
|
||||
0xa47e, 0xa48e, 0xa49d, 0xa4ad, 0xa4bc, 0xa4cc,
|
||||
0xa4dc, 0xa4eb, 0xa4fb, 0xa50a, 0xa51a, 0xa52a,
|
||||
0xa539, 0xa549, 0xa558, 0xa568, 0xa577, 0xa587,
|
||||
0xa597, 0xa5a6, 0xa5b6, 0xa5c5, 0xa5d5, 0xa5e4,
|
||||
0xa5f4, 0xa603, 0xa613, 0xa622, 0xa632, 0xa641,
|
||||
0xa651, 0xa660, 0xa670, 0xa67f, 0xa68f, 0xa69e,
|
||||
0xa6ae, 0xa6bd, 0xa6cd, 0xa6dc, 0xa6ec, 0xa6fb,
|
||||
0xa70b, 0xa71a, 0xa72a, 0xa739, 0xa749, 0xa758,
|
||||
0xa768, 0xa777, 0xa787, 0xa796, 0xa7a5, 0xa7b5,
|
||||
0xa7c4, 0xa7d4, 0xa7e3, 0xa7f3, 0xa802, 0xa812,
|
||||
0xa821, 0xa830, 0xa840, 0xa84f, 0xa85f, 0xa86e,
|
||||
0xa87d, 0xa88d, 0xa89c, 0xa8ac, 0xa8bb, 0xa8ca,
|
||||
0xa8da, 0xa8e9, 0xa8f8, 0xa908, 0xa917, 0xa927,
|
||||
0xa936, 0xa945, 0xa955, 0xa964, 0xa973, 0xa983,
|
||||
0xa992, 0xa9a1, 0xa9b1, 0xa9c0, 0xa9cf, 0xa9df,
|
||||
0xa9ee, 0xa9fd, 0xaa0d, 0xaa1c, 0xaa2b, 0xaa3b,
|
||||
0xaa4a, 0xaa59, 0xaa69, 0xaa78, 0xaa87, 0xaa96,
|
||||
0xaaa6, 0xaab5, 0xaac4, 0xaad4, 0xaae3, 0xaaf2,
|
||||
0xab01, 0xab11, 0xab20, 0xab2f, 0xab3e, 0xab4e,
|
||||
0xab5d, 0xab6c, 0xab7b, 0xab8b, 0xab9a, 0xaba9,
|
||||
0xabb8, 0xabc7, 0xabd7, 0xabe6, 0xabf5, 0xac04,
|
||||
0xac14, 0xac23, 0xac32, 0xac41, 0xac50, 0xac60,
|
||||
0xac6f, 0xac7e, 0xac8d, 0xac9c, 0xacab, 0xacbb,
|
||||
0xacca, 0xacd9, 0xace8, 0xacf7, 0xad06, 0xad16,
|
||||
0xad25, 0xad34, 0xad43, 0xad52, 0xad61, 0xad70,
|
||||
0xad80, 0xad8f, 0xad9e, 0xadad, 0xadbc, 0xadcb,
|
||||
0xadda, 0xade9, 0xadf8, 0xae08, 0xae17, 0xae26,
|
||||
0xae35, 0xae44, 0xae53, 0xae62, 0xae71, 0xae80,
|
||||
0xae8f, 0xae9e, 0xaead, 0xaebd, 0xaecc, 0xaedb,
|
||||
0xaeea, 0xaef9, 0xaf08, 0xaf17, 0xaf26, 0xaf35,
|
||||
0xaf44, 0xaf53, 0xaf62, 0xaf71, 0xaf80, 0xaf8f,
|
||||
0xaf9e, 0xafad, 0xafbc, 0xafcb, 0xafda, 0xafe9,
|
||||
0xaff8, 0xb007, 0xb016, 0xb025, 0xb034, 0xb043,
|
||||
0xb052, 0xb061, 0xb070, 0xb07f, 0xb08e, 0xb09d,
|
||||
0xb0ac, 0xb0bb, 0xb0ca, 0xb0d9, 0xb0e8, 0xb0f6,
|
||||
0xb105, 0xb114, 0xb123, 0xb132, 0xb141, 0xb150,
|
||||
0xb15f, 0xb16e, 0xb17d, 0xb18c, 0xb19b, 0xb1aa,
|
||||
0xb1b8, 0xb1c7, 0xb1d6, 0xb1e5, 0xb1f4, 0xb203,
|
||||
0xb212, 0xb221, 0xb22f, 0xb23e, 0xb24d, 0xb25c,
|
||||
0xb26b, 0xb27a, 0xb289, 0xb297, 0xb2a6, 0xb2b5,
|
||||
0xb2c4, 0xb2d3, 0xb2e2, 0xb2f1, 0xb2ff, 0xb30e,
|
||||
0xb31d, 0xb32c, 0xb33b, 0xb349, 0xb358, 0xb367,
|
||||
0xb376, 0xb385, 0xb393, 0xb3a2, 0xb3b1, 0xb3c0,
|
||||
0xb3cf, 0xb3dd, 0xb3ec, 0xb3fb, 0xb40a, 0xb418,
|
||||
0xb427, 0xb436, 0xb445, 0xb453, 0xb462, 0xb471,
|
||||
0xb480, 0xb48e, 0xb49d, 0xb4ac, 0xb4bb, 0xb4c9,
|
||||
0xb4d8, 0xb4e7, 0xb4f6, 0xb504, 0xb513, 0xb522,
|
||||
0xb530, 0xb53f, 0xb54e, 0xb55c, 0xb56b, 0xb57a,
|
||||
0xb588, 0xb597, 0xb5a6, 0xb5b5, 0xb5c3, 0xb5d2,
|
||||
0xb5e1, 0xb5ef, 0xb5fe, 0xb60d, 0xb61b, 0xb62a,
|
||||
0xb638, 0xb647, 0xb656, 0xb664, 0xb673, 0xb682,
|
||||
0xb690, 0xb69f, 0xb6ae, 0xb6bc, 0xb6cb, 0xb6d9,
|
||||
0xb6e8, 0xb6f7, 0xb705, 0xb714, 0xb722, 0xb731,
|
||||
0xb740, 0xb74e, 0xb75d, 0xb76b, 0xb77a, 0xb788,
|
||||
0xb797, 0xb7a6, 0xb7b4, 0xb7c3, 0xb7d1, 0xb7e0,
|
||||
0xb7ee, 0xb7fd, 0xb80b, 0xb81a, 0xb829, 0xb837,
|
||||
0xb846, 0xb854, 0xb863, 0xb871, 0xb880, 0xb88e,
|
||||
0xb89d, 0xb8ab, 0xb8ba, 0xb8c8, 0xb8d7, 0xb8e5,
|
||||
0xb8f4, 0xb902, 0xb911, 0xb91f, 0xb92e, 0xb93c,
|
||||
0xb94b, 0xb959, 0xb968, 0xb976, 0xb984, 0xb993,
|
||||
0xb9a1, 0xb9b0, 0xb9be, 0xb9cd, 0xb9db, 0xb9ea,
|
||||
0xb9f8, 0xba06, 0xba15, 0xba23, 0xba32, 0xba40,
|
||||
0xba4f, 0xba5d, 0xba6b, 0xba7a, 0xba88, 0xba97,
|
||||
0xbaa5, 0xbab3, 0xbac2, 0xbad0, 0xbade, 0xbaed,
|
||||
0xbafb, 0xbb0a, 0xbb18, 0xbb26, 0xbb35, 0xbb43,
|
||||
0xbb51, 0xbb60, 0xbb6e, 0xbb7c, 0xbb8b, 0xbb99,
|
||||
0xbba8, 0xbbb6, 0xbbc4, 0xbbd3, 0xbbe1, 0xbbef,
|
||||
0xbbfd, 0xbc0c, 0xbc1a, 0xbc28, 0xbc37, 0xbc45,
|
||||
0xbc53, 0xbc62, 0xbc70, 0xbc7e, 0xbc8c, 0xbc9b,
|
||||
0xbca9, 0xbcb7, 0xbcc6, 0xbcd4, 0xbce2, 0xbcf0,
|
||||
0xbcff, 0xbd0d, 0xbd1b, 0xbd29, 0xbd38, 0xbd46,
|
||||
0xbd54, 0xbd62, 0xbd71, 0xbd7f, 0xbd8d, 0xbd9b,
|
||||
0xbdaa, 0xbdb8, 0xbdc6, 0xbdd4, 0xbde2, 0xbdf1,
|
||||
0xbdff, 0xbe0d, 0xbe1b, 0xbe29, 0xbe38, 0xbe46,
|
||||
0xbe54, 0xbe62, 0xbe70, 0xbe7f, 0xbe8d, 0xbe9b,
|
||||
0xbea9, 0xbeb7, 0xbec5, 0xbed4, 0xbee2, 0xbef0,
|
||||
0xbefe, 0xbf0c, 0xbf1a, 0xbf28, 0xbf37, 0xbf45,
|
||||
0xbf53, 0xbf61, 0xbf6f, 0xbf7d, 0xbf8b, 0xbf99,
|
||||
0xbfa7, 0xbfb6, 0xbfc4, 0xbfd2, 0xbfe0, 0xbfee,
|
||||
0xbffc, 0xc00a, 0xc018, 0xc026, 0xc034, 0xc042,
|
||||
0xc051, 0xc05f, 0xc06d, 0xc07b, 0xc089, 0xc097,
|
||||
0xc0a5, 0xc0b3, 0xc0c1, 0xc0cf, 0xc0dd, 0xc0eb,
|
||||
0xc0f9, 0xc107, 0xc115, 0xc123, 0xc131, 0xc13f,
|
||||
0xc14d, 0xc15b, 0xc169, 0xc177, 0xc185, 0xc193,
|
||||
0xc1a1, 0xc1af, 0xc1bd, 0xc1cb, 0xc1d9, 0xc1e7,
|
||||
0xc1f5, 0xc203, 0xc211, 0xc21f, 0xc22d, 0xc23b,
|
||||
0xc249, 0xc257, 0xc265, 0xc273, 0xc281, 0xc28f,
|
||||
0xc29d, 0xc2ab, 0xc2b8, 0xc2c6, 0xc2d4, 0xc2e2,
|
||||
0xc2f0, 0xc2fe, 0xc30c, 0xc31a, 0xc328, 0xc336,
|
||||
0xc344, 0xc352, 0xc35f, 0xc36d, 0xc37b, 0xc389,
|
||||
0xc397, 0xc3a5, 0xc3b3, 0xc3c1, 0xc3ce, 0xc3dc,
|
||||
0xc3ea, 0xc3f8, 0xc406, 0xc414, 0xc422, 0xc42f,
|
||||
0xc43d, 0xc44b, 0xc459, 0xc467, 0xc475, 0xc482,
|
||||
0xc490, 0xc49e, 0xc4ac, 0xc4ba, 0xc4c7, 0xc4d5,
|
||||
0xc4e3, 0xc4f1, 0xc4ff, 0xc50d, 0xc51a, 0xc528,
|
||||
0xc536, 0xc544, 0xc551, 0xc55f, 0xc56d, 0xc57b,
|
||||
0xc589, 0xc596, 0xc5a4, 0xc5b2, 0xc5c0, 0xc5cd,
|
||||
0xc5db, 0xc5e9, 0xc5f7, 0xc604, 0xc612, 0xc620,
|
||||
0xc62d, 0xc63b, 0xc649, 0xc657, 0xc664, 0xc672,
|
||||
0xc680, 0xc68d, 0xc69b, 0xc6a9, 0xc6b7, 0xc6c4,
|
||||
0xc6d2, 0xc6e0, 0xc6ed, 0xc6fb, 0xc709, 0xc716,
|
||||
0xc724, 0xc732, 0xc73f, 0xc74d, 0xc75b, 0xc768,
|
||||
0xc776, 0xc784, 0xc791, 0xc79f, 0xc7ad, 0xc7ba,
|
||||
0xc7c8, 0xc7d6, 0xc7e3, 0xc7f1, 0xc7fe, 0xc80c,
|
||||
0xc81a, 0xc827, 0xc835, 0xc842, 0xc850, 0xc85e,
|
||||
0xc86b, 0xc879, 0xc886, 0xc894, 0xc8a2, 0xc8af,
|
||||
0xc8bd, 0xc8ca, 0xc8d8, 0xc8e5, 0xc8f3, 0xc901,
|
||||
0xc90e, 0xc91c, 0xc929, 0xc937, 0xc944, 0xc952,
|
||||
0xc95f, 0xc96d, 0xc97b, 0xc988, 0xc996, 0xc9a3,
|
||||
0xc9b1, 0xc9be, 0xc9cc, 0xc9d9, 0xc9e7, 0xc9f4,
|
||||
0xca02, 0xca0f, 0xca1d, 0xca2a, 0xca38, 0xca45,
|
||||
0xca53, 0xca60, 0xca6e, 0xca7b, 0xca89, 0xca96,
|
||||
0xcaa4, 0xcab1, 0xcabe, 0xcacc, 0xcad9, 0xcae7,
|
||||
0xcaf4, 0xcb02, 0xcb0f, 0xcb1d, 0xcb2a, 0xcb37,
|
||||
0xcb45, 0xcb52, 0xcb60, 0xcb6d, 0xcb7b, 0xcb88,
|
||||
0xcb95, 0xcba3, 0xcbb0, 0xcbbe, 0xcbcb, 0xcbd8,
|
||||
0xcbe6, 0xcbf3, 0xcc01, 0xcc0e, 0xcc1b, 0xcc29,
|
||||
0xcc36, 0xcc43, 0xcc51, 0xcc5e, 0xcc6c, 0xcc79,
|
||||
0xcc86, 0xcc94, 0xcca1, 0xccae, 0xccbc, 0xccc9,
|
||||
0xccd6, 0xcce4, 0xccf1, 0xccfe, 0xcd0c, 0xcd19,
|
||||
0xcd26, 0xcd34, 0xcd41, 0xcd4e, 0xcd5b, 0xcd69,
|
||||
0xcd76, 0xcd83, 0xcd91, 0xcd9e, 0xcdab, 0xcdb9,
|
||||
0xcdc6, 0xcdd3, 0xcde0, 0xcdee, 0xcdfb, 0xce08,
|
||||
0xce15, 0xce23, 0xce30, 0xce3d, 0xce4a, 0xce58,
|
||||
0xce65, 0xce72, 0xce7f, 0xce8d, 0xce9a, 0xcea7,
|
||||
0xceb4, 0xcec2, 0xcecf, 0xcedc, 0xcee9, 0xcef6,
|
||||
0xcf04, 0xcf11, 0xcf1e, 0xcf2b, 0xcf38, 0xcf46,
|
||||
0xcf53, 0xcf60, 0xcf6d, 0xcf7a, 0xcf87, 0xcf95,
|
||||
0xcfa2, 0xcfaf, 0xcfbc, 0xcfc9, 0xcfd6, 0xcfe4,
|
||||
0xcff1, 0xcffe, 0xd00b, 0xd018, 0xd025, 0xd032,
|
||||
0xd040, 0xd04d, 0xd05a, 0xd067, 0xd074, 0xd081,
|
||||
0xd08e, 0xd09b, 0xd0a9, 0xd0b6, 0xd0c3, 0xd0d0,
|
||||
0xd0dd, 0xd0ea, 0xd0f7, 0xd104, 0xd111, 0xd11e,
|
||||
0xd12b, 0xd139, 0xd146, 0xd153, 0xd160, 0xd16d,
|
||||
0xd17a, 0xd187, 0xd194, 0xd1a1, 0xd1ae, 0xd1bb,
|
||||
0xd1c8, 0xd1d5, 0xd1e2, 0xd1ef, 0xd1fc, 0xd209,
|
||||
0xd216, 0xd223, 0xd230, 0xd23d, 0xd24a, 0xd257,
|
||||
0xd264, 0xd271, 0xd27e, 0xd28b, 0xd298, 0xd2a5,
|
||||
0xd2b2, 0xd2bf, 0xd2cc, 0xd2d9, 0xd2e6, 0xd2f3,
|
||||
0xd300, 0xd30d, 0xd31a, 0xd327, 0xd334, 0xd341,
|
||||
0xd34e, 0xd35b, 0xd368, 0xd375, 0xd382, 0xd38f,
|
||||
0xd39c, 0xd3a8, 0xd3b5, 0xd3c2, 0xd3cf, 0xd3dc,
|
||||
0xd3e9, 0xd3f6, 0xd403, 0xd410, 0xd41d, 0xd42a,
|
||||
0xd436, 0xd443, 0xd450, 0xd45d, 0xd46a, 0xd477,
|
||||
0xd484, 0xd491, 0xd49e, 0xd4aa, 0xd4b7, 0xd4c4,
|
||||
0xd4d1, 0xd4de, 0xd4eb, 0xd4f8, 0xd504, 0xd511,
|
||||
0xd51e, 0xd52b, 0xd538, 0xd545, 0xd551, 0xd55e,
|
||||
0xd56b, 0xd578, 0xd585, 0xd591, 0xd59e, 0xd5ab,
|
||||
0xd5b8, 0xd5c5, 0xd5d1, 0xd5de, 0xd5eb, 0xd5f8,
|
||||
0xd605, 0xd611, 0xd61e, 0xd62b, 0xd638, 0xd645,
|
||||
0xd651, 0xd65e, 0xd66b, 0xd678, 0xd684, 0xd691,
|
||||
0xd69e, 0xd6ab, 0xd6b7, 0xd6c4, 0xd6d1, 0xd6de,
|
||||
0xd6ea, 0xd6f7, 0xd704, 0xd710, 0xd71d, 0xd72a,
|
||||
0xd737, 0xd743, 0xd750, 0xd75d, 0xd769, 0xd776,
|
||||
0xd783, 0xd78f, 0xd79c, 0xd7a9, 0xd7b6, 0xd7c2,
|
||||
0xd7cf, 0xd7dc, 0xd7e8, 0xd7f5, 0xd802, 0xd80e,
|
||||
0xd81b, 0xd828, 0xd834, 0xd841, 0xd84e, 0xd85a,
|
||||
0xd867, 0xd873, 0xd880, 0xd88d, 0xd899, 0xd8a6,
|
||||
0xd8b3, 0xd8bf, 0xd8cc, 0xd8d8, 0xd8e5, 0xd8f2,
|
||||
0xd8fe, 0xd90b, 0xd917, 0xd924, 0xd931, 0xd93d,
|
||||
0xd94a, 0xd956, 0xd963, 0xd970, 0xd97c, 0xd989,
|
||||
0xd995, 0xd9a2, 0xd9ae, 0xd9bb, 0xd9c8, 0xd9d4,
|
||||
0xd9e1, 0xd9ed, 0xd9fa, 0xda06, 0xda13, 0xda1f,
|
||||
0xda2c, 0xda38, 0xda45, 0xda51, 0xda5e, 0xda6a,
|
||||
0xda77, 0xda84, 0xda90, 0xda9d, 0xdaa9, 0xdab6,
|
||||
0xdac2, 0xdacf, 0xdadb, 0xdae7, 0xdaf4, 0xdb00,
|
||||
0xdb0d, 0xdb19, 0xdb26, 0xdb32, 0xdb3f, 0xdb4b,
|
||||
0xdb58, 0xdb64, 0xdb71, 0xdb7d, 0xdb8a, 0xdb96,
|
||||
0xdba2, 0xdbaf, 0xdbbb, 0xdbc8, 0xdbd4, 0xdbe1,
|
||||
0xdbed, 0xdbf9, 0xdc06, 0xdc12, 0xdc1f, 0xdc2b,
|
||||
0xdc38, 0xdc44, 0xdc50, 0xdc5d, 0xdc69, 0xdc76,
|
||||
0xdc82, 0xdc8e, 0xdc9b, 0xdca7, 0xdcb3, 0xdcc0,
|
||||
0xdccc, 0xdcd9, 0xdce5, 0xdcf1, 0xdcfe, 0xdd0a,
|
||||
0xdd16, 0xdd23, 0xdd2f, 0xdd3b, 0xdd48, 0xdd54,
|
||||
0xdd60, 0xdd6d, 0xdd79, 0xdd85, 0xdd92, 0xdd9e,
|
||||
0xddaa, 0xddb7, 0xddc3, 0xddcf, 0xdddc, 0xdde8,
|
||||
0xddf4, 0xde01, 0xde0d, 0xde19, 0xde25, 0xde32,
|
||||
0xde3e, 0xde4a, 0xde57, 0xde63, 0xde6f, 0xde7b,
|
||||
0xde88, 0xde94, 0xdea0, 0xdeac, 0xdeb9, 0xdec5,
|
||||
0xded1, 0xdedd, 0xdeea, 0xdef6, 0xdf02, 0xdf0e,
|
||||
0xdf1b, 0xdf27, 0xdf33, 0xdf3f, 0xdf4c, 0xdf58,
|
||||
0xdf64, 0xdf70, 0xdf7c, 0xdf89, 0xdf95, 0xdfa1,
|
||||
0xdfad, 0xdfb9, 0xdfc6, 0xdfd2, 0xdfde, 0xdfea,
|
||||
0xdff6, 0xe003, 0xe00f, 0xe01b, 0xe027, 0xe033,
|
||||
0xe03f, 0xe04c, 0xe058, 0xe064, 0xe070, 0xe07c,
|
||||
0xe088, 0xe094, 0xe0a1, 0xe0ad, 0xe0b9, 0xe0c5,
|
||||
0xe0d1, 0xe0dd, 0xe0e9, 0xe0f5, 0xe102, 0xe10e,
|
||||
0xe11a, 0xe126, 0xe132, 0xe13e, 0xe14a, 0xe156,
|
||||
0xe162, 0xe16e, 0xe17b, 0xe187, 0xe193, 0xe19f,
|
||||
0xe1ab, 0xe1b7, 0xe1c3, 0xe1cf, 0xe1db, 0xe1e7,
|
||||
0xe1f3, 0xe1ff, 0xe20b, 0xe217, 0xe223, 0xe22f,
|
||||
0xe23c, 0xe248, 0xe254, 0xe260, 0xe26c, 0xe278,
|
||||
0xe284, 0xe290, 0xe29c, 0xe2a8, 0xe2b4, 0xe2c0,
|
||||
0xe2cc, 0xe2d8, 0xe2e4, 0xe2f0, 0xe2fc, 0xe308,
|
||||
0xe314, 0xe320, 0xe32c, 0xe338, 0xe344, 0xe350,
|
||||
0xe35c, 0xe368, 0xe374, 0xe380, 0xe38b, 0xe397,
|
||||
0xe3a3, 0xe3af, 0xe3bb, 0xe3c7, 0xe3d3, 0xe3df,
|
||||
0xe3eb, 0xe3f7, 0xe403, 0xe40f, 0xe41b, 0xe427,
|
||||
0xe433, 0xe43f, 0xe44a, 0xe456, 0xe462, 0xe46e,
|
||||
0xe47a, 0xe486, 0xe492, 0xe49e, 0xe4aa, 0xe4b6,
|
||||
0xe4c1, 0xe4cd, 0xe4d9, 0xe4e5, 0xe4f1, 0xe4fd,
|
||||
0xe509, 0xe515, 0xe520, 0xe52c, 0xe538, 0xe544,
|
||||
0xe550, 0xe55c, 0xe567, 0xe573, 0xe57f, 0xe58b,
|
||||
0xe597, 0xe5a3, 0xe5af, 0xe5ba, 0xe5c6, 0xe5d2,
|
||||
0xe5de, 0xe5ea, 0xe5f5, 0xe601, 0xe60d, 0xe619,
|
||||
0xe625, 0xe630, 0xe63c, 0xe648, 0xe654, 0xe660,
|
||||
0xe66b, 0xe677, 0xe683, 0xe68f, 0xe69a, 0xe6a6,
|
||||
0xe6b2, 0xe6be, 0xe6ca, 0xe6d5, 0xe6e1, 0xe6ed,
|
||||
0xe6f9, 0xe704, 0xe710, 0xe71c, 0xe727, 0xe733,
|
||||
0xe73f, 0xe74b, 0xe756, 0xe762, 0xe76e, 0xe77a,
|
||||
0xe785, 0xe791, 0xe79d, 0xe7a8, 0xe7b4, 0xe7c0,
|
||||
0xe7cb, 0xe7d7, 0xe7e3, 0xe7ef, 0xe7fa, 0xe806,
|
||||
0xe812, 0xe81d, 0xe829, 0xe835, 0xe840, 0xe84c,
|
||||
0xe858, 0xe863, 0xe86f, 0xe87b, 0xe886, 0xe892,
|
||||
0xe89e, 0xe8a9, 0xe8b5, 0xe8c0, 0xe8cc, 0xe8d8,
|
||||
0xe8e3, 0xe8ef, 0xe8fb, 0xe906, 0xe912, 0xe91d,
|
||||
0xe929, 0xe935, 0xe940, 0xe94c, 0xe958, 0xe963,
|
||||
0xe96f, 0xe97a, 0xe986, 0xe991, 0xe99d, 0xe9a9,
|
||||
0xe9b4, 0xe9c0, 0xe9cb, 0xe9d7, 0xe9e3, 0xe9ee,
|
||||
0xe9fa, 0xea05, 0xea11, 0xea1c, 0xea28, 0xea33,
|
||||
0xea3f, 0xea4a, 0xea56, 0xea62, 0xea6d, 0xea79,
|
||||
0xea84, 0xea90, 0xea9b, 0xeaa7, 0xeab2, 0xeabe,
|
||||
0xeac9, 0xead5, 0xeae0, 0xeaec, 0xeaf7, 0xeb03,
|
||||
0xeb0e, 0xeb1a, 0xeb25, 0xeb31, 0xeb3c, 0xeb48,
|
||||
0xeb53, 0xeb5f, 0xeb6a, 0xeb76, 0xeb81, 0xeb8d,
|
||||
0xeb98, 0xeba3, 0xebaf, 0xebba, 0xebc6, 0xebd1,
|
||||
0xebdd, 0xebe8, 0xebf4, 0xebff, 0xec0a, 0xec16,
|
||||
0xec21, 0xec2d, 0xec38, 0xec44, 0xec4f, 0xec5a,
|
||||
0xec66, 0xec71, 0xec7d, 0xec88, 0xec93, 0xec9f,
|
||||
0xecaa, 0xecb6, 0xecc1, 0xeccc, 0xecd8, 0xece3,
|
||||
0xecef, 0xecfa, 0xed05, 0xed11, 0xed1c, 0xed27,
|
||||
0xed33, 0xed3e, 0xed4a, 0xed55, 0xed60, 0xed6c,
|
||||
0xed77, 0xed82, 0xed8e, 0xed99, 0xeda4, 0xedb0,
|
||||
0xedbb, 0xedc6, 0xedd2, 0xeddd, 0xede8, 0xedf4,
|
||||
0xedff, 0xee0a, 0xee15, 0xee21, 0xee2c, 0xee37,
|
||||
0xee43, 0xee4e, 0xee59, 0xee65, 0xee70, 0xee7b,
|
||||
0xee86, 0xee92, 0xee9d, 0xeea8, 0xeeb3, 0xeebf,
|
||||
0xeeca, 0xeed5, 0xeee1, 0xeeec, 0xeef7, 0xef02,
|
||||
0xef0e, 0xef19, 0xef24, 0xef2f, 0xef3a, 0xef46,
|
||||
0xef51, 0xef5c, 0xef67, 0xef73, 0xef7e, 0xef89,
|
||||
0xef94, 0xef9f, 0xefab, 0xefb6, 0xefc1, 0xefcc,
|
||||
0xefd7, 0xefe3, 0xefee, 0xeff9, 0xf004, 0xf00f,
|
||||
0xf01b, 0xf026, 0xf031, 0xf03c, 0xf047, 0xf052,
|
||||
0xf05e, 0xf069, 0xf074, 0xf07f, 0xf08a, 0xf095,
|
||||
0xf0a1, 0xf0ac, 0xf0b7, 0xf0c2, 0xf0cd, 0xf0d8,
|
||||
0xf0e3, 0xf0ef, 0xf0fa, 0xf105, 0xf110, 0xf11b,
|
||||
0xf126, 0xf131, 0xf13c, 0xf147, 0xf153, 0xf15e,
|
||||
0xf169, 0xf174, 0xf17f, 0xf18a, 0xf195, 0xf1a0,
|
||||
0xf1ab, 0xf1b6, 0xf1c2, 0xf1cd, 0xf1d8, 0xf1e3,
|
||||
0xf1ee, 0xf1f9, 0xf204, 0xf20f, 0xf21a, 0xf225,
|
||||
0xf230, 0xf23b, 0xf246, 0xf251, 0xf25c, 0xf267,
|
||||
0xf272, 0xf27d, 0xf288, 0xf293, 0xf29f, 0xf2aa,
|
||||
0xf2b5, 0xf2c0, 0xf2cb, 0xf2d6, 0xf2e1, 0xf2ec,
|
||||
0xf2f7, 0xf302, 0xf30d, 0xf318, 0xf323, 0xf32e,
|
||||
0xf339, 0xf344, 0xf34f, 0xf35a, 0xf364, 0xf36f,
|
||||
0xf37a, 0xf385, 0xf390, 0xf39b, 0xf3a6, 0xf3b1,
|
||||
0xf3bc, 0xf3c7, 0xf3d2, 0xf3dd, 0xf3e8, 0xf3f3,
|
||||
0xf3fe, 0xf409, 0xf414, 0xf41f, 0xf42a, 0xf435,
|
||||
0xf43f, 0xf44a, 0xf455, 0xf460, 0xf46b, 0xf476,
|
||||
0xf481, 0xf48c, 0xf497, 0xf4a2, 0xf4ad, 0xf4b7,
|
||||
0xf4c2, 0xf4cd, 0xf4d8, 0xf4e3, 0xf4ee, 0xf4f9,
|
||||
0xf504, 0xf50f, 0xf519, 0xf524, 0xf52f, 0xf53a,
|
||||
0xf545, 0xf550, 0xf55b, 0xf565, 0xf570, 0xf57b,
|
||||
0xf586, 0xf591, 0xf59c, 0xf5a6, 0xf5b1, 0xf5bc,
|
||||
0xf5c7, 0xf5d2, 0xf5dd, 0xf5e7, 0xf5f2, 0xf5fd,
|
||||
0xf608, 0xf613, 0xf61d, 0xf628, 0xf633, 0xf63e,
|
||||
0xf649, 0xf653, 0xf65e, 0xf669, 0xf674, 0xf67f,
|
||||
0xf689, 0xf694, 0xf69f, 0xf6aa, 0xf6b4, 0xf6bf,
|
||||
0xf6ca, 0xf6d5, 0xf6e0, 0xf6ea, 0xf6f5, 0xf700,
|
||||
0xf70b, 0xf715, 0xf720, 0xf72b, 0xf736, 0xf740,
|
||||
0xf74b, 0xf756, 0xf760, 0xf76b, 0xf776, 0xf781,
|
||||
0xf78b, 0xf796, 0xf7a1, 0xf7ab, 0xf7b6, 0xf7c1,
|
||||
0xf7cc, 0xf7d6, 0xf7e1, 0xf7ec, 0xf7f6, 0xf801,
|
||||
0xf80c, 0xf816, 0xf821, 0xf82c, 0xf836, 0xf841,
|
||||
0xf84c, 0xf856, 0xf861, 0xf86c, 0xf876, 0xf881,
|
||||
0xf88c, 0xf896, 0xf8a1, 0xf8ac, 0xf8b6, 0xf8c1,
|
||||
0xf8cc, 0xf8d6, 0xf8e1, 0xf8ec, 0xf8f6, 0xf901,
|
||||
0xf90b, 0xf916, 0xf921, 0xf92b, 0xf936, 0xf941,
|
||||
0xf94b, 0xf956, 0xf960, 0xf96b, 0xf976, 0xf980,
|
||||
0xf98b, 0xf995, 0xf9a0, 0xf9aa, 0xf9b5, 0xf9c0,
|
||||
0xf9ca, 0xf9d5, 0xf9df, 0xf9ea, 0xf9f4, 0xf9ff,
|
||||
0xfa0a, 0xfa14, 0xfa1f, 0xfa29, 0xfa34, 0xfa3e,
|
||||
0xfa49, 0xfa53, 0xfa5e, 0xfa69, 0xfa73, 0xfa7e,
|
||||
0xfa88, 0xfa93, 0xfa9d, 0xfaa8, 0xfab2, 0xfabd,
|
||||
0xfac7, 0xfad2, 0xfadc, 0xfae7, 0xfaf1, 0xfafc,
|
||||
0xfb06, 0xfb11, 0xfb1b, 0xfb26, 0xfb30, 0xfb3b,
|
||||
0xfb45, 0xfb50, 0xfb5a, 0xfb65, 0xfb6f, 0xfb7a,
|
||||
0xfb84, 0xfb8f, 0xfb99, 0xfba4, 0xfbae, 0xfbb8,
|
||||
0xfbc3, 0xfbcd, 0xfbd8, 0xfbe2, 0xfbed, 0xfbf7,
|
||||
0xfc02, 0xfc0c, 0xfc16, 0xfc21, 0xfc2b, 0xfc36,
|
||||
0xfc40, 0xfc4b, 0xfc55, 0xfc5f, 0xfc6a, 0xfc74,
|
||||
0xfc7f, 0xfc89, 0xfc93, 0xfc9e, 0xfca8, 0xfcb3,
|
||||
0xfcbd, 0xfcc7, 0xfcd2, 0xfcdc, 0xfce7, 0xfcf1,
|
||||
0xfcfb, 0xfd06, 0xfd10, 0xfd1a, 0xfd25, 0xfd2f,
|
||||
0xfd3a, 0xfd44, 0xfd4e, 0xfd59, 0xfd63, 0xfd6d,
|
||||
0xfd78, 0xfd82, 0xfd8c, 0xfd97, 0xfda1, 0xfdab,
|
||||
0xfdb6, 0xfdc0, 0xfdca, 0xfdd5, 0xfddf, 0xfde9,
|
||||
0xfdf4, 0xfdfe, 0xfe08, 0xfe13, 0xfe1d, 0xfe27,
|
||||
0xfe32, 0xfe3c, 0xfe46, 0xfe50, 0xfe5b, 0xfe65,
|
||||
0xfe6f, 0xfe7a, 0xfe84, 0xfe8e, 0xfe98, 0xfea3,
|
||||
0xfead, 0xfeb7, 0xfec1, 0xfecc, 0xfed6, 0xfee0,
|
||||
0xfeeb, 0xfef5, 0xfeff, 0xff09, 0xff14, 0xff1e,
|
||||
0xff28, 0xff32, 0xff3c, 0xff47, 0xff51, 0xff5b,
|
||||
0xff65, 0xff70, 0xff7a, 0xff84, 0xff8e, 0xff98,
|
||||
0xffa3, 0xffad, 0xffb7, 0xffc1, 0xffcc, 0xffd6,
|
||||
0xffe0, 0xffea, 0xfff4, 0xffff
|
||||
};
|
||||
|
||||
// max value is pi/4
|
||||
constexpr double SCALING_FACTOR = 4. / M_PI * 0xFFFF;
|
||||
|
||||
inline double atan2_lookup(double y, double x)
|
||||
{
|
||||
if (std::abs(x) < std::numeric_limits<double>::epsilon())
|
||||
{
|
||||
if (y >= 0.)
|
||||
{
|
||||
return M_PI / 2.;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -M_PI / 2.;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned octant = 0;
|
||||
|
||||
if (x < 0.)
|
||||
{
|
||||
octant = 1;
|
||||
x = -x;
|
||||
}
|
||||
if (y < 0.)
|
||||
{
|
||||
octant |= 2;
|
||||
y = -y;
|
||||
}
|
||||
|
||||
double t = y / x;
|
||||
if (t > 1.0)
|
||||
{
|
||||
octant |= 4;
|
||||
t = 1.0 / t;
|
||||
}
|
||||
|
||||
double angle = atan_table[(unsigned)(t * 4095)] / SCALING_FACTOR;
|
||||
|
||||
switch (octant)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
angle = M_PI - angle;
|
||||
break;
|
||||
case 2:
|
||||
angle = -angle;
|
||||
break;
|
||||
case 3:
|
||||
angle = -M_PI + angle;
|
||||
break;
|
||||
case 4:
|
||||
angle = M_PI / 2.0 - angle;
|
||||
break;
|
||||
case 5:
|
||||
angle = M_PI / 2.0 + angle;
|
||||
break;
|
||||
case 6:
|
||||
angle = -M_PI / 2.0 + angle;
|
||||
break;
|
||||
case 7:
|
||||
angle = -M_PI / 2.0 - angle;
|
||||
break;
|
||||
}
|
||||
return angle;
|
||||
}
|
||||
|
||||
#endif // TRIGONOMETRY_TABLES_H
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "bearing.hpp"
|
||||
|
||||
std::string Bearing::Get(const double heading)
|
||||
{
|
||||
if (heading <= 202.5)
|
||||
{
|
||||
if (heading >= 0. && heading <= 22.5)
|
||||
{
|
||||
return "N";
|
||||
}
|
||||
if (heading > 22.5 && heading <= 67.5)
|
||||
{
|
||||
return "NE";
|
||||
}
|
||||
if (heading > 67.5 && heading <= 112.5)
|
||||
{
|
||||
return "E";
|
||||
}
|
||||
if (heading > 112.5 && heading <= 157.5)
|
||||
{
|
||||
return "SE";
|
||||
}
|
||||
return "S";
|
||||
}
|
||||
if (heading > 202.5 && heading <= 247.5)
|
||||
{
|
||||
return "SW";
|
||||
}
|
||||
if (heading > 247.5 && heading <= 292.5)
|
||||
{
|
||||
return "W";
|
||||
}
|
||||
if (heading > 292.5 && heading <= 337.5)
|
||||
{
|
||||
return "NW";
|
||||
}
|
||||
return "N";
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef BEARING_HPP_
|
||||
#define BEARING_HPP_
|
||||
|
||||
#include <string>
|
||||
|
||||
struct Bearing
|
||||
{
|
||||
static std::string Get(const double heading);
|
||||
};
|
||||
|
||||
#endif // BEARING_HPP_
|
||||
-188
@@ -1,188 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef CAST_HPP
|
||||
#define CAST_HPP
|
||||
|
||||
#include <boost/spirit/include/karma.hpp>
|
||||
#include <boost/spirit/include/qi.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
struct cast
|
||||
{
|
||||
// convert scoped enums to integers
|
||||
template <typename Enumeration>
|
||||
static auto enum_to_underlying(Enumeration const value) -> typename std::underlying_type<Enumeration>::type
|
||||
{
|
||||
return static_cast<typename std::underlying_type<Enumeration>::type>(value);
|
||||
}
|
||||
|
||||
template <typename Number>
|
||||
static typename std::enable_if<std::is_integral<Number>::value, std::string>::type
|
||||
integral_to_string(const Number value)
|
||||
{
|
||||
std::string output;
|
||||
std::back_insert_iterator<std::string> sink(output);
|
||||
|
||||
if (8 == sizeof(Number))
|
||||
{
|
||||
boost::spirit::karma::generate(sink, boost::spirit::karma::long_long, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (std::is_signed<Number>::value)
|
||||
{
|
||||
boost::spirit::karma::generate(sink, boost::spirit::karma::int_, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
boost::spirit::karma::generate(sink, boost::spirit::karma::uint_, value);
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
static int string_to_int(const std::string &input)
|
||||
{
|
||||
auto first_digit = input.begin();
|
||||
// Delete any trailing white-spaces
|
||||
while (first_digit != input.end() && std::isspace(*first_digit))
|
||||
{
|
||||
++first_digit;
|
||||
}
|
||||
int value = 0;
|
||||
boost::spirit::qi::parse(first_digit, input.end(), boost::spirit::int_, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
static unsigned string_to_uint(const std::string &input)
|
||||
{
|
||||
auto first_digit = input.begin();
|
||||
// Delete any trailing white-spaces
|
||||
while (first_digit != input.end() && (std::isspace(*first_digit) || '-' == *first_digit))
|
||||
{
|
||||
++first_digit;
|
||||
}
|
||||
unsigned value = 0;
|
||||
boost::spirit::qi::parse(first_digit, input.end(), boost::spirit::uint_, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
static uint64_t string_to_uint64(const std::string &input)
|
||||
{
|
||||
auto first_digit = input.begin();
|
||||
// Delete any trailing white-spaces
|
||||
while (first_digit != input.end() && std::isspace(*first_digit))
|
||||
{
|
||||
++first_digit;
|
||||
}
|
||||
uint64_t value = 0;
|
||||
boost::spirit::qi::parse(first_digit, input.end(), boost::spirit::long_long, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
// source: http://tinodidriksen.com/2011/05/28/cpp-convert-string-to-double-speed/
|
||||
static double string_to_double(const char *p)
|
||||
{
|
||||
double r = 0.0;
|
||||
bool neg = false;
|
||||
if (*p == '-')
|
||||
{
|
||||
neg = true;
|
||||
++p;
|
||||
}
|
||||
while (*p >= '0' && *p <= '9')
|
||||
{
|
||||
r = (r * 10.0) + (*p - '0');
|
||||
++p;
|
||||
}
|
||||
if (*p == '.')
|
||||
{
|
||||
double f = 0.0;
|
||||
int n = 0;
|
||||
++p;
|
||||
while (*p >= '0' && *p <= '9')
|
||||
{
|
||||
f = (f * 10.0) + (*p - '0');
|
||||
++p;
|
||||
++n;
|
||||
}
|
||||
r += f / std::pow(10.0, n);
|
||||
}
|
||||
if (neg)
|
||||
{
|
||||
r = -r;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
template <typename T> struct scientific_policy : boost::spirit::karma::real_policies<T>
|
||||
{
|
||||
// we want the numbers always to be in fixed format
|
||||
static int floatfield(T)
|
||||
{
|
||||
return boost::spirit::karma::real_policies<T>::fmtflags::fixed;
|
||||
}
|
||||
static unsigned int precision(T) { return 6; }
|
||||
};
|
||||
typedef boost::spirit::karma::real_generator<double, scientific_policy<double>> science_type;
|
||||
|
||||
static std::string double_fixed_to_string(const double value)
|
||||
{
|
||||
std::string output;
|
||||
std::back_insert_iterator<std::string> sink(output);
|
||||
boost::spirit::karma::generate(sink, science_type(), value);
|
||||
if (output.size() >= 2 && output[output.size() - 2] == '.' &&
|
||||
output[output.size() - 1] == '0')
|
||||
{
|
||||
output.resize(output.size() - 2);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
static std::string double_to_string(const double value)
|
||||
{
|
||||
std::string output;
|
||||
std::back_insert_iterator<std::string> sink(output);
|
||||
boost::spirit::karma::generate(sink, value);
|
||||
return output;
|
||||
}
|
||||
|
||||
static void double_with_two_digits_to_string(const double value,
|
||||
std::string &output)
|
||||
{
|
||||
// The largest 32-bit integer is 4294967295, that is 10 chars
|
||||
// On the safe side, add 1 for sign, and 1 for trailing zero
|
||||
char buffer[12];
|
||||
sprintf(buffer, "%g", value);
|
||||
output = buffer;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CAST_HPP
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "compute_angle.hpp"
|
||||
|
||||
#include "TrigonometryTables.h"
|
||||
#include "../Util/MercatorUtil.h"
|
||||
#include <osrm/Coordinate.h>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
double ComputeAngle::OfThreeFixedPointCoordinates(const FixedPointCoordinate &A,
|
||||
const FixedPointCoordinate &C,
|
||||
const FixedPointCoordinate &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_lookup(v2y, v2x) - atan2_lookup(v1y, v1x)) * 180. / M_PI;
|
||||
while (angle < 0.)
|
||||
{
|
||||
angle += 360.;
|
||||
}
|
||||
return angle;
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef COMPUTE_ANGLE_HPP
|
||||
#define COMPUTE_ANGLE_HPP
|
||||
|
||||
struct FixedPointCoordinate;
|
||||
struct NodeInfo;
|
||||
|
||||
struct ComputeAngle
|
||||
{
|
||||
/* Get angle of line segment (A,C)->(C,B), atan2 magic, formerly cosine theorem*/
|
||||
static double OfThreeFixedPointCoordinates(const FixedPointCoordinate &A,
|
||||
const FixedPointCoordinate &C,
|
||||
const FixedPointCoordinate &B);
|
||||
};
|
||||
#endif // COMPUTE_ANGLE_HPP
|
||||
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef CONTAINER_HPP_
|
||||
#define CONTAINER_HPP_
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <vector>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
template <typename T> void sort_unique_resize(std::vector<T> &vector)
|
||||
{
|
||||
std::sort(vector.begin(), vector.end());
|
||||
const auto 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);
|
||||
// vector.shrink_to_fit();
|
||||
// }
|
||||
|
||||
// template <typename T> inline void remove_consecutive_duplicates_from_vector(std::vector<T> &vector)
|
||||
// {
|
||||
// const auto number_of_unique_elements = std::unique(vector.begin(), vector.end()) - vector.begin();
|
||||
// vector.resize(number_of_unique_elements);
|
||||
// }
|
||||
|
||||
template <typename ForwardIterator, typename Function>
|
||||
Function for_each_pair(ForwardIterator begin, ForwardIterator end, Function function)
|
||||
{
|
||||
if (begin == end)
|
||||
{
|
||||
return function;
|
||||
}
|
||||
|
||||
auto next = begin;
|
||||
next = std::next(next);
|
||||
|
||||
while (next != end)
|
||||
{
|
||||
function(*begin, *next);
|
||||
begin = std::next(begin); next = std::next(next);
|
||||
}
|
||||
return function;
|
||||
}
|
||||
|
||||
template <class ContainerT, typename Function>
|
||||
Function for_each_pair(ContainerT &container, Function function)
|
||||
{
|
||||
return for_each_pair(std::begin(container), std::end(container), function);
|
||||
}
|
||||
|
||||
}
|
||||
#endif /* CONTAINER_HPP_ */
|
||||
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "FingerPrint.h"
|
||||
|
||||
#include "osrm_exception.hpp"
|
||||
|
||||
#include <boost/uuid/name_generator.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#cmakedefine01 HAS64BITS
|
||||
#cmakedefine MD5PREPARE "${MD5PREPARE}"
|
||||
#cmakedefine MD5RTREE "${MD5RTREE}"
|
||||
#cmakedefine MD5GRAPH "${MD5GRAPH}"
|
||||
#cmakedefine MD5OBJECTS "${MD5OBJECTS}"
|
||||
|
||||
FingerPrint::FingerPrint() : magic_number(1297240911)
|
||||
{
|
||||
md5_prepare[32] = md5_tree[32] = md5_graph[32] = md5_objects[32] = '\0';
|
||||
|
||||
boost::uuids::name_generator gen(named_uuid);
|
||||
std::string temp_string;
|
||||
|
||||
std::memcpy(md5_prepare, MD5PREPARE, strlen(MD5PREPARE));
|
||||
temp_string += md5_prepare;
|
||||
std::memcpy(md5_tree, MD5RTREE, 32);
|
||||
temp_string += md5_tree;
|
||||
std::memcpy(md5_graph, MD5GRAPH, 32);
|
||||
temp_string += md5_graph;
|
||||
std::memcpy(md5_objects, MD5OBJECTS, 32);
|
||||
temp_string += md5_objects;
|
||||
|
||||
named_uuid = gen(temp_string);
|
||||
has_64_bits = HAS64BITS;
|
||||
}
|
||||
|
||||
FingerPrint::~FingerPrint() {}
|
||||
|
||||
const boost::uuids::uuid &FingerPrint::GetFingerPrint() const { return named_uuid; }
|
||||
|
||||
bool FingerPrint::IsMagicNumberOK() const { return 1297240911 == magic_number; }
|
||||
|
||||
bool FingerPrint::TestGraphUtil(const FingerPrint &other) const
|
||||
{
|
||||
if (!other.IsMagicNumberOK())
|
||||
{
|
||||
throw osrm::exception("hsgr input file misses magic number. Check or reprocess the file");
|
||||
}
|
||||
return std::equal(md5_graph, md5_graph + 32, other.md5_graph);
|
||||
}
|
||||
|
||||
bool FingerPrint::TestPrepare(const FingerPrint &other) const
|
||||
{
|
||||
if (!other.IsMagicNumberOK())
|
||||
{
|
||||
throw osrm::exception("osrm input file misses magic number. Check or reprocess the file");
|
||||
}
|
||||
return std::equal(md5_prepare, md5_prepare + 32, other.md5_prepare);
|
||||
}
|
||||
|
||||
bool FingerPrint::TestRTree(const FingerPrint &other) const
|
||||
{
|
||||
if (!other.IsMagicNumberOK())
|
||||
{
|
||||
throw osrm::exception("r-tree input file misses magic number. Check or reprocess the file");
|
||||
}
|
||||
return std::equal(md5_tree, md5_tree + 32, other.md5_tree);
|
||||
}
|
||||
|
||||
bool FingerPrint::TestQueryObjects(const FingerPrint &other) const
|
||||
{
|
||||
if (!other.IsMagicNumberOK())
|
||||
{
|
||||
throw osrm::exception("missing magic number. Check or reprocess the file");
|
||||
}
|
||||
return std::equal(md5_objects, md5_objects + 32, other.md5_objects);
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef FLOATING_POINT_HPP
|
||||
#define FLOATING_POINT_HPP
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
template <typename FloatT> bool epsilon_compare(const FloatT number1, const FloatT number2)
|
||||
{
|
||||
static_assert(std::is_floating_point<FloatT>::value, "type must be floating point");
|
||||
return (std::abs(number1 - number2) < std::numeric_limits<FloatT>::epsilon());
|
||||
}
|
||||
}
|
||||
|
||||
#endif // FLOATING_POINT_HPP
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "git_sha.hpp"
|
||||
|
||||
#define GIT_DESCRIPTION "${GIT_DESCRIPTION}"
|
||||
char g_GIT_DESCRIPTION[] = GIT_DESCRIPTION;
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef GIT_SHA_HPP
|
||||
#define GIT_SHA_HPP
|
||||
|
||||
extern char g_GIT_DESCRIPTION[];
|
||||
|
||||
#endif //GIT_SHA_HPP
|
||||
@@ -1,325 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef GRAPHLOADER_H
|
||||
#define GRAPHLOADER_H
|
||||
|
||||
#include "osrm_exception.hpp"
|
||||
#include "../data_structures/external_memory_node.hpp"
|
||||
#include "../data_structures/import_edge.hpp"
|
||||
#include "../data_structures/query_node.hpp"
|
||||
#include "../data_structures/restriction.hpp"
|
||||
#include "../Util/simple_logger.hpp"
|
||||
#include "../Util/FingerPrint.h"
|
||||
#include "../typedefs.h"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
|
||||
#include <tbb/parallel_sort.h>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
template <typename EdgeT>
|
||||
NodeID readBinaryOSRMGraphFromStream(std::istream &input_stream,
|
||||
std::vector<EdgeT> &edge_list,
|
||||
std::vector<NodeID> &barrier_node_list,
|
||||
std::vector<NodeID> &traffic_light_node_list,
|
||||
std::vector<QueryNode> *int_to_ext_node_id_map,
|
||||
std::vector<TurnRestriction> &restriction_list)
|
||||
{
|
||||
const FingerPrint fingerprint_orig;
|
||||
FingerPrint fingerprint_loaded;
|
||||
input_stream.read((char *)&fingerprint_loaded, sizeof(FingerPrint));
|
||||
|
||||
if (!fingerprint_loaded.TestGraphUtil(fingerprint_orig))
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << ".osrm was prepared with different build.\n"
|
||||
"Reprocess to get rid of this warning.";
|
||||
}
|
||||
|
||||
std::unordered_map<NodeID, NodeID> ext_to_int_id_map;
|
||||
|
||||
NodeID n;
|
||||
input_stream.read((char *)&n, sizeof(NodeID));
|
||||
SimpleLogger().Write() << "Importing n = " << n << " nodes ";
|
||||
|
||||
ExternalMemoryNode current_node;
|
||||
for (NodeID i = 0; i < n; ++i)
|
||||
{
|
||||
input_stream.read((char *)¤t_node, sizeof(ExternalMemoryNode));
|
||||
int_to_ext_node_id_map->emplace_back(current_node.lat, current_node.lon, current_node.node_id);
|
||||
ext_to_int_id_map.emplace(current_node.node_id, i);
|
||||
if (current_node.barrier)
|
||||
{
|
||||
barrier_node_list.emplace_back(i);
|
||||
}
|
||||
if (current_node.traffic_lights)
|
||||
{
|
||||
traffic_light_node_list.emplace_back(i);
|
||||
}
|
||||
}
|
||||
|
||||
// tighten vector sizes
|
||||
barrier_node_list.shrink_to_fit();
|
||||
traffic_light_node_list.shrink_to_fit();
|
||||
|
||||
// renumber nodes in turn restrictions
|
||||
for (TurnRestriction ¤t_restriction : restriction_list)
|
||||
{
|
||||
auto internal_id_iter = ext_to_int_id_map.find(current_restriction.from.node);
|
||||
if (internal_id_iter == ext_to_int_id_map.end())
|
||||
{
|
||||
SimpleLogger().Write(logDEBUG) << "Unmapped from Node of restriction";
|
||||
continue;
|
||||
}
|
||||
current_restriction.from.node = internal_id_iter->second;
|
||||
|
||||
internal_id_iter = ext_to_int_id_map.find(current_restriction.via.node);
|
||||
if (internal_id_iter == ext_to_int_id_map.end())
|
||||
{
|
||||
SimpleLogger().Write(logDEBUG) << "Unmapped via node of restriction";
|
||||
continue;
|
||||
}
|
||||
current_restriction.via.node = internal_id_iter->second;
|
||||
|
||||
internal_id_iter = ext_to_int_id_map.find(current_restriction.to.node);
|
||||
if (internal_id_iter == ext_to_int_id_map.end())
|
||||
{
|
||||
SimpleLogger().Write(logDEBUG) << "Unmapped to node of restriction";
|
||||
continue;
|
||||
}
|
||||
current_restriction.to.node = internal_id_iter->second;
|
||||
}
|
||||
|
||||
EdgeWeight weight;
|
||||
NodeID source, target;
|
||||
unsigned nameID;
|
||||
int length;
|
||||
short dir; // direction (0 = open, 1 = forward, 2+ = open)
|
||||
bool is_roundabout, ignore_in_grid, is_access_restricted, is_split;
|
||||
TravelMode travel_mode;
|
||||
|
||||
EdgeID m;
|
||||
input_stream.read((char *)&m, sizeof(unsigned));
|
||||
edge_list.reserve(m);
|
||||
SimpleLogger().Write() << " and " << m << " edges ";
|
||||
|
||||
for (EdgeID i = 0; i < m; ++i)
|
||||
{
|
||||
input_stream.read((char *)&source, sizeof(unsigned));
|
||||
input_stream.read((char *)&target, sizeof(unsigned));
|
||||
input_stream.read((char *)&length, sizeof(int));
|
||||
input_stream.read((char *)&dir, sizeof(short));
|
||||
input_stream.read((char *)&weight, sizeof(int));
|
||||
input_stream.read((char *)&nameID, sizeof(unsigned));
|
||||
input_stream.read((char *)&is_roundabout, sizeof(bool));
|
||||
input_stream.read((char *)&ignore_in_grid, sizeof(bool));
|
||||
input_stream.read((char *)&is_access_restricted, sizeof(bool));
|
||||
input_stream.read((char *)&travel_mode, sizeof(TravelMode));
|
||||
input_stream.read((char *)&is_split, sizeof(bool));
|
||||
|
||||
BOOST_ASSERT_MSG(length > 0, "loaded null length edge");
|
||||
BOOST_ASSERT_MSG(weight > 0, "loaded null weight");
|
||||
BOOST_ASSERT_MSG(0 <= dir && dir <= 2, "loaded bogus direction");
|
||||
|
||||
bool forward = true;
|
||||
bool backward = true;
|
||||
if (1 == dir)
|
||||
{
|
||||
backward = false;
|
||||
}
|
||||
if (2 == dir)
|
||||
{
|
||||
forward = false;
|
||||
}
|
||||
|
||||
// translate the external NodeIDs to internal IDs
|
||||
auto internal_id_iter = ext_to_int_id_map.find(source);
|
||||
if (ext_to_int_id_map.find(source) == ext_to_int_id_map.end())
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
SimpleLogger().Write(logWARNING) << " unresolved source NodeID: " << source;
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
source = internal_id_iter->second;
|
||||
internal_id_iter = ext_to_int_id_map.find(target);
|
||||
if (ext_to_int_id_map.find(target) == ext_to_int_id_map.end())
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
SimpleLogger().Write(logWARNING) << "unresolved target NodeID : " << target;
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
target = internal_id_iter->second;
|
||||
BOOST_ASSERT_MSG(source != SPECIAL_NODEID && target != SPECIAL_NODEID,
|
||||
"nonexisting source or target");
|
||||
|
||||
if (source > target)
|
||||
{
|
||||
std::swap(source, target);
|
||||
std::swap(forward, backward);
|
||||
}
|
||||
|
||||
edge_list.emplace_back(source,
|
||||
target,
|
||||
nameID,
|
||||
weight,
|
||||
forward,
|
||||
backward,
|
||||
is_roundabout,
|
||||
ignore_in_grid,
|
||||
is_access_restricted,
|
||||
travel_mode,
|
||||
is_split);
|
||||
}
|
||||
ext_to_int_id_map.clear();
|
||||
|
||||
tbb::parallel_sort(edge_list.begin(), edge_list.end());
|
||||
|
||||
for (unsigned i = 1; i < edge_list.size(); ++i)
|
||||
{
|
||||
if ((edge_list[i - 1].target == edge_list[i].target) &&
|
||||
(edge_list[i - 1].source == edge_list[i].source))
|
||||
{
|
||||
const bool edge_flags_equivalent =
|
||||
(edge_list[i - 1].forward == edge_list[i].forward) &&
|
||||
(edge_list[i - 1].backward == edge_list[i].backward);
|
||||
const bool edge_flags_are_superset1 =
|
||||
(edge_list[i - 1].forward && edge_list[i - 1].backward) &&
|
||||
(edge_list[i].forward != edge_list[i].backward);
|
||||
const bool edge_flags_are_superset_2 =
|
||||
(edge_list[i].forward && edge_list[i].backward) &&
|
||||
(edge_list[i - 1].forward != edge_list[i - 1].backward);
|
||||
|
||||
if (edge_flags_equivalent)
|
||||
{
|
||||
edge_list[i].weight = std::min(edge_list[i - 1].weight, edge_list[i].weight);
|
||||
edge_list[i - 1].source = SPECIAL_NODEID;
|
||||
}
|
||||
else if (edge_flags_are_superset1)
|
||||
{
|
||||
if (edge_list[i - 1].weight <= edge_list[i].weight)
|
||||
{
|
||||
// edge i-1 is smaller and goes in both directions. Throw away the other edge
|
||||
edge_list[i].source = SPECIAL_NODEID;
|
||||
}
|
||||
else
|
||||
{
|
||||
// edge i-1 is open in both directions, but edge i is smaller in one direction.
|
||||
// Close edge i-1 in this direction
|
||||
edge_list[i - 1].forward = !edge_list[i].forward;
|
||||
edge_list[i - 1].backward = !edge_list[i].backward;
|
||||
}
|
||||
}
|
||||
else if (edge_flags_are_superset_2)
|
||||
{
|
||||
if (edge_list[i - 1].weight <= edge_list[i].weight)
|
||||
{
|
||||
// edge i-1 is smaller for one direction. edge i is open in both. close edge i
|
||||
// in the other direction
|
||||
edge_list[i].forward = !edge_list[i - 1].forward;
|
||||
edge_list[i].backward = !edge_list[i - 1].backward;
|
||||
}
|
||||
else
|
||||
{
|
||||
// edge i is smaller and goes in both direction. Throw away edge i-1
|
||||
edge_list[i - 1].source = SPECIAL_NODEID;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const auto new_end_iter = std::remove_if(edge_list.begin(), edge_list.end(), [] (const EdgeT &edge)
|
||||
{
|
||||
return edge.source == SPECIAL_NODEID ||
|
||||
edge.target == SPECIAL_NODEID;
|
||||
});
|
||||
edge_list.erase(new_end_iter, edge_list.end()); // remove excess candidates.
|
||||
edge_list.shrink_to_fit();
|
||||
SimpleLogger().Write() << "Graph loaded ok and has " << edge_list.size() << " edges";
|
||||
return n;
|
||||
}
|
||||
|
||||
template <typename NodeT, typename EdgeT>
|
||||
unsigned readHSGRFromStream(const boost::filesystem::path &hsgr_file,
|
||||
std::vector<NodeT> &node_list,
|
||||
std::vector<EdgeT> &edge_list,
|
||||
unsigned *check_sum)
|
||||
{
|
||||
if (!boost::filesystem::exists(hsgr_file))
|
||||
{
|
||||
throw osrm::exception("hsgr file does not exist");
|
||||
}
|
||||
if (0 == boost::filesystem::file_size(hsgr_file))
|
||||
{
|
||||
throw osrm::exception("hsgr file is empty");
|
||||
}
|
||||
|
||||
boost::filesystem::ifstream hsgr_input_stream(hsgr_file, std::ios::binary);
|
||||
|
||||
FingerPrint fingerprint_loaded, fingerprint_orig;
|
||||
hsgr_input_stream.read((char *)&fingerprint_loaded, sizeof(FingerPrint));
|
||||
if (!fingerprint_loaded.TestGraphUtil(fingerprint_orig))
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << ".hsgr was prepared with different build.\n"
|
||||
"Reprocess to get rid of this warning.";
|
||||
}
|
||||
|
||||
unsigned number_of_nodes = 0;
|
||||
unsigned number_of_edges = 0;
|
||||
hsgr_input_stream.read((char *)check_sum, sizeof(unsigned));
|
||||
hsgr_input_stream.read((char *)&number_of_nodes, sizeof(unsigned));
|
||||
BOOST_ASSERT_MSG(0 != number_of_nodes, "number of nodes is zero");
|
||||
hsgr_input_stream.read((char *)&number_of_edges, sizeof(unsigned));
|
||||
|
||||
SimpleLogger().Write() << "number_of_nodes: " << number_of_nodes
|
||||
<< ", number_of_edges: " << number_of_edges;
|
||||
|
||||
// BOOST_ASSERT_MSG( 0 != number_of_edges, "number of edges is zero");
|
||||
node_list.resize(number_of_nodes);
|
||||
hsgr_input_stream.read((char *)&(node_list[0]), number_of_nodes * sizeof(NodeT));
|
||||
|
||||
edge_list.resize(number_of_edges);
|
||||
if (number_of_edges > 0)
|
||||
{
|
||||
hsgr_input_stream.read((char *)&(edge_list[0]), number_of_edges * sizeof(EdgeT));
|
||||
}
|
||||
hsgr_input_stream.close();
|
||||
|
||||
return number_of_nodes;
|
||||
}
|
||||
|
||||
#endif // GRAPHLOADER_H
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013,2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef INTEGER_RANGE_HPP
|
||||
#define INTEGER_RANGE_HPP
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
|
||||
template <typename Integer> class range
|
||||
{
|
||||
private:
|
||||
Integer last;
|
||||
Integer iter;
|
||||
|
||||
public:
|
||||
range(Integer start, Integer end) : last(end), iter(start)
|
||||
{
|
||||
static_assert(std::is_integral<Integer>::value, "range type must be integral");
|
||||
}
|
||||
|
||||
// Iterable functions
|
||||
const range &begin() const { return *this; }
|
||||
const range &end() const { return *this; }
|
||||
Integer front() const { return iter; }
|
||||
Integer back() const { return last - 1; }
|
||||
|
||||
// Iterator functions
|
||||
bool operator!=(const range &) const { return iter < last; }
|
||||
void operator++() { ++iter; }
|
||||
Integer operator*() const { return iter; }
|
||||
};
|
||||
|
||||
// convenience function to construct an integer range with type deduction
|
||||
template <typename Integer>
|
||||
range<Integer> irange(const Integer first,
|
||||
const Integer last,
|
||||
typename std::enable_if<std::is_integral<Integer>::value>::type * = 0)
|
||||
{
|
||||
return range<Integer>(first, last);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // INTEGER_RANGE_HPP
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef RANGE_HPP_
|
||||
#define RANGE_HPP_
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
template <typename Iterator> class Range
|
||||
{
|
||||
public:
|
||||
Range(Iterator begin, Iterator end) : begin_(begin), end_(end) {}
|
||||
|
||||
Iterator begin() const { return begin_; }
|
||||
Iterator end() const { return end_; }
|
||||
|
||||
private:
|
||||
Iterator begin_;
|
||||
Iterator end_;
|
||||
};
|
||||
|
||||
// Convenience functions for template parameter inference,
|
||||
// akin to std::make_pair.
|
||||
|
||||
template <typename Iterator> Range<Iterator> range(Iterator begin, Iterator end)
|
||||
{
|
||||
return Range<Iterator>(begin, end);
|
||||
}
|
||||
|
||||
template <typename Reversable>
|
||||
Range<typename Reversable::reverse_iterator> reverse(Reversable *reversable)
|
||||
{
|
||||
return Range<typename Reversable::reverse_iterator>(reversable->rbegin(), reversable->rend());
|
||||
}
|
||||
|
||||
template <typename ConstReversable>
|
||||
Range<typename ConstReversable::const_reverse_iterator>
|
||||
const_reverse(const ConstReversable *const_reversable)
|
||||
{
|
||||
return Range<typename ConstReversable::const_reverse_iterator>(const_reversable->crbegin(),
|
||||
const_reversable->crend());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // RANGE_HPP_
|
||||
@@ -1,182 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
// based on
|
||||
// https://svn.apache.org/repos/asf/mesos/tags/release-0.9.0-incubating-RC0/src/common/json.hpp
|
||||
|
||||
#ifndef JSON_RENDERER_HPP
|
||||
#define JSON_RENDERER_HPP
|
||||
|
||||
#include "../data_structures/json_container.hpp"
|
||||
#include "cast.hpp"
|
||||
|
||||
namespace JSON {
|
||||
|
||||
struct Renderer : mapbox::util::static_visitor<>
|
||||
{
|
||||
explicit Renderer(std::ostream &_out) : out(_out) {}
|
||||
|
||||
void operator()(const String &string) const { out << "\"" << string.value << "\""; }
|
||||
|
||||
void operator()(const Number &number) const
|
||||
{
|
||||
out.precision(10);
|
||||
out << number.value;
|
||||
}
|
||||
|
||||
void operator()(const Object &object) const
|
||||
{
|
||||
out << "{";
|
||||
auto iterator = object.values.begin();
|
||||
while (iterator != object.values.end())
|
||||
{
|
||||
out << "\"" << (*iterator).first << "\":";
|
||||
mapbox::util::apply_visitor(Renderer(out), (*iterator).second);
|
||||
if (++iterator != object.values.end())
|
||||
{
|
||||
out << ",";
|
||||
}
|
||||
}
|
||||
out << "}";
|
||||
}
|
||||
|
||||
void operator()(const Array &array) const
|
||||
{
|
||||
out << "[";
|
||||
std::vector<Value>::const_iterator iterator;
|
||||
iterator = array.values.begin();
|
||||
while (iterator != array.values.end())
|
||||
{
|
||||
mapbox::util::apply_visitor(Renderer(out), *iterator);
|
||||
if (++iterator != array.values.end())
|
||||
{
|
||||
out << ",";
|
||||
}
|
||||
}
|
||||
out << "]";
|
||||
}
|
||||
|
||||
void operator()(const True &) const { out << "true"; }
|
||||
|
||||
void operator()(const False &) const { out << "false"; }
|
||||
|
||||
void operator()(const Null &) const { out << "null"; }
|
||||
|
||||
private:
|
||||
std::ostream &out;
|
||||
};
|
||||
|
||||
struct ArrayRenderer : mapbox::util::static_visitor<>
|
||||
{
|
||||
explicit ArrayRenderer(std::vector<char> &_out) : out(_out) {}
|
||||
|
||||
void operator()(const String &string) const
|
||||
{
|
||||
out.push_back('\"');
|
||||
out.insert(out.end(), string.value.begin(), string.value.end());
|
||||
out.push_back('\"');
|
||||
}
|
||||
|
||||
void operator()(const Number &number) const
|
||||
{
|
||||
const std::string number_string = cast::double_fixed_to_string(number.value);
|
||||
out.insert(out.end(), number_string.begin(), number_string.end());
|
||||
}
|
||||
|
||||
void operator()(const Object &object) const
|
||||
{
|
||||
out.push_back('{');
|
||||
auto iterator = object.values.begin();
|
||||
while (iterator != object.values.end())
|
||||
{
|
||||
out.push_back('\"');
|
||||
out.insert(out.end(), (*iterator).first.begin(), (*iterator).first.end());
|
||||
out.push_back('\"');
|
||||
out.push_back(':');
|
||||
|
||||
mapbox::util::apply_visitor(ArrayRenderer(out), (*iterator).second);
|
||||
if (++iterator != object.values.end())
|
||||
{
|
||||
out.push_back(',');
|
||||
}
|
||||
}
|
||||
out.push_back('}');
|
||||
}
|
||||
|
||||
void operator()(const Array &array) const
|
||||
{
|
||||
out.push_back('[');
|
||||
std::vector<Value>::const_iterator iterator;
|
||||
iterator = array.values.begin();
|
||||
while (iterator != array.values.end())
|
||||
{
|
||||
mapbox::util::apply_visitor(ArrayRenderer(out), *iterator);
|
||||
if (++iterator != array.values.end())
|
||||
{
|
||||
out.push_back(',');
|
||||
}
|
||||
}
|
||||
out.push_back(']');
|
||||
}
|
||||
|
||||
void operator()(const True &) const
|
||||
{
|
||||
const std::string temp("true");
|
||||
out.insert(out.end(), temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
void operator()(const False &) const
|
||||
{
|
||||
const std::string temp("false");
|
||||
out.insert(out.end(), temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
void operator()(const Null &) const
|
||||
{
|
||||
const std::string temp("null");
|
||||
out.insert(out.end(), temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<char> &out;
|
||||
};
|
||||
|
||||
inline void render(std::ostream &out, const Object &object)
|
||||
{
|
||||
Value value = object;
|
||||
mapbox::util::apply_visitor(Renderer(out), value);
|
||||
}
|
||||
|
||||
inline void render(std::vector<char> &out, const Object &object)
|
||||
{
|
||||
Value value = object;
|
||||
mapbox::util::apply_visitor(ArrayRenderer(out), value);
|
||||
}
|
||||
|
||||
} // namespace JSON
|
||||
|
||||
#endif // JSON_RENDERER_HPP
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef LUA_UTIL_HPP
|
||||
#define LUA_UTIL_HPP
|
||||
|
||||
extern "C" {
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
#include <lualib.h>
|
||||
}
|
||||
|
||||
#include <boost/filesystem/convenience.hpp>
|
||||
#include <luabind/luabind.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
template <typename T> void LUA_print(T output) { std::cout << "[LUA] " << output << std::endl; }
|
||||
|
||||
// Check if the lua function <name> is defined
|
||||
inline bool lua_function_exists(lua_State *lua_state, const char *name)
|
||||
{
|
||||
luabind::object globals_table = luabind::globals(lua_state);
|
||||
luabind::object lua_function = globals_table[name];
|
||||
return lua_function && (luabind::type(lua_function) == LUA_TFUNCTION);
|
||||
}
|
||||
|
||||
// Add the folder contain the script to the lua load path, so script can easily require() other lua
|
||||
// scripts inside that folder, or subfolders.
|
||||
// See http://lua-users.org/wiki/PackagePath for details on the package.path syntax.
|
||||
inline void luaAddScriptFolderToLoadPath(lua_State *lua_state, const char *file_name)
|
||||
{
|
||||
const boost::filesystem::path profile_path(file_name);
|
||||
std::string folder = profile_path.parent_path().string();
|
||||
// TODO: This code is most probably not Windows safe since it uses UNIX'ish path delimiters
|
||||
const std::string lua_code =
|
||||
"package.path = \"" + folder + "/?.lua;profiles/?.lua;\" .. package.path";
|
||||
luaL_dostring(lua_state, lua_code.c_str());
|
||||
}
|
||||
|
||||
#endif // LUA_UTIL_HPP
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef MAKE_UNIQUE_H_
|
||||
#define MAKE_UNIQUE_H_
|
||||
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
// Taken from http://msdn.microsoft.com/en-us/library/dn439780.asp
|
||||
// Note, that the snippet was broken there and needed minor massaging
|
||||
|
||||
// make_unique<T>
|
||||
template <class T, class... Types> std::unique_ptr<T> make_unique(Types &&... Args)
|
||||
{
|
||||
return (std::unique_ptr<T>(new T(std::forward<Types>(Args)...)));
|
||||
}
|
||||
|
||||
// make_unique<T[]>
|
||||
template <class T> std::unique_ptr<T[]> make_unique(std::size_t Size)
|
||||
{
|
||||
return (std::unique_ptr<T>(new T[Size]()));
|
||||
}
|
||||
|
||||
// make_unique<T[N]> disallowed
|
||||
template <class T, class... Types>
|
||||
typename std::enable_if<std::extent<T>::value != 0, void>::type make_unique(Types &&...) = delete;
|
||||
}
|
||||
|
||||
#endif //MAKE_UNIQUE_H_
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "osrm_exception.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
// This function exists to 'anchor' the class, and stop the compiler from
|
||||
// copying vtable and RTTI info into every object file that includes
|
||||
// this header. (Caught by -Wweak-vtables under Clang.)
|
||||
|
||||
// More information from the LLVM Coding Standards:
|
||||
// If a class is defined in a header file and has a vtable (either it has
|
||||
// virtual methods or it derives from classes with virtual methods), it must
|
||||
// always have at least one out-of-line virtual method in the class. Without
|
||||
// this, the compiler will copy the vtable and RTTI into every .o file that
|
||||
// #includes the header, bloating .o file sizes and increasing link times.
|
||||
void exception::anchor() const { }
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef OSRM_EXCEPTION_HPP
|
||||
#define OSRM_EXCEPTION_HPP
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
class exception final : public std::exception
|
||||
{
|
||||
public:
|
||||
explicit exception(const char *message) : message(message) {}
|
||||
explicit exception(const std::string &message) : message(message) {}
|
||||
|
||||
private:
|
||||
// This function exists to 'anchor' the class, and stop the compiler from
|
||||
// copying vtable and RTTI info into every object file that includes
|
||||
// this header. (Caught by -Wweak-vtables under Clang.)
|
||||
virtual void anchor() const;
|
||||
const char *what() const noexcept { return message.c_str(); }
|
||||
const std::string message;
|
||||
};
|
||||
}
|
||||
#endif /* OSRM_EXCEPTION_HPP */
|
||||
@@ -1,135 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "simple_logger.hpp"
|
||||
|
||||
#include "osrm_exception.hpp"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <io.h>
|
||||
#define isatty _isatty
|
||||
#define fileno _fileno
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <ostream>
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
|
||||
namespace
|
||||
{
|
||||
static const char COL_RESET[] { "\x1b[0m"};
|
||||
static const char RED[] { "\x1b[31m"};
|
||||
#ifndef NDEBUG
|
||||
static const char YELLOW[] { "\x1b[33m"};
|
||||
#endif
|
||||
// static const char GREEN[] { "\x1b[32m"};
|
||||
// static const char BLUE[] { "\x1b[34m"};
|
||||
// static const char MAGENTA[] { "\x1b[35m"};
|
||||
// static const char CYAN[] { "\x1b[36m"};
|
||||
}
|
||||
|
||||
void LogPolicy::Unmute() { m_is_mute = false; }
|
||||
|
||||
void LogPolicy::Mute() { m_is_mute = true; }
|
||||
|
||||
bool LogPolicy::IsMute() const { return m_is_mute; }
|
||||
|
||||
LogPolicy &LogPolicy::GetInstance()
|
||||
{
|
||||
static LogPolicy runningInstance;
|
||||
return runningInstance;
|
||||
}
|
||||
|
||||
SimpleLogger::SimpleLogger() : level(logINFO) {}
|
||||
|
||||
std::mutex &SimpleLogger::get_mutex()
|
||||
{
|
||||
static std::mutex mtx;
|
||||
return mtx;
|
||||
}
|
||||
|
||||
std::ostringstream &SimpleLogger::Write(LogLevel lvl)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(get_mutex());
|
||||
try
|
||||
{
|
||||
level = lvl;
|
||||
os << "[";
|
||||
switch (level)
|
||||
{
|
||||
case logWARNING:
|
||||
os << "warn";
|
||||
break;
|
||||
case logDEBUG:
|
||||
#ifndef NDEBUG
|
||||
os << "debug";
|
||||
#endif
|
||||
break;
|
||||
default: //logINFO:
|
||||
os << "info";
|
||||
break;
|
||||
}
|
||||
os << "] ";
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
// encapsulate in osrm::exception
|
||||
throw osrm::exception(std::string(e.what()) + ", getting ostringstream");
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
SimpleLogger::~SimpleLogger()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(get_mutex());
|
||||
if (!LogPolicy::GetInstance().IsMute())
|
||||
{
|
||||
const bool is_terminal = static_cast<bool>(isatty(fileno(stdout)));
|
||||
switch (level)
|
||||
{
|
||||
case logWARNING:
|
||||
std::cerr << (is_terminal ? RED : "") << os.str() << (is_terminal ? COL_RESET : "")
|
||||
<< std::endl;
|
||||
break;
|
||||
case logDEBUG:
|
||||
#ifndef NDEBUG
|
||||
std::cout << (is_terminal ? YELLOW : "") << os.str() << (is_terminal ? COL_RESET : "")
|
||||
<< std::endl;
|
||||
#endif
|
||||
break;
|
||||
default: //logINFO:
|
||||
std::cout << os.str() << (is_terminal ? COL_RESET : "") << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef SIMPLE_LOGGER_HPP
|
||||
#define SIMPLE_LOGGER_HPP
|
||||
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
|
||||
enum LogLevel
|
||||
{
|
||||
logINFO,
|
||||
logWARNING,
|
||||
logDEBUG
|
||||
};
|
||||
|
||||
class LogPolicy
|
||||
{
|
||||
public:
|
||||
void Unmute();
|
||||
|
||||
void Mute();
|
||||
|
||||
bool IsMute() const;
|
||||
|
||||
static LogPolicy &GetInstance();
|
||||
|
||||
LogPolicy(const LogPolicy &) = delete;
|
||||
|
||||
private:
|
||||
LogPolicy() : m_is_mute(true) {}
|
||||
std::atomic<bool> m_is_mute;
|
||||
};
|
||||
|
||||
class SimpleLogger
|
||||
{
|
||||
public:
|
||||
SimpleLogger();
|
||||
|
||||
virtual ~SimpleLogger();
|
||||
std::mutex &get_mutex();
|
||||
std::ostringstream &Write(LogLevel l = logINFO);
|
||||
|
||||
private:
|
||||
std::ostringstream os;
|
||||
LogLevel level;
|
||||
};
|
||||
|
||||
#endif /* SIMPLE_LOGGER_HPP */
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef STD_HASH_HPP
|
||||
#define STD_HASH_HPP
|
||||
|
||||
#include <functional>
|
||||
|
||||
// this is largely inspired by boost's hash combine as can be found in
|
||||
// "The C++ Standard Library" 2nd Edition. Nicolai M. Josuttis. 2012.
|
||||
|
||||
namespace {
|
||||
|
||||
template<typename T>
|
||||
void hash_combine(std::size_t &seed, const T& val)
|
||||
{
|
||||
seed ^= std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void hash_val(std::size_t &seed, const T& val)
|
||||
{
|
||||
hash_combine(seed, val);
|
||||
}
|
||||
|
||||
template<typename T, typename ... Types>
|
||||
void hash_val(std::size_t &seed, const T& val, const Types& ... args)
|
||||
{
|
||||
hash_combine(seed, val);
|
||||
hash_val(seed, args ...);
|
||||
}
|
||||
|
||||
template<typename ... Types>
|
||||
std::size_t hash_val(const Types&... args)
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
hash_val(seed, args...);
|
||||
return seed;
|
||||
}
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <typename T1, typename T2> struct hash<std::pair<T1, T2>>
|
||||
{
|
||||
size_t operator()(const std::pair<T1, T2> &pair) const
|
||||
{
|
||||
return hash_val(pair.first, pair.second);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // STD_HASH_HPP
|
||||
@@ -1,150 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef STRING_UTIL_HPP
|
||||
#define STRING_UTIL_HPP
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include <cctype>
|
||||
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// precision: position after decimal point
|
||||
// length: maximum number of digits including comma and decimals
|
||||
// work with negative values to prevent overflowing when taking -value
|
||||
template <int length, int precision> static inline char *printInt(char *buffer, int value)
|
||||
{
|
||||
bool minus = true;
|
||||
if (value > 0)
|
||||
{
|
||||
minus = false;
|
||||
value = -value;
|
||||
}
|
||||
buffer += length - 1;
|
||||
for (int i = 0; i < precision; i++)
|
||||
{
|
||||
*buffer = '0' - (value % 10);
|
||||
value /= 10;
|
||||
buffer--;
|
||||
}
|
||||
*buffer = '.';
|
||||
buffer--;
|
||||
for (int i = precision + 1; i < length; i++)
|
||||
{
|
||||
*buffer = '0' - (value % 10);
|
||||
value /= 10;
|
||||
if (value == 0)
|
||||
break;
|
||||
buffer--;
|
||||
}
|
||||
if (minus)
|
||||
{
|
||||
buffer--;
|
||||
*buffer = '-';
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
inline void replaceAll(std::string &s, const std::string &sub, const std::string &other)
|
||||
{
|
||||
boost::replace_all(s, sub, other);
|
||||
}
|
||||
|
||||
inline std::string EscapeJSONString(const std::string &input)
|
||||
{
|
||||
std::string output;
|
||||
output.reserve(input.size());
|
||||
for (auto iter = input.begin(); iter != input.end(); ++iter)
|
||||
{
|
||||
switch (iter[0])
|
||||
{
|
||||
case '\\':
|
||||
output += "\\\\";
|
||||
break;
|
||||
case '"':
|
||||
output += "\\\"";
|
||||
break;
|
||||
case '/':
|
||||
output += "\\/";
|
||||
break;
|
||||
case '\b':
|
||||
output += "\\b";
|
||||
break;
|
||||
case '\f':
|
||||
output += "\\f";
|
||||
break;
|
||||
case '\n':
|
||||
output += "\\n";
|
||||
break;
|
||||
case '\r':
|
||||
output += "\\r";
|
||||
break;
|
||||
case '\t':
|
||||
output += "\\t";
|
||||
break;
|
||||
default:
|
||||
output += *iter;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
static std::string originals[] = {"&", "\"", "<", ">", "'", "[", "]", "\\"};
|
||||
static std::string entities[] = {
|
||||
"&", """, "<", ">", "'", "&91;", "&93;", " \"};
|
||||
|
||||
inline std::size_t URIDecode(const std::string &input, std::string &output)
|
||||
{
|
||||
auto src_iter = input.begin();
|
||||
output.resize(input.size() + 1);
|
||||
std::size_t decoded_length = 0;
|
||||
for (decoded_length = 0; src_iter != input.end(); ++decoded_length)
|
||||
{
|
||||
if (src_iter[0] == '%' && src_iter[1] && src_iter[2] && isxdigit(src_iter[1]) &&
|
||||
isxdigit(src_iter[2]))
|
||||
{
|
||||
std::string::value_type a = src_iter[1];
|
||||
std::string::value_type b = src_iter[2];
|
||||
a -= src_iter[1] < 58 ? 48 : src_iter[1] < 71 ? 55 : 87;
|
||||
b -= src_iter[2] < 58 ? 48 : src_iter[2] < 71 ? 55 : 87;
|
||||
output[decoded_length] = 16 * a + b;
|
||||
src_iter += 3;
|
||||
continue;
|
||||
}
|
||||
output[decoded_length] = *src_iter++;
|
||||
}
|
||||
output.resize(decoded_length);
|
||||
return decoded_length;
|
||||
}
|
||||
|
||||
inline std::size_t URIDecodeInPlace(std::string &URI) { return URIDecode(URI, URI); }
|
||||
|
||||
#endif // STRING_UTIL_HPP
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef TIMING_UTIL_HPP
|
||||
#define TIMING_UTIL_HPP
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
struct GlobalTimer
|
||||
{
|
||||
GlobalTimer() : time(0) {}
|
||||
std::atomic<uint64_t> time;
|
||||
};
|
||||
|
||||
class GlobalTimerFactory
|
||||
{
|
||||
public:
|
||||
static GlobalTimerFactory& get()
|
||||
{
|
||||
static GlobalTimerFactory instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
GlobalTimer& getGlobalTimer(const std::string& name)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(map_mutex);
|
||||
return timer_map[name];
|
||||
}
|
||||
|
||||
private:
|
||||
std::mutex map_mutex;
|
||||
std::unordered_map<std::string, GlobalTimer> timer_map;
|
||||
};
|
||||
|
||||
#define GLOBAL_TIMER_AQUIRE(_X) auto& _X##_global_timer = GlobalTimerFactory::get().getGlobalTimer(#_X)
|
||||
#define GLOBAL_TIMER_RESET(_X) _X##_global_timer.time = 0
|
||||
#define GLOBAL_TIMER_START(_X) TIMER_START(_X)
|
||||
#define GLOBAL_TIMER_STOP(_X) TIMER_STOP(_X); _X##_global_timer.time += TIMER_NSEC(_X)
|
||||
#define GLOBAL_TIMER_NSEC(_X) static_cast<double>(_X##_global_timer.time)
|
||||
#define GLOBAL_TIMER_USEC(_X) (_X##_global_timer.time / 1000.0)
|
||||
#define GLOBAL_TIMER_MSEC(_X) (_X##_global_timer.time / 1000.0 / 1000.0)
|
||||
#define GLOBAL_TIMER_SEC(_X) (_X##_global_timer.time / 1000.0 / 1000.0 / 1000.0)
|
||||
|
||||
#define TIMER_START(_X) auto _X##_start = std::chrono::steady_clock::now(), _X##_stop = _X##_start
|
||||
#define TIMER_STOP(_X) _X##_stop = std::chrono::steady_clock::now()
|
||||
#define TIMER_NSEC(_X) std::chrono::duration_cast<std::chrono::nanoseconds>(_X##_stop - _X##_start).count()
|
||||
#define TIMER_USEC(_X) std::chrono::duration_cast<std::chrono::microseconds>(_X##_stop - _X##_start).count()
|
||||
#define TIMER_MSEC(_X) (0.000001*std::chrono::duration_cast<std::chrono::nanoseconds>(_X##_stop - _X##_start).count())
|
||||
#define TIMER_SEC(_X) (0.000001*std::chrono::duration_cast<std::chrono::microseconds>(_X##_stop - _X##_start).count())
|
||||
#define TIMER_MIN(_X) std::chrono::duration_cast<std::chrono::minutes>(_X##_stop - _X##_start).count()
|
||||
|
||||
#endif // TIMING_UTIL_HPP
|
||||
@@ -1,140 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef XML_RENDERER_HPP
|
||||
#define XML_RENDERER_HPP
|
||||
|
||||
#include "../data_structures/json_container.hpp"
|
||||
#include "cast.hpp"
|
||||
|
||||
namespace JSON {
|
||||
|
||||
struct XMLToArrayRenderer : mapbox::util::static_visitor<>
|
||||
{
|
||||
explicit XMLToArrayRenderer(std::vector<char> &_out) : out(_out) {}
|
||||
|
||||
void operator()(const String &string) const
|
||||
{
|
||||
out.push_back('\"');
|
||||
out.insert(out.end(), string.value.begin(), string.value.end());
|
||||
out.push_back('\"');
|
||||
}
|
||||
|
||||
void operator()(const Number &number) const
|
||||
{
|
||||
const std::string number_string = cast::double_fixed_to_string(number.value);
|
||||
out.insert(out.end(), number_string.begin(), number_string.end());
|
||||
}
|
||||
|
||||
void operator()(const Object &object) const
|
||||
{
|
||||
auto iterator = object.values.begin();
|
||||
while (iterator != object.values.end())
|
||||
{
|
||||
if (iterator->first.at(0) != '_')
|
||||
{
|
||||
out.push_back('<');
|
||||
out.insert(out.end(), (*iterator).first.begin(), (*iterator).first.end());
|
||||
}
|
||||
else
|
||||
{
|
||||
out.push_back(' ');
|
||||
out.insert(out.end(), ++(*iterator).first.begin(), (*iterator).first.end());
|
||||
out.push_back('=');
|
||||
|
||||
}
|
||||
mapbox::util::apply_visitor(XMLToArrayRenderer(out), (*iterator).second);
|
||||
if (iterator->first.at(0) != '_')
|
||||
{
|
||||
out.push_back('/');
|
||||
out.push_back('>');
|
||||
}
|
||||
++iterator;
|
||||
}
|
||||
}
|
||||
|
||||
void operator()(const Array &array) const
|
||||
{
|
||||
std::vector<Value>::const_iterator iterator;
|
||||
iterator = array.values.begin();
|
||||
while (iterator != array.values.end())
|
||||
{
|
||||
mapbox::util::apply_visitor(XMLToArrayRenderer(out), *iterator);
|
||||
++iterator;
|
||||
}
|
||||
}
|
||||
|
||||
void operator()(const True &) const
|
||||
{
|
||||
const std::string temp("true");
|
||||
out.insert(out.end(), temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
void operator()(const False &) const
|
||||
{
|
||||
const std::string temp("false");
|
||||
out.insert(out.end(), temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
void operator()(const Null &) const
|
||||
{
|
||||
const std::string temp("null");
|
||||
out.insert(out.end(), temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<char> &out;
|
||||
};
|
||||
|
||||
template<class JSONObject>
|
||||
inline void xml_render(std::vector<char> &out, const JSONObject &object)
|
||||
{
|
||||
Value value = object;
|
||||
mapbox::util::apply_visitor(XMLToArrayRenderer(out), value);
|
||||
}
|
||||
|
||||
template<class JSONObject>
|
||||
inline void gpx_render(std::vector<char> &out, const JSONObject &object)
|
||||
{
|
||||
// add header
|
||||
|
||||
const std::string header {"<?xml version=\"1.0\" encoding=\"UTF-8\"?><gpx creator=\"OSRM Routing Engine\""
|
||||
" version=\"1.1\" xmlns=\"http://www.topografix.com/GPX/1/1\" xmlns:xsi=\"http:"
|
||||
"//www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topogr"
|
||||
"afix.com/GPX/1/1 gpx.xsd\"><metadata><copyright author=\"Project OSRM\"><lice"
|
||||
"nse>Data (c) OpenStreetMap contributors (ODbL)</license></copyright></metadat"
|
||||
"a><rte>"};
|
||||
out.insert(out.end(), header.begin(), header.end());
|
||||
|
||||
xml_render(out, object);
|
||||
|
||||
const std::string footer {"</rte></gpx>"};
|
||||
out.insert(out.end(), footer.begin(), footer.end());
|
||||
}
|
||||
} // namespace JSON
|
||||
|
||||
#endif // XML_RENDERER_HPP
|
||||
@@ -1,42 +1,28 @@
|
||||
/*
|
||||
open source routing machine
|
||||
Copyright (C) Dennis Luxen, others 2010
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
#ifndef RANGE_ALGORITHMS_HPP
|
||||
#define RANGE_ALGORITHMS_HPP
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace osrm {
|
||||
|
||||
template<class Container>
|
||||
auto max_element(const Container & c) -> decltype(std::max_element(c.begin(), c.end()))
|
||||
{
|
||||
return std::max_element(c.begin(), c.end());
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
auto max_element(const Container & c) -> decltype(std::max_element(c.cbegin(), c.cend()))
|
||||
{
|
||||
return std::max_element(c.cbegin(), c.cend());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // RANGE_ALGORITHMS_HPP
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM base class
|
||||
// [has to be loaded before all other OSRM classes]
|
||||
|
||||
var OSRM = {};
|
||||
OSRM.VERSION = '0.1.6';
|
||||
OSRM.DATE = '120516';
|
||||
OSRM.CONSTANTS = {};
|
||||
OSRM.DEFAULTS = {};
|
||||
OSRM.GLOBALS = {};
|
||||
OSRM.G = OSRM.GLOBALS; // abbreviations
|
||||
OSRM.C = OSRM.CONSTANTS;
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM config file
|
||||
// [has to be loaded directly after OSRM.base]
|
||||
|
||||
OSRM.DEFAULTS = {
|
||||
HOST_ROUTING_URL: 'http://router.project-osrm.org/viaroute',
|
||||
HOST_SHORTENER_URL: 'http://map.project-osrm.org/shorten/',
|
||||
HOST_TIMESTAMP_URL: 'http://router.project-osrm.org/timestamp',
|
||||
HOST_GEOCODER_URL: 'http://nominatim.openstreetmap.org/search',
|
||||
HOST_REVERSE_GEOCODER_URL: 'http://nominatim.openstreetmap.org/reverse',
|
||||
WEBSITE_URL: document.URL.replace(/#*(\?.*|$)/i,""), // truncates URL before first ?, and removes tailing #
|
||||
JSONP_TIMEOUT: 10000,
|
||||
ZOOM_LEVEL: 14,
|
||||
ONLOAD_ZOOM_LEVEL: 5,
|
||||
ONLOAD_LATITUDE: 48.84,
|
||||
ONLOAD_LONGITUDE: 10.10,
|
||||
ONLOAD_SOURCE: "",
|
||||
ONLOAD_TARGET: "",
|
||||
HIGHLIGHT_ZOOM_LEVEL: 16,
|
||||
DISTANCE_FORMAT: 0, // 0: km, 1: miles
|
||||
GEOCODER_BOUNDS: '', // the world is not enough!
|
||||
//GEOCODER_BOUNDS: '&bounded=1&viewbox=-27.0,72.0,46.0,36.0', // bounds for Europe
|
||||
|
||||
SHORTENER_PARAMETERS: '%url&jsonp=%jsonp',
|
||||
SHORTENER_REPLY_PARAMETER: 'ShortURL',
|
||||
|
||||
LANGUAGE: "en",
|
||||
LANUGAGE_ONDEMAND_RELOADING: true,
|
||||
LANGUAGE_SUPPORTED: [
|
||||
{encoding:"en", name:"English"},
|
||||
{encoding:"de", name:"Deutsch"},
|
||||
{encoding:"dk", name:"Dansk"},
|
||||
{encoding:"fi", name:"Suomi"},
|
||||
{encoding:"fr", name:"Français"},
|
||||
{encoding:"it", name:"Italiano"},
|
||||
{encoding:"pl", name:"Polski", culture:"en-US"}
|
||||
],
|
||||
|
||||
TILE_SERVERS: [
|
||||
{ display_name: 'osm.org',
|
||||
url:'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
attribution:'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 Mapnik',
|
||||
options:{maxZoom: 18}
|
||||
},
|
||||
{ display_name: 'osm.de',
|
||||
url:'http://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png',
|
||||
attribution:'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 Mapnik',
|
||||
options:{maxZoom: 18}
|
||||
},
|
||||
{ display_name: 'MapQuest',
|
||||
url:'http://otile{s}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png',
|
||||
attribution:'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 MapQuest',
|
||||
options:{maxZoom: 18, subdomains: '1234'}
|
||||
},
|
||||
{ display_name: 'CloudMade',
|
||||
url:'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png',
|
||||
attribution:'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 CloudMade',
|
||||
options:{maxZoom: 18}
|
||||
},
|
||||
{
|
||||
display_name: 'Bing Road',
|
||||
apikey:'AjCb2f6Azv_xt9c6pl_xok96bgAYrXQNctnG4o07sTj4iS9N68Za4B3pRJyeCjGr', // please use your own apikey (http://msdn.microsoft.com/en-us/library/ff428642.aspx)
|
||||
type:"Road",
|
||||
options:{minZoom: 1},
|
||||
bing:true,
|
||||
},
|
||||
{
|
||||
display_name: 'Bing Aerial',
|
||||
apikey:'AjCb2f6Azv_xt9c6pl_xok96bgAYrXQNctnG4o07sTj4iS9N68Za4B3pRJyeCjGr', // please use your own apikey (http://msdn.microsoft.com/en-us/library/ff428642.aspx)
|
||||
type:"Aerial",
|
||||
options:{minZoom: 1},
|
||||
bing:true,
|
||||
}
|
||||
],
|
||||
|
||||
MAINTENANCE: false,
|
||||
MAINTENANCE_HEADER: "Scheduled Maintenance",
|
||||
MAINTENANCE_TEXT: "The OSRM Website is down for a scheduled maintenance. Please be patient while required updates are performed. The site will be back online shortly.<br/><br/>In the meantime you may want to go out an map a friendly neighborhood near you...<br/><br/><br/>[OSRM]",
|
||||
};
|
||||
@@ -0,0 +1,217 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM geocoding routines
|
||||
// [geocoder query, management and display of geocoder results]
|
||||
|
||||
// some constants
|
||||
OSRM.CONSTANTS.SOURCE_LABEL = "source";
|
||||
OSRM.CONSTANTS.TARGET_LABEL = "target";
|
||||
OSRM.CONSTANTS.VIA_LABEL = "via";
|
||||
OSRM.CONSTANTS.DO_FALLBACK_TO_LAT_LNG = true;
|
||||
|
||||
|
||||
OSRM.Geocoder = {
|
||||
|
||||
//[normal geocoding]
|
||||
|
||||
// process input request and call geocoder if needed
|
||||
call: function(marker_id, query) {
|
||||
if(query=="")
|
||||
return;
|
||||
|
||||
//geo coordinates given -> directly draw results
|
||||
if(query.match(/^\s*[-+]?[0-9]*\.?[0-9]+\s*[,;]\s*[-+]?[0-9]*\.?[0-9]+\s*$/)){
|
||||
var coord = query.split(/[,;]/);
|
||||
OSRM.Geocoder._onclickResult(marker_id, coord[0], coord[1]);
|
||||
OSRM.Geocoder.updateAddress( marker_id );
|
||||
return;
|
||||
}
|
||||
|
||||
//build request for geocoder
|
||||
var call = OSRM.DEFAULTS.HOST_GEOCODER_URL + "?format=json&json_callback=%jsonp" + OSRM.DEFAULTS.GEOCODER_BOUNDS + "&accept-language="+OSRM.Localization.current_language+"&q=" + query;
|
||||
OSRM.JSONP.call( call, OSRM.Geocoder._showResults, OSRM.Geocoder._showResults_Timeout, OSRM.DEFAULTS.JSONP_TIMEOUT, "geocoder_"+marker_id, {marker_id:marker_id,query:query} );
|
||||
},
|
||||
|
||||
|
||||
// helper function for clicks on geocoder search results
|
||||
_onclickResult: function(marker_id, lat, lon) {
|
||||
var index;
|
||||
if( marker_id == OSRM.C.SOURCE_LABEL )
|
||||
index = OSRM.G.markers.setSource( new L.LatLng(lat, lon) );
|
||||
else if( marker_id == OSRM.C.TARGET_LABEL )
|
||||
index = OSRM.G.markers.setTarget( new L.LatLng(lat, lon) );
|
||||
else
|
||||
return;
|
||||
|
||||
OSRM.G.markers.route[index].show();
|
||||
OSRM.G.markers.route[index].centerView();
|
||||
if( OSRM.G.markers.route.length > 1 )
|
||||
OSRM.Routing.getRoute();
|
||||
},
|
||||
|
||||
|
||||
// process geocoder response
|
||||
_showResults: function(response, parameters) {
|
||||
if(!response){
|
||||
OSRM.Geocoder._showResults_Empty(parameters);
|
||||
return;
|
||||
}
|
||||
|
||||
if(response.length == 0) {
|
||||
OSRM.Geocoder._showResults_Empty(parameters);
|
||||
return;
|
||||
}
|
||||
|
||||
// show first result
|
||||
OSRM.Geocoder._onclickResult(parameters.marker_id, response[0].lat, response[0].lon);
|
||||
if( OSRM.G.markers.route.length > 1 ) // if a route is displayed, we don't need to show other possible geocoding results
|
||||
return;
|
||||
|
||||
// show possible results for input
|
||||
var html = "";
|
||||
html += '<table class="results medium-font">';
|
||||
for(var i=0; i < response.length; i++){
|
||||
var result = response[i];
|
||||
|
||||
//odd or even ?
|
||||
var rowstyle='results-body-odd';
|
||||
if(i%2==0) { rowstyle='results-body-even'; }
|
||||
|
||||
html += '<tr class="'+rowstyle+'">';
|
||||
html += '<td class="results-body-counter"><span">'+(i+1)+'.</span></td>';
|
||||
html += '<td class="results-body-items">';
|
||||
|
||||
if(result.display_name){
|
||||
html += '<div class="results-body-item" onclick="OSRM.Geocoder._onclickResult(\''+parameters.marker_id+'\', '+result.lat+', '+result.lon+');">'+result.display_name+'</div>';
|
||||
}
|
||||
html += "</td></tr>";
|
||||
}
|
||||
html += '</table>';
|
||||
|
||||
document.getElementById('information-box-header').innerHTML =
|
||||
"<div class='header-title'>"+OSRM.loc("SEARCH_RESULTS")+"</div>" +
|
||||
"<div class='header-content'>("+OSRM.loc("FOUND_X_RESULTS").replace(/%i/,response.length)+")</div>";
|
||||
"<div class='header-content'>(found "+response.length+" results)"+"</div>";
|
||||
document.getElementById('information-box').innerHTML = html;
|
||||
},
|
||||
_showResults_Empty: function(parameters) {
|
||||
document.getElementById('information-box-header').innerHTML =
|
||||
"<div class='header-title'>"+OSRM.loc("SEARCH_RESULTS")+"</div>" +
|
||||
"<div class='header-content'>("+OSRM.loc("FOUND_X_RESULTS").replace(/%i/,0)+")</div>";
|
||||
if(parameters.marker_id == OSRM.C.SOURCE_LABEL)
|
||||
document.getElementById('information-box').innerHTML = "<div class='no-results big-font'>"+OSRM.loc("NO_RESULTS_FOUND_SOURCE")+": "+parameters.query +"</div>";
|
||||
else if(parameters.marker_id == OSRM.C.TARGET_LABEL)
|
||||
document.getElementById('information-box').innerHTML = "<div class='no-results big-font'>"+OSRM.loc("NO_RESULTS_FOUND_TARGET")+": "+parameters.query +"</div>";
|
||||
else
|
||||
document.getElementById('information-box').innerHTML = "<div class='no-results big-font'>"+OSRM.loc("NO_RESULTS_FOUND")+": "+parameters.query +"</div>";
|
||||
},
|
||||
_showResults_Timeout: function() {
|
||||
document.getElementById('information-box-header').innerHTML =
|
||||
"<div class='header-title'>"+OSRM.loc("SEARCH_RESULTS")+"</div>" +
|
||||
"<div class='header-content'>("+OSRM.loc("FOUND_X_RESULTS").replace(/%i/,0)+")</div>";
|
||||
document.getElementById('information-box').innerHTML = "<div class='no-results big-font'>"+OSRM.loc("TIMED_OUT")+"</div>";
|
||||
},
|
||||
|
||||
|
||||
// [reverse geocoding]
|
||||
|
||||
//update geo coordinates in input boxes
|
||||
updateLocation: function(marker_id) {
|
||||
if (marker_id == OSRM.C.SOURCE_LABEL && OSRM.G.markers.hasSource()) {
|
||||
document.getElementById("gui-input-source").value = OSRM.G.markers.route[0].getLat().toFixed(6) + ", " + OSRM.G.markers.route[0].getLng().toFixed(6);
|
||||
} else if (marker_id == OSRM.C.TARGET_LABEL && OSRM.G.markers.hasTarget()) {
|
||||
document.getElementById("gui-input-target").value = OSRM.G.markers.route[OSRM.G.markers.route.length-1].getLat().toFixed(6) + ", " + OSRM.G.markers.route[OSRM.G.markers.route.length-1].getLng().toFixed(6);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
// update address in input boxes
|
||||
updateAddress: function(marker_id, do_fallback_to_lat_lng) {
|
||||
// build request for reverse geocoder
|
||||
var lat = null;
|
||||
var lng = null;
|
||||
|
||||
if(marker_id == OSRM.C.SOURCE_LABEL && OSRM.G.markers.hasSource()) {
|
||||
lat = OSRM.G.markers.route[0].getLat();
|
||||
lng = OSRM.G.markers.route[0].getLng();
|
||||
} else if(marker_id == OSRM.C.TARGET_LABEL && OSRM.G.markers.hasTarget() ) {
|
||||
lat = OSRM.G.markers.route[OSRM.G.markers.route.length-1].getLat();
|
||||
lng = OSRM.G.markers.route[OSRM.G.markers.route.length-1].getLng();
|
||||
} else
|
||||
return;
|
||||
|
||||
var call = OSRM.DEFAULTS.HOST_REVERSE_GEOCODER_URL + "?format=json&json_callback=%jsonp" + "&accept-language="+OSRM.Localization.current_language + "&lat=" + lat.toFixed(6) + "&lon=" + lng.toFixed(6);
|
||||
OSRM.JSONP.call( call, OSRM.Geocoder._showReverseResults, OSRM.Geocoder._showReverseResults_Timeout, OSRM.DEFAULTS.JSONP_TIMEOUT, "reverse_geocoder_"+marker_id, {marker_id:marker_id, do_fallback: do_fallback_to_lat_lng} );
|
||||
},
|
||||
|
||||
|
||||
// processing JSONP response of reverse geocoder
|
||||
_showReverseResults: function(response, parameters) {
|
||||
if(!response) {
|
||||
OSRM.Geocoder._showReverseResults_Timeout(response, parameters);
|
||||
return;
|
||||
}
|
||||
|
||||
if(response.address == undefined) {
|
||||
OSRM.Geocoder._showReverseResults_Timeout(response, parameters);
|
||||
return;
|
||||
}
|
||||
|
||||
// build reverse geocoding address
|
||||
var used_address_data = 0;
|
||||
var address = "";
|
||||
if( response.address.road) {
|
||||
address += response.address.road;
|
||||
used_address_data++;
|
||||
}
|
||||
if( response.address.city ) {
|
||||
if( used_address_data > 0 )
|
||||
address += ", ";
|
||||
address += response.address.city;
|
||||
used_address_data++;
|
||||
} else if( response.address.village ) {
|
||||
if( used_address_data > 0 )
|
||||
address += ", ";
|
||||
address += response.address.village;
|
||||
used_address_data++;
|
||||
}
|
||||
if( used_address_data < 2 && response.address.country ) {
|
||||
if( used_address_data > 0 )
|
||||
address += ", ";
|
||||
address += response.address.country;
|
||||
used_address_data++;
|
||||
}
|
||||
if( used_address_data == 0 ) {
|
||||
OSRM.Geocoder._showReverseResults_Timeout(response, parameters);
|
||||
return;
|
||||
}
|
||||
|
||||
// add result to DOM
|
||||
if(parameters.marker_id == OSRM.C.SOURCE_LABEL && OSRM.G.markers.hasSource() )
|
||||
document.getElementById("gui-input-source").value = address;
|
||||
else if(parameters.marker_id == OSRM.C.TARGET_LABEL && OSRM.G.markers.hasTarget() )
|
||||
document.getElementById("gui-input-target").value = address;
|
||||
},
|
||||
_showReverseResults_Timeout: function(response, parameters) {
|
||||
if(!parameters.do_fallback)
|
||||
return;
|
||||
|
||||
OSRM.Geocoder.updateLocation(parameters.marker_id);
|
||||
}
|
||||
|
||||
};
|
||||
@@ -0,0 +1,193 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM route management (handles drawing of route geometry - current route, old route, unnamed route, highlight unnamed streets)
|
||||
// [this holds the route geometry]
|
||||
|
||||
|
||||
OSRM.HistoryRoute = function() {
|
||||
// style and count of history routes
|
||||
this._history_styles = [{dashed:false, color:'#FFFFFF', opacity:0.5, weight:5},
|
||||
{dashed:false, color:'#0000DD', opacity:0.45, weight:5},
|
||||
{dashed:false, color:'#0000BB', opacity:0.40, weight:5},
|
||||
{dashed:false, color:'#000099', opacity:0.35, weight:5},
|
||||
{dashed:false, color:'#000077', opacity:0.30, weight:5},
|
||||
{dashed:false, color:'#000055', opacity:0.25, weight:5},
|
||||
{dashed:false, color:'#000033', opacity:0.20, weight:5},
|
||||
{dashed:false, color:'#000011', opacity:0.15, weight:5},
|
||||
{dashed:false, color:'#000000', opacity:0.10, weight:5}
|
||||
];
|
||||
this._history_length = this._history_styles.length;
|
||||
|
||||
// actual history data
|
||||
this._history = [];
|
||||
for(var i=0, size=this._history_length; i<size; i++) {
|
||||
var history = {};
|
||||
history.route = new OSRM.SimpleRoute("current" , {dashed:false} );
|
||||
history.markers = [];
|
||||
history.checksum = null;
|
||||
this._history.push(history);
|
||||
}
|
||||
|
||||
// helper functions bound to this
|
||||
this._initiate_redrawHistory = OSRM.bind(this, this._getRoute_RedrawHistory);
|
||||
this._callback_redrawHistory = OSRM.bind(this, this._showRoute_RedrawHistory);
|
||||
};
|
||||
OSRM.extend( OSRM.HistoryRoute,{
|
||||
// switch history routes on/off
|
||||
activate: function() {
|
||||
this.storeHistoryRoute = this._storeHistoryRoute;
|
||||
this.fetchHistoryRoute = this._fetchHistoryRoute;
|
||||
this.showHistoryRoutes = this._showHistoryRoutes;
|
||||
this.clearHistoryRoutes = this._clearHistoryRoutes;
|
||||
OSRM.G.map.on('zoomend', this._initiate_redrawHistory );
|
||||
|
||||
this.storeHistoryRoute();
|
||||
},
|
||||
deactivate: function() {
|
||||
this.clearHistoryRoutes();
|
||||
|
||||
this.storeHistoryRoute = this.empty;
|
||||
this.fetchHistoryRoute = this.empty;
|
||||
this.showHistoryRoutes = this.empty;
|
||||
this.clearHistoryRoutes = this.empty;
|
||||
OSRM.G.map.off('zoomend', this._initiate_redrawHistory );
|
||||
},
|
||||
|
||||
// empty function
|
||||
empty: function() {},
|
||||
storeHistoryRoute: function() {},
|
||||
fetchHistoryRoute: function() {},
|
||||
showHistoryRoutes: function() {},
|
||||
clearHistoryRoutes: function() {},
|
||||
|
||||
// actual functions
|
||||
_storeHistoryRoute: function() {
|
||||
var route = OSRM.G.route;
|
||||
if( !route.isShown() || !route.isRoute() )
|
||||
return;
|
||||
|
||||
// store current route in staging spot
|
||||
var hint_data = OSRM.G.response.hint_data;
|
||||
this._history[0].route.setPositions( route.getPositions() );
|
||||
this._history[0].checksum = hint_data.checksum;
|
||||
this._history[0].markers = [];
|
||||
|
||||
var markers = this._getCurrentMarkers();
|
||||
for(var i=0,size=markers.length; i<size; i++) {
|
||||
var position = { lat:markers[i].lat, lng:markers[i].lng, hint:hint_data.locations[i] };
|
||||
this._history[0].markers.push(position);
|
||||
}
|
||||
},
|
||||
_fetchHistoryRoute: function() {
|
||||
if( this._history[0].markers.length == 0 )
|
||||
return;
|
||||
if( OSRM.G.route.isShown() && this._equalMarkers(this._history[0].markers, this._getCurrentMarkers()) )
|
||||
return;
|
||||
if( this._equalMarkers(this._history[0].markers, this._history[1].markers) )
|
||||
return;
|
||||
|
||||
// move all routes down one position
|
||||
for(var i=this._history_length-1; i>0; i--) {
|
||||
this._history[i].route.setPositions( this._history[i-1].route.getPositions() ); // copying positions quicker than creating new route!
|
||||
this._history[i].markers = this._history[i-1].markers;
|
||||
this._history[i].checksum = this._history[i-1].checksum;
|
||||
}
|
||||
// reset staging spot
|
||||
this._history[0].route.setPositions( [] );
|
||||
this._history[0].markers = [];
|
||||
this._history[0].checksum = null;
|
||||
},
|
||||
_showHistoryRoutes: function() {
|
||||
for(var i=1,size=this._history_length; i<size; i++) {
|
||||
this._history[i].route.setStyle( this._history_styles[i] );
|
||||
this._history[i].route.show();
|
||||
OSRM.G.route.hideOldRoute();
|
||||
}
|
||||
},
|
||||
_clearHistoryRoutes: function() {
|
||||
for(var i=0,size=this._history_length; i<size; i++) {
|
||||
this._history[i].route.hide();
|
||||
this._history[i].route.setPositions( [] );
|
||||
this._history[i].markers = [];
|
||||
this._history[i].checksum = null;
|
||||
}
|
||||
},
|
||||
|
||||
// get positions of current markers (data of jsonp response used, as not all data structures up-to-date!)
|
||||
_getCurrentMarkers: function() {
|
||||
var route = [];
|
||||
|
||||
var positions = OSRM.G.route.getPositions();
|
||||
if(positions.length == 0)
|
||||
return route;
|
||||
|
||||
for(var i=0; i<OSRM.G.response.via_points.length; i++)
|
||||
route.push( {lat:OSRM.G.response.via_points[i][0], lng:OSRM.G.response.via_points[i][1]} );
|
||||
return route;
|
||||
},
|
||||
|
||||
// check if two routes are equivalent by checking their markers
|
||||
_equalMarkers: function(lhs, rhs) {
|
||||
if(lhs.length != rhs.length)
|
||||
return false;
|
||||
for(var i=0,size=lhs.length; i<size; i++) {
|
||||
if( lhs[i].lat.toFixed(5) != rhs[i].lat.toFixed(5) || lhs[i].lng.toFixed(5) != rhs[i].lng.toFixed(5) )
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
// requery history routes
|
||||
_showRoute_RedrawHistory: function(response, history_id) {
|
||||
if(!response)
|
||||
return;
|
||||
|
||||
var positions = OSRM.RoutingGeometry._decode(response.route_geometry, 5);
|
||||
this._history[history_id].route.setPositions(positions);
|
||||
this._updateHints(response, history_id);
|
||||
},
|
||||
_getRoute_RedrawHistory: function() {
|
||||
for(var i=0,size=this._history_length; i<size; i++)
|
||||
if( this._history[i].markers.length > 0 ) {
|
||||
OSRM.JSONP.clear('history'+i);
|
||||
OSRM.JSONP.call(this._buildCall(i)+'&instructions=false', this._callback_redrawHistory, OSRM.JSONP.empty, OSRM.DEFAULTS.JSONP_TIMEOUT, 'history'+i, i);
|
||||
}
|
||||
},
|
||||
_buildCall: function(history_id) {
|
||||
var source = OSRM.DEFAULTS.HOST_ROUTING_URL;
|
||||
source += '?z=' + OSRM.G.map.getZoom() + '&output=json&jsonp=%jsonp&geomformat=cmp';
|
||||
|
||||
if(this._history[history_id].checksum)
|
||||
source += '&checksum=' + this._history[history_id].checksum;
|
||||
|
||||
var history_markers = this._history[history_id].markers;
|
||||
for(var i=0,size=history_markers.length; i<size; i++) {
|
||||
source += '&loc=' + history_markers[i].lat.toFixed(6) + ',' + history_markers[i].lng.toFixed(6);
|
||||
if( history_markers[i].hint )
|
||||
source += '&hint=' + history_markers[i].hint;
|
||||
}
|
||||
return source;
|
||||
},
|
||||
_updateHints: function(response, history_id) {
|
||||
this._history[history_id].checksum = response.hint_data.checksum;
|
||||
|
||||
var hints = response.hint_data.locations;
|
||||
for(var i=0; i<hints.length; i++)
|
||||
this._history[history_id].markers[i].hint = hints[i];
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM map handling
|
||||
// [initialization, event handling, centering relative to UI]
|
||||
|
||||
// will hold the map object
|
||||
OSRM.GLOBALS.map = null;
|
||||
|
||||
|
||||
// map controller
|
||||
// [map initialization, event handling]
|
||||
OSRM.Map = {
|
||||
|
||||
// map initialization
|
||||
init: function() {
|
||||
// check if GUI is initialized!
|
||||
if(OSRM.G.main_handle == null)
|
||||
OSRM.GUI.init();
|
||||
|
||||
// setup tile servers
|
||||
var tile_servers = OSRM.DEFAULTS.TILE_SERVERS;
|
||||
var base_maps = {};
|
||||
for(var i=0, size=tile_servers.length; i<size; i++) {
|
||||
if( tile_servers[i].bing == true ) {
|
||||
base_maps[ tile_servers[i].display_name ] = new L.TileLayer.Bing( tile_servers[i].apikey, tile_servers[i].type, tile_servers[i].options );
|
||||
} else {
|
||||
tile_servers[i].options.attribution = tile_servers[i].attribution;
|
||||
base_maps[ tile_servers[i].display_name ] = new L.TileLayer( tile_servers[i].url, tile_servers[i].options );
|
||||
}
|
||||
}
|
||||
|
||||
// setup map
|
||||
OSRM.G.map = new OSRM.MapView('map', {
|
||||
center: new L.LatLng(OSRM.DEFAULTS.ONLOAD_LATITUDE, OSRM.DEFAULTS.ONLOAD_LONGITUDE),
|
||||
zoom: OSRM.DEFAULTS.ONLOAD_ZOOM_LEVEL,
|
||||
layers: [base_maps[tile_servers[0].display_name]],
|
||||
zoomAnimation: false, // remove animations -> routes are not hidden during zoom
|
||||
fadeAnimation: false
|
||||
});
|
||||
|
||||
// add layer control
|
||||
var layerControl = new L.Control.QueryableLayers(base_maps, {});
|
||||
OSRM.G.map.addLayerControl(layerControl);
|
||||
|
||||
// move zoom markers
|
||||
OSRM.Browser.getElementsByClassName(document,'leaflet-control-zoom')[0].style.left=(OSRM.G.main_handle.boxWidth()+10)+"px";
|
||||
OSRM.Browser.getElementsByClassName(document,'leaflet-control-zoom')[0].style.top="5px";
|
||||
|
||||
// map events
|
||||
OSRM.G.map.on('zoomend', OSRM.Map.zoomed );
|
||||
OSRM.G.map.on('click', OSRM.Map.click );
|
||||
OSRM.G.map.on('contextmenu', OSRM.Map.contextmenu );
|
||||
OSRM.G.map.on('mousemove', OSRM.Map.mousemove );
|
||||
},
|
||||
|
||||
// init map position and zoom (respect UI visibility / use browser geolocation)
|
||||
initPosition: function() {
|
||||
var position = new L.LatLng( OSRM.DEFAULTS.ONLOAD_LATITUDE, OSRM.DEFAULTS.ONLOAD_LONGITUDE);
|
||||
OSRM.G.map.setViewUI( position, OSRM.DEFAULTS.ONLOAD_ZOOM_LEVEL, true);
|
||||
if (navigator.geolocation && document.URL.indexOf("file://") == -1) // convenience: FF does not save access rights for local files
|
||||
navigator.geolocation.getCurrentPosition(OSRM.Map.geolocationResponse);
|
||||
},
|
||||
|
||||
// map event handlers
|
||||
zoomed: function(e) {
|
||||
if(OSRM.G.dragging)
|
||||
OSRM.Routing.getRoute_Dragging();
|
||||
else
|
||||
OSRM.Routing.getRoute_Redraw();
|
||||
},
|
||||
contextmenu: function(e) {;},
|
||||
mousemove: function(e) { OSRM.Via.drawDragMarker(e); },
|
||||
click: function(e) {
|
||||
if( !OSRM.G.markers.hasSource() ) {
|
||||
var index = OSRM.G.markers.setSource( e.latlng );
|
||||
OSRM.Geocoder.updateAddress( OSRM.C.SOURCE_LABEL, OSRM.C.DO_FALLBACK_TO_LAT_LNG );
|
||||
OSRM.G.markers.route[index].show();
|
||||
OSRM.G.markers.route[index].centerView( OSRM.G.map.getZoom() );
|
||||
OSRM.Routing.getRoute();
|
||||
} else if( !OSRM.G.markers.hasTarget() ) {
|
||||
var index = OSRM.G.markers.setTarget( e.latlng );
|
||||
OSRM.Geocoder.updateAddress( OSRM.C.TARGET_LABEL, OSRM.C.DO_FALLBACK_TO_LAT_LNG );
|
||||
OSRM.G.markers.route[index].show();
|
||||
OSRM.G.markers.route[index].centerView( OSRM.G.map.getZoom() );
|
||||
OSRM.Routing.getRoute();
|
||||
}
|
||||
},
|
||||
geolocationResponse: function(response) {
|
||||
var latlng = new L.LatLng(response.coords.latitude, response.coords.longitude);
|
||||
OSRM.G.map.setViewUI(latlng, OSRM.DEFAULTS.ZOOM_LEVEL );
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM marker management (all route markers should only be set and deleted with these routines!)
|
||||
// [this holds the vital information of the route]
|
||||
|
||||
OSRM.Markers = function() {
|
||||
this.route = new Array();
|
||||
this.highlight = new OSRM.DragMarker("highlight", {draggable:true,icon:OSRM.G.icons['marker-highlight'],dragicon:OSRM.G.icons['marker-highlight-drag']});;
|
||||
this.dragger = new OSRM.DragMarker("drag", {draggable:true,icon:OSRM.G.icons['marker-drag'],dragicon:OSRM.G.icons['marker-drag']});;
|
||||
};
|
||||
OSRM.extend( OSRM.Markers,{
|
||||
reset: function() {
|
||||
// remove route markers
|
||||
for(var i=0; i<this.route.length;i++)
|
||||
this.route[i].hide();
|
||||
this.route.splice(0, this.route.length);
|
||||
document.getElementById('gui-delete-source').style.visibility = "hidden";
|
||||
document.getElementById('gui-delete-target').style.visibility = "hidden";
|
||||
// remove special markers
|
||||
this.highlight.hide();
|
||||
this.dragger.hide();
|
||||
},
|
||||
removeVias: function() {
|
||||
// assert correct route array s - v - t
|
||||
for(var i=1; i<this.route.length-1;i++)
|
||||
this.route[i].hide();
|
||||
this.route.splice(1, this.route.length-2);
|
||||
},
|
||||
setSource: function(position) {
|
||||
// source node is always first node
|
||||
if( this.route[0] && this.route[0].label == OSRM.C.SOURCE_LABEL )
|
||||
this.route[0].setPosition(position);
|
||||
else
|
||||
this.route.splice(0,0, new OSRM.RouteMarker(OSRM.C.SOURCE_LABEL, {draggable:true,icon:OSRM.G.icons['marker-source'],dragicon:OSRM.G.icons['marker-source-drag']}, position));
|
||||
document.getElementById('gui-delete-source').style.visibility = "visible";
|
||||
return 0;
|
||||
},
|
||||
setTarget: function(position) {
|
||||
// target node is always last node
|
||||
if( this.route[this.route.length-1] && this.route[ this.route.length-1 ].label == OSRM.C.TARGET_LABEL )
|
||||
this.route[this.route.length-1].setPosition(position);
|
||||
else
|
||||
this.route.splice( this.route.length,0, new OSRM.RouteMarker(OSRM.C.TARGET_LABEL, {draggable:true,icon:OSRM.G.icons['marker-target'],dragicon:OSRM.G.icons['marker-target-drag']}, position));
|
||||
document.getElementById('gui-delete-target').style.visibility = "visible";
|
||||
return this.route.length-1;
|
||||
},
|
||||
setVia: function(id, position) {
|
||||
// via nodes only between source and target nodes
|
||||
if( this.route.length<2 || id > this.route.length-2 )
|
||||
return -1;
|
||||
|
||||
this.route.splice(id+1,0, new OSRM.RouteMarker(OSRM.C.VIA_LABEL, {draggable:true,icon:OSRM.G.icons['marker-via'],dragicon:OSRM.G.icons['marker-via-drag']}, position));
|
||||
return id+1;
|
||||
},
|
||||
removeMarker: function(id) {
|
||||
if( id >= this.route.length )
|
||||
return;
|
||||
|
||||
// also remove vias if source or target are removed
|
||||
if( id==0 && this.route[0].label == OSRM.C.SOURCE_LABEL ) {
|
||||
this.removeVias();
|
||||
document.getElementById('gui-input-source').value = "";
|
||||
document.getElementById('information-box').innerHTML = "";
|
||||
document.getElementById('information-box-header').innerHTML = "";
|
||||
document.getElementById('gui-delete-source').style.visibility = "hidden";
|
||||
} else if( id == this.route.length-1 && this.route[ this.route.length-1 ].label == OSRM.C.TARGET_LABEL ) {
|
||||
this.removeVias();
|
||||
id = this.route.length-1;
|
||||
document.getElementById('gui-input-target').value = "";
|
||||
document.getElementById('information-box').innerHTML = "";
|
||||
document.getElementById('information-box-header').innerHTML = "";
|
||||
document.getElementById('gui-delete-target').style.visibility = "hidden";
|
||||
}
|
||||
|
||||
this.route[id].hide();
|
||||
this.route.splice(id, 1);
|
||||
},
|
||||
reverseMarkers: function() {
|
||||
var size = this.route.length;
|
||||
|
||||
// invert route, if a route is shown
|
||||
if( size > 1 ) {
|
||||
// switch positions in nodes
|
||||
var temp_position = this.route[0].getPosition();
|
||||
this.route[0].setPosition( this.route[size-1].getPosition() );
|
||||
this.route[size-1].setPosition( temp_position );
|
||||
// switch nodes in array
|
||||
var temp_node = this.route[0];
|
||||
this.route[0] = this.route[size-1];
|
||||
this.route[size-1] = temp_node;
|
||||
// reverse route
|
||||
this.route.reverse();
|
||||
// clear information (both delete markers stay visible)
|
||||
document.getElementById('information-box').innerHTML = "";
|
||||
document.getElementById('information-box-header').innerHTML = "";
|
||||
|
||||
// invert marker, if only one marker is shown (implicit clear of information / delete markers)
|
||||
} else if( size > 0 ) {
|
||||
var position = this.route[0].getPosition();
|
||||
var label = this.route[0].label;
|
||||
this.removeMarker(0);
|
||||
if( label == OSRM.C.TARGET_LABEL )
|
||||
this.setSource( position );
|
||||
else if( label == OSRM.C.SOURCE_LABEL )
|
||||
this.setTarget( position );
|
||||
this.route[0].show();
|
||||
}
|
||||
|
||||
},
|
||||
hasSource: function() {
|
||||
if( this.route[0] && this.route[0].label == OSRM.C.SOURCE_LABEL )
|
||||
return true;
|
||||
return false;
|
||||
},
|
||||
hasTarget: function() {
|
||||
if( this.route[this.route.length-1] && this.route[this.route.length-1].label == OSRM.C.TARGET_LABEL )
|
||||
return true;
|
||||
return false;
|
||||
},
|
||||
|
||||
//relabel all via markers
|
||||
relabelViaMarkers: function() {
|
||||
for(var i=1, size=this.route.length-1; i<size; i++)
|
||||
this.route[i].marker.setLabel(i);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM route management (handles drawing of route geometry - current route, old route, unnamed route, highlight unnamed streets)
|
||||
// [this holds the route geometry]
|
||||
|
||||
|
||||
OSRM.Route = function() {
|
||||
this._current_route = new OSRM.SimpleRoute("current" , {dashed:false} );
|
||||
this._old_route = new OSRM.SimpleRoute("old", {dashed:false,color:"#123"} );
|
||||
this._unnamed_route = new OSRM.MultiRoute("unnamed");
|
||||
|
||||
this._current_route_style = {dashed:false,color:'#0033FF', weight:5};
|
||||
this._current_noroute_style = {dashed:true, color:'#222222', weight:2};
|
||||
this._old_route_style = {dashed:false,color:'#112233', weight:5};
|
||||
this._old_noroute_style = {dashed:true, color:'#000000', weight:2};
|
||||
this._unnamed_route_style = {dashed:false, color:'#FF00FF', weight:10};
|
||||
this._old_unnamed_route_style = {dashed:false, color:'#990099', weight:10};
|
||||
|
||||
this._noroute = OSRM.Route.ROUTE;
|
||||
this._history = new OSRM.HistoryRoute();
|
||||
};
|
||||
OSRM.Route.NOROUTE = true;
|
||||
OSRM.Route.ROUTE = false;
|
||||
OSRM.extend( OSRM.Route,{
|
||||
|
||||
// show/hide route
|
||||
showRoute: function(positions, noroute) {
|
||||
this._noroute = noroute;
|
||||
this._current_route.setPositions( positions );
|
||||
if ( this._noroute == OSRM.Route.NOROUTE )
|
||||
this._current_route.setStyle( this._current_noroute_style );
|
||||
else
|
||||
this._current_route.setStyle( this._current_route_style );
|
||||
this._current_route.show();
|
||||
//this._raiseUnnamedRoute();
|
||||
|
||||
this._history.fetchHistoryRoute();
|
||||
this._history.showHistoryRoutes();
|
||||
this._history.storeHistoryRoute();
|
||||
},
|
||||
hideRoute: function() {
|
||||
this._current_route.hide();
|
||||
this._unnamed_route.hide();
|
||||
|
||||
this._history.fetchHistoryRoute();
|
||||
this._history.showHistoryRoutes();
|
||||
// deactivate printing
|
||||
OSRM.Printing.deactivate();
|
||||
},
|
||||
|
||||
// show/hide highlighting for unnamed routes
|
||||
showUnnamedRoute: function(positions) {
|
||||
this._unnamed_route.clearRoutes();
|
||||
for(var i=0; i<positions.length; i++) {
|
||||
this._unnamed_route.addRoute(positions[i]);
|
||||
}
|
||||
this._unnamed_route.setStyle( this._unnamed_route_style );
|
||||
this._unnamed_route.show();
|
||||
},
|
||||
hideUnnamedRoute: function() {
|
||||
this._unnamed_route.hide();
|
||||
},
|
||||
// TODO: hack to put unnamed_route above old_route -> easier way in will be available Leaflet 0.4
|
||||
_raiseUnnamedRoute: function() {
|
||||
if(this._unnamed_route.isShown()) {
|
||||
this._unnamed_route.hide();
|
||||
this._unnamed_route.show();
|
||||
}
|
||||
},
|
||||
|
||||
// show/hide previous route as shadow
|
||||
showOldRoute: function() {
|
||||
this._old_route.setPositions( this._current_route.getPositions() );
|
||||
if ( this._noroute == OSRM.Route.NOROUTE)
|
||||
this._old_route.setStyle( this._old_noroute_style );
|
||||
else
|
||||
this._old_route.setStyle( this._old_route_style );
|
||||
this._old_route.show();
|
||||
this._raiseUnnamedRoute();
|
||||
// change color of unnamed route highlighting - no separate object as dragged route does not have unnamed route highlighting
|
||||
this._unnamed_route.setStyle( this._old_unnamed_route_style );
|
||||
},
|
||||
hideOldRoute: function() {
|
||||
this._old_route.hide();
|
||||
},
|
||||
|
||||
// query routines
|
||||
isShown: function() {
|
||||
return this._current_route.isShown();
|
||||
},
|
||||
isRoute: function() {
|
||||
return !(this._noroute);
|
||||
},
|
||||
getPositions: function() {
|
||||
return this._current_route.getPositions();
|
||||
},
|
||||
getPoints: function() {
|
||||
return this._current_route.getPoints();
|
||||
},
|
||||
|
||||
// helper routines
|
||||
reset: function() {
|
||||
this.hideRoute();
|
||||
this._old_route.hide();
|
||||
this._noroute = OSRM.Route.ROUTE;
|
||||
this._history.clearHistoryRoutes();
|
||||
},
|
||||
fire: function(type,event) {
|
||||
this._current_route.route.fire(type,event);
|
||||
},
|
||||
centerView: function() {
|
||||
this._current_route.centerView();
|
||||
},
|
||||
|
||||
// handle history routes
|
||||
activateHistoryRoutes: function() {
|
||||
this._history.activate();
|
||||
},
|
||||
deactivateHistoryRoutes: function() {
|
||||
this._history.deactivate();
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM via marker routines
|
||||
// [find correct position for a via marker]
|
||||
|
||||
|
||||
OSRM.Via = {
|
||||
|
||||
// find route segment of current route geometry that is closest to the new via node (marked by index of its endpoint)
|
||||
_findNearestRouteSegment: function( new_via ) {
|
||||
var min_dist = Number.MAX_VALUE;
|
||||
var min_index = undefined;
|
||||
|
||||
var p = OSRM.G.map.latLngToLayerPoint( new_via );
|
||||
var positions = OSRM.G.route.getPoints();
|
||||
for(var i=1; i<positions.length; i++) {
|
||||
var _sqDist = L.LineUtil._sqClosestPointOnSegment(p, positions[i-1], positions[i], true);
|
||||
if( _sqDist < min_dist) {
|
||||
min_dist = _sqDist;
|
||||
min_index = i;
|
||||
}
|
||||
}
|
||||
|
||||
return min_index;
|
||||
},
|
||||
|
||||
|
||||
// find the correct index among all via nodes to insert the new via node, and insert it
|
||||
findViaIndex: function( new_via_position ) {
|
||||
// find route segment that is closest to click position (marked by last index)
|
||||
var nearest_index = OSRM.Via._findNearestRouteSegment( new_via_position );
|
||||
|
||||
// find correct index to insert new via node
|
||||
var via_points = OSRM.G.response.via_points;
|
||||
var new_via_index = via_points.length-2;
|
||||
var via_index = Array();
|
||||
for(var i=1; i<via_points.length-1; i++) {
|
||||
via_index[i-1] = OSRM.Via._findNearestRouteSegment( new L.LatLng(via_points[i][0], via_points[i][1]) );
|
||||
if(via_index[i-1] > nearest_index) {
|
||||
new_via_index = i-1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// add via node
|
||||
return new_via_index;
|
||||
},
|
||||
|
||||
|
||||
//function that draws a drag marker
|
||||
dragTimer: new Date(),
|
||||
|
||||
drawDragMarker: function(event) {
|
||||
if( OSRM.G.route.isShown() == false)
|
||||
return;
|
||||
if( OSRM.G.dragging == true )
|
||||
return;
|
||||
|
||||
// throttle computation
|
||||
if( (new Date() - OSRM.Via.dragTimer) < 25 )
|
||||
return;
|
||||
OSRM.Via.dragTimer = new Date();
|
||||
|
||||
// get distance to route
|
||||
var minpoint = OSRM.G.route._current_route.route.closestLayerPoint( event.layerPoint );
|
||||
var min_dist = minpoint ? minpoint._sqDist : 1000;
|
||||
|
||||
// get distance to markers
|
||||
var mouse = event.latlng;
|
||||
for(var i=0, size=OSRM.G.markers.route.length; i<size; i++) {
|
||||
if(OSRM.G.markers.route[i].label=='drag')
|
||||
continue;
|
||||
var position = OSRM.G.markers.route[i].getPosition();
|
||||
var dist = OSRM.G.map.project(mouse).distanceTo(OSRM.G.map.project(position));
|
||||
if( dist < 20 )
|
||||
min_dist = 1000;
|
||||
}
|
||||
|
||||
// check whether mouse is over another marker
|
||||
var pos = OSRM.G.map.layerPointToContainerPoint(event.layerPoint);
|
||||
var obj = document.elementFromPoint(pos.x,pos.y);
|
||||
for(var i=0, size=OSRM.G.markers.route.length; i<size; i++) {
|
||||
if(OSRM.G.markers.route[i].label=='drag')
|
||||
continue;
|
||||
if( obj == OSRM.G.markers.route[i].marker._icon)
|
||||
min_dist = 1000;
|
||||
}
|
||||
|
||||
// special care for highlight marker
|
||||
if( OSRM.G.markers.highlight.isShown() ) {
|
||||
if( OSRM.G.map.project(mouse).distanceTo(OSRM.G.map.project( OSRM.G.markers.highlight.getPosition() ) ) < 20 )
|
||||
min_dist = 1000;
|
||||
else if( obj == OSRM.G.markers.highlight.marker._icon)
|
||||
min_dist = 1000;
|
||||
}
|
||||
|
||||
if( min_dist < 400) {
|
||||
OSRM.G.markers.dragger.setPosition( OSRM.G.map.layerPointToLatLng(minpoint) );
|
||||
OSRM.G.markers.dragger.show();
|
||||
} else
|
||||
OSRM.G.markers.dragger.hide();
|
||||
}
|
||||
|
||||
};
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// Leaflet bugfixes
|
||||
// [assorted bugfixes to Leaflet functions we use]
|
||||
|
||||
|
||||
// return closest point on segment or distance to that point
|
||||
L.LineUtil._sqClosestPointOnSegment = function (p, p1, p2, sqDist) {
|
||||
var x = p1.x,
|
||||
y = p1.y,
|
||||
dx = p2.x - x,
|
||||
dy = p2.y - y,
|
||||
dot = dx * dx + dy * dy,
|
||||
t;
|
||||
|
||||
if (dot > 0) {
|
||||
t = ((p.x - x) * dx + (p.y - y) * dy) / dot;
|
||||
|
||||
if (t > 1) {
|
||||
x = p2.x;
|
||||
y = p2.y;
|
||||
} else if (t > 0) {
|
||||
x += dx * t;
|
||||
y += dy * t;
|
||||
}
|
||||
}
|
||||
|
||||
dx = p.x - x;
|
||||
dy = p.y - y;
|
||||
|
||||
// DS_CHANGE: modified return values
|
||||
if(sqDist)
|
||||
return dx*dx + dy*dy;
|
||||
else {
|
||||
var p = new L.Point(x,y);
|
||||
p._sqDist = dx*dx + dy*dy;
|
||||
return p;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// makes requestAnimFrame respect the immediate paramter -> prevents drag events after dragend events
|
||||
// (alternatively: add if(!this.dragging ) return to L.Draggable._updatePosition, but must be done in leaflet.js!)
|
||||
// [TODO: In Leaflet 0.4 use L.Util.cancelAnimFrame(this._animRequest) in L.Draggable._onUp() instead, also has to be done in leaflet.js!]
|
||||
L.Util.requestAnimFrame = (function () {
|
||||
function timeoutDefer(callback) {
|
||||
window.setTimeout(callback, 1000 / 60);
|
||||
}
|
||||
|
||||
var requestFn = window.requestAnimationFrame ||
|
||||
window.webkitRequestAnimationFrame ||
|
||||
window.mozRequestAnimationFrame ||
|
||||
window.oRequestAnimationFrame ||
|
||||
window.msRequestAnimationFrame ||
|
||||
timeoutDefer;
|
||||
|
||||
return function (callback, context, immediate, contextEl) {
|
||||
callback = context ? L.Util.bind(callback, context) : callback;
|
||||
if (immediate ) { // DS_CHANGE: removed additional condition requestFn === timeoutDefer
|
||||
callback();
|
||||
} else {
|
||||
requestFn(callback, contextEl);
|
||||
}
|
||||
};
|
||||
}());
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// queryable Layers control
|
||||
// [simply Control.Layers extended by query functions]
|
||||
L.Control.QueryableLayers = L.Control.Layers.extend({
|
||||
getActiveLayerName: function () {
|
||||
var i, input, obj,
|
||||
inputs = this._form.getElementsByTagName('input'),
|
||||
inputsLen = inputs.length;
|
||||
|
||||
for (i = 0; i < inputsLen; i++) {
|
||||
input = inputs[i];
|
||||
obj = this._layers[input.layerId];
|
||||
if (input.checked && !obj.overlay) {
|
||||
return obj.name;
|
||||
}
|
||||
}
|
||||
},
|
||||
getActiveLayer: function () {
|
||||
var i, input, obj,
|
||||
inputs = this._form.getElementsByTagName('input'),
|
||||
inputsLen = inputs.length;
|
||||
|
||||
for (i = 0; i < inputsLen; i++) {
|
||||
input = inputs[i];
|
||||
obj = this._layers[input.layerId];
|
||||
if (input.checked && !obj.overlay) {
|
||||
return obj.layer;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// Leaflet extension: Dashed Polyline
|
||||
// [adds dashed optionally dashed lines when using SVG or VML rendering]
|
||||
|
||||
|
||||
// dashed polyline class
|
||||
L.DashedPolyline = L.Polyline.extend({
|
||||
initialize: function(latlngs, options) {
|
||||
L.Polyline.prototype.initialize.call(this, latlngs, options);
|
||||
},
|
||||
|
||||
options: {
|
||||
dashed: true
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// svg rendering
|
||||
L.DashedPolyline = !L.Browser.svg ? L.DashedPolyline : L.DashedPolyline.extend({
|
||||
_updateStyle: function () {
|
||||
L.Polyline.prototype._updateStyle.call(this);
|
||||
if (this.options.stroke) {
|
||||
if (this.options.dashed == true)
|
||||
this._path.setAttribute('stroke-dasharray', '8,6');
|
||||
else
|
||||
this._path.setAttribute('stroke-dasharray', '');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// vml rendering
|
||||
L.DashedPolyline = L.Browser.svg || !L.Browser.vml ? L.DashedPolyline : L.DashedPolyline.extend({
|
||||
_updateStyle: function () {
|
||||
L.Polyline.prototype._updateStyle.call(this);
|
||||
if (this.options.stroke) {
|
||||
if (this.options.dashed == true)
|
||||
this._stroke.dashstyle = "dash";
|
||||
else
|
||||
this._stroke.dashstyle = "solid";
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// Leaflet extension: MouseMarker
|
||||
// [marker class that propagates modifier and button presses in mouse click events and allows for changing icons]
|
||||
|
||||
|
||||
// extended marker class
|
||||
L.MouseMarker = L.Marker.extend({
|
||||
initialize: function (latlng, options) {
|
||||
L.Marker.prototype.initialize.apply(this, arguments);
|
||||
},
|
||||
|
||||
switchIcon: function( icon ) {
|
||||
this.options.icon = icon;
|
||||
|
||||
if (this._map) {
|
||||
this._changeIcon();
|
||||
this._reset();
|
||||
}
|
||||
},
|
||||
|
||||
setLabel: function( label ) {
|
||||
if(this._icon) {
|
||||
this._icon.lastChild.innerHTML=label;
|
||||
this._icon.lastChild.style.display = "block";
|
||||
}
|
||||
},
|
||||
|
||||
_changeIcon: function () {
|
||||
var options = this.options;
|
||||
|
||||
if (this._icon) {
|
||||
this._icon = options.icon.switchIcon( this._icon );
|
||||
if (this.options.clickable) // TODO: only needed until Leaflet 0.4
|
||||
this._icon.className += ' leaflet-clickable';
|
||||
}
|
||||
|
||||
var panes = this._map._panes;
|
||||
|
||||
if (this._shadow)
|
||||
panes.shadowPane.removeChild(this._shadow);
|
||||
this._shadow = options.icon.createShadow();
|
||||
if (this._shadow)
|
||||
panes.shadowPane.appendChild(this._shadow);
|
||||
},
|
||||
|
||||
_onMouseClick: function (e) {
|
||||
L.DomEvent.stopPropagation(e);
|
||||
if (this.dragging && this.dragging.moved()) { return; }
|
||||
this.fire(e.type, {
|
||||
altKey: e.altKey,
|
||||
ctrlKey: e.ctrlKey,
|
||||
shiftKey: e.shiftKey,
|
||||
button: e.button
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// Leaflet extension: SwitchableIcon
|
||||
// [will be an extension of L.Icon in Leaflet 0.4, for now it is a copy with added functionality]
|
||||
|
||||
|
||||
// icon class with functions to simply switch the icon images
|
||||
L.SwitchableIcon = L.Class.extend({
|
||||
options: {
|
||||
/*
|
||||
iconUrl: (String) (required)
|
||||
iconSize: (Point) (can be set through CSS)
|
||||
iconAnchor: (Point) (centered by default if size is specified, can be set in CSS with negative margins)
|
||||
popupAnchor: (Point) (if not specified, popup opens in the anchor point)
|
||||
shadowUrl: (Point) (no shadow by default)
|
||||
shadowSize: (Point)
|
||||
*/
|
||||
className: ''
|
||||
},
|
||||
|
||||
initialize: function (options) {
|
||||
L.Util.setOptions(this, options);
|
||||
},
|
||||
|
||||
createIcon: function () {
|
||||
return this._createIcon('icon');
|
||||
},
|
||||
|
||||
createShadow: function () {
|
||||
return this.options.shadowUrl ? this._createIcon('shadow') : null;
|
||||
},
|
||||
|
||||
_createIcon: function (name) {
|
||||
var img = this._createImg(this.options[name + 'Url']);
|
||||
this._setIconStyles(img, name);
|
||||
return img;
|
||||
},
|
||||
|
||||
_setIconStyles: function (img, name) {
|
||||
var options = this.options,
|
||||
size = options[name + 'Size'],
|
||||
anchor = options.iconAnchor;
|
||||
|
||||
if (!anchor && size) {
|
||||
anchor = size.divideBy(2, true);
|
||||
}
|
||||
|
||||
if (name === 'shadow' && anchor && options.shadowOffset) {
|
||||
anchor._add(options.shadowOffset);
|
||||
}
|
||||
|
||||
img.className = 'leaflet-marker-' + name + ' ' + options.className;
|
||||
|
||||
if (anchor) {
|
||||
img.style.marginLeft = (-anchor.x) + 'px';
|
||||
img.style.marginTop = (-anchor.y) + 'px';
|
||||
}
|
||||
|
||||
if (size) {
|
||||
img.style.width = size.x + 'px';
|
||||
img.style.height = size.y + 'px';
|
||||
}
|
||||
},
|
||||
|
||||
_createImg: function (src) {
|
||||
var el;
|
||||
if (!L.Browser.ie6) {
|
||||
el = document.createElement('div');
|
||||
|
||||
var img = document.createElement('img');
|
||||
var num = document.createElement('div');
|
||||
img.src = src;
|
||||
num.className = 'via-counter';
|
||||
num.innerHTML = "";
|
||||
|
||||
el.appendChild(img);
|
||||
el.appendChild(num);
|
||||
} else {
|
||||
el = document.createElement('div');
|
||||
el.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + src + '")';
|
||||
}
|
||||
return el;
|
||||
},
|
||||
|
||||
// new functions start here
|
||||
switchIcon: function (el) {
|
||||
return this._switchIcon('icon', el);
|
||||
},
|
||||
|
||||
switchShadow: function (el) {
|
||||
return this.options.shadowUrl ? this._switchIcon('shadow', el) : null;
|
||||
},
|
||||
|
||||
_switchIcon: function (name, el) {
|
||||
var img = this._switchImg(this.options[name + 'Url'], el);
|
||||
this._setIconStyles(img, name);
|
||||
return img;
|
||||
},
|
||||
|
||||
_switchImg: function (src, el) {
|
||||
if (!L.Browser.ie6) {
|
||||
el.firstChild.src = src;
|
||||
} else {
|
||||
el.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + src + '")';
|
||||
}
|
||||
return el;
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,191 @@
|
||||
/*
|
||||
* Portions of this code and logic copied from OpenLayers and
|
||||
* redistributed under the original Clear BSD license terms:
|
||||
*
|
||||
* http://trac.osgeo.org/openlayers/browser/license.txt
|
||||
*
|
||||
* Copyright 2005-2010 OpenLayers Contributors, released under
|
||||
* the Clear BSD license. See authors.txt for a list of contributors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* --
|
||||
*
|
||||
* Leaflet-specific modifications are released under the following
|
||||
* terms:
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What The Fuck You Want
|
||||
* To Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
*/
|
||||
|
||||
L.TileLayer.Bing = L.TileLayer.extend({
|
||||
|
||||
supportedTypes: ['Road', 'Aerial', 'AerialWithLabels'],
|
||||
|
||||
attributionTemplate: '<span style="display:inline-block">' +
|
||||
'<a target="_blank" href="http://www.bing.com/maps/">' +
|
||||
//'<img src="{logo}" /></a><br><span>{copyrights}' +
|
||||
'</a><span>{copyrights}' +
|
||||
'<a style="white-space: nowrap" target="_blank" '+
|
||||
'href="http://www.microsoft.com/maps/product/terms.html">' +
|
||||
'Terms of Use</a></span></span>',
|
||||
|
||||
supportedCultures: {"en":"en-US", "de":"de-DE", "fr":"fr-FR", "it":"it-IT", "es":"es-ES", "nl":"nl-BE"},
|
||||
|
||||
initialize: function(/*String*/ apiKey, /*String*/ mapType, /*Object*/ options) {
|
||||
|
||||
this._apiKey = apiKey;
|
||||
this._mapType = mapType;
|
||||
|
||||
this._loadMetadata();
|
||||
|
||||
L.Util.setOptions(this, options);
|
||||
},
|
||||
|
||||
redraw: function() {
|
||||
this._reset();
|
||||
this._update();
|
||||
},
|
||||
|
||||
_loadMetadata: function() {
|
||||
this._callbackId = "_l_tilelayer_bing_" + (L.TileLayer.Bing._callbackId++);
|
||||
var that = this;
|
||||
window[this._callbackId] = function() {
|
||||
L.TileLayer.Bing.processMetadata.apply(that, arguments);
|
||||
};
|
||||
|
||||
var params = {
|
||||
key: this._apiKey,
|
||||
jsonp: this._callbackId,
|
||||
include: 'ImageryProviders'
|
||||
},
|
||||
url = "http://dev.virtualearth.net/REST/v1/Imagery/Metadata/" +
|
||||
this._mapType + L.Util.getParamString(params),
|
||||
script = document.createElement("script");
|
||||
|
||||
script.type = "text/javascript";
|
||||
script.src = url;
|
||||
script.id = this._callbackId;
|
||||
document.getElementsByTagName("head")[0].appendChild(script);
|
||||
},
|
||||
|
||||
_onMetadataLoaded: function() {},
|
||||
|
||||
onAdd: function(map, insertAtTheBottom) {
|
||||
if (!this.metadata) {
|
||||
this._onMetadataLoaded = L.Util.bind(function() {
|
||||
L.TileLayer.prototype.onAdd.call(this, map, insertAtTheBottom);
|
||||
map.on('moveend', this._updateAttribution, this);
|
||||
this._updateAttribution();
|
||||
}, this);
|
||||
} else {
|
||||
L.TileLayer.prototype.onAdd.call(this, map, insertAtTheBottom);
|
||||
map.on('moveend', this._updateAttribution, this);
|
||||
this._updateAttribution();
|
||||
}
|
||||
},
|
||||
|
||||
onRemove: function(map) {
|
||||
if (this._map.attributionControl) {
|
||||
this._map.attributionControl.removeAttribution(this.attribution);
|
||||
}
|
||||
this._map.off('moveend', this._updateAttribution, this);
|
||||
L.TileLayer.prototype.onRemove.call(this, map);
|
||||
},
|
||||
|
||||
getTileUrl: function(xy, z) {
|
||||
var subdomains = this.options.subdomains,
|
||||
quadDigits = [],
|
||||
i = z,
|
||||
digit,
|
||||
mask,
|
||||
quadKey;
|
||||
// borrowed directly from OpenLayers
|
||||
for (; i > 0; --i) {
|
||||
digit = '0';
|
||||
mask = 1 << (i - 1);
|
||||
if ((xy.x & mask) != 0) {
|
||||
digit++;
|
||||
}
|
||||
if ((xy.y & mask) != 0) {
|
||||
digit++;
|
||||
digit++;
|
||||
}
|
||||
quadDigits.push(digit);
|
||||
}
|
||||
|
||||
return this._url
|
||||
.replace('{culture}', this.supportedCultures[OSRM.Localization.current_language] || "en-US" )
|
||||
.replace('{subdomain}', subdomains[(xy.x + xy.y) % subdomains.length])
|
||||
.replace('{quadkey}', quadDigits.join(""));
|
||||
},
|
||||
|
||||
_updateAttribution: function() {
|
||||
if (this._map.attributionControl) {
|
||||
var metadata = this.metadata;
|
||||
var res = metadata.resourceSets[0].resources[0];
|
||||
var bounds = this._map.getBounds();
|
||||
var providers = res.imageryProviders, zoom = this._map.getZoom() + 1,
|
||||
copyrights = "", provider, i, ii, j, jj, bbox, coverage;
|
||||
for (i=0,ii=providers.length; i<ii; ++i) {
|
||||
provider = providers[i];
|
||||
for (j=0,jj=provider.coverageAreas.length; j<jj; ++j) {
|
||||
coverage = provider.coverageAreas[j];
|
||||
if (zoom <= coverage.zoomMax && zoom >= coverage.zoomMin && coverage.bbox.intersects(bounds)) {
|
||||
copyrights += provider.attribution + " ";
|
||||
j = jj;
|
||||
}
|
||||
}
|
||||
}
|
||||
this._map.attributionControl.removeAttribution(this.attribution);
|
||||
this._map.attributionControl._attributions = {};
|
||||
this._map.attributionControl._update();
|
||||
this.attribution = this.attributionTemplate
|
||||
.replace('{logo}', metadata.brandLogoUri)
|
||||
.replace('{copyrights}', copyrights);
|
||||
this._map.attributionControl.addAttribution(this.attribution);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
L.TileLayer.Bing._callbackId = 0;
|
||||
|
||||
L.TileLayer.Bing.processMetadata = function(metadata) {
|
||||
if (metadata.authenticationResultCode != 'ValidCredentials') {
|
||||
throw "Invalid Bing Maps API Key"
|
||||
}
|
||||
|
||||
if (!metadata.resourceSets.length || !metadata.resourceSets[0].resources.length) {
|
||||
throw "No resources returned, perhaps " + this._mapType + " is an invalid map type?";
|
||||
}
|
||||
|
||||
if (metadata.statusCode != 200) {
|
||||
throw "Bing Maps API request failed with status code " + metadata.statusCode;
|
||||
}
|
||||
|
||||
this.metadata = metadata;
|
||||
var res = metadata.resourceSets[0].resources[0],
|
||||
providers = res.imageryProviders,
|
||||
i = 0,
|
||||
j,
|
||||
provider,
|
||||
bbox,
|
||||
script = document.getElementById(this._callbackId);
|
||||
|
||||
for (; i<providers.length; i++) {
|
||||
provider = providers[i];
|
||||
for (j=0; j<provider.coverageAreas.length; j++) {
|
||||
bbox = provider.coverageAreas[j].bbox;
|
||||
provider.coverageAreas[j].bbox = new L.LatLngBounds(new L.LatLng(bbox[0],bbox[1],true),new L.LatLng(bbox[2],bbox[3], true));
|
||||
}
|
||||
}
|
||||
|
||||
this._url = res.imageUrl;
|
||||
this.options.subdomains = [].concat(res.imageUrlSubdomains);
|
||||
script.parentNode.removeChild(script);
|
||||
window[this._callbackId] = undefined; // cannot delete from window in IE
|
||||
delete this._callbackId;
|
||||
this._onMetadataLoaded();
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// map view/model
|
||||
// [extending Leaflet L.Map with setView/fitBounds methods that respect UI visibility, better layerControl]
|
||||
OSRM.MapView = L.Map.extend({
|
||||
setViewUI: function(position, zoom, no_animation) {
|
||||
if( OSRM.G.main_handle.boxVisible() ) {
|
||||
var point = this.project( position, zoom);
|
||||
point.x-=OSRM.G.main_handle.boxWidth()/2;
|
||||
position = this.unproject(point,zoom);
|
||||
}
|
||||
this.setView( position, zoom, no_animation);
|
||||
},
|
||||
fitBoundsUI: function(bounds) {
|
||||
var southwest = bounds.getSouthWest();
|
||||
var northeast = bounds.getNorthEast();
|
||||
var zoom = this.getBoundsZoom(bounds);
|
||||
var sw_point = this.project( southwest, zoom);
|
||||
if( OSRM.G.main_handle.boxVisible() )
|
||||
sw_point.x-=OSRM.G.main_handle.boxWidth()+20;
|
||||
else
|
||||
sw_point.x-=20;
|
||||
sw_point.y+=20;
|
||||
var ne_point = this.project( northeast, zoom);
|
||||
ne_point.y-=20;
|
||||
ne_point.x+=20;
|
||||
bounds.extend( this.unproject(sw_point,zoom) );
|
||||
bounds.extend( this.unproject(ne_point,zoom) );
|
||||
this.fitBounds( bounds );
|
||||
},
|
||||
getBoundsUI: function(unbounded) {
|
||||
var bounds = this.getPixelBounds();
|
||||
if( OSRM.G.main_handle.boxVisible() )
|
||||
bounds.min.x+=OSRM.G.main_handle.boxWidth();
|
||||
var sw = this.unproject(new L.Point(bounds.min.x, bounds.max.y), this._zoom, true),
|
||||
ne = this.unproject(new L.Point(bounds.max.x, bounds.min.y), this._zoom, true);
|
||||
return new L.LatLngBounds(sw, ne);
|
||||
},
|
||||
getCenterUI: function(unbounded) {
|
||||
var viewHalf = this.getSize();
|
||||
if( OSRM.G.main_handle.boxVisible() )
|
||||
viewHalf.x += OSRM.G.main_handle.boxWidth();
|
||||
var centerPoint = this._getTopLeftPoint().add(viewHalf.divideBy(2));
|
||||
|
||||
return this.unproject(centerPoint, this._zoom, unbounded);
|
||||
},
|
||||
addLayerControl: function( layerControl ) {
|
||||
if( this.layerControl )
|
||||
return;
|
||||
|
||||
this.layerControl = layerControl;
|
||||
this.addControl(this.layerControl);
|
||||
},
|
||||
getActiveLayerId: function() {
|
||||
var tile_server_id = 0;
|
||||
|
||||
var tile_servers = OSRM.DEFAULTS.TILE_SERVERS;
|
||||
var tile_server_name = this.layerControl.getActiveLayerName();
|
||||
for(var i=0, size=tile_servers.length; i<size; i++) {
|
||||
if( tile_servers[i].display_name == tile_server_name ) {
|
||||
tile_server_id = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return tile_server_id;
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM markers
|
||||
// [base marker class, derived highlight marker and route marker classes]
|
||||
|
||||
|
||||
// base marker class (wraps Leaflet markers)
|
||||
OSRM.Marker = function( label, style, position ) {
|
||||
this.label = label ? label : "marker";
|
||||
this.position = position ? position : new L.LatLng(0,0);
|
||||
|
||||
this.marker = new L.MouseMarker( this.position, style );
|
||||
this.marker.parent = this;
|
||||
|
||||
this.shown = false;
|
||||
this.hint = null;
|
||||
};
|
||||
OSRM.extend( OSRM.Marker,{
|
||||
show: function() {
|
||||
OSRM.G.map.addLayer(this.marker);
|
||||
this.shown = true;
|
||||
},
|
||||
hide: function() {
|
||||
OSRM.G.map.removeLayer(this.marker);
|
||||
this.shown = false;
|
||||
},
|
||||
setPosition: function( position ) {
|
||||
this.position = position;
|
||||
this.marker.setLatLng( position );
|
||||
this.hint = null;
|
||||
},
|
||||
getPosition: function() {
|
||||
return this.position;
|
||||
},
|
||||
getLat: function() {
|
||||
return this.position.lat;
|
||||
},
|
||||
getLng: function() {
|
||||
return this.position.lng;
|
||||
},
|
||||
isShown: function() {
|
||||
return this.shown;
|
||||
},
|
||||
centerView: function(zoom) {
|
||||
if( zoom == undefined )
|
||||
zoom = OSRM.DEFAULTS.ZOOM_LEVEL;
|
||||
OSRM.G.map.setViewUI( this.position, zoom );
|
||||
},
|
||||
toString: function() {
|
||||
return "OSRM.Marker: \""+this.label+"\", "+this.position+")";
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// route marker class (draggable, invokes route drawing routines)
|
||||
OSRM.RouteMarker = function ( label, style, position ) {
|
||||
style.baseicon = style.icon;
|
||||
OSRM.RouteMarker.prototype.base.constructor.apply( this, arguments );
|
||||
this.label = label ? label : "route_marker";
|
||||
|
||||
this.marker.on( 'click', this.onClick );
|
||||
this.marker.on( 'drag', this.onDrag );
|
||||
this.marker.on( 'dragstart', this.onDragStart );
|
||||
this.marker.on( 'dragend', this.onDragEnd );
|
||||
};
|
||||
OSRM.inheritFrom( OSRM.RouteMarker, OSRM.Marker );
|
||||
OSRM.extend( OSRM.RouteMarker, {
|
||||
onClick: function(e) {
|
||||
for( var i=0; i<OSRM.G.markers.route.length; i++) {
|
||||
if( OSRM.G.markers.route[i].marker === this ) {
|
||||
OSRM.G.markers.removeMarker( i );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
OSRM.Routing.getRoute();
|
||||
OSRM.G.markers.highlight.hide();
|
||||
OSRM.G.markers.dragger.hide();
|
||||
},
|
||||
onDrag: function(e) {
|
||||
this.parent.setPosition( e.target.getLatLng() );
|
||||
if(OSRM.G.markers.route.length>1)
|
||||
OSRM.Routing.getRoute_Dragging();
|
||||
OSRM.Geocoder.updateLocation( this.parent.label );
|
||||
},
|
||||
onDragStart: function(e) {
|
||||
OSRM.G.dragging = true;
|
||||
this.switchIcon(this.options.dragicon);
|
||||
|
||||
// store id of dragged marker
|
||||
for( var i=0; i<OSRM.G.markers.route.length; i++)
|
||||
if( OSRM.G.markers.route[i].marker === this ) {
|
||||
OSRM.G.dragid = i;
|
||||
break;
|
||||
}
|
||||
|
||||
if( this.parent != OSRM.G.markers.highlight)
|
||||
OSRM.G.markers.highlight.hide();
|
||||
if( this.parent != OSRM.G.markers.dragger)
|
||||
OSRM.G.markers.dragger.hide();
|
||||
if (OSRM.G.route.isShown())
|
||||
OSRM.G.route.showOldRoute();
|
||||
},
|
||||
onDragEnd: function(e) {
|
||||
OSRM.G.dragging = false;
|
||||
this.switchIcon(this.options.baseicon);
|
||||
|
||||
this.parent.setPosition( e.target.getLatLng() );
|
||||
if (OSRM.G.route.isShown()) {
|
||||
OSRM.Routing.getRoute();
|
||||
OSRM.G.route.hideOldRoute();
|
||||
OSRM.G.route.hideUnnamedRoute();
|
||||
} else {
|
||||
OSRM.Geocoder.updateAddress(this.parent.label);
|
||||
OSRM.GUI.clearResults();
|
||||
}
|
||||
},
|
||||
toString: function() {
|
||||
return "OSRM.RouteMarker: \""+this.label+"\", "+this.position+")";
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//drag marker class (draggable, invokes route drawing routines)
|
||||
OSRM.DragMarker = function ( label, style, position ) {
|
||||
OSRM.DragMarker.prototype.base.constructor.apply( this, arguments );
|
||||
this.label = label ? label : "drag_marker";
|
||||
};
|
||||
OSRM.inheritFrom( OSRM.DragMarker, OSRM.RouteMarker );
|
||||
OSRM.extend( OSRM.DragMarker, {
|
||||
onClick: function(e) {
|
||||
if( this.parent != OSRM.G.markers.dragger)
|
||||
this.parent.hide();
|
||||
},
|
||||
onDragStart: function(e) {
|
||||
var new_via_index = OSRM.Via.findViaIndex( e.target.getLatLng() );
|
||||
OSRM.G.markers.route.splice(new_via_index+1,0, this.parent );
|
||||
|
||||
OSRM.RouteMarker.prototype.onDragStart.call(this,e);
|
||||
},
|
||||
onDragEnd: function(e) {
|
||||
OSRM.G.markers.route[OSRM.G.dragid] = new OSRM.RouteMarker(OSRM.C.VIA_LABEL, {draggable:true,icon:OSRM.G.icons['marker-via'],dragicon:OSRM.G.icons['marker-via-drag']}, e.target.getLatLng() );
|
||||
OSRM.G.markers.route[OSRM.G.dragid].show();
|
||||
|
||||
OSRM.RouteMarker.prototype.onDragEnd.call(this,e);
|
||||
this.parent.hide();
|
||||
},
|
||||
toString: function() {
|
||||
return "OSRM.DragMarker: \""+this.label+"\", "+this.position+")";
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM routes
|
||||
// [drawing of all types of route geometry]
|
||||
|
||||
|
||||
// simple route class (wraps Leaflet Polyline)
|
||||
OSRM.SimpleRoute = function (label, style) {
|
||||
this.label = (label ? label : "route");
|
||||
this.route = new L.DashedPolyline();
|
||||
this.route.setLatLngs( [] );
|
||||
if(style) this.route.setStyle( style );
|
||||
|
||||
this.shown = false;
|
||||
};
|
||||
OSRM.extend( OSRM.SimpleRoute,{
|
||||
show: function() {
|
||||
OSRM.G.map.addLayer(this.route);
|
||||
this.shown = true;
|
||||
},
|
||||
hide: function() {
|
||||
OSRM.G.map.removeLayer(this.route);
|
||||
this.shown = false;
|
||||
},
|
||||
isShown: function() {
|
||||
return this.shown;
|
||||
},
|
||||
getPoints: function() {
|
||||
return this.route._originalPoints;
|
||||
},
|
||||
getPositions: function() {
|
||||
return this.route.getLatLngs();
|
||||
},
|
||||
setPositions: function(positions) {
|
||||
this.route.setLatLngs( positions );
|
||||
},
|
||||
setStyle: function(style) {
|
||||
this.route.setStyle(style);
|
||||
},
|
||||
centerView: function() {
|
||||
var bounds = new L.LatLngBounds( this.getPositions() );
|
||||
OSRM.g.map.fitBoundsUI( bounds );
|
||||
},
|
||||
toString: function() {
|
||||
return "OSRM.Route("+ this.label + ", " + this.route.getLatLngs().length + " points)";
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// multiroute class (wraps Leaflet LayerGroup to hold several disjoint routes)
|
||||
OSRM.MultiRoute = function (label) {
|
||||
this.label = (label ? label : "multiroute");
|
||||
this.route = new L.LayerGroup();
|
||||
|
||||
this.shown = false;
|
||||
};
|
||||
OSRM.extend( OSRM.MultiRoute,{
|
||||
show: function() {
|
||||
OSRM.G.map.addLayer(this.route);
|
||||
this.shown = true;
|
||||
},
|
||||
hide: function() {
|
||||
OSRM.G.map.removeLayer(this.route);
|
||||
this.shown = false;
|
||||
},
|
||||
isShown: function() {
|
||||
return this.shown;
|
||||
},
|
||||
addRoute: function(positions) {
|
||||
var line = new L.DashedPolyline( positions );
|
||||
line.on('click', function(e) { OSRM.G.route.fire('click',e); });
|
||||
this.route.addLayer( line );
|
||||
},
|
||||
clearRoutes: function() {
|
||||
this.route.clearLayers();
|
||||
},
|
||||
setStyle: function(style) {
|
||||
this.route.invoke('setStyle', style);
|
||||
},
|
||||
toString: function() {
|
||||
return "OSRM.MultiRoute("+ this.label + ")";
|
||||
}
|
||||
});
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM GUI
|
||||
// [base GUI class, all other GUI modules extend this class]
|
||||
|
||||
|
||||
OSRM.GUI = {
|
||||
|
||||
// initialization functions of all GUI parts
|
||||
init_functions: [],
|
||||
|
||||
// init GUI
|
||||
init: function() {
|
||||
for(var i=0, size=OSRM.GUI.init_functions.length; i<size; i++) {
|
||||
OSRM.GUI.init_functions[i]();
|
||||
}
|
||||
},
|
||||
|
||||
//extend GUI class and add init functions to the array
|
||||
extend: function( properties ) {
|
||||
for( property in properties ) {
|
||||
if( property == 'init' )
|
||||
OSRM.GUI.init_functions.push( properties[property] );
|
||||
else
|
||||
OSRM.GUI[property] = properties[property];
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM MainGUI
|
||||
// [handles all GUI events that interact with appearance of main window]
|
||||
|
||||
|
||||
// OSRM GUIBoxGroup
|
||||
// [group UI boxes so that handles can be shown/hidden together]
|
||||
|
||||
OSRM.GUIBoxGroup = function() {
|
||||
this._handles = [];
|
||||
};
|
||||
|
||||
OSRM.extend( OSRM.GUIBoxGroup, {
|
||||
add: function( handle ) {
|
||||
this._handles.push( handle );
|
||||
handle.$addToGroup(this);
|
||||
},
|
||||
select: function( handle ) {
|
||||
for(var i=0; i< this._handles.length; i++) {
|
||||
if( this._handles[i] != handle )
|
||||
this._handles[i].$hideBox();
|
||||
else
|
||||
this._handles[i].$showBox();
|
||||
}
|
||||
},
|
||||
|
||||
$hide: function() {
|
||||
for(var i=0; i< this._handles.length; i++) {
|
||||
this._handles[i].$hide();
|
||||
}
|
||||
},
|
||||
$show: function() {
|
||||
for(var i=0; i< this._handles.length; i++) {
|
||||
this._handles[i].$show();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM GUIBoxHandle
|
||||
// [performs showing and hiding of UI boxes]
|
||||
|
||||
OSRM.GUIBoxHandle = function( box_name, side, css, transitionStartFct, transitionEndFct ) {
|
||||
// do not create handle if box does not contain a toggle button
|
||||
var toggle = document.getElementById( box_name + '-toggle');
|
||||
if( toggle == null ) {
|
||||
console.log("[error] No toggle button for " + box_name);
|
||||
return;
|
||||
}
|
||||
|
||||
// create handle DOM elements
|
||||
var wrapper = document.createElement('div');
|
||||
wrapper.id = box_name + '-handle-wrapper';
|
||||
wrapper.className = 'not-selectable box-wrapper box-handle-wrapper-'+side;
|
||||
wrapper.style.cssText += css;
|
||||
var content = document.createElement('div');
|
||||
content.id = box_name + '-handle-content';
|
||||
content.className = 'box-content box-handle-content-'+side;
|
||||
var icon = document.createElement('div');
|
||||
icon.id = box_name + '-handle-icon';
|
||||
icon.className = 'iconic-button';
|
||||
|
||||
content.appendChild(icon);
|
||||
wrapper.appendChild(content);
|
||||
document.body.appendChild(wrapper);
|
||||
|
||||
// create attributes
|
||||
this._box = document.getElementById( box_name + '-wrapper' );
|
||||
this._class = this._box.className;
|
||||
this._width = this._box.clientWidth;
|
||||
this._side = side;
|
||||
this._handle = wrapper;
|
||||
this._box_group = null;
|
||||
this._transitionEndFct = transitionEndFct;
|
||||
|
||||
// hide box and show handle by default
|
||||
this._box.style[this._side]=-this._width+"px";
|
||||
this._box_visible = false;
|
||||
this._handle.style.visibility="visible";
|
||||
|
||||
// add functionality
|
||||
var full_fct = transitionStartFct ? OSRM.concat(this._toggle, transitionStartFct) : this._toggle;
|
||||
var fct = OSRM.bind( this, full_fct );
|
||||
toggle.onclick = fct;
|
||||
icon.onclick = fct;
|
||||
|
||||
var full_fct = transitionEndFct ? OSRM.concat(this._onTransitionEnd, transitionEndFct) : this._onTransitionEnd;
|
||||
var fct = OSRM.bind( this, full_fct );
|
||||
if( OSRM.Browser.FF3==-1 && OSRM.Browser.IE6_9==-1 ) {
|
||||
var box_wrapper = document.getElementById(box_name + '-wrapper');
|
||||
box_wrapper.addEventListener("transitionend", fct, false);
|
||||
box_wrapper.addEventListener("webkitTransitionEnd", fct, false);
|
||||
box_wrapper.addEventListener("oTransitionEnd", fct, false);
|
||||
box_wrapper.addEventListener("MSTransitionEnd", fct, false);
|
||||
} else {
|
||||
this._legacyTransitionEndFct = fct; // legacy browser support
|
||||
}
|
||||
};
|
||||
|
||||
OSRM.extend( OSRM.GUIBoxHandle, {
|
||||
boxVisible: function() {
|
||||
return this._box_visible;
|
||||
},
|
||||
boxWidth: function() {
|
||||
return this._width;
|
||||
},
|
||||
|
||||
$addToGroup: function(group) {
|
||||
this._box_group = group;
|
||||
},
|
||||
$show: function() {
|
||||
this._handle.style.visibility="visible";
|
||||
},
|
||||
$hide: function() {
|
||||
this._handle.style.visibility="hidden";
|
||||
},
|
||||
$showBox: function() {
|
||||
this._box_visible = true;
|
||||
this._handle.style.visibility="hidden";
|
||||
this._box.style[this._side]="5px";
|
||||
this._transitionEndFct();
|
||||
},
|
||||
$hideBox: function() {
|
||||
this._box_visible = false;
|
||||
this._handle.style.visibility="visible";
|
||||
this._box.style[this._side]=-this._width+"px";
|
||||
},
|
||||
|
||||
_toggle: function() {
|
||||
this._box.className += " box-animated";
|
||||
if( this._box_visible == false ) {
|
||||
this._box_group.$hide();
|
||||
this._box.style[this._side]="5px";
|
||||
} else {
|
||||
this._box.style[this._side]=-this._width+"px";
|
||||
}
|
||||
// legacy browser support
|
||||
if( OSRM.Browser.FF3!=-1 || OSRM.Browser.IE6_9!=-1 )
|
||||
setTimeout(this._legacyTransitionEndFct, 0);
|
||||
},
|
||||
_onTransitionEnd: function() {
|
||||
this._box.className = this._class;
|
||||
if( this._box_visible == true ) {
|
||||
this._box_group.$show();
|
||||
this._box_visible = false;
|
||||
} else {
|
||||
this._box_visible = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM MainGUI
|
||||
// [handles all GUI events that interact with appearance of main window]
|
||||
|
||||
|
||||
OSRM.GUI.extend( {
|
||||
|
||||
// init GUI
|
||||
init: function() {
|
||||
// init main box
|
||||
var main_group = new OSRM.GUIBoxGroup();
|
||||
OSRM.G.main_handle = new OSRM.GUIBoxHandle("main", "left", "left:-5px;top:5px;", OSRM.GUI.beforeMainTransition, OSRM.GUI.afterMainTransition);
|
||||
main_group.add( OSRM.G.main_handle );
|
||||
main_group.select( OSRM.G.main_handle );
|
||||
|
||||
// init additional boxes
|
||||
var option_group = new OSRM.GUIBoxGroup();
|
||||
var config_handle = new OSRM.GUIBoxHandle("config", "right", "right:-5px;bottom:70px;");
|
||||
var mapping_handle = new OSRM.GUIBoxHandle("mapping", "right", "right:-5px;bottom:25px;");
|
||||
option_group.add( config_handle );
|
||||
option_group.add( mapping_handle );
|
||||
option_group.select( null );
|
||||
|
||||
// init starting source/target
|
||||
document.getElementById('gui-input-source').value = OSRM.DEFAULTS.ONLOAD_SOURCE;
|
||||
document.getElementById('gui-input-target').value = OSRM.DEFAULTS.ONLOAD_TARGET;
|
||||
|
||||
// init units selector
|
||||
OSRM.GUI.selectorInit( "gui-units-toggle", [{display:"Kilometers",value:0},{display:"Miles",value:1}], 0, OSRM.GUI.onUnitsChanged );
|
||||
|
||||
// query last update of data
|
||||
OSRM.G.data_timestamp = "n/a";
|
||||
OSRM.JSONP.call(OSRM.DEFAULTS.HOST_TIMESTAMP_URL+"?jsonp=%jsonp", OSRM.GUI.setDataTimestamp, OSRM.JSONP.empty, OSRM.DEFAULTS.JSONP_TIMEOUT, 'data_timestamp');
|
||||
},
|
||||
|
||||
// set language dependent labels
|
||||
setLabels: function() {
|
||||
document.getElementById("open-josm").innerHTML = OSRM.loc("OPEN_JOSM");
|
||||
document.getElementById("open-osmbugs").innerHTML = OSRM.loc("OPEN_OSMBUGS");
|
||||
document.getElementById("gui-reset").innerHTML = OSRM.loc("GUI_RESET");
|
||||
document.getElementById("gui-reverse").innerHTML = OSRM.loc("GUI_REVERSE");
|
||||
document.getElementById("gui-option-highlight-nonames-label").innerHTML = OSRM.loc("GUI_HIGHLIGHT_UNNAMED_ROADS");
|
||||
document.getElementById("gui-option-show-previous-routes-label").innerHTML = OSRM.loc("GUI_SHOW_PREVIOUS_ROUTES");
|
||||
document.getElementById("gui-search-source").innerHTML = OSRM.loc("GUI_SEARCH");
|
||||
document.getElementById("gui-search-target").innerHTML = OSRM.loc("GUI_SEARCH");
|
||||
document.getElementById("gui-search-source-label").innerHTML = OSRM.loc("GUI_START")+":";
|
||||
document.getElementById("gui-search-target-label").innerHTML = OSRM.loc("GUI_END")+":";
|
||||
document.getElementById("gui-input-source").title = OSRM.loc("GUI_START_TOOLTIP");
|
||||
document.getElementById("gui-input-target").title = OSRM.loc("GUI_END_TOOLTIP");
|
||||
document.getElementById("legal-notice").innerHTML = OSRM.loc("GUI_LEGAL_NOTICE");
|
||||
document.getElementById("gui-mapping-label").innerHTML = OSRM.loc("GUI_MAPPING_TOOLS");
|
||||
document.getElementById("gui-config-label").innerHTML = OSRM.loc("GUI_CONFIGURATION");
|
||||
document.getElementById("gui-language-2-label").innerHTML = OSRM.loc("GUI_LANGUAGE")+":";
|
||||
document.getElementById("gui-units-label").innerHTML = OSRM.loc("GUI_UNITS")+":";
|
||||
document.getElementById('gui-data-timestamp').innerHTML = OSRM.loc("GUI_DATA_TIMESTAMP")+": " + OSRM.G.data_timestamp;
|
||||
|
||||
document.getElementById("gui-units-toggle").getElementsByTagName("option")[0].innerHTML = OSRM.loc("GUI_KILOMETERS");
|
||||
document.getElementById("gui-units-toggle").getElementsByTagName("option")[1].innerHTML = OSRM.loc("GUI_MILES");
|
||||
OSRM.GUI.selectorOnChange( document.getElementById("gui-units-toggle") );
|
||||
},
|
||||
|
||||
// clear output area
|
||||
clearResults: function() {
|
||||
document.getElementById('information-box').innerHTML = "";
|
||||
document.getElementById('information-box-header').innerHTML = "";
|
||||
},
|
||||
|
||||
// reposition and hide zoom controls before main box animation
|
||||
beforeMainTransition: function() {
|
||||
var zoom_controls = OSRM.Browser.getElementsByClassName(document,'leaflet-control-zoom');
|
||||
if( zoom_controls.length > 0)
|
||||
zoom_controls[0].style.visibility="hidden";
|
||||
},
|
||||
|
||||
// show zoom controls after main box animation
|
||||
afterMainTransition: function() {
|
||||
var zoom_controls = OSRM.Browser.getElementsByClassName(document,'leaflet-control-zoom');
|
||||
if( zoom_controls.length > 0) {
|
||||
zoom_controls[0].style.left = ( OSRM.G.main_handle.boxVisible() == true ? (OSRM.G.main_handle.boxWidth()+10) : "30") + "px";
|
||||
zoom_controls[0].style.visibility="visible";
|
||||
}
|
||||
},
|
||||
|
||||
// toggle distance units
|
||||
onUnitsChanged: function(value) {
|
||||
OSRM.Utils.setToHumanDistanceFunction(value);
|
||||
OSRM.Routing.getRoute();
|
||||
},
|
||||
|
||||
// set timestamp of data
|
||||
setDataTimestamp: function(response) {
|
||||
if(!response)
|
||||
return;
|
||||
|
||||
OSRM.G.data_timestamp = response.timestamp.slice(0,25).replace(/<\/?[^>]+(>|$)/g ,""); // discard tags
|
||||
document.getElementById('gui-data-timestamp').innerHTML = OSRM.loc("GUI_DATA_TIMESTAMP")+": " + OSRM.G.data_timestamp;
|
||||
}
|
||||
|
||||
});
|
||||
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM RoutingGUI
|
||||
// [handles all GUI events that interact with routing in main window]
|
||||
|
||||
|
||||
OSRM.GUI.extend( {
|
||||
|
||||
// init
|
||||
init: function() {
|
||||
// init variables
|
||||
OSRM.Utils.setToHumanDistanceFunction(OSRM.DEFAULTS.DISTANCE_FORMAT);
|
||||
|
||||
// init events
|
||||
document.getElementById("gui-input-source").onchange = function() {OSRM.GUI.inputChanged(OSRM.C.SOURCE_LABEL);};
|
||||
document.getElementById("gui-delete-source").onclick = function() {OSRM.GUI.deleteMarker(OSRM.C.SOURCE_LABEL);};
|
||||
document.getElementById("gui-search-source").onclick = function() {OSRM.GUI.showMarker(OSRM.C.SOURCE_LABEL);};
|
||||
|
||||
document.getElementById("gui-input-target").onchange = function() {OSRM.GUI.inputChanged(OSRM.C.TARGET_LABEL);};
|
||||
document.getElementById("gui-delete-target").onclick = function() {OSRM.GUI.deleteMarker(OSRM.C.TARGET_LABEL);};
|
||||
document.getElementById("gui-search-target").onclick = function() {OSRM.GUI.showMarker(OSRM.C.TARGET_LABEL);};
|
||||
|
||||
document.getElementById("gui-reset").onclick = OSRM.GUI.resetRouting;
|
||||
document.getElementById("gui-reverse").onclick = OSRM.GUI.reverseRouting;
|
||||
document.getElementById("open-josm").onclick = OSRM.GUI.openJOSM;
|
||||
document.getElementById("open-osmbugs").onclick = OSRM.GUI.openOSMBugs;
|
||||
document.getElementById("option-highlight-nonames").onclick = OSRM.Routing.getRoute_Redraw;
|
||||
document.getElementById("option-show-previous-routes").onclick = OSRM.GUI.showPreviousRoutes;
|
||||
},
|
||||
|
||||
// click: button "reset"
|
||||
resetRouting: function() {
|
||||
document.getElementById('gui-input-source').value = "";
|
||||
document.getElementById('gui-input-target').value = "";
|
||||
|
||||
OSRM.G.route.reset();
|
||||
OSRM.G.markers.reset();
|
||||
|
||||
document.getElementById('information-box').innerHTML = "";
|
||||
document.getElementById('information-box-header').innerHTML = "";
|
||||
|
||||
OSRM.JSONP.reset();
|
||||
},
|
||||
|
||||
// click: button "reverse"
|
||||
reverseRouting: function() {
|
||||
// invert input boxes
|
||||
var tmp = document.getElementById("gui-input-source").value;
|
||||
document.getElementById("gui-input-source").value = document.getElementById("gui-input-target").value;
|
||||
document.getElementById("gui-input-target").value = tmp;
|
||||
|
||||
// recompute route if needed
|
||||
if( OSRM.G.route.isShown() ) {
|
||||
OSRM.G.markers.route.reverse();
|
||||
OSRM.Routing.getRoute_Reversed(); // temporary route reversal for query, actual reversal done after receiving response
|
||||
OSRM.G.markers.route.reverse();
|
||||
OSRM.G.markers.highlight.hide();
|
||||
OSRM.RoutingDescription.showSimple( OSRM.G.response );
|
||||
|
||||
// simply reverse markers
|
||||
} else {
|
||||
OSRM.G.markers.reverseMarkers();
|
||||
}
|
||||
},
|
||||
|
||||
// click: button "show"
|
||||
showMarker: function(marker_id) {
|
||||
if( OSRM.JSONP.fences["geocoder_source"] || OSRM.JSONP.fences["geocoder_target"] ) // needed when focus was on input box and user clicked on button
|
||||
return;
|
||||
|
||||
if( marker_id == OSRM.C.SOURCE_LABEL && OSRM.G.markers.hasSource() )
|
||||
OSRM.G.markers.route[0].centerView();
|
||||
else if( marker_id == OSRM.C.TARGET_LABEL && OSRM.G.markers.hasTarget() )
|
||||
OSRM.G.markers.route[OSRM.G.markers.route.length-1].centerView();
|
||||
},
|
||||
|
||||
// changed: any inputbox (is called when enter is pressed [after] or focus is lost [before])
|
||||
inputChanged: function(marker_id) {
|
||||
if( marker_id == OSRM.C.SOURCE_LABEL)
|
||||
OSRM.Geocoder.call(OSRM.C.SOURCE_LABEL, document.getElementById('gui-input-source').value);
|
||||
else if( marker_id == OSRM.C.TARGET_LABEL)
|
||||
OSRM.Geocoder.call(OSRM.C.TARGET_LABEL, document.getElementById('gui-input-target').value);
|
||||
},
|
||||
|
||||
// click: button "open JOSM"
|
||||
openJOSM: function() {
|
||||
var center = OSRM.G.map.getCenterUI();
|
||||
var bounds = OSRM.G.map.getBoundsUI();
|
||||
|
||||
var xdelta = Math.min(0.02, Math.abs(bounds.getSouthWest().lng - center.lng) );
|
||||
var ydelta = Math.min(0.01, Math.abs(bounds.getSouthWest().lat - center.lat) );
|
||||
|
||||
var p = [ 'left=' + (center.lng - xdelta).toFixed(6), 'bottom=' + (center.lat - ydelta).toFixed(6), 'right=' + (center.lng + xdelta).toFixed(6), 'top=' + (center.lat + ydelta).toFixed(6)];
|
||||
var url = 'http://127.0.0.1:8111/load_and_zoom?' + p.join('&');
|
||||
|
||||
var frame = document.getElementById('josm-frame');
|
||||
if(!frame) {
|
||||
frame = L.DomUtil.create('iframe', null, document.body);
|
||||
frame.style.display = "none";
|
||||
frame.id = 'josm-frame';
|
||||
}
|
||||
frame.src = url;
|
||||
},
|
||||
|
||||
//click: button "open OSM Bugs"
|
||||
openOSMBugs: function() {
|
||||
var position = OSRM.G.map.getCenterUI();
|
||||
window.open( "http://osmbugs.org/?lat="+position.lat.toFixed(6)+"&lon="+position.lng.toFixed(6)+"&zoom="+OSRM.G.map.getZoom() );
|
||||
},
|
||||
|
||||
//click: button "delete marker"
|
||||
deleteMarker: function(marker_id) {
|
||||
var id = null;
|
||||
if(marker_id == 'source' && OSRM.G.markers.hasSource() )
|
||||
id = 0;
|
||||
else if(marker_id == 'target' && OSRM.G.markers.hasTarget() )
|
||||
id = OSRM.G.markers.route.length-1;
|
||||
if( id == null)
|
||||
return;
|
||||
|
||||
OSRM.G.markers.removeMarker( id );
|
||||
OSRM.Routing.getRoute();
|
||||
OSRM.G.markers.highlight.hide();
|
||||
},
|
||||
|
||||
//click: checkbox "show previous routes"
|
||||
showPreviousRoutes: function(value) {
|
||||
if( document.getElementById('option-show-previous-routes').checked == false)
|
||||
OSRM.G.route.deactivateHistoryRoutes();
|
||||
else
|
||||
OSRM.G.route.activateHistoryRoutes();
|
||||
}
|
||||
|
||||
});
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM selector
|
||||
// [create special selector elements]
|
||||
|
||||
|
||||
OSRM.GUI.extend( {
|
||||
|
||||
// initialize selector with all options and our look&feel
|
||||
selectorInit: function(id, options, selected, onchange_fct) {
|
||||
// create dropdown menu
|
||||
var select = document.getElementById(id);
|
||||
select.className += " styled-select-helper base-font";
|
||||
select.onchange = function() { OSRM.GUI.selectorOnChange(this); onchange_fct(this.value); };
|
||||
|
||||
// fill dropdown menu
|
||||
for(var i=0, size=options.length; i<size; i++) {
|
||||
var option=document.createElement("option");
|
||||
option.innerHTML = options[i].display;
|
||||
option.value = options[i].value;
|
||||
select.appendChild(option);
|
||||
}
|
||||
select.value = options[selected].value;
|
||||
|
||||
// create visible dropdown menu
|
||||
var textnode = document.createTextNode( options[selected].display );
|
||||
var myspan = document.createElement("span");
|
||||
myspan.className = "styled-select base-font";
|
||||
myspan.id = "styled-select-" + select.id;
|
||||
myspan.appendChild(textnode);
|
||||
select.parentNode.insertBefore(myspan, select);
|
||||
myspan.style.width = (select.clientWidth-2)+"px";
|
||||
myspan.style.height = (select.clientHeight)+"px";
|
||||
},
|
||||
|
||||
// required behaviour of selector on change to switch shown name
|
||||
selectorOnChange: function(select) {
|
||||
var option = select.getElementsByTagName("option");
|
||||
for(var i = 0; i < option.length; i++)
|
||||
if(option[i].selected == true) {
|
||||
document.getElementById("styled-select-" + select.id).childNodes[0].nodeValue = option[i].childNodes[0].nodeValue;
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
// change selector value
|
||||
selectorChange: function(select, value) {
|
||||
select.value = value;
|
||||
OSRM.GUI.selectorOnChange(select);
|
||||
}
|
||||
|
||||
});
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 402 B |
Binary file not shown.
|
After Width: | Height: | Size: 484 B |
Binary file not shown.
|
After Width: | Height: | Size: 483 B |
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user