diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 9076864..07acdf4 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -21,14 +21,12 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Configure Python - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - name: Lint & Style Check run: | python -m pip install -r dev-requirements.txt pre-commit run --all-files --show-diff-on-failure - uses: pypa/cibuildwheel@v2.12.1 + env: + CIBW_BUILD: cp37* + MACOSX_DEPLOYMENT_TARGET: 10.15 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5ec4ac7..5c84fe0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ repos: language_version: python3 # temp exlude osrm: black fails to reformat for some reason args: [valhalla] -- repo: https://gitlab.com/pycqa/flake8 +- repo: https://github.com/pycqa/flake8 rev: 5.0.4 # pick a git hash / tag to point to hooks: - id: flake8 diff --git a/CHANGELOG.md b/CHANGELOG.md index b6d0596..b75cff2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ## Unreleased -_Valhalla version 3.3.0_ +_Valhalla version [3.4.0](https://github.com/valhalla/valhalla/releases/tag/3.4.0)_ + +## [3.2.0](https://pypi.org/project/pyvalhalla/3.2.0/) - 2023-05-16 + +_Valhalla version [3.4.0](https://github.com/valhalla/valhalla/releases/tag/3.4.0)_ ## [3.1.1](https://pypi.org/project/pyvalhalla/3.1.1/) - 2023-04-16 -_Valhalla version 3.3.0_ +_Valhalla version [3.3.0](https://github.com/valhalla/valhalla/releases/tag/3.3.0)_ ### FIXED @@ -19,7 +23,7 @@ _Valhalla version 3.3.0_ ## [3.1.0](https://pypi.org/project/pyvalhalla/3.1.0/) - 2023-04-13 -_Valhalla version 3.3.0_ +_Valhalla version [3.3.0](https://github.com/valhalla/valhalla/releases/tag/3.3.0)_ ### CHANGED @@ -32,7 +36,7 @@ _Valhalla version 3.3.0_ ## [3.0.4](https://pypi.org/project/pyvalhalla/3.0.4/) - 2023-04-12 -_Valhalla version 3.1.4_ +_Valhalla version [3.1.4](https://github.com/valhalla/valhalla/releases/tag/3.1.4)_ ### CHANGED @@ -40,7 +44,7 @@ _Valhalla version 3.1.4_ ## [3.0.3](https://pypi.org/project/pyvalhalla/3.0.3/) - 2022-09-11 -_Valhalla version 3.1.4_ +_Valhalla version [3.1.4](https://github.com/valhalla/valhalla/releases/tag/3.1.4)_ ### CHANGED @@ -48,7 +52,7 @@ _Valhalla version 3.1.4_ ## [3.0.2](https://pypi.org/project/pyvalhalla/3.0.2/) - 2022-03-10 -_Valhalla version 3.1.4_ +_Valhalla version [3.1.4](https://github.com/valhalla/valhalla/releases/tag/3.1.4)_ ### ADDED @@ -56,7 +60,7 @@ _Valhalla version 3.1.4_ ## [3.0.1](https://pypi.org/project/pyvalhalla/3.0.1/) - 2022-03-08 -_Valhalla version 3.1.4_ +_Valhalla version [3.1.4](https://github.com/valhalla/valhalla/releases/tag/3.1.4)_ ### Fixed @@ -64,6 +68,6 @@ _Valhalla version 3.1.4_ ## [3.0.0](https://pypi.org/project/pyvalhalla/3.0.0/) - 2022-03-08 -_Valhalla version 3.1.4_ +_Valhalla version [3.1.4](https://github.com/valhalla/valhalla/releases/tag/3.1.4)_ ### First release diff --git a/include/common/rapidjson/allocators.h b/include/common/rapidjson/allocators.h index 06b3420..ddcf478 100644 --- a/include/common/rapidjson/allocators.h +++ b/include/common/rapidjson/allocators.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at @@ -16,6 +16,14 @@ #define RAPIDJSON_ALLOCATORS_H_ #include "rapidjson.h" +#include "internal/meta.h" + +#include +#include + +#if RAPIDJSON_HAS_CXX11 +#include +#endif RAPIDJSON_NAMESPACE_BEGIN @@ -53,7 +61,7 @@ concept Allocator { */ -/*! \def RAPIDJSON_ALLOCATOR_DEFUALT_CHUNK_CAPACITY +/*! \def RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY \ingroup RAPIDJSON_CONFIG \brief User-defined kDefaultChunkCapacity definition. @@ -77,19 +85,26 @@ class CrtAllocator { static const bool kNeedFree = true; void* Malloc(size_t size) { if (size) // behavior of malloc(0) is implementation defined. - return std::malloc(size); + return RAPIDJSON_MALLOC(size); else return NULL; // standardize to returning NULL. } void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) { (void)originalSize; if (newSize == 0) { - std::free(originalPtr); + RAPIDJSON_FREE(originalPtr); return NULL; } - return std::realloc(originalPtr, newSize); + return RAPIDJSON_REALLOC(originalPtr, newSize); + } + static void Free(void *ptr) RAPIDJSON_NOEXCEPT { RAPIDJSON_FREE(ptr); } + + bool operator==(const CrtAllocator&) const RAPIDJSON_NOEXCEPT { + return true; + } + bool operator!=(const CrtAllocator&) const RAPIDJSON_NOEXCEPT { + return false; } - static void Free(void *ptr) { std::free(ptr); } }; /////////////////////////////////////////////////////////////////////////////// @@ -113,16 +128,64 @@ class CrtAllocator { */ template class MemoryPoolAllocator { + //! Chunk header for perpending to each chunk. + /*! Chunks are stored as a singly linked list. + */ + struct ChunkHeader { + size_t capacity; //!< Capacity of the chunk in bytes (excluding the header itself). + size_t size; //!< Current size of allocated memory in bytes. + ChunkHeader *next; //!< Next chunk in the linked list. + }; + + struct SharedData { + ChunkHeader *chunkHead; //!< Head of the chunk linked-list. Only the head chunk serves allocation. + BaseAllocator* ownBaseAllocator; //!< base allocator created by this object. + size_t refcount; + bool ownBuffer; + }; + + static const size_t SIZEOF_SHARED_DATA = RAPIDJSON_ALIGN(sizeof(SharedData)); + static const size_t SIZEOF_CHUNK_HEADER = RAPIDJSON_ALIGN(sizeof(ChunkHeader)); + + static inline ChunkHeader *GetChunkHead(SharedData *shared) + { + return reinterpret_cast(reinterpret_cast(shared) + SIZEOF_SHARED_DATA); + } + static inline uint8_t *GetChunkBuffer(SharedData *shared) + { + return reinterpret_cast(shared->chunkHead) + SIZEOF_CHUNK_HEADER; + } + + static const size_t kDefaultChunkCapacity = RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY; //!< Default chunk capacity. + public: static const bool kNeedFree = false; //!< Tell users that no need to call Free() with this allocator. (concept Allocator) + static const bool kRefCounted = true; //!< Tell users that this allocator is reference counted on copy //! Constructor with chunkSize. /*! \param chunkSize The size of memory chunk. The default is kDefaultChunkSize. \param baseAllocator The allocator for allocating memory chunks. */ + explicit MemoryPoolAllocator(size_t chunkSize = kDefaultChunkCapacity, BaseAllocator* baseAllocator = 0) : - chunkHead_(0), chunk_capacity_(chunkSize), userBuffer_(0), baseAllocator_(baseAllocator), ownBaseAllocator_(0) + chunk_capacity_(chunkSize), + baseAllocator_(baseAllocator ? baseAllocator : RAPIDJSON_NEW(BaseAllocator)()), + shared_(static_cast(baseAllocator_ ? baseAllocator_->Malloc(SIZEOF_SHARED_DATA + SIZEOF_CHUNK_HEADER) : 0)) { + RAPIDJSON_ASSERT(baseAllocator_ != 0); + RAPIDJSON_ASSERT(shared_ != 0); + if (baseAllocator) { + shared_->ownBaseAllocator = 0; + } + else { + shared_->ownBaseAllocator = baseAllocator_; + } + shared_->chunkHead = GetChunkHead(shared_); + shared_->chunkHead->capacity = 0; + shared_->chunkHead->size = 0; + shared_->chunkHead->next = 0; + shared_->ownBuffer = true; + shared_->refcount = 1; } //! Constructor with user-supplied buffer. @@ -136,41 +199,101 @@ class MemoryPoolAllocator { \param baseAllocator The allocator for allocating memory chunks. */ MemoryPoolAllocator(void *buffer, size_t size, size_t chunkSize = kDefaultChunkCapacity, BaseAllocator* baseAllocator = 0) : - chunkHead_(0), chunk_capacity_(chunkSize), userBuffer_(buffer), baseAllocator_(baseAllocator), ownBaseAllocator_(0) + chunk_capacity_(chunkSize), + baseAllocator_(baseAllocator), + shared_(static_cast(AlignBuffer(buffer, size))) + { + RAPIDJSON_ASSERT(size >= SIZEOF_SHARED_DATA + SIZEOF_CHUNK_HEADER); + shared_->chunkHead = GetChunkHead(shared_); + shared_->chunkHead->capacity = size - SIZEOF_SHARED_DATA - SIZEOF_CHUNK_HEADER; + shared_->chunkHead->size = 0; + shared_->chunkHead->next = 0; + shared_->ownBaseAllocator = 0; + shared_->ownBuffer = false; + shared_->refcount = 1; + } + + MemoryPoolAllocator(const MemoryPoolAllocator& rhs) RAPIDJSON_NOEXCEPT : + chunk_capacity_(rhs.chunk_capacity_), + baseAllocator_(rhs.baseAllocator_), + shared_(rhs.shared_) + { + RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0); + ++shared_->refcount; + } + MemoryPoolAllocator& operator=(const MemoryPoolAllocator& rhs) RAPIDJSON_NOEXCEPT { - RAPIDJSON_ASSERT(buffer != 0); - RAPIDJSON_ASSERT(size > sizeof(ChunkHeader)); - chunkHead_ = reinterpret_cast(buffer); - chunkHead_->capacity = size - sizeof(ChunkHeader); - chunkHead_->size = 0; - chunkHead_->next = 0; + RAPIDJSON_NOEXCEPT_ASSERT(rhs.shared_->refcount > 0); + ++rhs.shared_->refcount; + this->~MemoryPoolAllocator(); + baseAllocator_ = rhs.baseAllocator_; + chunk_capacity_ = rhs.chunk_capacity_; + shared_ = rhs.shared_; + return *this; } +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS + MemoryPoolAllocator(MemoryPoolAllocator&& rhs) RAPIDJSON_NOEXCEPT : + chunk_capacity_(rhs.chunk_capacity_), + baseAllocator_(rhs.baseAllocator_), + shared_(rhs.shared_) + { + RAPIDJSON_NOEXCEPT_ASSERT(rhs.shared_->refcount > 0); + rhs.shared_ = 0; + } + MemoryPoolAllocator& operator=(MemoryPoolAllocator&& rhs) RAPIDJSON_NOEXCEPT + { + RAPIDJSON_NOEXCEPT_ASSERT(rhs.shared_->refcount > 0); + this->~MemoryPoolAllocator(); + baseAllocator_ = rhs.baseAllocator_; + chunk_capacity_ = rhs.chunk_capacity_; + shared_ = rhs.shared_; + rhs.shared_ = 0; + return *this; + } +#endif + //! Destructor. /*! This deallocates all memory chunks, excluding the user-supplied buffer. */ - ~MemoryPoolAllocator() { + ~MemoryPoolAllocator() RAPIDJSON_NOEXCEPT { + if (!shared_) { + // do nothing if moved + return; + } + if (shared_->refcount > 1) { + --shared_->refcount; + return; + } Clear(); - RAPIDJSON_DELETE(ownBaseAllocator_); + BaseAllocator *a = shared_->ownBaseAllocator; + if (shared_->ownBuffer) { + baseAllocator_->Free(shared_); + } + RAPIDJSON_DELETE(a); } - //! Deallocates all memory chunks, excluding the user-supplied buffer. - void Clear() { - while (chunkHead_ && chunkHead_ != userBuffer_) { - ChunkHeader* next = chunkHead_->next; - baseAllocator_->Free(chunkHead_); - chunkHead_ = next; + //! Deallocates all memory chunks, excluding the first/user one. + void Clear() RAPIDJSON_NOEXCEPT { + RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0); + for (;;) { + ChunkHeader* c = shared_->chunkHead; + if (!c->next) { + break; + } + shared_->chunkHead = c->next; + baseAllocator_->Free(c); } - if (chunkHead_ && chunkHead_ == userBuffer_) - chunkHead_->size = 0; // Clear user buffer + shared_->chunkHead->size = 0; } //! Computes the total capacity of allocated memory chunks. /*! \return total capacity in bytes. */ - size_t Capacity() const { + size_t Capacity() const RAPIDJSON_NOEXCEPT { + RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0); size_t capacity = 0; - for (ChunkHeader* c = chunkHead_; c != 0; c = c->next) + for (ChunkHeader* c = shared_->chunkHead; c != 0; c = c->next) capacity += c->capacity; return capacity; } @@ -178,25 +301,35 @@ class MemoryPoolAllocator { //! Computes the memory blocks allocated. /*! \return total used bytes. */ - size_t Size() const { + size_t Size() const RAPIDJSON_NOEXCEPT { + RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0); size_t size = 0; - for (ChunkHeader* c = chunkHead_; c != 0; c = c->next) + for (ChunkHeader* c = shared_->chunkHead; c != 0; c = c->next) size += c->size; return size; } + //! Whether the allocator is shared. + /*! \return true or false. + */ + bool Shared() const RAPIDJSON_NOEXCEPT { + RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0); + return shared_->refcount > 1; + } + //! Allocates a memory block. (concept Allocator) void* Malloc(size_t size) { + RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0); if (!size) return NULL; size = RAPIDJSON_ALIGN(size); - if (chunkHead_ == 0 || chunkHead_->size + size > chunkHead_->capacity) + if (RAPIDJSON_UNLIKELY(shared_->chunkHead->size + size > shared_->chunkHead->capacity)) if (!AddChunk(chunk_capacity_ > size ? chunk_capacity_ : size)) return NULL; - void *buffer = reinterpret_cast(chunkHead_) + RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + chunkHead_->size; - chunkHead_->size += size; + void *buffer = GetChunkBuffer(shared_) + shared_->chunkHead->size; + shared_->chunkHead->size += size; return buffer; } @@ -205,6 +338,7 @@ class MemoryPoolAllocator { if (originalPtr == 0) return Malloc(newSize); + RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0); if (newSize == 0) return NULL; @@ -216,10 +350,10 @@ class MemoryPoolAllocator { return originalPtr; // Simply expand it if it is the last allocation and there is sufficient space - if (originalPtr == reinterpret_cast(chunkHead_) + RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + chunkHead_->size - originalSize) { + if (originalPtr == GetChunkBuffer(shared_) + shared_->chunkHead->size - originalSize) { size_t increment = static_cast(newSize - originalSize); - if (chunkHead_->size + increment <= chunkHead_->capacity) { - chunkHead_->size += increment; + if (shared_->chunkHead->size + increment <= shared_->chunkHead->capacity) { + shared_->chunkHead->size += increment; return originalPtr; } } @@ -235,50 +369,325 @@ class MemoryPoolAllocator { } //! Frees a memory block (concept Allocator) - static void Free(void *ptr) { (void)ptr; } // Do nothing + static void Free(void *ptr) RAPIDJSON_NOEXCEPT { (void)ptr; } // Do nothing -private: - //! Copy constructor is not permitted. - MemoryPoolAllocator(const MemoryPoolAllocator& rhs) /* = delete */; - //! Copy assignment operator is not permitted. - MemoryPoolAllocator& operator=(const MemoryPoolAllocator& rhs) /* = delete */; + //! Compare (equality) with another MemoryPoolAllocator + bool operator==(const MemoryPoolAllocator& rhs) const RAPIDJSON_NOEXCEPT { + RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0); + RAPIDJSON_NOEXCEPT_ASSERT(rhs.shared_->refcount > 0); + return shared_ == rhs.shared_; + } + //! Compare (inequality) with another MemoryPoolAllocator + bool operator!=(const MemoryPoolAllocator& rhs) const RAPIDJSON_NOEXCEPT { + return !operator==(rhs); + } +private: //! Creates a new chunk. /*! \param capacity Capacity of the chunk in bytes. \return true if success. */ bool AddChunk(size_t capacity) { if (!baseAllocator_) - ownBaseAllocator_ = baseAllocator_ = RAPIDJSON_NEW(BaseAllocator)(); - if (ChunkHeader* chunk = reinterpret_cast(baseAllocator_->Malloc(RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + capacity))) { + shared_->ownBaseAllocator = baseAllocator_ = RAPIDJSON_NEW(BaseAllocator)(); + if (ChunkHeader* chunk = static_cast(baseAllocator_->Malloc(SIZEOF_CHUNK_HEADER + capacity))) { chunk->capacity = capacity; chunk->size = 0; - chunk->next = chunkHead_; - chunkHead_ = chunk; + chunk->next = shared_->chunkHead; + shared_->chunkHead = chunk; return true; } else return false; } - static const int kDefaultChunkCapacity = RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY; //!< Default chunk capacity. - - //! Chunk header for perpending to each chunk. - /*! Chunks are stored as a singly linked list. - */ - struct ChunkHeader { - size_t capacity; //!< Capacity of the chunk in bytes (excluding the header itself). - size_t size; //!< Current size of allocated memory in bytes. - ChunkHeader *next; //!< Next chunk in the linked list. - }; + static inline void* AlignBuffer(void* buf, size_t &size) + { + RAPIDJSON_NOEXCEPT_ASSERT(buf != 0); + const uintptr_t mask = sizeof(void*) - 1; + const uintptr_t ubuf = reinterpret_cast(buf); + if (RAPIDJSON_UNLIKELY(ubuf & mask)) { + const uintptr_t abuf = (ubuf + mask) & ~mask; + RAPIDJSON_ASSERT(size >= abuf - ubuf); + buf = reinterpret_cast(abuf); + size -= abuf - ubuf; + } + return buf; + } - ChunkHeader *chunkHead_; //!< Head of the chunk linked-list. Only the head chunk serves allocation. size_t chunk_capacity_; //!< The minimum capacity of chunk when they are allocated. - void *userBuffer_; //!< User supplied buffer. BaseAllocator* baseAllocator_; //!< base allocator for allocating memory chunks. - BaseAllocator* ownBaseAllocator_; //!< base allocator created by this object. + SharedData *shared_; //!< The shared data of the allocator }; +namespace internal { + template + struct IsRefCounted : + public FalseType + { }; + template + struct IsRefCounted::Type> : + public TrueType + { }; +} + +template +inline T* Realloc(A& a, T* old_p, size_t old_n, size_t new_n) +{ + RAPIDJSON_NOEXCEPT_ASSERT(old_n <= std::numeric_limits::max() / sizeof(T) && new_n <= std::numeric_limits::max() / sizeof(T)); + return static_cast(a.Realloc(old_p, old_n * sizeof(T), new_n * sizeof(T))); +} + +template +inline T *Malloc(A& a, size_t n = 1) +{ + return Realloc(a, NULL, 0, n); +} + +template +inline void Free(A& a, T *p, size_t n = 1) +{ + static_cast(Realloc(a, p, n, 0)); +} + +#ifdef __GNUC__ +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(effc++) // std::allocator can safely be inherited +#endif + +template +class StdAllocator : + public std::allocator +{ + typedef std::allocator allocator_type; +#if RAPIDJSON_HAS_CXX11 + typedef std::allocator_traits traits_type; +#else + typedef allocator_type traits_type; +#endif + +public: + typedef BaseAllocator BaseAllocatorType; + + StdAllocator() RAPIDJSON_NOEXCEPT : + allocator_type(), + baseAllocator_() + { } + + StdAllocator(const StdAllocator& rhs) RAPIDJSON_NOEXCEPT : + allocator_type(rhs), + baseAllocator_(rhs.baseAllocator_) + { } + + template + StdAllocator(const StdAllocator& rhs) RAPIDJSON_NOEXCEPT : + allocator_type(rhs), + baseAllocator_(rhs.baseAllocator_) + { } + +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS + StdAllocator(StdAllocator&& rhs) RAPIDJSON_NOEXCEPT : + allocator_type(std::move(rhs)), + baseAllocator_(std::move(rhs.baseAllocator_)) + { } +#endif +#if RAPIDJSON_HAS_CXX11 + using propagate_on_container_move_assignment = std::true_type; + using propagate_on_container_swap = std::true_type; +#endif + + /* implicit */ + StdAllocator(const BaseAllocator& allocator) RAPIDJSON_NOEXCEPT : + allocator_type(), + baseAllocator_(allocator) + { } + + ~StdAllocator() RAPIDJSON_NOEXCEPT + { } + + template + struct rebind { + typedef StdAllocator other; + }; + + typedef typename traits_type::size_type size_type; + typedef typename traits_type::difference_type difference_type; + + typedef typename traits_type::value_type value_type; + typedef typename traits_type::pointer pointer; + typedef typename traits_type::const_pointer const_pointer; + +#if RAPIDJSON_HAS_CXX11 + + typedef typename std::add_lvalue_reference::type &reference; + typedef typename std::add_lvalue_reference::type>::type &const_reference; + + pointer address(reference r) const RAPIDJSON_NOEXCEPT + { + return std::addressof(r); + } + const_pointer address(const_reference r) const RAPIDJSON_NOEXCEPT + { + return std::addressof(r); + } + + size_type max_size() const RAPIDJSON_NOEXCEPT + { + return traits_type::max_size(*this); + } + + template + void construct(pointer p, Args&&... args) + { + traits_type::construct(*this, p, std::forward(args)...); + } + void destroy(pointer p) + { + traits_type::destroy(*this, p); + } + +#else // !RAPIDJSON_HAS_CXX11 + + typedef typename allocator_type::reference reference; + typedef typename allocator_type::const_reference const_reference; + + pointer address(reference r) const RAPIDJSON_NOEXCEPT + { + return allocator_type::address(r); + } + const_pointer address(const_reference r) const RAPIDJSON_NOEXCEPT + { + return allocator_type::address(r); + } + + size_type max_size() const RAPIDJSON_NOEXCEPT + { + return allocator_type::max_size(); + } + + void construct(pointer p, const_reference r) + { + allocator_type::construct(p, r); + } + void destroy(pointer p) + { + allocator_type::destroy(p); + } + +#endif // !RAPIDJSON_HAS_CXX11 + + template + U* allocate(size_type n = 1, const void* = 0) + { + return RAPIDJSON_NAMESPACE::Malloc(baseAllocator_, n); + } + template + void deallocate(U* p, size_type n = 1) + { + RAPIDJSON_NAMESPACE::Free(baseAllocator_, p, n); + } + + pointer allocate(size_type n = 1, const void* = 0) + { + return allocate(n); + } + void deallocate(pointer p, size_type n = 1) + { + deallocate(p, n); + } + +#if RAPIDJSON_HAS_CXX11 + using is_always_equal = std::is_empty; +#endif + + template + bool operator==(const StdAllocator& rhs) const RAPIDJSON_NOEXCEPT + { + return baseAllocator_ == rhs.baseAllocator_; + } + template + bool operator!=(const StdAllocator& rhs) const RAPIDJSON_NOEXCEPT + { + return !operator==(rhs); + } + + //! rapidjson Allocator concept + static const bool kNeedFree = BaseAllocator::kNeedFree; + static const bool kRefCounted = internal::IsRefCounted::Value; + void* Malloc(size_t size) + { + return baseAllocator_.Malloc(size); + } + void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) + { + return baseAllocator_.Realloc(originalPtr, originalSize, newSize); + } + static void Free(void *ptr) RAPIDJSON_NOEXCEPT + { + BaseAllocator::Free(ptr); + } + +private: + template + friend class StdAllocator; // access to StdAllocator.* + + BaseAllocator baseAllocator_; +}; + +#if !RAPIDJSON_HAS_CXX17 // std::allocator deprecated in C++17 +template +class StdAllocator : + public std::allocator +{ + typedef std::allocator allocator_type; + +public: + typedef BaseAllocator BaseAllocatorType; + + StdAllocator() RAPIDJSON_NOEXCEPT : + allocator_type(), + baseAllocator_() + { } + + StdAllocator(const StdAllocator& rhs) RAPIDJSON_NOEXCEPT : + allocator_type(rhs), + baseAllocator_(rhs.baseAllocator_) + { } + + template + StdAllocator(const StdAllocator& rhs) RAPIDJSON_NOEXCEPT : + allocator_type(rhs), + baseAllocator_(rhs.baseAllocator_) + { } + + /* implicit */ + StdAllocator(const BaseAllocator& baseAllocator) RAPIDJSON_NOEXCEPT : + allocator_type(), + baseAllocator_(baseAllocator) + { } + + ~StdAllocator() RAPIDJSON_NOEXCEPT + { } + + template + struct rebind { + typedef StdAllocator other; + }; + + typedef typename allocator_type::value_type value_type; + +private: + template + friend class StdAllocator; // access to StdAllocator.* + + BaseAllocator baseAllocator_; +}; +#endif + +#ifdef __GNUC__ +RAPIDJSON_DIAG_POP +#endif + RAPIDJSON_NAMESPACE_END #endif // RAPIDJSON_ENCODINGS_H_ diff --git a/include/common/rapidjson/cursorstreamwrapper.h b/include/common/rapidjson/cursorstreamwrapper.h index 52c11a7..fd6513d 100644 --- a/include/common/rapidjson/cursorstreamwrapper.h +++ b/include/common/rapidjson/cursorstreamwrapper.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at diff --git a/include/common/rapidjson/document.h b/include/common/rapidjson/document.h index bf9e6fd..2cd9a70 100644 --- a/include/common/rapidjson/document.h +++ b/include/common/rapidjson/document.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at @@ -24,6 +24,9 @@ #include "encodedstream.h" #include // placement new #include +#ifdef __cpp_lib_three_way_comparison +#include +#endif RAPIDJSON_DIAG_PUSH #ifdef __clang__ @@ -37,17 +40,23 @@ RAPIDJSON_DIAG_OFF(4244) // conversion from kXxxFlags to 'uint16_t', possible lo #ifdef __GNUC__ RAPIDJSON_DIAG_OFF(effc++) -#if __GNUC__ >= 6 -RAPIDJSON_DIAG_OFF(terminate) // ignore throwing RAPIDJSON_ASSERT in RAPIDJSON_NOEXCEPT functions -#endif #endif // __GNUC__ +#ifdef GetObject +// see https://github.com/Tencent/rapidjson/issues/1448 +// a former included windows.h might have defined a macro called GetObject, which affects +// GetObject defined here. This ensures the macro does not get applied +#pragma push_macro("GetObject") +#define RAPIDJSON_WINDOWS_GETOBJECT_WORKAROUND_APPLIED +#undef GetObject +#endif + #ifndef RAPIDJSON_NOMEMBERITERATORCLASS #include // std::random_access_iterator_tag #endif -#if RAPIDJSON_HAS_CXX11_RVALUE_REFS -#include // std::move +#if RAPIDJSON_USE_MEMBERSMAP +#include // std::multimap #endif RAPIDJSON_NAMESPACE_BEGIN @@ -59,6 +68,48 @@ class GenericValue; template class GenericDocument; +/*! \def RAPIDJSON_DEFAULT_ALLOCATOR + \ingroup RAPIDJSON_CONFIG + \brief Allows to choose default allocator. + + User can define this to use CrtAllocator or MemoryPoolAllocator. +*/ +#ifndef RAPIDJSON_DEFAULT_ALLOCATOR +#define RAPIDJSON_DEFAULT_ALLOCATOR ::RAPIDJSON_NAMESPACE::MemoryPoolAllocator<::RAPIDJSON_NAMESPACE::CrtAllocator> +#endif + +/*! \def RAPIDJSON_DEFAULT_STACK_ALLOCATOR + \ingroup RAPIDJSON_CONFIG + \brief Allows to choose default stack allocator for Document. + + User can define this to use CrtAllocator or MemoryPoolAllocator. +*/ +#ifndef RAPIDJSON_DEFAULT_STACK_ALLOCATOR +#define RAPIDJSON_DEFAULT_STACK_ALLOCATOR ::RAPIDJSON_NAMESPACE::CrtAllocator +#endif + +/*! \def RAPIDJSON_VALUE_DEFAULT_OBJECT_CAPACITY + \ingroup RAPIDJSON_CONFIG + \brief User defined kDefaultObjectCapacity value. + + User can define this as any natural number. +*/ +#ifndef RAPIDJSON_VALUE_DEFAULT_OBJECT_CAPACITY +// number of objects that rapidjson::Value allocates memory for by default +#define RAPIDJSON_VALUE_DEFAULT_OBJECT_CAPACITY 16 +#endif + +/*! \def RAPIDJSON_VALUE_DEFAULT_ARRAY_CAPACITY + \ingroup RAPIDJSON_CONFIG + \brief User defined kDefaultArrayCapacity value. + + User can define this as any natural number. +*/ +#ifndef RAPIDJSON_VALUE_DEFAULT_ARRAY_CAPACITY +// number of array elements that rapidjson::Value allocates memory for by default +#define RAPIDJSON_VALUE_DEFAULT_ARRAY_CAPACITY 16 +#endif + //! Name-value pair in a JSON object value. /*! This class was internal to GenericValue. It used to be a inner struct. @@ -66,9 +117,45 @@ class GenericDocument; https://code.google.com/p/rapidjson/issues/detail?id=64 */ template -struct GenericMember { +class GenericMember { +public: GenericValue name; //!< name of member (must be a string) GenericValue value; //!< value of member. + +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS + //! Move constructor in C++11 + GenericMember(GenericMember&& rhs) RAPIDJSON_NOEXCEPT + : name(std::move(rhs.name)), + value(std::move(rhs.value)) + { + } + + //! Move assignment in C++11 + GenericMember& operator=(GenericMember&& rhs) RAPIDJSON_NOEXCEPT { + return *this = static_cast(rhs); + } +#endif + + //! Assignment with move semantics. + /*! \param rhs Source of the assignment. Its name and value will become a null value after assignment. + */ + GenericMember& operator=(GenericMember& rhs) RAPIDJSON_NOEXCEPT { + if (RAPIDJSON_LIKELY(this != &rhs)) { + name = rhs.name; + value = rhs.value; + } + return *this; + } + + // swap() for std::sort() and other potential use in STL. + friend inline void swap(GenericMember& a, GenericMember& b) RAPIDJSON_NOEXCEPT { + a.name.Swap(b.name); + a.value.Swap(b.value); + } + +private: + //! Copy constructor is not permitted. + GenericMember(const GenericMember& rhs); }; /////////////////////////////////////////////////////////////////////////////// @@ -172,12 +259,16 @@ class GenericMemberIterator { //! @name relations //@{ - bool operator==(ConstIterator that) const { return ptr_ == that.ptr_; } - bool operator!=(ConstIterator that) const { return ptr_ != that.ptr_; } - bool operator<=(ConstIterator that) const { return ptr_ <= that.ptr_; } - bool operator>=(ConstIterator that) const { return ptr_ >= that.ptr_; } - bool operator< (ConstIterator that) const { return ptr_ < that.ptr_; } - bool operator> (ConstIterator that) const { return ptr_ > that.ptr_; } + template bool operator==(const GenericMemberIterator& that) const { return ptr_ == that.ptr_; } + template bool operator!=(const GenericMemberIterator& that) const { return ptr_ != that.ptr_; } + template bool operator<=(const GenericMemberIterator& that) const { return ptr_ <= that.ptr_; } + template bool operator>=(const GenericMemberIterator& that) const { return ptr_ >= that.ptr_; } + template bool operator< (const GenericMemberIterator& that) const { return ptr_ < that.ptr_; } + template bool operator> (const GenericMemberIterator& that) const { return ptr_ > that.ptr_; } + +#ifdef __cpp_lib_three_way_comparison + template std::strong_ordering operator<=>(const GenericMemberIterator& that) const { return ptr_ <=> that.ptr_; } +#endif //@} //! @name dereference @@ -202,17 +293,19 @@ class GenericMemberIterator { // class-based member iterator implementation disabled, use plain pointers template -struct GenericMemberIterator; +class GenericMemberIterator; //! non-const GenericMemberIterator template -struct GenericMemberIterator { +class GenericMemberIterator { +public: //! use plain pointer as iterator type typedef GenericMember* Iterator; }; //! const GenericMemberIterator template -struct GenericMemberIterator { +class GenericMemberIterator { +public: //! use plain const pointer as iterator type typedef const GenericMember* Iterator; }; @@ -571,7 +664,7 @@ template class GenericObject; \tparam Encoding Encoding of the value. (Even non-string values need to have the same encoding in a document) \tparam Allocator Allocator type for allocating memory of object, array and string. */ -template > +template class GenericValue { public: //! Name-value pair in an object. @@ -625,11 +718,11 @@ class GenericValue { \note Default content for number is zero. */ explicit GenericValue(Type type) RAPIDJSON_NOEXCEPT : data_() { - static const uint16_t defaultFlags[7] = { + static const uint16_t defaultFlags[] = { kNullFlag, kFalseFlag, kTrueFlag, kObjectFlag, kArrayFlag, kShortStringFlag, kNumberAnyFlag }; - RAPIDJSON_ASSERT(type >= kNullType && type <= kNumberType); + RAPIDJSON_NOEXCEPT_ASSERT(type >= kNullType && type <= kNumberType); data_.f.flags = defaultFlags[type]; // Use ShortString to store empty string. @@ -648,18 +741,8 @@ class GenericValue { template GenericValue(const GenericValue& rhs, Allocator& allocator, bool copyConstStrings = false) { switch (rhs.GetType()) { - case kObjectType: { - SizeType count = rhs.data_.o.size; - Member* lm = reinterpret_cast(allocator.Malloc(count * sizeof(Member))); - const typename GenericValue::Member* rm = rhs.GetMembersPointer(); - for (SizeType i = 0; i < count; i++) { - new (&lm[i].name) GenericValue(rm[i].name, allocator, copyConstStrings); - new (&lm[i].value) GenericValue(rm[i].value, allocator, copyConstStrings); - } - data_.f.flags = kObjectFlag; - data_.o.size = data_.o.capacity = count; - SetMembersPointer(lm); - } + case kObjectType: + DoCopyMembers(rhs, allocator, copyConstStrings); break; case kArrayType: { SizeType count = rhs.data_.a.size; @@ -795,25 +878,30 @@ class GenericValue { /*! Need to destruct elements of array, members of object, or copy-string. */ ~GenericValue() { - if (Allocator::kNeedFree) { // Shortcut by Allocator's trait + // With RAPIDJSON_USE_MEMBERSMAP, the maps need to be destroyed to release + // their Allocator if it's refcounted (e.g. MemoryPoolAllocator). + if (Allocator::kNeedFree || (RAPIDJSON_USE_MEMBERSMAP+0 && + internal::IsRefCounted::Value)) { switch(data_.f.flags) { case kArrayFlag: { GenericValue* e = GetElementsPointer(); for (GenericValue* v = e; v != e + data_.a.size; ++v) v->~GenericValue(); - Allocator::Free(e); + if (Allocator::kNeedFree) { // Shortcut by Allocator's trait + Allocator::Free(e); + } } break; case kObjectFlag: - for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m) - m->~Member(); - Allocator::Free(GetMembersPointer()); + DoFreeMembers(); break; case kCopyStringFlag: - Allocator::Free(const_cast(GetStringPointer())); + if (Allocator::kNeedFree) { // Shortcut by Allocator's trait + Allocator::Free(const_cast(GetStringPointer())); + } break; default: @@ -831,9 +919,15 @@ class GenericValue { /*! \param rhs Source of the assignment. It will become a null value after assignment. */ GenericValue& operator=(GenericValue& rhs) RAPIDJSON_NOEXCEPT { - RAPIDJSON_ASSERT(this != &rhs); - this->~GenericValue(); - RawAssign(rhs); + if (RAPIDJSON_LIKELY(this != &rhs)) { + // Can't destroy "this" before assigning "rhs", otherwise "rhs" + // could be used after free if it's an sub-Value of "this", + // hence the temporary danse. + GenericValue temp; + temp.RawAssign(rhs); + this->~GenericValue(); + RawAssign(temp); + } return *this; } @@ -925,7 +1019,7 @@ class GenericValue { //! Equal-to operator /*! \note If an object contains duplicated named member, comparing equality with any object is always \c false. - \note Linear time complexity (number of all values in the subtree and total lengths of all strings). + \note Complexity is quadratic in Object's member number and linear for the rest (number of all values in the subtree and total lengths of all strings). */ template bool operator==(const GenericValue& rhs) const { @@ -984,6 +1078,7 @@ class GenericValue { */ template RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr,internal::IsGenericValue >), (bool)) operator==(const T& rhs) const { return *this == GenericValue(rhs); } +#ifndef __cpp_impl_three_way_comparison //! Not-equal-to operator /*! \return !(*this == rhs) */ @@ -1008,6 +1103,7 @@ class GenericValue { */ template friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue), (bool)) operator!=(const T& lhs, const GenericValue& rhs) { return !(rhs == lhs); } //@} +#endif //!@name Type //@{ @@ -1134,13 +1230,28 @@ class GenericValue { else { RAPIDJSON_ASSERT(false); // see above note - // This will generate -Wexit-time-destructors in clang - // static GenericValue NullValue; - // return NullValue; - - // Use static buffer and placement-new to prevent destruction - static char buffer[sizeof(GenericValue)]; +#if RAPIDJSON_HAS_CXX11 + // Use thread-local storage to prevent races between threads. + // Use static buffer and placement-new to prevent destruction, with + // alignas() to ensure proper alignment. + alignas(GenericValue) thread_local static char buffer[sizeof(GenericValue)]; return *new (buffer) GenericValue(); +#elif defined(_MSC_VER) && _MSC_VER < 1900 + // There's no way to solve both thread locality and proper alignment + // simultaneously. + __declspec(thread) static char buffer[sizeof(GenericValue)]; + return *new (buffer) GenericValue(); +#elif defined(__GNUC__) || defined(__clang__) + // This will generate -Wexit-time-destructors in clang, but that's + // better than having under-alignment. + __thread static GenericValue buffer; + return buffer; +#else + // Don't know what compiler this is, so don't know how to ensure + // thread-locality. + static GenericValue buffer; + return buffer; +#endif } } template @@ -1173,10 +1284,7 @@ class GenericValue { */ GenericValue& MemberReserve(SizeType newCapacity, Allocator &allocator) { RAPIDJSON_ASSERT(IsObject()); - if (newCapacity > data_.o.capacity) { - SetMembersPointer(reinterpret_cast(allocator.Realloc(GetMembersPointer(), data_.o.capacity * sizeof(Member), newCapacity * sizeof(Member)))); - data_.o.capacity = newCapacity; - } + DoReserveMembers(newCapacity, allocator); return *this; } @@ -1250,11 +1358,7 @@ class GenericValue { MemberIterator FindMember(const GenericValue& name) { RAPIDJSON_ASSERT(IsObject()); RAPIDJSON_ASSERT(name.IsString()); - MemberIterator member = MemberBegin(); - for ( ; member != MemberEnd(); ++member) - if (name.StringEqual(member->name)) - break; - return member; + return DoFindMember(name); } template ConstMemberIterator FindMember(const GenericValue& name) const { return const_cast(*this).FindMember(name); } @@ -1283,14 +1387,7 @@ class GenericValue { GenericValue& AddMember(GenericValue& name, GenericValue& value, Allocator& allocator) { RAPIDJSON_ASSERT(IsObject()); RAPIDJSON_ASSERT(name.IsString()); - - ObjectData& o = data_.o; - if (o.size >= o.capacity) - MemberReserve(o.capacity == 0 ? kDefaultObjectCapacity : (o.capacity + (o.capacity + 1) / 2), allocator); - Member* members = GetMembersPointer(); - members[o.size].name.RawAssign(name); - members[o.size].value.RawAssign(value); - o.size++; + DoAddMember(name, value, allocator); return *this; } @@ -1424,9 +1521,7 @@ class GenericValue { */ void RemoveAllMembers() { RAPIDJSON_ASSERT(IsObject()); - for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m) - m->~Member(); - data_.o.size = 0; + DoClearMembers(); } //! Remove a member in object by its name. @@ -1470,14 +1565,7 @@ class GenericValue { RAPIDJSON_ASSERT(data_.o.size > 0); RAPIDJSON_ASSERT(GetMembersPointer() != 0); RAPIDJSON_ASSERT(m >= MemberBegin() && m < MemberEnd()); - - MemberIterator last(GetMembersPointer() + (data_.o.size - 1)); - if (data_.o.size > 1 && m != last) - *m = *last; // Move the last one to this place - else - m->~Member(); // Only one left, just destroy - --data_.o.size; - return m; + return DoRemoveMember(m); } //! Remove a member from an object by iterator. @@ -1509,13 +1597,7 @@ class GenericValue { RAPIDJSON_ASSERT(first >= MemberBegin()); RAPIDJSON_ASSERT(first <= last); RAPIDJSON_ASSERT(last <= MemberEnd()); - - MemberIterator pos = MemberBegin() + (first - MemberBegin()); - for (MemberIterator itr = pos; itr != last; ++itr) - itr->~Member(); - std::memmove(static_cast(&*pos), &*last, static_cast(MemberEnd() - last) * sizeof(Member)); - data_.o.size -= static_cast(last - first); - return pos; + return DoEraseMembers(first, last); } //! Erase a member in object by its name. @@ -1544,7 +1626,9 @@ class GenericValue { } Object GetObject() { RAPIDJSON_ASSERT(IsObject()); return Object(*this); } + Object GetObj() { RAPIDJSON_ASSERT(IsObject()); return Object(*this); } ConstObject GetObject() const { RAPIDJSON_ASSERT(IsObject()); return ConstObject(*this); } + ConstObject GetObj() const { RAPIDJSON_ASSERT(IsObject()); return ConstObject(*this); } //@} @@ -1766,12 +1850,12 @@ class GenericValue { //!@name String //@{ - const Ch* GetString() const { RAPIDJSON_ASSERT(IsString()); return (data_.f.flags & kInlineStrFlag) ? data_.ss.str : GetStringPointer(); } + const Ch* GetString() const { RAPIDJSON_ASSERT(IsString()); return DataString(data_); } //! Get the length of string. /*! Since rapidjson permits "\\u0000" in the json string, strlen(v.GetString()) may not equal to v.GetStringLength(). */ - SizeType GetStringLength() const { RAPIDJSON_ASSERT(IsString()); return ((data_.f.flags & kInlineStrFlag) ? (data_.ss.GetLength()) : data_.s.length); } + SizeType GetStringLength() const { RAPIDJSON_ASSERT(IsString()); return DataStringLength(data_); } //! Set this value as a string without copying source string. /*! This version has better performance with supplied length, and also support string containing null character. @@ -1882,7 +1966,7 @@ class GenericValue { case kArrayType: if (RAPIDJSON_UNLIKELY(!handler.StartArray())) return false; - for (const GenericValue* v = Begin(); v != End(); ++v) + for (ConstValueIterator v = Begin(); v != End(); ++v) if (RAPIDJSON_UNLIKELY(!v->Accept(handler))) return false; return handler.EndArray(data_.a.size); @@ -1918,25 +2002,26 @@ class GenericValue { // Initial flags of different types. kNullFlag = kNullType, - kTrueFlag = kTrueType | kBoolFlag, - kFalseFlag = kFalseType | kBoolFlag, - kNumberIntFlag = kNumberType | kNumberFlag | kIntFlag | kInt64Flag, - kNumberUintFlag = kNumberType | kNumberFlag | kUintFlag | kUint64Flag | kInt64Flag, - kNumberInt64Flag = kNumberType | kNumberFlag | kInt64Flag, - kNumberUint64Flag = kNumberType | kNumberFlag | kUint64Flag, - kNumberDoubleFlag = kNumberType | kNumberFlag | kDoubleFlag, - kNumberAnyFlag = kNumberType | kNumberFlag | kIntFlag | kInt64Flag | kUintFlag | kUint64Flag | kDoubleFlag, - kConstStringFlag = kStringType | kStringFlag, - kCopyStringFlag = kStringType | kStringFlag | kCopyFlag, - kShortStringFlag = kStringType | kStringFlag | kCopyFlag | kInlineStrFlag, + // These casts are added to suppress the warning on MSVC about bitwise operations between enums of different types. + kTrueFlag = static_cast(kTrueType) | static_cast(kBoolFlag), + kFalseFlag = static_cast(kFalseType) | static_cast(kBoolFlag), + kNumberIntFlag = static_cast(kNumberType) | static_cast(kNumberFlag | kIntFlag | kInt64Flag), + kNumberUintFlag = static_cast(kNumberType) | static_cast(kNumberFlag | kUintFlag | kUint64Flag | kInt64Flag), + kNumberInt64Flag = static_cast(kNumberType) | static_cast(kNumberFlag | kInt64Flag), + kNumberUint64Flag = static_cast(kNumberType) | static_cast(kNumberFlag | kUint64Flag), + kNumberDoubleFlag = static_cast(kNumberType) | static_cast(kNumberFlag | kDoubleFlag), + kNumberAnyFlag = static_cast(kNumberType) | static_cast(kNumberFlag | kIntFlag | kInt64Flag | kUintFlag | kUint64Flag | kDoubleFlag), + kConstStringFlag = static_cast(kStringType) | static_cast(kStringFlag), + kCopyStringFlag = static_cast(kStringType) | static_cast(kStringFlag | kCopyFlag), + kShortStringFlag = static_cast(kStringType) | static_cast(kStringFlag | kCopyFlag | kInlineStrFlag), kObjectFlag = kObjectType, kArrayFlag = kArrayType, kTypeMask = 0x07 }; - static const SizeType kDefaultArrayCapacity = 16; - static const SizeType kDefaultObjectCapacity = 16; + static const SizeType kDefaultArrayCapacity = RAPIDJSON_VALUE_DEFAULT_ARRAY_CAPACITY; + static const SizeType kDefaultObjectCapacity = RAPIDJSON_VALUE_DEFAULT_OBJECT_CAPACITY; struct Flag { #if RAPIDJSON_48BITPOINTER_OPTIMIZATION @@ -2019,6 +2104,13 @@ class GenericValue { Flag f; }; // 16 bytes in 32-bit mode, 24 bytes in 64-bit mode, 16 bytes in 64-bit with RAPIDJSON_48BITPOINTER_OPTIMIZATION + static RAPIDJSON_FORCEINLINE const Ch* DataString(const Data& data) { + return (data.f.flags & kInlineStrFlag) ? data.ss.str : RAPIDJSON_GETPOINTER(Ch, data.s.str); + } + static RAPIDJSON_FORCEINLINE SizeType DataStringLength(const Data& data) { + return (data.f.flags & kInlineStrFlag) ? data.ss.GetLength() : data.s.length; + } + RAPIDJSON_FORCEINLINE const Ch* GetStringPointer() const { return RAPIDJSON_GETPOINTER(Ch, data_.s.str); } RAPIDJSON_FORCEINLINE const Ch* SetStringPointer(const Ch* str) { return RAPIDJSON_SETPOINTER(Ch, data_.s.str, str); } RAPIDJSON_FORCEINLINE GenericValue* GetElementsPointer() const { return RAPIDJSON_GETPOINTER(GenericValue, data_.a.elements); } @@ -2026,6 +2118,286 @@ class GenericValue { RAPIDJSON_FORCEINLINE Member* GetMembersPointer() const { return RAPIDJSON_GETPOINTER(Member, data_.o.members); } RAPIDJSON_FORCEINLINE Member* SetMembersPointer(Member* members) { return RAPIDJSON_SETPOINTER(Member, data_.o.members, members); } +#if RAPIDJSON_USE_MEMBERSMAP + + struct MapTraits { + struct Less { + bool operator()(const Data& s1, const Data& s2) const { + SizeType n1 = DataStringLength(s1), n2 = DataStringLength(s2); + int cmp = std::memcmp(DataString(s1), DataString(s2), sizeof(Ch) * (n1 < n2 ? n1 : n2)); + return cmp < 0 || (cmp == 0 && n1 < n2); + } + }; + typedef std::pair Pair; + typedef std::multimap > Map; + typedef typename Map::iterator Iterator; + }; + typedef typename MapTraits::Map Map; + typedef typename MapTraits::Less MapLess; + typedef typename MapTraits::Pair MapPair; + typedef typename MapTraits::Iterator MapIterator; + + // + // Layout of the members' map/array, re(al)located according to the needed capacity: + // + // {Map*}<>{capacity}<>{Member[capacity]}<>{MapIterator[capacity]} + // + // (where <> stands for the RAPIDJSON_ALIGN-ment, if needed) + // + + static RAPIDJSON_FORCEINLINE size_t GetMapLayoutSize(SizeType capacity) { + return RAPIDJSON_ALIGN(sizeof(Map*)) + + RAPIDJSON_ALIGN(sizeof(SizeType)) + + RAPIDJSON_ALIGN(capacity * sizeof(Member)) + + capacity * sizeof(MapIterator); + } + + static RAPIDJSON_FORCEINLINE SizeType &GetMapCapacity(Map* &map) { + return *reinterpret_cast(reinterpret_cast(&map) + + RAPIDJSON_ALIGN(sizeof(Map*))); + } + + static RAPIDJSON_FORCEINLINE Member* GetMapMembers(Map* &map) { + return reinterpret_cast(reinterpret_cast(&map) + + RAPIDJSON_ALIGN(sizeof(Map*)) + + RAPIDJSON_ALIGN(sizeof(SizeType))); + } + + static RAPIDJSON_FORCEINLINE MapIterator* GetMapIterators(Map* &map) { + return reinterpret_cast(reinterpret_cast(&map) + + RAPIDJSON_ALIGN(sizeof(Map*)) + + RAPIDJSON_ALIGN(sizeof(SizeType)) + + RAPIDJSON_ALIGN(GetMapCapacity(map) * sizeof(Member))); + } + + static RAPIDJSON_FORCEINLINE Map* &GetMap(Member* members) { + RAPIDJSON_ASSERT(members != 0); + return *reinterpret_cast(reinterpret_cast(members) - + RAPIDJSON_ALIGN(sizeof(SizeType)) - + RAPIDJSON_ALIGN(sizeof(Map*))); + } + + // Some compilers' debug mechanisms want all iterators to be destroyed, for their accounting.. + RAPIDJSON_FORCEINLINE MapIterator DropMapIterator(MapIterator& rhs) { +#if RAPIDJSON_HAS_CXX11 + MapIterator ret = std::move(rhs); +#else + MapIterator ret = rhs; +#endif + rhs.~MapIterator(); + return ret; + } + + Map* &DoReallocMap(Map** oldMap, SizeType newCapacity, Allocator& allocator) { + Map **newMap = static_cast(allocator.Malloc(GetMapLayoutSize(newCapacity))); + GetMapCapacity(*newMap) = newCapacity; + if (!oldMap) { + *newMap = new (allocator.Malloc(sizeof(Map))) Map(MapLess(), allocator); + } + else { + *newMap = *oldMap; + size_t count = (*oldMap)->size(); + std::memcpy(static_cast(GetMapMembers(*newMap)), + static_cast(GetMapMembers(*oldMap)), + count * sizeof(Member)); + MapIterator *oldIt = GetMapIterators(*oldMap), + *newIt = GetMapIterators(*newMap); + while (count--) { + new (&newIt[count]) MapIterator(DropMapIterator(oldIt[count])); + } + Allocator::Free(oldMap); + } + return *newMap; + } + + RAPIDJSON_FORCEINLINE Member* DoAllocMembers(SizeType capacity, Allocator& allocator) { + return GetMapMembers(DoReallocMap(0, capacity, allocator)); + } + + void DoReserveMembers(SizeType newCapacity, Allocator& allocator) { + ObjectData& o = data_.o; + if (newCapacity > o.capacity) { + Member* oldMembers = GetMembersPointer(); + Map **oldMap = oldMembers ? &GetMap(oldMembers) : 0, + *&newMap = DoReallocMap(oldMap, newCapacity, allocator); + RAPIDJSON_SETPOINTER(Member, o.members, GetMapMembers(newMap)); + o.capacity = newCapacity; + } + } + + template + MemberIterator DoFindMember(const GenericValue& name) { + if (Member* members = GetMembersPointer()) { + Map* &map = GetMap(members); + MapIterator mit = map->find(reinterpret_cast(name.data_)); + if (mit != map->end()) { + return MemberIterator(&members[mit->second]); + } + } + return MemberEnd(); + } + + void DoClearMembers() { + if (Member* members = GetMembersPointer()) { + Map* &map = GetMap(members); + MapIterator* mit = GetMapIterators(map); + for (SizeType i = 0; i < data_.o.size; i++) { + map->erase(DropMapIterator(mit[i])); + members[i].~Member(); + } + data_.o.size = 0; + } + } + + void DoFreeMembers() { + if (Member* members = GetMembersPointer()) { + GetMap(members)->~Map(); + for (SizeType i = 0; i < data_.o.size; i++) { + members[i].~Member(); + } + if (Allocator::kNeedFree) { // Shortcut by Allocator's trait + Map** map = &GetMap(members); + Allocator::Free(*map); + Allocator::Free(map); + } + } + } + +#else // !RAPIDJSON_USE_MEMBERSMAP + + RAPIDJSON_FORCEINLINE Member* DoAllocMembers(SizeType capacity, Allocator& allocator) { + return Malloc(allocator, capacity); + } + + void DoReserveMembers(SizeType newCapacity, Allocator& allocator) { + ObjectData& o = data_.o; + if (newCapacity > o.capacity) { + Member* newMembers = Realloc(allocator, GetMembersPointer(), o.capacity, newCapacity); + RAPIDJSON_SETPOINTER(Member, o.members, newMembers); + o.capacity = newCapacity; + } + } + + template + MemberIterator DoFindMember(const GenericValue& name) { + MemberIterator member = MemberBegin(); + for ( ; member != MemberEnd(); ++member) + if (name.StringEqual(member->name)) + break; + return member; + } + + void DoClearMembers() { + for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m) + m->~Member(); + data_.o.size = 0; + } + + void DoFreeMembers() { + for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m) + m->~Member(); + Allocator::Free(GetMembersPointer()); + } + +#endif // !RAPIDJSON_USE_MEMBERSMAP + + void DoAddMember(GenericValue& name, GenericValue& value, Allocator& allocator) { + ObjectData& o = data_.o; + if (o.size >= o.capacity) + DoReserveMembers(o.capacity ? (o.capacity + (o.capacity + 1) / 2) : kDefaultObjectCapacity, allocator); + Member* members = GetMembersPointer(); + Member* m = members + o.size; + m->name.RawAssign(name); + m->value.RawAssign(value); +#if RAPIDJSON_USE_MEMBERSMAP + Map* &map = GetMap(members); + MapIterator* mit = GetMapIterators(map); + new (&mit[o.size]) MapIterator(map->insert(MapPair(m->name.data_, o.size))); +#endif + ++o.size; + } + + MemberIterator DoRemoveMember(MemberIterator m) { + ObjectData& o = data_.o; + Member* members = GetMembersPointer(); +#if RAPIDJSON_USE_MEMBERSMAP + Map* &map = GetMap(members); + MapIterator* mit = GetMapIterators(map); + SizeType mpos = static_cast(&*m - members); + map->erase(DropMapIterator(mit[mpos])); +#endif + MemberIterator last(members + (o.size - 1)); + if (o.size > 1 && m != last) { +#if RAPIDJSON_USE_MEMBERSMAP + new (&mit[mpos]) MapIterator(DropMapIterator(mit[&*last - members])); + mit[mpos]->second = mpos; +#endif + *m = *last; // Move the last one to this place + } + else { + m->~Member(); // Only one left, just destroy + } + --o.size; + return m; + } + + MemberIterator DoEraseMembers(ConstMemberIterator first, ConstMemberIterator last) { + ObjectData& o = data_.o; + MemberIterator beg = MemberBegin(), + pos = beg + (first - beg), + end = MemberEnd(); +#if RAPIDJSON_USE_MEMBERSMAP + Map* &map = GetMap(GetMembersPointer()); + MapIterator* mit = GetMapIterators(map); +#endif + for (MemberIterator itr = pos; itr != last; ++itr) { +#if RAPIDJSON_USE_MEMBERSMAP + map->erase(DropMapIterator(mit[itr - beg])); +#endif + itr->~Member(); + } +#if RAPIDJSON_USE_MEMBERSMAP + if (first != last) { + // Move remaining members/iterators + MemberIterator next = pos + (last - first); + for (MemberIterator itr = pos; next != end; ++itr, ++next) { + std::memcpy(static_cast(&*itr), &*next, sizeof(Member)); + SizeType mpos = static_cast(itr - beg); + new (&mit[mpos]) MapIterator(DropMapIterator(mit[next - beg])); + mit[mpos]->second = mpos; + } + } +#else + std::memmove(static_cast(&*pos), &*last, + static_cast(end - last) * sizeof(Member)); +#endif + o.size -= static_cast(last - first); + return pos; + } + + template + void DoCopyMembers(const GenericValue& rhs, Allocator& allocator, bool copyConstStrings) { + RAPIDJSON_ASSERT(rhs.GetType() == kObjectType); + + data_.f.flags = kObjectFlag; + SizeType count = rhs.data_.o.size; + Member* lm = DoAllocMembers(count, allocator); + const typename GenericValue::Member* rm = rhs.GetMembersPointer(); +#if RAPIDJSON_USE_MEMBERSMAP + Map* &map = GetMap(lm); + MapIterator* mit = GetMapIterators(map); +#endif + for (SizeType i = 0; i < count; i++) { + new (&lm[i].name) GenericValue(rm[i].name, allocator, copyConstStrings); + new (&lm[i].value) GenericValue(rm[i].value, allocator, copyConstStrings); +#if RAPIDJSON_USE_MEMBERSMAP + new (&mit[i]) MapIterator(map->insert(MapPair(lm[i].name.data_, i))); +#endif + } + data_.o.size = data_.o.capacity = count; + SetMembersPointer(lm); + } + // Initialize this value as array with initial data, without calling destructor. void SetArrayRaw(GenericValue* values, SizeType count, Allocator& allocator) { data_.f.flags = kArrayFlag; @@ -2043,9 +2415,16 @@ class GenericValue { void SetObjectRaw(Member* members, SizeType count, Allocator& allocator) { data_.f.flags = kObjectFlag; if (count) { - Member* m = static_cast(allocator.Malloc(count * sizeof(Member))); + Member* m = DoAllocMembers(count, allocator); SetMembersPointer(m); std::memcpy(static_cast(m), members, count * sizeof(Member)); +#if RAPIDJSON_USE_MEMBERSMAP + Map* &map = GetMap(m); + MapIterator* mit = GetMapIterators(map); + for (SizeType i = 0; i < count; i++) { + new (&mit[i]) MapIterator(map->insert(MapPair(m[i].name.data_, i))); + } +#endif } else SetMembersPointer(0); @@ -2116,12 +2495,13 @@ typedef GenericValue > Value; \tparam StackAllocator Allocator for allocating memory for stack during parsing. \warning Although GenericDocument inherits from GenericValue, the API does \b not provide any virtual functions, especially no virtual destructor. To avoid memory leaks, do not \c delete a GenericDocument object via a pointer to a GenericValue. */ -template , typename StackAllocator = CrtAllocator> +template class GenericDocument : public GenericValue { public: typedef typename Encoding::Ch Ch; //!< Character type derived from Encoding. typedef GenericValue ValueType; //!< Value type of the document. typedef Allocator AllocatorType; //!< Allocator type from template parameter. + typedef StackAllocator StackAllocatorType; //!< StackAllocator type from template parameter. //! Constructor /*! Creates an empty document of specified type. @@ -2166,6 +2546,13 @@ class GenericDocument : public GenericValue { #endif ~GenericDocument() { + // Clear the ::ValueType before ownAllocator is destroyed, ~ValueType() + // runs last and may access its elements or members which would be freed + // with an allocator like MemoryPoolAllocator (CrtAllocator does not + // free its data when destroyed, but MemoryPoolAllocator does). + if (ownAllocator_) { + ValueType::SetNull(); + } Destroy(); } @@ -2501,6 +2888,7 @@ class GenericDocument : public GenericValue { //! GenericDocument with UTF8 encoding typedef GenericDocument > Document; + //! Helper class for accessing Value of array type. /*! Instance of this helper class is obtained by \c GenericValue::GetArray(). @@ -2525,6 +2913,7 @@ class GenericArray { GenericArray& operator=(const GenericArray& rhs) { value_ = rhs.value_; return *this; } ~GenericArray() {} + operator ValueType&() const { return value_; } SizeType Size() const { return value_.Size(); } SizeType Capacity() const { return value_.Capacity(); } bool Empty() const { return value_.Empty(); } @@ -2580,6 +2969,7 @@ class GenericObject { GenericObject& operator=(const GenericObject& rhs) { value_ = rhs.value_; return *this; } ~GenericObject() {} + operator ValueType&() const { return value_; } SizeType MemberCount() const { return value_.MemberCount(); } SizeType MemberCapacity() const { return value_.MemberCapacity(); } bool ObjectEmpty() const { return value_.ObjectEmpty(); } @@ -2645,4 +3035,9 @@ class GenericObject { RAPIDJSON_NAMESPACE_END RAPIDJSON_DIAG_POP +#ifdef RAPIDJSON_WINDOWS_GETOBJECT_WORKAROUND_APPLIED +#pragma pop_macro("GetObject") +#undef RAPIDJSON_WINDOWS_GETOBJECT_WORKAROUND_APPLIED +#endif + #endif // RAPIDJSON_DOCUMENT_H_ diff --git a/include/common/rapidjson/encodedstream.h b/include/common/rapidjson/encodedstream.h index 223601c..cf046b8 100644 --- a/include/common/rapidjson/encodedstream.h +++ b/include/common/rapidjson/encodedstream.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at diff --git a/include/common/rapidjson/encodings.h b/include/common/rapidjson/encodings.h index 0b24467..50ad18b 100644 --- a/include/common/rapidjson/encodings.h +++ b/include/common/rapidjson/encodings.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at diff --git a/include/common/rapidjson/error/en.h b/include/common/rapidjson/error/en.h index 2db838b..c87b04e 100644 --- a/include/common/rapidjson/error/en.h +++ b/include/common/rapidjson/error/en.h @@ -1,15 +1,15 @@ // Tencent is pleased to support the open source community by making RapidJSON available. -// -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at // // http://opensource.org/licenses/MIT // -// Unless required by applicable law or agreed to in writing, software distributed -// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the // specific language governing permissions and limitations under the License. #ifndef RAPIDJSON_ERROR_EN_H_ @@ -39,13 +39,13 @@ inline const RAPIDJSON_ERROR_CHARTYPE* GetParseError_En(ParseErrorCode parseErro case kParseErrorDocumentEmpty: return RAPIDJSON_ERROR_STRING("The document is empty."); case kParseErrorDocumentRootNotSingular: return RAPIDJSON_ERROR_STRING("The document root must not be followed by other values."); - + case kParseErrorValueInvalid: return RAPIDJSON_ERROR_STRING("Invalid value."); - + case kParseErrorObjectMissName: return RAPIDJSON_ERROR_STRING("Missing a name for object member."); case kParseErrorObjectMissColon: return RAPIDJSON_ERROR_STRING("Missing a colon after a name of object member."); case kParseErrorObjectMissCommaOrCurlyBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or '}' after an object member."); - + case kParseErrorArrayMissCommaOrSquareBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or ']' after an array element."); case kParseErrorStringUnicodeEscapeInvalidHex: return RAPIDJSON_ERROR_STRING("Incorrect hex digit after \\u escape in string."); @@ -65,6 +65,108 @@ inline const RAPIDJSON_ERROR_CHARTYPE* GetParseError_En(ParseErrorCode parseErro } } +//! Maps error code of validation into error message. +/*! + \ingroup RAPIDJSON_ERRORS + \param validateErrorCode Error code obtained from validator. + \return the error message. + \note User can make a copy of this function for localization. + Using switch-case is safer for future modification of error codes. +*/ +inline const RAPIDJSON_ERROR_CHARTYPE* GetValidateError_En(ValidateErrorCode validateErrorCode) { + switch (validateErrorCode) { + case kValidateErrors: return RAPIDJSON_ERROR_STRING("One or more validation errors have occurred"); + case kValidateErrorNone: return RAPIDJSON_ERROR_STRING("No error."); + + case kValidateErrorMultipleOf: return RAPIDJSON_ERROR_STRING("Number '%actual' is not a multiple of the 'multipleOf' value '%expected'."); + case kValidateErrorMaximum: return RAPIDJSON_ERROR_STRING("Number '%actual' is greater than the 'maximum' value '%expected'."); + case kValidateErrorExclusiveMaximum: return RAPIDJSON_ERROR_STRING("Number '%actual' is greater than or equal to the 'exclusiveMaximum' value '%expected'."); + case kValidateErrorMinimum: return RAPIDJSON_ERROR_STRING("Number '%actual' is less than the 'minimum' value '%expected'."); + case kValidateErrorExclusiveMinimum: return RAPIDJSON_ERROR_STRING("Number '%actual' is less than or equal to the 'exclusiveMinimum' value '%expected'."); + + case kValidateErrorMaxLength: return RAPIDJSON_ERROR_STRING("String '%actual' is longer than the 'maxLength' value '%expected'."); + case kValidateErrorMinLength: return RAPIDJSON_ERROR_STRING("String '%actual' is shorter than the 'minLength' value '%expected'."); + case kValidateErrorPattern: return RAPIDJSON_ERROR_STRING("String '%actual' does not match the 'pattern' regular expression."); + + case kValidateErrorMaxItems: return RAPIDJSON_ERROR_STRING("Array of length '%actual' is longer than the 'maxItems' value '%expected'."); + case kValidateErrorMinItems: return RAPIDJSON_ERROR_STRING("Array of length '%actual' is shorter than the 'minItems' value '%expected'."); + case kValidateErrorUniqueItems: return RAPIDJSON_ERROR_STRING("Array has duplicate items at indices '%duplicates' but 'uniqueItems' is true."); + case kValidateErrorAdditionalItems: return RAPIDJSON_ERROR_STRING("Array has an additional item at index '%disallowed' that is not allowed by the schema."); + + case kValidateErrorMaxProperties: return RAPIDJSON_ERROR_STRING("Object has '%actual' members which is more than 'maxProperties' value '%expected'."); + case kValidateErrorMinProperties: return RAPIDJSON_ERROR_STRING("Object has '%actual' members which is less than 'minProperties' value '%expected'."); + case kValidateErrorRequired: return RAPIDJSON_ERROR_STRING("Object is missing the following members required by the schema: '%missing'."); + case kValidateErrorAdditionalProperties: return RAPIDJSON_ERROR_STRING("Object has an additional member '%disallowed' that is not allowed by the schema."); + case kValidateErrorPatternProperties: return RAPIDJSON_ERROR_STRING("Object has 'patternProperties' that are not allowed by the schema."); + case kValidateErrorDependencies: return RAPIDJSON_ERROR_STRING("Object has missing property or schema dependencies, refer to following errors."); + + case kValidateErrorEnum: return RAPIDJSON_ERROR_STRING("Property has a value that is not one of its allowed enumerated values."); + case kValidateErrorType: return RAPIDJSON_ERROR_STRING("Property has a type '%actual' that is not in the following list: '%expected'."); + + case kValidateErrorOneOf: return RAPIDJSON_ERROR_STRING("Property did not match any of the sub-schemas specified by 'oneOf', refer to following errors."); + case kValidateErrorOneOfMatch: return RAPIDJSON_ERROR_STRING("Property matched more than one of the sub-schemas specified by 'oneOf', indices '%matches'."); + case kValidateErrorAllOf: return RAPIDJSON_ERROR_STRING("Property did not match all of the sub-schemas specified by 'allOf', refer to following errors."); + case kValidateErrorAnyOf: return RAPIDJSON_ERROR_STRING("Property did not match any of the sub-schemas specified by 'anyOf', refer to following errors."); + case kValidateErrorNot: return RAPIDJSON_ERROR_STRING("Property matched the sub-schema specified by 'not'."); + + case kValidateErrorReadOnly: return RAPIDJSON_ERROR_STRING("Property is read-only but has been provided when validation is for writing."); + case kValidateErrorWriteOnly: return RAPIDJSON_ERROR_STRING("Property is write-only but has been provided when validation is for reading."); + + default: return RAPIDJSON_ERROR_STRING("Unknown error."); + } +} + +//! Maps error code of schema document compilation into error message. +/*! + \ingroup RAPIDJSON_ERRORS + \param schemaErrorCode Error code obtained from compiling the schema document. + \return the error message. + \note User can make a copy of this function for localization. + Using switch-case is safer for future modification of error codes. +*/ + inline const RAPIDJSON_ERROR_CHARTYPE* GetSchemaError_En(SchemaErrorCode schemaErrorCode) { + switch (schemaErrorCode) { + case kSchemaErrorNone: return RAPIDJSON_ERROR_STRING("No error."); + + case kSchemaErrorStartUnknown: return RAPIDJSON_ERROR_STRING("Pointer '%value' to start of schema does not resolve to a location in the document."); + case kSchemaErrorRefPlainName: return RAPIDJSON_ERROR_STRING("$ref fragment '%value' must be a JSON pointer."); + case kSchemaErrorRefInvalid: return RAPIDJSON_ERROR_STRING("$ref must not be an empty string."); + case kSchemaErrorRefPointerInvalid: return RAPIDJSON_ERROR_STRING("$ref fragment '%value' is not a valid JSON pointer at offset '%offset'."); + case kSchemaErrorRefUnknown: return RAPIDJSON_ERROR_STRING("$ref '%value' does not resolve to a location in the target document."); + case kSchemaErrorRefCyclical: return RAPIDJSON_ERROR_STRING("$ref '%value' is cyclical."); + case kSchemaErrorRefNoRemoteProvider: return RAPIDJSON_ERROR_STRING("$ref is remote but there is no remote provider."); + case kSchemaErrorRefNoRemoteSchema: return RAPIDJSON_ERROR_STRING("$ref '%value' is remote but the remote provider did not return a schema."); + case kSchemaErrorRegexInvalid: return RAPIDJSON_ERROR_STRING("Invalid regular expression '%value' in 'pattern' or 'patternProperties'."); + case kSchemaErrorSpecUnknown: return RAPIDJSON_ERROR_STRING("JSON schema draft or OpenAPI version is not recognized."); + case kSchemaErrorSpecUnsupported: return RAPIDJSON_ERROR_STRING("JSON schema draft or OpenAPI version is not supported."); + case kSchemaErrorSpecIllegal: return RAPIDJSON_ERROR_STRING("Both JSON schema draft and OpenAPI version found in document."); + case kSchemaErrorReadOnlyAndWriteOnly: return RAPIDJSON_ERROR_STRING("Property must not be both 'readOnly' and 'writeOnly'."); + + default: return RAPIDJSON_ERROR_STRING("Unknown error."); + } + } + +//! Maps error code of pointer parse into error message. +/*! + \ingroup RAPIDJSON_ERRORS + \param pointerParseErrorCode Error code obtained from pointer parse. + \return the error message. + \note User can make a copy of this function for localization. + Using switch-case is safer for future modification of error codes. +*/ +inline const RAPIDJSON_ERROR_CHARTYPE* GetPointerParseError_En(PointerParseErrorCode pointerParseErrorCode) { + switch (pointerParseErrorCode) { + case kPointerParseErrorNone: return RAPIDJSON_ERROR_STRING("No error."); + + case kPointerParseErrorTokenMustBeginWithSolidus: return RAPIDJSON_ERROR_STRING("A token must begin with a '/'."); + case kPointerParseErrorInvalidEscape: return RAPIDJSON_ERROR_STRING("Invalid escape."); + case kPointerParseErrorInvalidPercentEncoding: return RAPIDJSON_ERROR_STRING("Invalid percent encoding in URI fragment."); + case kPointerParseErrorCharacterMustPercentEncode: return RAPIDJSON_ERROR_STRING("A character must be percent encoded in a URI fragment."); + + default: return RAPIDJSON_ERROR_STRING("Unknown error."); + } +} + RAPIDJSON_NAMESPACE_END #ifdef __clang__ diff --git a/include/common/rapidjson/error/error.h b/include/common/rapidjson/error/error.h index 9311d2f..cae345d 100644 --- a/include/common/rapidjson/error/error.h +++ b/include/common/rapidjson/error/error.h @@ -1,15 +1,15 @@ // Tencent is pleased to support the open source community by making RapidJSON available. -// -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at // // http://opensource.org/licenses/MIT // -// Unless required by applicable law or agreed to in writing, software distributed -// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the // specific language governing permissions and limitations under the License. #ifndef RAPIDJSON_ERROR_ERROR_H_ @@ -42,7 +42,7 @@ RAPIDJSON_DIAG_OFF(padded) /////////////////////////////////////////////////////////////////////////////// // RAPIDJSON_ERROR_STRING -//! Macro for converting string literial to \ref RAPIDJSON_ERROR_CHARTYPE[]. +//! Macro for converting string literal to \ref RAPIDJSON_ERROR_CHARTYPE[]. /*! \ingroup RAPIDJSON_ERRORS By default this conversion macro does nothing. On Windows, user can define this macro as \c _T(x) for supporting both @@ -152,6 +152,130 @@ struct ParseResult { */ typedef const RAPIDJSON_ERROR_CHARTYPE* (*GetParseErrorFunc)(ParseErrorCode); +/////////////////////////////////////////////////////////////////////////////// +// ValidateErrorCode + +//! Error codes when validating. +/*! \ingroup RAPIDJSON_ERRORS + \see GenericSchemaValidator +*/ +enum ValidateErrorCode { + kValidateErrors = -1, //!< Top level error code when kValidateContinueOnErrorsFlag set. + kValidateErrorNone = 0, //!< No error. + + kValidateErrorMultipleOf, //!< Number is not a multiple of the 'multipleOf' value. + kValidateErrorMaximum, //!< Number is greater than the 'maximum' value. + kValidateErrorExclusiveMaximum, //!< Number is greater than or equal to the 'maximum' value. + kValidateErrorMinimum, //!< Number is less than the 'minimum' value. + kValidateErrorExclusiveMinimum, //!< Number is less than or equal to the 'minimum' value. + + kValidateErrorMaxLength, //!< String is longer than the 'maxLength' value. + kValidateErrorMinLength, //!< String is longer than the 'maxLength' value. + kValidateErrorPattern, //!< String does not match the 'pattern' regular expression. + + kValidateErrorMaxItems, //!< Array is longer than the 'maxItems' value. + kValidateErrorMinItems, //!< Array is shorter than the 'minItems' value. + kValidateErrorUniqueItems, //!< Array has duplicate items but 'uniqueItems' is true. + kValidateErrorAdditionalItems, //!< Array has additional items that are not allowed by the schema. + + kValidateErrorMaxProperties, //!< Object has more members than 'maxProperties' value. + kValidateErrorMinProperties, //!< Object has less members than 'minProperties' value. + kValidateErrorRequired, //!< Object is missing one or more members required by the schema. + kValidateErrorAdditionalProperties, //!< Object has additional members that are not allowed by the schema. + kValidateErrorPatternProperties, //!< See other errors. + kValidateErrorDependencies, //!< Object has missing property or schema dependencies. + + kValidateErrorEnum, //!< Property has a value that is not one of its allowed enumerated values. + kValidateErrorType, //!< Property has a type that is not allowed by the schema. + + kValidateErrorOneOf, //!< Property did not match any of the sub-schemas specified by 'oneOf'. + kValidateErrorOneOfMatch, //!< Property matched more than one of the sub-schemas specified by 'oneOf'. + kValidateErrorAllOf, //!< Property did not match all of the sub-schemas specified by 'allOf'. + kValidateErrorAnyOf, //!< Property did not match any of the sub-schemas specified by 'anyOf'. + kValidateErrorNot, //!< Property matched the sub-schema specified by 'not'. + + kValidateErrorReadOnly, //!< Property is read-only but has been provided when validation is for writing + kValidateErrorWriteOnly //!< Property is write-only but has been provided when validation is for reading +}; + +//! Function pointer type of GetValidateError(). +/*! \ingroup RAPIDJSON_ERRORS + + This is the prototype for \c GetValidateError_X(), where \c X is a locale. + User can dynamically change locale in runtime, e.g.: +\code + GetValidateErrorFunc GetValidateError = GetValidateError_En; // or whatever + const RAPIDJSON_ERROR_CHARTYPE* s = GetValidateError(validator.GetInvalidSchemaCode()); +\endcode +*/ +typedef const RAPIDJSON_ERROR_CHARTYPE* (*GetValidateErrorFunc)(ValidateErrorCode); + +/////////////////////////////////////////////////////////////////////////////// +// SchemaErrorCode + +//! Error codes when validating. +/*! \ingroup RAPIDJSON_ERRORS + \see GenericSchemaValidator +*/ +enum SchemaErrorCode { + kSchemaErrorNone = 0, //!< No error. + + kSchemaErrorStartUnknown, //!< Pointer to start of schema does not resolve to a location in the document + kSchemaErrorRefPlainName, //!< $ref fragment must be a JSON pointer + kSchemaErrorRefInvalid, //!< $ref must not be an empty string + kSchemaErrorRefPointerInvalid, //!< $ref fragment is not a valid JSON pointer at offset + kSchemaErrorRefUnknown, //!< $ref does not resolve to a location in the target document + kSchemaErrorRefCyclical, //!< $ref is cyclical + kSchemaErrorRefNoRemoteProvider, //!< $ref is remote but there is no remote provider + kSchemaErrorRefNoRemoteSchema, //!< $ref is remote but the remote provider did not return a schema + kSchemaErrorRegexInvalid, //!< Invalid regular expression in 'pattern' or 'patternProperties' + kSchemaErrorSpecUnknown, //!< JSON schema draft or OpenAPI version is not recognized + kSchemaErrorSpecUnsupported, //!< JSON schema draft or OpenAPI version is not supported + kSchemaErrorSpecIllegal, //!< Both JSON schema draft and OpenAPI version found in document + kSchemaErrorReadOnlyAndWriteOnly //!< Property must not be both 'readOnly' and 'writeOnly' +}; + +//! Function pointer type of GetSchemaError(). +/*! \ingroup RAPIDJSON_ERRORS + + This is the prototype for \c GetSchemaError_X(), where \c X is a locale. + User can dynamically change locale in runtime, e.g.: +\code + GetSchemaErrorFunc GetSchemaError = GetSchemaError_En; // or whatever + const RAPIDJSON_ERROR_CHARTYPE* s = GetSchemaError(validator.GetInvalidSchemaCode()); +\endcode +*/ +typedef const RAPIDJSON_ERROR_CHARTYPE* (*GetSchemaErrorFunc)(SchemaErrorCode); + +/////////////////////////////////////////////////////////////////////////////// +// PointerParseErrorCode + +//! Error code of JSON pointer parsing. +/*! \ingroup RAPIDJSON_ERRORS + \see GenericPointer::GenericPointer, GenericPointer::GetParseErrorCode +*/ +enum PointerParseErrorCode { + kPointerParseErrorNone = 0, //!< The parse is successful + + kPointerParseErrorTokenMustBeginWithSolidus, //!< A token must begin with a '/' + kPointerParseErrorInvalidEscape, //!< Invalid escape + kPointerParseErrorInvalidPercentEncoding, //!< Invalid percent encoding in URI fragment + kPointerParseErrorCharacterMustPercentEncode //!< A character must percent encoded in URI fragment +}; + +//! Function pointer type of GetPointerParseError(). +/*! \ingroup RAPIDJSON_ERRORS + + This is the prototype for \c GetPointerParseError_X(), where \c X is a locale. + User can dynamically change locale in runtime, e.g.: +\code + GetPointerParseErrorFunc GetPointerParseError = GetPointerParseError_En; // or whatever + const RAPIDJSON_ERROR_CHARTYPE* s = GetPointerParseError(pointer.GetParseErrorCode()); +\endcode +*/ +typedef const RAPIDJSON_ERROR_CHARTYPE* (*GetPointerParseErrorFunc)(PointerParseErrorCode); + + RAPIDJSON_NAMESPACE_END #ifdef __clang__ diff --git a/include/common/rapidjson/filereadstream.h b/include/common/rapidjson/filereadstream.h index f1bfb7d..f8bb43c 100644 --- a/include/common/rapidjson/filereadstream.h +++ b/include/common/rapidjson/filereadstream.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at @@ -59,7 +59,7 @@ class FileReadStream { // For encoding detection only. const Ch* Peek4() const { - return (current_ + 4 <= bufferLast_) ? current_ : 0; + return (current_ + 4 - !eof_ <= bufferLast_) ? current_ : 0; } private: diff --git a/include/common/rapidjson/filewritestream.h b/include/common/rapidjson/filewritestream.h index 8b48fee..5d89588 100644 --- a/include/common/rapidjson/filewritestream.h +++ b/include/common/rapidjson/filewritestream.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at diff --git a/include/common/rapidjson/fwd.h b/include/common/rapidjson/fwd.h index e8104e8..d62f77f 100644 --- a/include/common/rapidjson/fwd.h +++ b/include/common/rapidjson/fwd.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at @@ -102,7 +102,7 @@ class PrettyWriter; // document.h template -struct GenericMember; +class GenericMember; template class GenericMemberIterator; diff --git a/include/common/rapidjson/internal/biginteger.h b/include/common/rapidjson/internal/biginteger.h index a31c8a8..af48738 100644 --- a/include/common/rapidjson/internal/biginteger.h +++ b/include/common/rapidjson/internal/biginteger.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at @@ -17,9 +17,13 @@ #include "../rapidjson.h" -#if defined(_MSC_VER) && !__INTEL_COMPILER && defined(_M_AMD64) +#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && defined(_M_AMD64) #include // for _umul128 +#if !defined(_ARM64EC_) #pragma intrinsic(_umul128) +#else +#pragma comment(lib,"softintrin") +#endif #endif RAPIDJSON_NAMESPACE_BEGIN @@ -37,7 +41,8 @@ class BigInteger { digits_[0] = u; } - BigInteger(const char* decimals, size_t length) : count_(1) { + template + BigInteger(const Ch* decimals, size_t length) : count_(1) { RAPIDJSON_ASSERT(length > 0); digits_[0] = 0; size_t i = 0; @@ -221,7 +226,8 @@ class BigInteger { bool IsZero() const { return count_ == 1 && digits_[0] == 0; } private: - void AppendDecimal64(const char* begin, const char* end) { + template + void AppendDecimal64(const Ch* begin, const Ch* end) { uint64_t u = ParseUint64(begin, end); if (IsZero()) *this = u; @@ -236,11 +242,12 @@ class BigInteger { digits_[count_++] = digit; } - static uint64_t ParseUint64(const char* begin, const char* end) { + template + static uint64_t ParseUint64(const Ch* begin, const Ch* end) { uint64_t r = 0; - for (const char* p = begin; p != end; ++p) { - RAPIDJSON_ASSERT(*p >= '0' && *p <= '9'); - r = r * 10u + static_cast(*p - '0'); + for (const Ch* p = begin; p != end; ++p) { + RAPIDJSON_ASSERT(*p >= Ch('0') && *p <= Ch('9')); + r = r * 10u + static_cast(*p - Ch('0')); } return r; } diff --git a/include/common/rapidjson/internal/clzll.h b/include/common/rapidjson/internal/clzll.h new file mode 100644 index 0000000..8fc5118 --- /dev/null +++ b/include/common/rapidjson/internal/clzll.h @@ -0,0 +1,71 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_CLZLL_H_ +#define RAPIDJSON_CLZLL_H_ + +#include "../rapidjson.h" + +#if defined(_MSC_VER) && !defined(UNDER_CE) +#include +#if defined(_WIN64) +#pragma intrinsic(_BitScanReverse64) +#else +#pragma intrinsic(_BitScanReverse) +#endif +#endif + +RAPIDJSON_NAMESPACE_BEGIN +namespace internal { + +inline uint32_t clzll(uint64_t x) { + // Passing 0 to __builtin_clzll is UB in GCC and results in an + // infinite loop in the software implementation. + RAPIDJSON_ASSERT(x != 0); + +#if defined(_MSC_VER) && !defined(UNDER_CE) + unsigned long r = 0; +#if defined(_WIN64) + _BitScanReverse64(&r, x); +#else + // Scan the high 32 bits. + if (_BitScanReverse(&r, static_cast(x >> 32))) + return 63 - (r + 32); + + // Scan the low 32 bits. + _BitScanReverse(&r, static_cast(x & 0xFFFFFFFF)); +#endif // _WIN64 + + return 63 - r; +#elif (defined(__GNUC__) && __GNUC__ >= 4) || RAPIDJSON_HAS_BUILTIN(__builtin_clzll) + // __builtin_clzll wrapper + return static_cast(__builtin_clzll(x)); +#else + // naive version + uint32_t r = 0; + while (!(x & (static_cast(1) << 63))) { + x <<= 1; + ++r; + } + + return r; +#endif // _MSC_VER +} + +#define RAPIDJSON_CLZLL RAPIDJSON_NAMESPACE::internal::clzll + +} // namespace internal +RAPIDJSON_NAMESPACE_END + +#endif // RAPIDJSON_CLZLL_H_ diff --git a/include/common/rapidjson/internal/diyfp.h b/include/common/rapidjson/internal/diyfp.h index b6c2cf5..f7d4653 100644 --- a/include/common/rapidjson/internal/diyfp.h +++ b/include/common/rapidjson/internal/diyfp.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at @@ -20,12 +20,16 @@ #define RAPIDJSON_DIYFP_H_ #include "../rapidjson.h" +#include "clzll.h" #include #if defined(_MSC_VER) && defined(_M_AMD64) && !defined(__INTEL_COMPILER) #include -#pragma intrinsic(_BitScanReverse64) +#if !defined(_ARM64EC_) #pragma intrinsic(_umul128) +#else +#pragma comment(lib,"softintrin") +#endif #endif RAPIDJSON_NAMESPACE_BEGIN @@ -100,22 +104,8 @@ struct DiyFp { } DiyFp Normalize() const { - RAPIDJSON_ASSERT(f != 0); // https://stackoverflow.com/a/26809183/291737 -#if defined(_MSC_VER) && defined(_M_AMD64) - unsigned long index; - _BitScanReverse64(&index, f); - return DiyFp(f << (63 - index), e - (63 - index)); -#elif defined(__GNUC__) && __GNUC__ >= 4 - int s = __builtin_clzll(f); + int s = static_cast(clzll(f)); return DiyFp(f << s, e - s); -#else - DiyFp res = *this; - while (!(res.f & (static_cast(1) << 63))) { - res.f <<= 1; - res.e--; - } - return res; -#endif } DiyFp NormalizeBoundary() const { diff --git a/include/common/rapidjson/internal/dtoa.h b/include/common/rapidjson/internal/dtoa.h index bf2e9b2..cd45672 100644 --- a/include/common/rapidjson/internal/dtoa.h +++ b/include/common/rapidjson/internal/dtoa.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at @@ -58,7 +58,11 @@ inline int CountDecimalDigit32(uint32_t n) { } inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buffer, int* len, int* K) { - static const uint32_t kPow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; + static const uint64_t kPow10[] = { 1ULL, 10ULL, 100ULL, 1000ULL, 10000ULL, 100000ULL, 1000000ULL, 10000000ULL, 100000000ULL, + 1000000000ULL, 10000000000ULL, 100000000000ULL, 1000000000000ULL, + 10000000000000ULL, 100000000000000ULL, 1000000000000000ULL, + 10000000000000000ULL, 100000000000000000ULL, 1000000000000000000ULL, + 10000000000000000000ULL }; const DiyFp one(uint64_t(1) << -Mp.e, Mp.e); const DiyFp wp_w = Mp - W; uint32_t p1 = static_cast(Mp.f >> -one.e); @@ -86,7 +90,7 @@ inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buff uint64_t tmp = (static_cast(p1) << -one.e) + p2; if (tmp <= delta) { *K += kappa; - GrisuRound(buffer, *len, delta, tmp, static_cast(kPow10[kappa]) << -one.e, wp_w.f); + GrisuRound(buffer, *len, delta, tmp, kPow10[kappa] << -one.e, wp_w.f); return; } } @@ -103,7 +107,7 @@ inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buff if (p2 < delta) { *K += kappa; int index = -kappa; - GrisuRound(buffer, *len, delta, p2, one.f, wp_w.f * (index < 9 ? kPow10[index] : 0)); + GrisuRound(buffer, *len, delta, p2, one.f, wp_w.f * (index < 20 ? kPow10[index] : 0)); return; } } diff --git a/include/common/rapidjson/internal/ieee754.h b/include/common/rapidjson/internal/ieee754.h index c2684ba..68c9e96 100644 --- a/include/common/rapidjson/internal/ieee754.h +++ b/include/common/rapidjson/internal/ieee754.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at diff --git a/include/common/rapidjson/internal/itoa.h b/include/common/rapidjson/internal/itoa.h index 9b1c45c..9fe8c93 100644 --- a/include/common/rapidjson/internal/itoa.h +++ b/include/common/rapidjson/internal/itoa.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at diff --git a/include/common/rapidjson/internal/meta.h b/include/common/rapidjson/internal/meta.h index d401edf..27092dc 100644 --- a/include/common/rapidjson/internal/meta.h +++ b/include/common/rapidjson/internal/meta.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at diff --git a/include/common/rapidjson/internal/pow10.h b/include/common/rapidjson/internal/pow10.h index 02f475d..eae1a43 100644 --- a/include/common/rapidjson/internal/pow10.h +++ b/include/common/rapidjson/internal/pow10.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at diff --git a/include/common/rapidjson/internal/regex.h b/include/common/rapidjson/internal/regex.h index de06718..6446c40 100644 --- a/include/common/rapidjson/internal/regex.h +++ b/include/common/rapidjson/internal/regex.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at @@ -23,7 +23,6 @@ RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_OFF(padded) RAPIDJSON_DIAG_OFF(switch-enum) -RAPIDJSON_DIAG_OFF(implicit-fallthrough) #elif defined(_MSC_VER) RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated @@ -32,9 +31,6 @@ RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated #ifdef __GNUC__ RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_OFF(effc++) -#if __GNUC__ >= 7 -RAPIDJSON_DIAG_OFF(implicit-fallthrough) -#endif #endif #ifndef RAPIDJSON_REGEX_VERBOSE @@ -118,7 +114,8 @@ class GenericRegex { template friend class GenericRegexSearch; GenericRegex(const Ch* source, Allocator* allocator = 0) : - states_(allocator, 256), ranges_(allocator, 256), root_(kRegexInvalidState), stateCount_(), rangeCount_(), + ownAllocator_(allocator ? 0 : RAPIDJSON_NEW(Allocator)()), allocator_(allocator ? allocator : ownAllocator_), + states_(allocator_, 256), ranges_(allocator_, 256), root_(kRegexInvalidState), stateCount_(), rangeCount_(), anchorBegin_(), anchorEnd_() { GenericStringStream ss(source); @@ -126,7 +123,10 @@ class GenericRegex { Parse(ds); } - ~GenericRegex() {} + ~GenericRegex() + { + RAPIDJSON_DELETE(ownAllocator_); + } bool IsValid() const { return root_ != kRegexInvalidState; @@ -188,10 +188,9 @@ class GenericRegex { template void Parse(DecodedStream& ds) { - Allocator allocator; - Stack operandStack(&allocator, 256); // Frag - Stack operatorStack(&allocator, 256); // Operator - Stack atomCountStack(&allocator, 256); // unsigned (Atom per parenthesis) + Stack operandStack(allocator_, 256); // Frag + Stack operatorStack(allocator_, 256); // Operator + Stack atomCountStack(allocator_, 256); // unsigned (Atom per parenthesis) *atomCountStack.template Push() = 0; @@ -288,6 +287,7 @@ class GenericRegex { if (!CharacterEscape(ds, &codepoint)) return; // Unsupported escape character // fall through to default + RAPIDJSON_DELIBERATE_FALLTHROUGH; default: // Pattern character PushOperand(operandStack, codepoint); @@ -392,8 +392,7 @@ class GenericRegex { } return false; - default: - RAPIDJSON_ASSERT(op == kOneOrMore); + case kOneOrMore: if (operandStack.GetSize() >= sizeof(Frag)) { Frag e = *operandStack.template Pop(1); SizeType s = NewState(kRegexInvalidState, e.start, 0); @@ -402,6 +401,10 @@ class GenericRegex { return true; } return false; + + default: + // syntax error (e.g. unclosed kLeftParenthesis) + return false; } } @@ -514,6 +517,7 @@ class GenericRegex { else if (!CharacterEscape(ds, &codepoint)) return false; // fall through to default + RAPIDJSON_DELIBERATE_FALLTHROUGH; default: switch (step) { @@ -523,6 +527,7 @@ class GenericRegex { break; } // fall through to step 0 for other characters + RAPIDJSON_DELIBERATE_FALLTHROUGH; case 0: { @@ -582,6 +587,8 @@ class GenericRegex { } } + Allocator* ownAllocator_; + Allocator* allocator_; Stack states_; Stack ranges_; SizeType root_; diff --git a/include/common/rapidjson/internal/stack.h b/include/common/rapidjson/internal/stack.h index 89558d0..73abd70 100644 --- a/include/common/rapidjson/internal/stack.h +++ b/include/common/rapidjson/internal/stack.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at @@ -17,6 +17,7 @@ #include "../allocators.h" #include "swap.h" +#include #if defined(__clang__) RAPIDJSON_DIAG_PUSH @@ -114,7 +115,7 @@ class Stack { template RAPIDJSON_FORCEINLINE void Reserve(size_t count = 1) { // Expand the stack if needed - if (RAPIDJSON_UNLIKELY(stackTop_ + sizeof(T) * count > stackEnd_)) + if (RAPIDJSON_UNLIKELY(static_cast(sizeof(T) * count) > (stackEnd_ - stackTop_))) Expand(count); } @@ -127,7 +128,7 @@ class Stack { template RAPIDJSON_FORCEINLINE T* PushUnsafe(size_t count = 1) { RAPIDJSON_ASSERT(stackTop_); - RAPIDJSON_ASSERT(stackTop_ + sizeof(T) * count <= stackEnd_); + RAPIDJSON_ASSERT(static_cast(sizeof(T) * count) <= (stackEnd_ - stackTop_)); T* ret = reinterpret_cast(stackTop_); stackTop_ += sizeof(T) * count; return ret; diff --git a/include/common/rapidjson/internal/strfunc.h b/include/common/rapidjson/internal/strfunc.h index 226439a..b698a8f 100644 --- a/include/common/rapidjson/internal/strfunc.h +++ b/include/common/rapidjson/internal/strfunc.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at @@ -45,6 +45,20 @@ inline SizeType StrLen(const wchar_t* s) { return SizeType(std::wcslen(s)); } +//! Custom strcmpn() which works on different character types. +/*! \tparam Ch Character type (e.g. char, wchar_t, short) + \param s1 Null-terminated input string. + \param s2 Null-terminated input string. + \return 0 if equal +*/ +template +inline int StrCmp(const Ch* s1, const Ch* s2) { + RAPIDJSON_ASSERT(s1 != 0); + RAPIDJSON_ASSERT(s2 != 0); + while(*s1 && (*s1 == *s2)) { s1++; s2++; } + return static_cast(*s1) < static_cast(*s2) ? -1 : static_cast(*s1) > static_cast(*s2); +} + //! Returns number of code points in a encoded string. template bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) { diff --git a/include/common/rapidjson/internal/strtod.h b/include/common/rapidjson/internal/strtod.h index dfca22b..55f0e38 100644 --- a/include/common/rapidjson/internal/strtod.h +++ b/include/common/rapidjson/internal/strtod.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at @@ -128,17 +128,18 @@ inline bool StrtodFast(double d, int p, double* result) { } // Compute an approximation and see if it is within 1/2 ULP -inline bool StrtodDiyFp(const char* decimals, int dLen, int dExp, double* result) { +template +inline bool StrtodDiyFp(const Ch* decimals, int dLen, int dExp, double* result) { uint64_t significand = 0; int i = 0; // 2^64 - 1 = 18446744073709551615, 1844674407370955161 = 0x1999999999999999 for (; i < dLen; i++) { if (significand > RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) || - (significand == RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) && decimals[i] > '5')) + (significand == RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) && decimals[i] > Ch('5'))) break; - significand = significand * 10u + static_cast(decimals[i] - '0'); + significand = significand * 10u + static_cast(decimals[i] - Ch('0')); } - if (i < dLen && decimals[i] >= '5') // Rounding + if (i < dLen && decimals[i] >= Ch('5')) // Rounding significand++; int remaining = dLen - i; @@ -205,7 +206,8 @@ inline bool StrtodDiyFp(const char* decimals, int dLen, int dExp, double* result return halfWay - static_cast(error) >= precisionBits || precisionBits >= halfWay + static_cast(error); } -inline double StrtodBigInteger(double approx, const char* decimals, int dLen, int dExp) { +template +inline double StrtodBigInteger(double approx, const Ch* decimals, int dLen, int dExp) { RAPIDJSON_ASSERT(dLen >= 0); const BigInteger dInt(decimals, static_cast(dLen)); Double a(approx); @@ -223,7 +225,8 @@ inline double StrtodBigInteger(double approx, const char* decimals, int dLen, in return a.NextPositiveDouble(); } -inline double StrtodFullPrecision(double d, int p, const char* decimals, size_t length, size_t decimalPosition, int exp) { +template +inline double StrtodFullPrecision(double d, int p, const Ch* decimals, size_t length, size_t decimalPosition, int exp) { RAPIDJSON_ASSERT(d >= 0.0); RAPIDJSON_ASSERT(length >= 1); diff --git a/include/common/rapidjson/internal/swap.h b/include/common/rapidjson/internal/swap.h index 666e49f..2cf92f9 100644 --- a/include/common/rapidjson/internal/swap.h +++ b/include/common/rapidjson/internal/swap.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at diff --git a/include/common/rapidjson/istreamwrapper.h b/include/common/rapidjson/istreamwrapper.h index 5f81698..01437ec 100644 --- a/include/common/rapidjson/istreamwrapper.h +++ b/include/common/rapidjson/istreamwrapper.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at @@ -17,6 +17,7 @@ #include "stream.h" #include +#include #ifdef __clang__ RAPIDJSON_DIAG_PUSH @@ -48,57 +49,71 @@ template class BasicIStreamWrapper { public: typedef typename StreamType::char_type Ch; - BasicIStreamWrapper(StreamType& stream) : stream_(stream), count_(), peekBuffer_() {} - Ch Peek() const { - typename StreamType::int_type c = stream_.peek(); - return RAPIDJSON_LIKELY(c != StreamType::traits_type::eof()) ? static_cast(c) : static_cast('\0'); + //! Constructor. + /*! + \param stream stream opened for read. + */ + BasicIStreamWrapper(StreamType &stream) : stream_(stream), buffer_(peekBuffer_), bufferSize_(4), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) { + Read(); } - Ch Take() { - typename StreamType::int_type c = stream_.get(); - if (RAPIDJSON_LIKELY(c != StreamType::traits_type::eof())) { - count_++; - return static_cast(c); - } - else - return '\0'; + //! Constructor. + /*! + \param stream stream opened for read. + \param buffer user-supplied buffer. + \param bufferSize size of buffer in bytes. Must >=4 bytes. + */ + BasicIStreamWrapper(StreamType &stream, char* buffer, size_t bufferSize) : stream_(stream), buffer_(buffer), bufferSize_(bufferSize), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) { + RAPIDJSON_ASSERT(bufferSize >= 4); + Read(); } - // tellg() may return -1 when failed. So we count by ourself. - size_t Tell() const { return count_; } + Ch Peek() const { return *current_; } + Ch Take() { Ch c = *current_; Read(); return c; } + size_t Tell() const { return count_ + static_cast(current_ - buffer_); } - Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } + // Not implemented void Put(Ch) { RAPIDJSON_ASSERT(false); } - void Flush() { RAPIDJSON_ASSERT(false); } + void Flush() { RAPIDJSON_ASSERT(false); } + Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } // For encoding detection only. const Ch* Peek4() const { - RAPIDJSON_ASSERT(sizeof(Ch) == 1); // Only usable for byte stream. - int i; - bool hasError = false; - for (i = 0; i < 4; ++i) { - typename StreamType::int_type c = stream_.get(); - if (c == StreamType::traits_type::eof()) { - hasError = true; - stream_.clear(); - break; - } - peekBuffer_[i] = static_cast(c); - } - for (--i; i >= 0; --i) - stream_.putback(peekBuffer_[i]); - return !hasError ? peekBuffer_ : 0; + return (current_ + 4 - !eof_ <= bufferLast_) ? current_ : 0; } private: + BasicIStreamWrapper(); BasicIStreamWrapper(const BasicIStreamWrapper&); BasicIStreamWrapper& operator=(const BasicIStreamWrapper&); - StreamType& stream_; - size_t count_; //!< Number of characters read. Note: - mutable Ch peekBuffer_[4]; + void Read() { + if (current_ < bufferLast_) + ++current_; + else if (!eof_) { + count_ += readCount_; + readCount_ = bufferSize_; + bufferLast_ = buffer_ + readCount_ - 1; + current_ = buffer_; + + if (!stream_.read(buffer_, static_cast(bufferSize_))) { + readCount_ = static_cast(stream_.gcount()); + *(bufferLast_ = buffer_ + readCount_) = '\0'; + eof_ = true; + } + } + } + + StreamType &stream_; + Ch peekBuffer_[4], *buffer_; + size_t bufferSize_; + Ch *bufferLast_; + Ch *current_; + size_t readCount_; + size_t count_; //!< Number of characters read + bool eof_; }; typedef BasicIStreamWrapper IStreamWrapper; diff --git a/include/common/rapidjson/memorybuffer.h b/include/common/rapidjson/memorybuffer.h index 39bee1d..ffbc41e 100644 --- a/include/common/rapidjson/memorybuffer.h +++ b/include/common/rapidjson/memorybuffer.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at diff --git a/include/common/rapidjson/memorystream.h b/include/common/rapidjson/memorystream.h index 1d71d8a..77af6c9 100644 --- a/include/common/rapidjson/memorystream.h +++ b/include/common/rapidjson/memorystream.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at diff --git a/include/common/rapidjson/ostreamwrapper.h b/include/common/rapidjson/ostreamwrapper.h index 6f4667c..11ed4d3 100644 --- a/include/common/rapidjson/ostreamwrapper.h +++ b/include/common/rapidjson/ostreamwrapper.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at diff --git a/include/common/rapidjson/pointer.h b/include/common/rapidjson/pointer.h index 3d339f2..05b1704 100644 --- a/include/common/rapidjson/pointer.h +++ b/include/common/rapidjson/pointer.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at @@ -16,7 +16,9 @@ #define RAPIDJSON_POINTER_H_ #include "document.h" +#include "uri.h" #include "internal/itoa.h" +#include "error/error.h" // PointerParseErrorCode #ifdef __clang__ RAPIDJSON_DIAG_PUSH @@ -30,19 +32,6 @@ RAPIDJSON_NAMESPACE_BEGIN static const SizeType kPointerInvalidIndex = ~SizeType(0); //!< Represents an invalid index in GenericPointer::Token -//! Error code of parsing. -/*! \ingroup RAPIDJSON_ERRORS - \see GenericPointer::GenericPointer, GenericPointer::GetParseErrorCode -*/ -enum PointerParseErrorCode { - kPointerParseErrorNone = 0, //!< The parse is successful - - kPointerParseErrorTokenMustBeginWithSolidus, //!< A token must begin with a '/' - kPointerParseErrorInvalidEscape, //!< Invalid escape - kPointerParseErrorInvalidPercentEncoding, //!< Invalid percent encoding in URI fragment - kPointerParseErrorCharacterMustPercentEncode //!< A character must percent encoded in URI fragment -}; - /////////////////////////////////////////////////////////////////////////////// // GenericPointer @@ -68,10 +57,10 @@ enum PointerParseErrorCode { supplied tokens eliminates these. GenericPointer depends on GenericDocument and GenericValue. - + \tparam ValueType The value type of the DOM tree. E.g. GenericValue > \tparam Allocator The allocator type for allocating memory for internal representation. - + \note GenericPointer uses same encoding of ValueType. However, Allocator of GenericPointer is independent of Allocator of Value. */ @@ -80,8 +69,10 @@ class GenericPointer { public: typedef typename ValueType::EncodingType EncodingType; //!< Encoding type from Value typedef typename ValueType::Ch Ch; //!< Character type from Value + typedef GenericUri UriType; + - //! A token is the basic units of internal representation. + //! A token is the basic units of internal representation. /*! A JSON pointer string representation "/foo/123" is parsed to two tokens: "foo" and 123. 123 will be represented in both numeric form and string form. @@ -163,7 +154,7 @@ class GenericPointer { GenericPointer(const Token* tokens, size_t tokenCount) : allocator_(), ownAllocator_(), nameBuffer_(), tokens_(const_cast(tokens)), tokenCount_(tokenCount), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {} //! Copy constructor. - GenericPointer(const GenericPointer& rhs) : allocator_(rhs.allocator_), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) { + GenericPointer(const GenericPointer& rhs) : allocator_(), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) { *this = rhs; } @@ -200,6 +191,36 @@ class GenericPointer { return *this; } + //! Swap the content of this pointer with an other. + /*! + \param other The pointer to swap with. + \note Constant complexity. + */ + GenericPointer& Swap(GenericPointer& other) RAPIDJSON_NOEXCEPT { + internal::Swap(allocator_, other.allocator_); + internal::Swap(ownAllocator_, other.ownAllocator_); + internal::Swap(nameBuffer_, other.nameBuffer_); + internal::Swap(tokens_, other.tokens_); + internal::Swap(tokenCount_, other.tokenCount_); + internal::Swap(parseErrorOffset_, other.parseErrorOffset_); + internal::Swap(parseErrorCode_, other.parseErrorCode_); + return *this; + } + + //! free-standing swap function helper + /*! + Helper function to enable support for common swap implementation pattern based on \c std::swap: + \code + void swap(MyClass& a, MyClass& b) { + using std::swap; + swap(a.pointer, b.pointer); + // ... + } + \endcode + \see Swap() + */ + friend inline void swap(GenericPointer& a, GenericPointer& b) RAPIDJSON_NOEXCEPT { a.Swap(b); } + //@} //!@name Append token @@ -356,6 +377,33 @@ class GenericPointer { */ bool operator!=(const GenericPointer& rhs) const { return !(*this == rhs); } + //! Less than operator. + /*! + \note Invalid pointers are always greater than valid ones. + */ + bool operator<(const GenericPointer& rhs) const { + if (!IsValid()) + return false; + if (!rhs.IsValid()) + return true; + + if (tokenCount_ != rhs.tokenCount_) + return tokenCount_ < rhs.tokenCount_; + + for (size_t i = 0; i < tokenCount_; i++) { + if (tokens_[i].index != rhs.tokens_[i].index) + return tokens_[i].index < rhs.tokens_[i].index; + + if (tokens_[i].length != rhs.tokens_[i].length) + return tokens_[i].length < rhs.tokens_[i].length; + + if (int cmp = std::memcmp(tokens_[i].name, rhs.tokens_[i].name, sizeof(Ch) * tokens_[i].length)) + return cmp < 0; + } + + return false; + } + //@} //!@name Stringify @@ -431,10 +479,11 @@ class GenericPointer { v = &((*v)[t->index]); } else { - typename ValueType::MemberIterator m = v->FindMember(GenericStringRef(t->name, t->length)); + typename ValueType::MemberIterator m = v->FindMember(GenericValue(GenericStringRef(t->name, t->length))); if (m == v->MemberEnd()) { v->AddMember(ValueType(t->name, t->length, allocator).Move(), ValueType().Move(), allocator); - v = &(--v->MemberEnd())->value; // Assumes AddMember() appends at the end + m = v->MemberEnd(); + v = &(--m)->value; // Assumes AddMember() appends at the end exist = false; } else @@ -462,6 +511,70 @@ class GenericPointer { //@} + //!@name Compute URI + //@{ + + //! Compute the in-scope URI for a subtree. + // For use with JSON pointers into JSON schema documents. + /*! + \param root Root value of a DOM sub-tree to be resolved. It can be any value other than document root. + \param rootUri Root URI + \param unresolvedTokenIndex If the pointer cannot resolve a token in the pointer, this parameter can obtain the index of unresolved token. + \param allocator Allocator for Uris + \return Uri if it can be resolved. Otherwise null. + + \note + There are only 3 situations when a URI cannot be resolved: + 1. A value in the path is not an array nor object. + 2. An object value does not contain the token. + 3. A token is out of range of an array value. + + Use unresolvedTokenIndex to retrieve the token index. + */ + UriType GetUri(ValueType& root, const UriType& rootUri, size_t* unresolvedTokenIndex = 0, Allocator* allocator = 0) const { + static const Ch kIdString[] = { 'i', 'd', '\0' }; + static const ValueType kIdValue(kIdString, 2); + UriType base = UriType(rootUri, allocator); + RAPIDJSON_ASSERT(IsValid()); + ValueType* v = &root; + for (const Token *t = tokens_; t != tokens_ + tokenCount_; ++t) { + switch (v->GetType()) { + case kObjectType: + { + // See if we have an id, and if so resolve with the current base + typename ValueType::MemberIterator m = v->FindMember(kIdValue); + if (m != v->MemberEnd() && (m->value).IsString()) { + UriType here = UriType(m->value, allocator).Resolve(base, allocator); + base = here; + } + m = v->FindMember(GenericValue(GenericStringRef(t->name, t->length))); + if (m == v->MemberEnd()) + break; + v = &m->value; + } + continue; + case kArrayType: + if (t->index == kPointerInvalidIndex || t->index >= v->Size()) + break; + v = &((*v)[t->index]); + continue; + default: + break; + } + + // Error: unresolved token + if (unresolvedTokenIndex) + *unresolvedTokenIndex = static_cast(t - tokens_); + return UriType(allocator); + } + return base; + } + + UriType GetUri(const ValueType& root, const UriType& rootUri, size_t* unresolvedTokenIndex = 0, Allocator* allocator = 0) const { + return GetUri(const_cast(root), rootUri, unresolvedTokenIndex, allocator); + } + + //!@name Query value //@{ @@ -486,7 +599,7 @@ class GenericPointer { switch (v->GetType()) { case kObjectType: { - typename ValueType::MemberIterator m = v->FindMember(GenericStringRef(t->name, t->length)); + typename ValueType::MemberIterator m = v->FindMember(GenericValue(GenericStringRef(t->name, t->length))); if (m == v->MemberEnd()) break; v = &m->value; @@ -576,7 +689,7 @@ class GenericPointer { ValueType& GetWithDefault(GenericDocument& document, const Ch* defaultValue) const { return GetWithDefault(document, defaultValue, document.GetAllocator()); } - + #if RAPIDJSON_HAS_STDSTRING //! Query a value in a document with default std::basic_string. template @@ -722,7 +835,7 @@ class GenericPointer { switch (v->GetType()) { case kObjectType: { - typename ValueType::MemberIterator m = v->FindMember(GenericStringRef(t->name, t->length)); + typename ValueType::MemberIterator m = v->FindMember(GenericValue(GenericStringRef(t->name, t->length))); if (m == v->MemberEnd()) return false; v = &m->value; @@ -870,7 +983,7 @@ class GenericPointer { } i++; - + // Escaping "~0" -> '~', "~1" -> '/' if (c == '~') { if (i < length) { diff --git a/include/common/rapidjson/prettywriter.h b/include/common/rapidjson/prettywriter.h index 45afb69..fe45df1 100644 --- a/include/common/rapidjson/prettywriter.h +++ b/include/common/rapidjson/prettywriter.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at @@ -60,7 +60,7 @@ class PrettyWriter : public Writer #endif // RAPIDJSON_HAS_STDSTRING +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_USE_MEMBERSMAP + +/*! \def RAPIDJSON_USE_MEMBERSMAP + \ingroup RAPIDJSON_CONFIG + \brief Enable RapidJSON support for object members handling in a \c std::multimap + + By defining this preprocessor symbol to \c 1, \ref rapidjson::GenericValue object + members are stored in a \c std::multimap for faster lookup and deletion times, a + trade off with a slightly slower insertion time and a small object allocat(or)ed + memory overhead. + + \hideinitializer +*/ +#ifndef RAPIDJSON_USE_MEMBERSMAP +#define RAPIDJSON_USE_MEMBERSMAP 0 // not by default +#endif + /////////////////////////////////////////////////////////////////////////////// // RAPIDJSON_NO_INT64DEFINE @@ -164,7 +195,7 @@ */ #ifndef RAPIDJSON_NO_INT64DEFINE //!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN -#if defined(_MSC_VER) && (_MSC_VER < 1800) // Visual Studio 2013 +#if defined(_MSC_VER) && (_MSC_VER < 1800) // Visual Studio 2013 #include "msinttypes/stdint.h" #include "msinttypes/inttypes.h" #else @@ -246,7 +277,7 @@ # elif defined(RAPIDJSON_DOXYGEN_RUNNING) # define RAPIDJSON_ENDIAN # else -# error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN. +# error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN. # endif #endif // RAPIDJSON_ENDIAN @@ -411,7 +442,7 @@ RAPIDJSON_NAMESPACE_END // Prefer C++11 static_assert, if available #ifndef RAPIDJSON_STATIC_ASSERT -#if __cplusplus >= 201103L || ( defined(_MSC_VER) && _MSC_VER >= 1800 ) +#if RAPIDJSON_CPLUSPLUS >= 201103L || ( defined(_MSC_VER) && _MSC_VER >= 1800 ) #define RAPIDJSON_STATIC_ASSERT(x) \ static_assert(x, RAPIDJSON_STRINGIFY(x)) #endif // C++11 @@ -482,7 +513,7 @@ RAPIDJSON_NAMESPACE_END //!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN -#define RAPIDJSON_MULTILINEMACRO_BEGIN do { +#define RAPIDJSON_MULTILINEMACRO_BEGIN do { #define RAPIDJSON_MULTILINEMACRO_END \ } while((void)0, 0) @@ -490,6 +521,12 @@ RAPIDJSON_NAMESPACE_END #define RAPIDJSON_VERSION_CODE(x,y,z) \ (((x)*100000) + ((y)*100) + (z)) +#if defined(__has_builtin) +#define RAPIDJSON_HAS_BUILTIN(x) __has_builtin(x) +#else +#define RAPIDJSON_HAS_BUILTIN(x) 0 +#endif + /////////////////////////////////////////////////////////////////////////////// // RAPIDJSON_DIAG_PUSH/POP, RAPIDJSON_DIAG_OFF @@ -535,8 +572,14 @@ RAPIDJSON_NAMESPACE_END /////////////////////////////////////////////////////////////////////////////// // C++11 features +#ifndef RAPIDJSON_HAS_CXX11 +#define RAPIDJSON_HAS_CXX11 (RAPIDJSON_CPLUSPLUS >= 201103L) +#endif + #ifndef RAPIDJSON_HAS_CXX11_RVALUE_REFS -#if defined(__clang__) +#if RAPIDJSON_HAS_CXX11 +#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1 +#elif defined(__clang__) #if __has_feature(cxx_rvalue_references) && \ (defined(_MSC_VER) || defined(_LIBCPP_VERSION) || defined(__GLIBCXX__) && __GLIBCXX__ >= 20080306) #define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1 @@ -553,8 +596,14 @@ RAPIDJSON_NAMESPACE_END #endif #endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS +#include // std::move +#endif + #ifndef RAPIDJSON_HAS_CXX11_NOEXCEPT -#if defined(__clang__) +#if RAPIDJSON_HAS_CXX11 +#define RAPIDJSON_HAS_CXX11_NOEXCEPT 1 +#elif defined(__clang__) #define RAPIDJSON_HAS_CXX11_NOEXCEPT __has_feature(cxx_noexcept) #elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \ (defined(_MSC_VER) && _MSC_VER >= 1900) || \ @@ -564,11 +613,13 @@ RAPIDJSON_NAMESPACE_END #define RAPIDJSON_HAS_CXX11_NOEXCEPT 0 #endif #endif +#ifndef RAPIDJSON_NOEXCEPT #if RAPIDJSON_HAS_CXX11_NOEXCEPT #define RAPIDJSON_NOEXCEPT noexcept #else -#define RAPIDJSON_NOEXCEPT /* noexcept */ +#define RAPIDJSON_NOEXCEPT throw() #endif // RAPIDJSON_HAS_CXX11_NOEXCEPT +#endif // no automatic detection, yet #ifndef RAPIDJSON_HAS_CXX11_TYPETRAITS @@ -591,8 +642,68 @@ RAPIDJSON_NAMESPACE_END #endif #endif // RAPIDJSON_HAS_CXX11_RANGE_FOR +/////////////////////////////////////////////////////////////////////////////// +// C++17 features + +#ifndef RAPIDJSON_HAS_CXX17 +#define RAPIDJSON_HAS_CXX17 (RAPIDJSON_CPLUSPLUS >= 201703L) +#endif + +#if RAPIDJSON_HAS_CXX17 +# define RAPIDJSON_DELIBERATE_FALLTHROUGH [[fallthrough]] +#elif defined(__has_cpp_attribute) +# if __has_cpp_attribute(clang::fallthrough) +# define RAPIDJSON_DELIBERATE_FALLTHROUGH [[clang::fallthrough]] +# elif __has_cpp_attribute(fallthrough) +# define RAPIDJSON_DELIBERATE_FALLTHROUGH __attribute__((fallthrough)) +# else +# define RAPIDJSON_DELIBERATE_FALLTHROUGH +# endif +#else +# define RAPIDJSON_DELIBERATE_FALLTHROUGH +#endif + //!@endcond +//! Assertion (in non-throwing contexts). + /*! \ingroup RAPIDJSON_CONFIG + Some functions provide a \c noexcept guarantee, if the compiler supports it. + In these cases, the \ref RAPIDJSON_ASSERT macro cannot be overridden to + throw an exception. This macro adds a separate customization point for + such cases. + + Defaults to C \c assert() (as \ref RAPIDJSON_ASSERT), if \c noexcept is + supported, and to \ref RAPIDJSON_ASSERT otherwise. + */ + +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_NOEXCEPT_ASSERT + +#ifndef RAPIDJSON_NOEXCEPT_ASSERT +#ifdef RAPIDJSON_ASSERT_THROWS +#include +#define RAPIDJSON_NOEXCEPT_ASSERT(x) assert(x) +#else +#define RAPIDJSON_NOEXCEPT_ASSERT(x) RAPIDJSON_ASSERT(x) +#endif // RAPIDJSON_ASSERT_THROWS +#endif // RAPIDJSON_NOEXCEPT_ASSERT + +/////////////////////////////////////////////////////////////////////////////// +// malloc/realloc/free + +#ifndef RAPIDJSON_MALLOC +///! customization point for global \c malloc +#define RAPIDJSON_MALLOC(size) std::malloc(size) +#endif +#ifndef RAPIDJSON_REALLOC +///! customization point for global \c realloc +#define RAPIDJSON_REALLOC(ptr, new_size) std::realloc(ptr, new_size) +#endif +#ifndef RAPIDJSON_FREE +///! customization point for global \c free +#define RAPIDJSON_FREE(ptr) std::free(ptr) +#endif + /////////////////////////////////////////////////////////////////////////////// // new/delete @@ -620,7 +731,7 @@ enum Type { kFalseType = 1, //!< false kTrueType = 2, //!< true kObjectType = 3, //!< object - kArrayType = 4, //!< array + kArrayType = 4, //!< array kStringType = 5, //!< string kNumberType = 6 //!< number }; diff --git a/include/common/rapidjson/reader.h b/include/common/rapidjson/reader.h index 4bbde9e..5554660 100644 --- a/include/common/rapidjson/reader.h +++ b/include/common/rapidjson/reader.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at @@ -20,6 +20,7 @@ #include "allocators.h" #include "stream.h" #include "encodedstream.h" +#include "internal/clzll.h" #include "internal/meta.h" #include "internal/stack.h" #include "internal/strtod.h" @@ -153,6 +154,7 @@ enum ParseFlag { kParseNumbersAsStringsFlag = 64, //!< Parse all numbers (ints/doubles) as strings. kParseTrailingCommasFlag = 128, //!< Allow trailing commas at the end of objects and arrays. kParseNanAndInfFlag = 256, //!< Allow parsing NaN, Inf, Infinity, -Inf and -Infinity as doubles. + kParseEscapedApostropheFlag = 512, //!< Allow escaped apostrophe in strings. kParseDefaultFlags = RAPIDJSON_PARSE_DEFAULT_FLAGS //!< Default parse flags. Can be customized by defining RAPIDJSON_PARSE_DEFAULT_FLAGS }; @@ -443,16 +445,16 @@ inline const char *SkipWhitespace_SIMD(const char* p) { x = vmvnq_u8(x); // Negate x = vrev64q_u8(x); // Rev in 64 - uint64_t low = vgetq_lane_u64(reinterpret_cast(x), 0); // extract - uint64_t high = vgetq_lane_u64(reinterpret_cast(x), 1); // extract + uint64_t low = vgetq_lane_u64(vreinterpretq_u64_u8(x), 0); // extract + uint64_t high = vgetq_lane_u64(vreinterpretq_u64_u8(x), 1); // extract if (low == 0) { if (high != 0) { - int lz =__builtin_clzll(high);; + uint32_t lz = internal::clzll(high); return p + 8 + (lz >> 3); } } else { - int lz = __builtin_clzll(low);; + uint32_t lz = internal::clzll(low); return p + (lz >> 3); } } @@ -479,16 +481,16 @@ inline const char *SkipWhitespace_SIMD(const char* p, const char* end) { x = vmvnq_u8(x); // Negate x = vrev64q_u8(x); // Rev in 64 - uint64_t low = vgetq_lane_u64(reinterpret_cast(x), 0); // extract - uint64_t high = vgetq_lane_u64(reinterpret_cast(x), 1); // extract + uint64_t low = vgetq_lane_u64(vreinterpretq_u64_u8(x), 0); // extract + uint64_t high = vgetq_lane_u64(vreinterpretq_u64_u8(x), 1); // extract if (low == 0) { if (high != 0) { - int lz = __builtin_clzll(high); + uint32_t lz = internal::clzll(high); return p + 8 + (lz >> 3); } } else { - int lz = __builtin_clzll(low); + uint32_t lz = internal::clzll(low); return p + (lz >> 3); } } @@ -606,7 +608,7 @@ class GenericReader { parseResult_.Clear(); state_ = IterativeParsingStartState; } - + //! Parse one token from JSON text /*! \tparam InputStream Type of input stream, implementing Stream concept \tparam Handler Type of handler, implementing Handler concept. @@ -618,11 +620,11 @@ class GenericReader { bool IterativeParseNext(InputStream& is, Handler& handler) { while (RAPIDJSON_LIKELY(is.Peek() != '\0')) { SkipWhitespaceAndComments(is); - + Token t = Tokenize(is.Peek()); IterativeParsingState n = Predict(state_, t); IterativeParsingState d = Transit(state_, t, n, is, handler); - + // If we've finished or hit an error... if (RAPIDJSON_UNLIKELY(IsIterativeParsingCompleteState(d))) { // Report errors. @@ -630,11 +632,11 @@ class GenericReader { HandleError(state_, is); return false; } - + // Transition to the finish state. RAPIDJSON_ASSERT(d == IterativeParsingFinishState); state_ = d; - + // If StopWhenDone is not set... if (!(parseFlags & kParseStopWhenDoneFlag)) { // ... and extra non-whitespace data is found... @@ -645,11 +647,11 @@ class GenericReader { return false; } } - + // Success! We are done! return true; } - + // Transition to the new state. state_ = d; @@ -657,7 +659,7 @@ class GenericReader { if (!IsIterativeParsingDelimiterState(n)) return true; } - + // We reached the end of file. stack_.Clear(); @@ -665,10 +667,10 @@ class GenericReader { HandleError(state_, is); return false; } - + return true; } - + //! Check if token-by-token parsing JSON text is complete /*! \return Whether the JSON has been fully decoded. */ @@ -990,7 +992,7 @@ class GenericReader { //!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN #define Z16 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 static const char escape[256] = { - Z16, Z16, 0, 0,'\"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,'/', + Z16, Z16, 0, 0,'\"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '/', Z16, Z16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,'\\', 0, 0, 0, 0, 0,'\b', 0, 0, 0,'\f', 0, 0, 0, 0, 0, 0, 0,'\n', 0, 0, 0,'\r', 0,'\t', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -1013,19 +1015,31 @@ class GenericReader { is.Take(); os.Put(static_cast(escape[static_cast(e)])); } + else if ((parseFlags & kParseEscapedApostropheFlag) && RAPIDJSON_LIKELY(e == '\'')) { // Allow escaped apostrophe + is.Take(); + os.Put('\''); + } else if (RAPIDJSON_LIKELY(e == 'u')) { // Unicode is.Take(); unsigned codepoint = ParseHex4(is, escapeOffset); RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; - if (RAPIDJSON_UNLIKELY(codepoint >= 0xD800 && codepoint <= 0xDBFF)) { - // Handle UTF-16 surrogate pair - if (RAPIDJSON_UNLIKELY(!Consume(is, '\\') || !Consume(is, 'u'))) - RAPIDJSON_PARSE_ERROR(kParseErrorStringUnicodeSurrogateInvalid, escapeOffset); - unsigned codepoint2 = ParseHex4(is, escapeOffset); - RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; - if (RAPIDJSON_UNLIKELY(codepoint2 < 0xDC00 || codepoint2 > 0xDFFF)) + if (RAPIDJSON_UNLIKELY(codepoint >= 0xD800 && codepoint <= 0xDFFF)) { + // high surrogate, check if followed by valid low surrogate + if (RAPIDJSON_LIKELY(codepoint <= 0xDBFF)) { + // Handle UTF-16 surrogate pair + if (RAPIDJSON_UNLIKELY(!Consume(is, '\\') || !Consume(is, 'u'))) + RAPIDJSON_PARSE_ERROR(kParseErrorStringUnicodeSurrogateInvalid, escapeOffset); + unsigned codepoint2 = ParseHex4(is, escapeOffset); + RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; + if (RAPIDJSON_UNLIKELY(codepoint2 < 0xDC00 || codepoint2 > 0xDFFF)) + RAPIDJSON_PARSE_ERROR(kParseErrorStringUnicodeSurrogateInvalid, escapeOffset); + codepoint = (((codepoint - 0xD800) << 10) | (codepoint2 - 0xDC00)) + 0x10000; + } + // single low surrogate + else + { RAPIDJSON_PARSE_ERROR(kParseErrorStringUnicodeSurrogateInvalid, escapeOffset); - codepoint = (((codepoint - 0xD800) << 10) | (codepoint2 - 0xDC00)) + 0x10000; + } } TEncoding::Encode(os, codepoint); } @@ -1244,19 +1258,19 @@ class GenericReader { x = vorrq_u8(x, vcltq_u8(s, s3)); x = vrev64q_u8(x); // Rev in 64 - uint64_t low = vgetq_lane_u64(reinterpret_cast(x), 0); // extract - uint64_t high = vgetq_lane_u64(reinterpret_cast(x), 1); // extract + uint64_t low = vgetq_lane_u64(vreinterpretq_u64_u8(x), 0); // extract + uint64_t high = vgetq_lane_u64(vreinterpretq_u64_u8(x), 1); // extract SizeType length = 0; bool escaped = false; if (low == 0) { if (high != 0) { - unsigned lz = (unsigned)__builtin_clzll(high);; + uint32_t lz = internal::clzll(high); length = 8 + (lz >> 3); escaped = true; } } else { - unsigned lz = (unsigned)__builtin_clzll(low);; + uint32_t lz = internal::clzll(low); length = lz >> 3; escaped = true; } @@ -1314,19 +1328,19 @@ class GenericReader { x = vorrq_u8(x, vcltq_u8(s, s3)); x = vrev64q_u8(x); // Rev in 64 - uint64_t low = vgetq_lane_u64(reinterpret_cast(x), 0); // extract - uint64_t high = vgetq_lane_u64(reinterpret_cast(x), 1); // extract + uint64_t low = vgetq_lane_u64(vreinterpretq_u64_u8(x), 0); // extract + uint64_t high = vgetq_lane_u64(vreinterpretq_u64_u8(x), 1); // extract SizeType length = 0; bool escaped = false; if (low == 0) { if (high != 0) { - unsigned lz = (unsigned)__builtin_clzll(high); + uint32_t lz = internal::clzll(high); length = 8 + (lz >> 3); escaped = true; } } else { - unsigned lz = (unsigned)__builtin_clzll(low); + uint32_t lz = internal::clzll(low); length = lz >> 3; escaped = true; } @@ -1370,17 +1384,17 @@ class GenericReader { x = vorrq_u8(x, vcltq_u8(s, s3)); x = vrev64q_u8(x); // Rev in 64 - uint64_t low = vgetq_lane_u64(reinterpret_cast(x), 0); // extract - uint64_t high = vgetq_lane_u64(reinterpret_cast(x), 1); // extract + uint64_t low = vgetq_lane_u64(vreinterpretq_u64_u8(x), 0); // extract + uint64_t high = vgetq_lane_u64(vreinterpretq_u64_u8(x), 1); // extract if (low == 0) { if (high != 0) { - int lz = __builtin_clzll(high); + uint32_t lz = internal::clzll(high); p += 8 + (lz >> 3); break; } } else { - int lz = __builtin_clzll(low); + uint32_t lz = internal::clzll(low); p += lz >> 3; break; } @@ -1390,11 +1404,11 @@ class GenericReader { } #endif // RAPIDJSON_NEON - template + template class NumberStream; - template - class NumberStream { + template + class NumberStream { public: typedef typename InputStream::Ch Ch; @@ -1403,11 +1417,11 @@ class GenericReader { RAPIDJSON_FORCEINLINE Ch Peek() const { return is.Peek(); } RAPIDJSON_FORCEINLINE Ch TakePush() { return is.Take(); } RAPIDJSON_FORCEINLINE Ch Take() { return is.Take(); } - RAPIDJSON_FORCEINLINE void Push(char) {} + RAPIDJSON_FORCEINLINE void Push(char) {} size_t Tell() { return is.Tell(); } size_t Length() { return 0; } - const char* Pop() { return 0; } + const StackCharacter* Pop() { return 0; } protected: NumberStream& operator=(const NumberStream&); @@ -1415,45 +1429,47 @@ class GenericReader { InputStream& is; }; - template - class NumberStream : public NumberStream { - typedef NumberStream Base; + template + class NumberStream : public NumberStream { + typedef NumberStream Base; public: - NumberStream(GenericReader& reader, InputStream& is) : Base(reader, is), stackStream(reader.stack_) {} + NumberStream(GenericReader& reader, InputStream& s) : Base(reader, s), stackStream(reader.stack_) {} RAPIDJSON_FORCEINLINE Ch TakePush() { - stackStream.Put(static_cast(Base::is.Peek())); + stackStream.Put(static_cast(Base::is.Peek())); return Base::is.Take(); } - RAPIDJSON_FORCEINLINE void Push(char c) { + RAPIDJSON_FORCEINLINE void Push(StackCharacter c) { stackStream.Put(c); } size_t Length() { return stackStream.Length(); } - const char* Pop() { + const StackCharacter* Pop() { stackStream.Put('\0'); return stackStream.Pop(); } private: - StackStream stackStream; + StackStream stackStream; }; - template - class NumberStream : public NumberStream { - typedef NumberStream Base; + template + class NumberStream : public NumberStream { + typedef NumberStream Base; public: - NumberStream(GenericReader& reader, InputStream& is) : Base(reader, is) {} + NumberStream(GenericReader& reader, InputStream& s) : Base(reader, s) {} RAPIDJSON_FORCEINLINE Ch Take() { return Base::TakePush(); } }; template void ParseNumber(InputStream& is, Handler& handler) { + typedef typename internal::SelectIf, typename TargetEncoding::Ch, char>::Type NumberCharacter; + internal::StreamLocalCopy copy(is); - NumberStream(s.Length()); - StringStream srcStream(s.Pop()); + GenericStringStream > srcStream(s.Pop()); StackStream dstStream(stack_); while (numCharsToCopy--) { - Transcoder, TargetEncoding>::Transcode(srcStream, dstStream); + Transcoder, TargetEncoding>::Transcode(srcStream, dstStream); } dstStream.Put('\0'); const typename TargetEncoding::Ch* str = dstStream.Pop(); @@ -1691,7 +1707,7 @@ class GenericReader { } else { size_t length = s.Length(); - const char* decimal = s.Pop(); // Pop stack no matter if it will be used or not. + const NumberCharacter* decimal = s.Pop(); // Pop stack no matter if it will be used or not. if (useDouble) { int p = exp + expFrac; @@ -1769,12 +1785,12 @@ class GenericReader { // Single value state IterativeParsingValueState, - + // Delimiter states (at bottom) IterativeParsingElementDelimiterState, IterativeParsingMemberDelimiterState, IterativeParsingKeyValueDelimiterState, - + cIterativeParsingStateCount }; @@ -2167,43 +2183,43 @@ class GenericReader { RAPIDJSON_FORCEINLINE bool IsIterativeParsingDelimiterState(IterativeParsingState s) const { return s >= IterativeParsingElementDelimiterState; } - + RAPIDJSON_FORCEINLINE bool IsIterativeParsingCompleteState(IterativeParsingState s) const { return s <= IterativeParsingErrorState; } - + template ParseResult IterativeParse(InputStream& is, Handler& handler) { parseResult_.Clear(); ClearStackOnExit scope(*this); IterativeParsingState state = IterativeParsingStartState; - + SkipWhitespaceAndComments(is); RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_); while (is.Peek() != '\0') { Token t = Tokenize(is.Peek()); IterativeParsingState n = Predict(state, t); IterativeParsingState d = Transit(state, t, n, is, handler); - + if (d == IterativeParsingErrorState) { HandleError(state, is); break; } - + state = d; - + // Do not further consume streams if a root JSON has been parsed. if ((parseFlags & kParseStopWhenDoneFlag) && state == IterativeParsingFinishState) break; - + SkipWhitespaceAndComments(is); RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_); } - + // Handle the end of file. if (state != IterativeParsingFinishState) HandleError(state, is); - + return parseResult_; } diff --git a/include/common/rapidjson/schema.h b/include/common/rapidjson/schema.h index fa0d696..439133f 100644 --- a/include/common/rapidjson/schema.h +++ b/include/common/rapidjson/schema.h @@ -1,5 +1,5 @@ // Tencent is pleased to support the open source community by making RapidJSON available-> -// +// // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip-> All rights reserved-> // // Licensed under the MIT License (the "License"); you may not use this file except @@ -7,9 +7,9 @@ // // http://opensource->org/licenses/MIT // -// Unless required by applicable law or agreed to in writing, software distributed -// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, either express or implied-> See the License for the +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied-> See the License for the // specific language governing permissions and limitations under the License-> #ifndef RAPIDJSON_SCHEMA_H_ @@ -18,6 +18,8 @@ #include "document.h" #include "pointer.h" #include "stringbuffer.h" +#include "error/en.h" +#include "uri.h" #include // abs, floor #if !defined(RAPIDJSON_SCHEMA_USE_INTERNALREGEX) @@ -48,10 +50,6 @@ #define RAPIDJSON_SCHEMA_VERBOSE 0 #endif -#if RAPIDJSON_SCHEMA_VERBOSE -#include "stringbuffer.h" -#endif - RAPIDJSON_DIAG_PUSH #if defined(__GNUC__) @@ -76,50 +74,163 @@ RAPIDJSON_NAMESPACE_BEGIN namespace internal { -inline void PrintInvalidKeyword(const char* keyword) { - printf("Fail keyword: %s\n", keyword); +inline void PrintInvalidKeywordData(const char* keyword) { + printf(" Fail keyword: '%s'\n", keyword); +} + +inline void PrintInvalidKeywordData(const wchar_t* keyword) { + wprintf(L" Fail keyword: '%ls'\n", keyword); +} + +inline void PrintInvalidDocumentData(const char* document) { + printf(" Fail document: '%s'\n", document); } -inline void PrintInvalidKeyword(const wchar_t* keyword) { - wprintf(L"Fail keyword: %ls\n", keyword); +inline void PrintInvalidDocumentData(const wchar_t* document) { + wprintf(L" Fail document: '%ls'\n", document); } -inline void PrintInvalidDocument(const char* document) { - printf("Fail document: %s\n\n", document); +inline void PrintValidatorPointersData(const char* s, const char* d, unsigned depth) { + printf(" Sch: %*s'%s'\n Doc: %*s'%s'\n", depth * 4, " ", s, depth * 4, " ", d); } -inline void PrintInvalidDocument(const wchar_t* document) { - wprintf(L"Fail document: %ls\n\n", document); +inline void PrintValidatorPointersData(const wchar_t* s, const wchar_t* d, unsigned depth) { + wprintf(L" Sch: %*ls'%ls'\n Doc: %*ls'%ls'\n", depth * 4, L" ", s, depth * 4, L" ", d); } -inline void PrintValidatorPointers(unsigned depth, const char* s, const char* d) { - printf("S: %*s%s\nD: %*s%s\n\n", depth * 4, " ", s, depth * 4, " ", d); +inline void PrintSchemaIdsData(const char* base, const char* local, const char* resolved) { + printf(" Resolving id: Base: '%s', Local: '%s', Resolved: '%s'\n", base, local, resolved); } -inline void PrintValidatorPointers(unsigned depth, const wchar_t* s, const wchar_t* d) { - wprintf(L"S: %*ls%ls\nD: %*ls%ls\n\n", depth * 4, L" ", s, depth * 4, L" ", d); +inline void PrintSchemaIdsData(const wchar_t* base, const wchar_t* local, const wchar_t* resolved) { + wprintf(L" Resolving id: Base: '%ls', Local: '%ls', Resolved: '%ls'\n", base, local, resolved); +} + +inline void PrintMethodData(const char* method) { + printf("%s\n", method); +} + +inline void PrintMethodData(const char* method, bool b) { + printf("%s, Data: '%s'\n", method, b ? "true" : "false"); +} + +inline void PrintMethodData(const char* method, int64_t i) { + printf("%s, Data: '%" PRId64 "'\n", method, i); +} + +inline void PrintMethodData(const char* method, uint64_t u) { + printf("%s, Data: '%" PRIu64 "'\n", method, u); +} + +inline void PrintMethodData(const char* method, double d) { + printf("%s, Data: '%lf'\n", method, d); +} + +inline void PrintMethodData(const char* method, const char* s) { + printf("%s, Data: '%s'\n", method, s); +} + +inline void PrintMethodData(const char* method, const wchar_t* s) { + wprintf(L"%hs, Data: '%ls'\n", method, s); +} + +inline void PrintMethodData(const char* method, const char* s1, const char* s2) { + printf("%s, Data: '%s', '%s'\n", method, s1, s2); +} + +inline void PrintMethodData(const char* method, const wchar_t* s1, const wchar_t* s2) { + wprintf(L"%hs, Data: '%ls', '%ls'\n", method, s1, s2); } } // namespace internal #endif // RAPIDJSON_SCHEMA_VERBOSE -/////////////////////////////////////////////////////////////////////////////// -// RAPIDJSON_INVALID_KEYWORD_RETURN - +#ifndef RAPIDJSON_SCHEMA_PRINT #if RAPIDJSON_SCHEMA_VERBOSE -#define RAPIDJSON_INVALID_KEYWORD_VERBOSE(keyword) internal::PrintInvalidKeyword(keyword) +#define RAPIDJSON_SCHEMA_PRINT(name, ...) internal::Print##name##Data(__VA_ARGS__) #else -#define RAPIDJSON_INVALID_KEYWORD_VERBOSE(keyword) +#define RAPIDJSON_SCHEMA_PRINT(name, ...) +#endif #endif -#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)\ +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_INVALID_KEYWORD_RETURN + +#define RAPIDJSON_INVALID_KEYWORD_RETURN(code)\ RAPIDJSON_MULTILINEMACRO_BEGIN\ - context.invalidKeyword = keyword.GetString();\ - RAPIDJSON_INVALID_KEYWORD_VERBOSE(keyword.GetString());\ + context.invalidCode = code;\ + context.invalidKeyword = SchemaType::GetValidateErrorKeyword(code).GetString();\ + RAPIDJSON_SCHEMA_PRINT(InvalidKeyword, context.invalidKeyword);\ return false;\ RAPIDJSON_MULTILINEMACRO_END +/////////////////////////////////////////////////////////////////////////////// +// ValidateFlag + +/*! \def RAPIDJSON_VALIDATE_DEFAULT_FLAGS + \ingroup RAPIDJSON_CONFIG + \brief User-defined kValidateDefaultFlags definition. + + User can define this as any \c ValidateFlag combinations. +*/ +#ifndef RAPIDJSON_VALIDATE_DEFAULT_FLAGS +#define RAPIDJSON_VALIDATE_DEFAULT_FLAGS kValidateNoFlags +#endif + +//! Combination of validate flags +/*! \see + */ +enum ValidateFlag { + kValidateNoFlags = 0, //!< No flags are set. + kValidateContinueOnErrorFlag = 1, //!< Don't stop after first validation error. + kValidateReadFlag = 2, //!< Validation is for a read semantic. + kValidateWriteFlag = 4, //!< Validation is for a write semantic. + kValidateDefaultFlags = RAPIDJSON_VALIDATE_DEFAULT_FLAGS //!< Default validate flags. Can be customized by defining RAPIDJSON_VALIDATE_DEFAULT_FLAGS +}; + +/////////////////////////////////////////////////////////////////////////////// +// Specification +enum SchemaDraft { + kDraftUnknown = -1, + kDraftNone = 0, + kDraft03 = 3, + kDraftMin = 4, //!< Current minimum supported draft + kDraft04 = 4, + kDraft05 = 5, + kDraftMax = 5, //!< Current maximum supported draft + kDraft06 = 6, + kDraft07 = 7, + kDraft2019_09 = 8, + kDraft2020_12 = 9 +}; + +enum OpenApiVersion { + kVersionUnknown = -1, + kVersionNone = 0, + kVersionMin = 2, //!< Current minimum supported version + kVersion20 = 2, + kVersion30 = 3, + kVersionMax = 3, //!< Current maximum supported version + kVersion31 = 4, +}; + +struct Specification { + Specification(SchemaDraft d) : draft(d), oapi(kVersionNone) {} + Specification(OpenApiVersion o) : oapi(o) { + if (oapi == kVersion20) draft = kDraft04; + else if (oapi == kVersion30) draft = kDraft05; + else if (oapi == kVersion31) draft = kDraft2020_12; + else draft = kDraft04; + } + ~Specification() {} + bool IsSupported() const { + return ((draft >= kDraftMin && draft <= kDraftMax) && ((oapi == kVersionNone) || (oapi >= kVersionMin && oapi <= kVersionMax))); + } + SchemaDraft draft; + OpenApiVersion oapi; +}; + /////////////////////////////////////////////////////////////////////////////// // Forward declarations @@ -138,6 +249,8 @@ class ISchemaValidator { public: virtual ~ISchemaValidator() {} virtual bool IsValid() const = 0; + virtual void SetValidateFlags(unsigned flags) = 0; + virtual unsigned GetValidateFlags() const = 0; }; /////////////////////////////////////////////////////////////////////////////// @@ -147,7 +260,7 @@ template class ISchemaStateFactory { public: virtual ~ISchemaStateFactory() {} - virtual ISchemaValidator* CreateSchemaValidator(const SchemaType&) = 0; + virtual ISchemaValidator* CreateSchemaValidator(const SchemaType&, const bool inheritContinueOnErrors) = 0; virtual void DestroySchemaValidator(ISchemaValidator* validator) = 0; virtual void* CreateHasher() = 0; virtual uint64_t GetHashCode(void* hasher) = 0; @@ -201,14 +314,17 @@ class IValidationErrorHandler { virtual void AddDependencySchemaError(const SValue& souceName, ISchemaValidator* subvalidator) = 0; virtual bool EndDependencyErrors() = 0; - virtual void DisallowedValue() = 0; + virtual void DisallowedValue(const ValidateErrorCode code) = 0; virtual void StartDisallowedType() = 0; virtual void AddExpectedType(const typename SchemaType::ValueType& expectedType) = 0; virtual void EndDisallowedType(const typename SchemaType::ValueType& actualType) = 0; virtual void NotAllOf(ISchemaValidator** subvalidators, SizeType count) = 0; virtual void NoneOf(ISchemaValidator** subvalidators, SizeType count) = 0; virtual void NotOneOf(ISchemaValidator** subvalidators, SizeType count) = 0; + virtual void MultipleOneOf(SizeType index1, SizeType index2) = 0; virtual void Disallowed() = 0; + virtual void DisallowedWhenWriting() = 0; + virtual void DisallowedWhenReading() = 0; }; @@ -229,10 +345,10 @@ class Hasher { bool Uint(unsigned u) { Number n; n.u.u = u; n.d = static_cast(u); return WriteNumber(n); } bool Int64(int64_t i) { Number n; n.u.i = i; n.d = static_cast(i); return WriteNumber(n); } bool Uint64(uint64_t u) { Number n; n.u.u = u; n.d = static_cast(u); return WriteNumber(n); } - bool Double(double d) { - Number n; + bool Double(double d) { + Number n; if (d < 0) n.u.i = static_cast(d); - else n.u.u = static_cast(d); + else n.u.u = static_cast(d); n.d = d; return WriteNumber(n); } @@ -326,12 +442,14 @@ struct SchemaValidationContext { kPatternValidatorWithAdditionalProperty }; - SchemaValidationContext(SchemaValidatorFactoryType& f, ErrorHandlerType& eh, const SchemaType* s) : + SchemaValidationContext(SchemaValidatorFactoryType& f, ErrorHandlerType& eh, const SchemaType* s, unsigned fl = 0) : factory(f), error_handler(eh), schema(s), + flags(fl), valueSchema(), invalidKeyword(), + invalidCode(), hasher(), arrayElementHashCodes(), validators(), @@ -352,13 +470,19 @@ struct SchemaValidationContext { if (hasher) factory.DestroryHasher(hasher); if (validators) { - for (SizeType i = 0; i < validatorCount; i++) - factory.DestroySchemaValidator(validators[i]); + for (SizeType i = 0; i < validatorCount; i++) { + if (validators[i]) { + factory.DestroySchemaValidator(validators[i]); + } + } factory.FreeState(validators); } if (patternPropertiesValidators) { - for (SizeType i = 0; i < patternPropertiesValidatorCount; i++) - factory.DestroySchemaValidator(patternPropertiesValidators[i]); + for (SizeType i = 0; i < patternPropertiesValidatorCount; i++) { + if (patternPropertiesValidators[i]) { + factory.DestroySchemaValidator(patternPropertiesValidators[i]); + } + } factory.FreeState(patternPropertiesValidators); } if (patternPropertiesSchemas) @@ -370,8 +494,10 @@ struct SchemaValidationContext { SchemaValidatorFactoryType& factory; ErrorHandlerType& error_handler; const SchemaType* schema; + unsigned flags; const SchemaType* valueSchema; const Ch* invalidKeyword; + ValidateErrorCode invalidCode; void* hasher; // Only validator access void* arrayElementHashCodes; // Only validator access this ISchemaValidator** validators; @@ -404,12 +530,15 @@ class Schema { typedef Schema SchemaType; typedef GenericValue SValue; typedef IValidationErrorHandler ErrorHandler; + typedef GenericUri UriType; friend class GenericSchemaDocument; - Schema(SchemaDocumentType* schemaDocument, const PointerType& p, const ValueType& value, const ValueType& document, AllocatorType* allocator) : + Schema(SchemaDocumentType* schemaDocument, const PointerType& p, const ValueType& value, const ValueType& document, AllocatorType* allocator, const UriType& id = UriType()) : allocator_(allocator), uri_(schemaDocument->GetURI(), *allocator), - pointer_(p), + id_(id, allocator), + spec_(schemaDocument->GetSpecification()), + pointer_(p, allocator), typeless_(schemaDocument->GetTypeless()), enum_(), enumCount_(), @@ -441,15 +570,43 @@ class Schema { maxLength_(~SizeType(0)), exclusiveMinimum_(false), exclusiveMaximum_(false), - defaultValueLength_(0) + defaultValueLength_(0), + readOnly_(false), + writeOnly_(false), + nullable_(false) { - typedef typename SchemaDocumentType::ValueType ValueType; + GenericStringBuffer sb; + p.StringifyUriFragment(sb); + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::Schema", sb.GetString(), id.GetString()); + typedef typename ValueType::ConstValueIterator ConstValueIterator; typedef typename ValueType::ConstMemberIterator ConstMemberIterator; + // PR #1393 + // Early add this Schema and its $ref(s) in schemaDocument's map to avoid infinite + // recursion (with recursive schemas), since schemaDocument->getSchema() is always + // checked before creating a new one. Don't cache typeless_, though. + if (this != typeless_) { + typedef typename SchemaDocumentType::SchemaEntry SchemaEntry; + SchemaEntry *entry = schemaDocument->schemaMap_.template Push(); + new (entry) SchemaEntry(pointer_, this, true, allocator_); + schemaDocument->AddSchemaRefs(this); + } + if (!value.IsObject()) return; + // If we have an id property, resolve it with the in-scope id + // Not supported for open api 2.0 or 3.0 + if (spec_.oapi != kVersion20 && spec_.oapi != kVersion30) + if (const ValueType* v = GetMember(value, GetIdString())) { + if (v->IsString()) { + UriType local(*v, allocator); + id_ = local.Resolve(id_, allocator); + RAPIDJSON_SCHEMA_PRINT(SchemaIds, id.GetString(), v->GetString(), id_.GetString()); + } + } + if (const ValueType* v = GetMember(value, GetTypeString())) { type_ = 0; if (v->IsString()) @@ -459,29 +616,33 @@ class Schema { AddType(*itr); } - if (const ValueType* v = GetMember(value, GetEnumString())) + if (const ValueType* v = GetMember(value, GetEnumString())) { if (v->IsArray() && v->Size() > 0) { enum_ = static_cast(allocator_->Malloc(sizeof(uint64_t) * v->Size())); for (ConstValueIterator itr = v->Begin(); itr != v->End(); ++itr) { - typedef Hasher > EnumHasherType; + typedef Hasher > EnumHasherType; char buffer[256u + 24]; - MemoryPoolAllocator<> hasherAllocator(buffer, sizeof(buffer)); + MemoryPoolAllocator hasherAllocator(buffer, sizeof(buffer)); EnumHasherType h(&hasherAllocator, 256); itr->Accept(h); enum_[enumCount_++] = h.GetHashCode(); } } + } - if (schemaDocument) { + if (schemaDocument) AssignIfExist(allOf_, *schemaDocument, p, value, GetAllOfString(), document); + + // AnyOf, OneOf, Not not supported for open api 2.0 + if (schemaDocument && spec_.oapi != kVersion20) { AssignIfExist(anyOf_, *schemaDocument, p, value, GetAnyOfString(), document); AssignIfExist(oneOf_, *schemaDocument, p, value, GetOneOfString(), document); - } - if (const ValueType* v = GetMember(value, GetNotString())) { - schemaDocument->CreateSchema(¬_, p.Append(GetNotString(), allocator_), *v, document); - notValidatorIndex_ = validatorCount_; - validatorCount_++; + if (const ValueType* v = GetMember(value, GetNotString())) { + schemaDocument->CreateSchema(¬_, p.Append(GetNotString(), allocator_), *v, document, id_); + notValidatorIndex_ = validatorCount_; + validatorCount_++; + } } // Object @@ -496,12 +657,14 @@ class Schema { if (properties && properties->IsObject()) for (ConstMemberIterator itr = properties->MemberBegin(); itr != properties->MemberEnd(); ++itr) AddUniqueElement(allProperties, itr->name); - + if (required && required->IsArray()) for (ConstValueIterator itr = required->Begin(); itr != required->End(); ++itr) if (itr->IsString()) AddUniqueElement(allProperties, *itr); + // Dependencies not supported for open api 2.0 and 3.0 + if (spec_.oapi != kVersion20 && spec_.oapi != kVersion30) if (dependencies && dependencies->IsObject()) for (ConstMemberIterator itr = dependencies->MemberBegin(); itr != dependencies->MemberEnd(); ++itr) { AddUniqueElement(allProperties, itr->name); @@ -527,10 +690,12 @@ class Schema { for (ConstMemberIterator itr = properties->MemberBegin(); itr != properties->MemberEnd(); ++itr) { SizeType index; if (FindPropertyIndex(itr->name, &index)) - schemaDocument->CreateSchema(&properties_[index].schema, q.Append(itr->name, allocator_), itr->value, document); + schemaDocument->CreateSchema(&properties_[index].schema, q.Append(itr->name, allocator_), itr->value, document, id_); } } + // PatternProperties not supported for open api 2.0 and 3.0 + if (spec_.oapi != kVersion20 && spec_.oapi != kVersion30) if (const ValueType* v = GetMember(value, GetPatternPropertiesString())) { PointerType q = p.Append(GetPatternPropertiesString(), allocator_); patternProperties_ = static_cast(allocator_->Malloc(sizeof(PatternProperty) * v->MemberCount())); @@ -538,8 +703,9 @@ class Schema { for (ConstMemberIterator itr = v->MemberBegin(); itr != v->MemberEnd(); ++itr) { new (&patternProperties_[patternPropertyCount_]) PatternProperty(); - patternProperties_[patternPropertyCount_].pattern = CreatePattern(itr->name); - schemaDocument->CreateSchema(&patternProperties_[patternPropertyCount_].schema, q.Append(itr->name, allocator_), itr->value, document); + PointerType r = q.Append(itr->name, allocator_); + patternProperties_[patternPropertyCount_].pattern = CreatePattern(itr->name, schemaDocument, r); + schemaDocument->CreateSchema(&patternProperties_[patternPropertyCount_].schema, r, itr->value, document, id_); patternPropertyCount_++; } } @@ -554,6 +720,8 @@ class Schema { } } + // Dependencies not supported for open api 2.0 and 3.0 + if (spec_.oapi != kVersion20 && spec_.oapi != kVersion30) if (dependencies && dependencies->IsObject()) { PointerType q = p.Append(GetDependenciesString(), allocator_); hasDependencies_ = true; @@ -571,7 +739,7 @@ class Schema { } else if (itr->value.IsObject()) { hasSchemaDependencies_ = true; - schemaDocument->CreateSchema(&properties_[sourceIndex].dependenciesSchema, q.Append(itr->name, allocator_), itr->value, document); + schemaDocument->CreateSchema(&properties_[sourceIndex].dependenciesSchema, q.Append(itr->name, allocator_), itr->value, document, id_); properties_[sourceIndex].dependenciesValidatorIndex = validatorCount_; validatorCount_++; } @@ -583,7 +751,7 @@ class Schema { if (v->IsBool()) additionalProperties_ = v->GetBool(); else if (v->IsObject()) - schemaDocument->CreateSchema(&additionalPropertiesSchema_, p.Append(GetAdditionalPropertiesString(), allocator_), *v, document); + schemaDocument->CreateSchema(&additionalPropertiesSchema_, p.Append(GetAdditionalPropertiesString(), allocator_), *v, document, id_); } AssignIfExist(minProperties_, value, GetMinPropertiesString()); @@ -593,23 +761,25 @@ class Schema { if (const ValueType* v = GetMember(value, GetItemsString())) { PointerType q = p.Append(GetItemsString(), allocator_); if (v->IsObject()) // List validation - schemaDocument->CreateSchema(&itemsList_, q, *v, document); + schemaDocument->CreateSchema(&itemsList_, q, *v, document, id_); else if (v->IsArray()) { // Tuple validation itemsTuple_ = static_cast(allocator_->Malloc(sizeof(const Schema*) * v->Size())); SizeType index = 0; for (ConstValueIterator itr = v->Begin(); itr != v->End(); ++itr, index++) - schemaDocument->CreateSchema(&itemsTuple_[itemsTupleCount_++], q.Append(index, allocator_), *itr, document); + schemaDocument->CreateSchema(&itemsTuple_[itemsTupleCount_++], q.Append(index, allocator_), *itr, document, id_); } } AssignIfExist(minItems_, value, GetMinItemsString()); AssignIfExist(maxItems_, value, GetMaxItemsString()); + // AdditionalItems not supported for openapi 2.0 and 3.0 + if (spec_.oapi != kVersion20 && spec_.oapi != kVersion30) if (const ValueType* v = GetMember(value, GetAdditionalItemsString())) { if (v->IsBool()) additionalItems_ = v->GetBool(); else if (v->IsObject()) - schemaDocument->CreateSchema(&additionalItemsSchema_, p.Append(GetAdditionalItemsString(), allocator_), *v, document); + schemaDocument->CreateSchema(&additionalItemsSchema_, p.Append(GetAdditionalItemsString(), allocator_), *v, document, id_); } AssignIfExist(uniqueItems_, value, GetUniqueItemsString()); @@ -619,7 +789,7 @@ class Schema { AssignIfExist(maxLength_, value, GetMaxLengthString()); if (const ValueType* v = GetMember(value, GetPatternString())) - pattern_ = CreatePattern(*v); + pattern_ = CreatePattern(*v, schemaDocument, p.Append(GetPatternString(), allocator_)); // Number if (const ValueType* v = GetMember(value, GetMinimumString())) @@ -642,6 +812,23 @@ class Schema { if (v->IsString()) defaultValueLength_ = v->GetStringLength(); + // ReadOnly - open api only (until draft 7 supported) + // WriteOnly - open api 3 only (until draft 7 supported) + // Both can't be true + if (spec_.oapi != kVersionNone) + AssignIfExist(readOnly_, value, GetReadOnlyString()); + if (spec_.oapi >= kVersion30) + AssignIfExist(writeOnly_, value, GetWriteOnlyString()); + if (readOnly_ && writeOnly_) + schemaDocument->SchemaError(kSchemaErrorReadOnlyAndWriteOnly, p); + + // Nullable - open api 3 only + // If true add 'null' as allowable type + if (spec_.oapi >= kVersion30) { + AssignIfExist(nullable_, value, GetNullableString()); + if (nullable_) + AddType(GetNullString()); + } } ~Schema() { @@ -669,11 +856,20 @@ class Schema { return uri_; } + const UriType& GetId() const { + return id_; + } + + const Specification& GetSpecification() const { + return spec_; + } + const PointerType& GetPointer() const { return pointer_; } bool BeginValue(Context& context) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::BeginValue"); if (context.inArray) { if (uniqueItems_) context.valueUniqueness = true; @@ -689,7 +885,11 @@ class Schema { context.valueSchema = typeless_; else { context.error_handler.DisallowedItem(context.arrayElementIndex); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetItemsString()); + // Must set valueSchema for when kValidateContinueOnErrorFlag is set, else reports spurious type error + context.valueSchema = typeless_; + // Must bump arrayElementIndex for when kValidateContinueOnErrorFlag is set + context.arrayElementIndex++; + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorAdditionalItems); } } else @@ -701,6 +901,8 @@ class Schema { } RAPIDJSON_FORCEINLINE bool EndValue(Context& context) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::EndValue"); + // Only check pattern properties if we have validators if (context.patternPropertiesValidatorCount > 0) { bool otherValid = false; SizeType count = context.patternPropertiesValidatorCount; @@ -717,115 +919,127 @@ class Schema { if (context.objectPatternValidatorType == Context::kPatternValidatorOnly) { if (!patternValid) { context.error_handler.PropertyViolations(context.patternPropertiesValidators, count); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetPatternPropertiesString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorPatternProperties); } } else if (context.objectPatternValidatorType == Context::kPatternValidatorWithProperty) { if (!patternValid || !otherValid) { context.error_handler.PropertyViolations(context.patternPropertiesValidators, count + 1); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetPatternPropertiesString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorPatternProperties); } } else if (!patternValid && !otherValid) { // kPatternValidatorWithAdditionalProperty) context.error_handler.PropertyViolations(context.patternPropertiesValidators, count + 1); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetPatternPropertiesString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorPatternProperties); } } - if (enum_) { + // For enums only check if we have a hasher + if (enum_ && context.hasher) { const uint64_t h = context.factory.GetHashCode(context.hasher); for (SizeType i = 0; i < enumCount_; i++) if (enum_[i] == h) goto foundEnum; - context.error_handler.DisallowedValue(); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetEnumString()); + context.error_handler.DisallowedValue(kValidateErrorEnum); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorEnum); foundEnum:; } - if (allOf_.schemas) - for (SizeType i = allOf_.begin; i < allOf_.begin + allOf_.count; i++) - if (!context.validators[i]->IsValid()) { - context.error_handler.NotAllOf(&context.validators[allOf_.begin], allOf_.count); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetAllOfString()); - } - - if (anyOf_.schemas) { - for (SizeType i = anyOf_.begin; i < anyOf_.begin + anyOf_.count; i++) - if (context.validators[i]->IsValid()) - goto foundAny; - context.error_handler.NoneOf(&context.validators[anyOf_.begin], anyOf_.count); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetAnyOfString()); - foundAny:; - } - - if (oneOf_.schemas) { - bool oneValid = false; - for (SizeType i = oneOf_.begin; i < oneOf_.begin + oneOf_.count; i++) - if (context.validators[i]->IsValid()) { - if (oneValid) { - context.error_handler.NotOneOf(&context.validators[oneOf_.begin], oneOf_.count); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetOneOfString()); - } else - oneValid = true; + // Only check allOf etc if we have validators + if (context.validatorCount > 0) { + if (allOf_.schemas) + for (SizeType i = allOf_.begin; i < allOf_.begin + allOf_.count; i++) + if (!context.validators[i]->IsValid()) { + context.error_handler.NotAllOf(&context.validators[allOf_.begin], allOf_.count); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorAllOf); + } + + if (anyOf_.schemas) { + for (SizeType i = anyOf_.begin; i < anyOf_.begin + anyOf_.count; i++) + if (context.validators[i]->IsValid()) + goto foundAny; + context.error_handler.NoneOf(&context.validators[anyOf_.begin], anyOf_.count); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorAnyOf); + foundAny:; + } + + if (oneOf_.schemas) { + bool oneValid = false; + SizeType firstMatch = 0; + for (SizeType i = oneOf_.begin; i < oneOf_.begin + oneOf_.count; i++) + if (context.validators[i]->IsValid()) { + if (oneValid) { + context.error_handler.MultipleOneOf(firstMatch, i - oneOf_.begin); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorOneOfMatch); + } else { + oneValid = true; + firstMatch = i - oneOf_.begin; + } + } + if (!oneValid) { + context.error_handler.NotOneOf(&context.validators[oneOf_.begin], oneOf_.count); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorOneOf); } - if (!oneValid) { - context.error_handler.NotOneOf(&context.validators[oneOf_.begin], oneOf_.count); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetOneOfString()); } - } - if (not_ && context.validators[notValidatorIndex_]->IsValid()) { - context.error_handler.Disallowed(); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetNotString()); + if (not_ && context.validators[notValidatorIndex_]->IsValid()) { + context.error_handler.Disallowed(); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorNot); + } } return true; } bool Null(Context& context) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::Null"); if (!(type_ & (1 << kNullSchemaType))) { DisallowedType(context, GetNullString()); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorType); } return CreateParallelValidator(context); } - - bool Bool(Context& context, bool) const { - if (!(type_ & (1 << kBooleanSchemaType))) { - DisallowedType(context, GetBooleanString()); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString()); - } + + bool Bool(Context& context, bool b) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::Bool", b); + if (!CheckBool(context, b)) + return false; return CreateParallelValidator(context); } bool Int(Context& context, int i) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::Int", (int64_t)i); if (!CheckInt(context, i)) return false; return CreateParallelValidator(context); } bool Uint(Context& context, unsigned u) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::Uint", (uint64_t)u); if (!CheckUint(context, u)) return false; return CreateParallelValidator(context); } bool Int64(Context& context, int64_t i) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::Int64", i); if (!CheckInt(context, i)) return false; return CreateParallelValidator(context); } bool Uint64(Context& context, uint64_t u) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::Uint64", u); if (!CheckUint(context, u)) return false; return CreateParallelValidator(context); } bool Double(Context& context, double d) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::Double", d); if (!(type_ & (1 << kNumberSchemaType))) { DisallowedType(context, GetNumberString()); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorType); } if (!minimum_.IsNull() && !CheckDoubleMinimum(context, d)) @@ -833,17 +1047,18 @@ class Schema { if (!maximum_.IsNull() && !CheckDoubleMaximum(context, d)) return false; - + if (!multipleOf_.IsNull() && !CheckDoubleMultipleOf(context, d)) return false; - + return CreateParallelValidator(context); } - + bool String(Context& context, const Ch* str, SizeType length, bool) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::String", str); if (!(type_ & (1 << kStringSchemaType))) { DisallowedType(context, GetStringString()); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorType); } if (minLength_ != 0 || maxLength_ != SizeType(~0)) { @@ -851,27 +1066,28 @@ class Schema { if (internal::CountStringCodePoint(str, length, &count)) { if (count < minLength_) { context.error_handler.TooShort(str, length, minLength_); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetMinLengthString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorMinLength); } if (count > maxLength_) { context.error_handler.TooLong(str, length, maxLength_); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetMaxLengthString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorMaxLength); } } } if (pattern_ && !IsPatternMatch(pattern_, str, length)) { context.error_handler.DoesNotMatch(str, length); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetPatternString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorPattern); } return CreateParallelValidator(context); } bool StartObject(Context& context) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::StartObject"); if (!(type_ & (1 << kObjectSchemaType))) { DisallowedType(context, GetObjectString()); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorType); } if (hasDependencies_ || hasRequired_) { @@ -888,8 +1104,10 @@ class Schema { return CreateParallelValidator(context); } - + bool Key(Context& context, const Ch* str, SizeType len, bool) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::Key", str); + if (patternProperties_) { context.patternPropertiesSchemaCount = 0; for (SizeType i = 0; i < patternPropertyCount_; i++) @@ -899,7 +1117,7 @@ class Schema { } } - SizeType index; + SizeType index = 0; if (FindPropertyIndex(ValueType(str, len).Move(), &index)) { if (context.patternPropertiesSchemaCount > 0) { context.patternPropertiesSchemas[context.patternPropertiesSchemaCount++] = properties_[index].schema; @@ -916,7 +1134,7 @@ class Schema { } if (additionalPropertiesSchema_) { - if (additionalPropertiesSchema_ && context.patternPropertiesSchemaCount > 0) { + if (context.patternPropertiesSchemaCount > 0) { context.patternPropertiesSchemas[context.patternPropertiesSchemaCount++] = additionalPropertiesSchema_; context.valueSchema = typeless_; context.valuePatternValidatorType = Context::kPatternValidatorWithAdditionalProperty; @@ -931,14 +1149,17 @@ class Schema { } if (context.patternPropertiesSchemaCount == 0) { // patternProperties are not additional properties + // Must set valueSchema for when kValidateContinueOnErrorFlag is set, else reports spurious type error + context.valueSchema = typeless_; context.error_handler.DisallowedProperty(str, len); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetAdditionalPropertiesString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorAdditionalProperties); } return true; } bool EndObject(Context& context, SizeType memberCount) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::EndObject"); if (hasRequired_) { context.error_handler.StartMissingProperties(); for (SizeType index = 0; index < propertyCount_; index++) @@ -946,17 +1167,17 @@ class Schema { if (properties_[index].schema->defaultValueLength_ == 0 ) context.error_handler.AddMissingProperty(properties_[index].name); if (context.error_handler.EndMissingProperties()) - RAPIDJSON_INVALID_KEYWORD_RETURN(GetRequiredString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorRequired); } if (memberCount < minProperties_) { context.error_handler.TooFewProperties(memberCount, minProperties_); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetMinPropertiesString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorMinProperties); } if (memberCount > maxProperties_) { context.error_handler.TooManyProperties(memberCount, maxProperties_); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetMaxPropertiesString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorMaxProperties); } if (hasDependencies_) { @@ -979,40 +1200,83 @@ class Schema { } } if (context.error_handler.EndDependencyErrors()) - RAPIDJSON_INVALID_KEYWORD_RETURN(GetDependenciesString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorDependencies); } return true; } bool StartArray(Context& context) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::StartArray"); + context.arrayElementIndex = 0; + context.inArray = true; // Ensure we note that we are in an array + if (!(type_ & (1 << kArraySchemaType))) { DisallowedType(context, GetArrayString()); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorType); } - context.arrayElementIndex = 0; - context.inArray = true; - return CreateParallelValidator(context); } bool EndArray(Context& context, SizeType elementCount) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::EndArray"); context.inArray = false; - + if (elementCount < minItems_) { context.error_handler.TooFewItems(elementCount, minItems_); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetMinItemsString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorMinItems); } - + if (elementCount > maxItems_) { context.error_handler.TooManyItems(elementCount, maxItems_); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetMaxItemsString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorMaxItems); } return true; } + static const ValueType& GetValidateErrorKeyword(ValidateErrorCode validateErrorCode) { + switch (validateErrorCode) { + case kValidateErrorMultipleOf: return GetMultipleOfString(); + case kValidateErrorMaximum: return GetMaximumString(); + case kValidateErrorExclusiveMaximum: return GetMaximumString(); // Same + case kValidateErrorMinimum: return GetMinimumString(); + case kValidateErrorExclusiveMinimum: return GetMinimumString(); // Same + + case kValidateErrorMaxLength: return GetMaxLengthString(); + case kValidateErrorMinLength: return GetMinLengthString(); + case kValidateErrorPattern: return GetPatternString(); + + case kValidateErrorMaxItems: return GetMaxItemsString(); + case kValidateErrorMinItems: return GetMinItemsString(); + case kValidateErrorUniqueItems: return GetUniqueItemsString(); + case kValidateErrorAdditionalItems: return GetAdditionalItemsString(); + + case kValidateErrorMaxProperties: return GetMaxPropertiesString(); + case kValidateErrorMinProperties: return GetMinPropertiesString(); + case kValidateErrorRequired: return GetRequiredString(); + case kValidateErrorAdditionalProperties: return GetAdditionalPropertiesString(); + case kValidateErrorPatternProperties: return GetPatternPropertiesString(); + case kValidateErrorDependencies: return GetDependenciesString(); + + case kValidateErrorEnum: return GetEnumString(); + case kValidateErrorType: return GetTypeString(); + + case kValidateErrorOneOf: return GetOneOfString(); + case kValidateErrorOneOfMatch: return GetOneOfString(); // Same + case kValidateErrorAllOf: return GetAllOfString(); + case kValidateErrorAnyOf: return GetAnyOfString(); + case kValidateErrorNot: return GetNotString(); + + case kValidateErrorReadOnly: return GetReadOnlyString(); + case kValidateErrorWriteOnly: return GetWriteOnlyString(); + + default: return GetNullString(); + } + } + + // Generate functions for string literal according to Ch #define RAPIDJSON_STRING_(name, ...) \ static const ValueType& Get##name##String() {\ @@ -1055,6 +1319,14 @@ class Schema { RAPIDJSON_STRING_(ExclusiveMaximum, 'e', 'x', 'c', 'l', 'u', 's', 'i', 'v', 'e', 'M', 'a', 'x', 'i', 'm', 'u', 'm') RAPIDJSON_STRING_(MultipleOf, 'm', 'u', 'l', 't', 'i', 'p', 'l', 'e', 'O', 'f') RAPIDJSON_STRING_(DefaultValue, 'd', 'e', 'f', 'a', 'u', 'l', 't') + RAPIDJSON_STRING_(Schema, '$', 's', 'c', 'h', 'e', 'm', 'a') + RAPIDJSON_STRING_(Ref, '$', 'r', 'e', 'f') + RAPIDJSON_STRING_(Id, 'i', 'd') + RAPIDJSON_STRING_(Swagger, 's', 'w', 'a', 'g', 'g', 'e', 'r') + RAPIDJSON_STRING_(OpenApi, 'o', 'p', 'e', 'n', 'a', 'p', 'i') + RAPIDJSON_STRING_(ReadOnly, 'r', 'e', 'a', 'd', 'O', 'n', 'l', 'y') + RAPIDJSON_STRING_(WriteOnly, 'w', 'r', 'i', 't', 'e', 'O', 'n', 'l', 'y') + RAPIDJSON_STRING_(Nullable, 'n', 'u', 'l', 'l', 'a', 'b', 'l', 'e') #undef RAPIDJSON_STRING_ @@ -1120,7 +1392,7 @@ class Schema { out.schemas = static_cast(allocator_->Malloc(out.count * sizeof(const Schema*))); memset(out.schemas, 0, sizeof(Schema*)* out.count); for (SizeType i = 0; i < out.count; i++) - schemaDocument.CreateSchema(&out.schemas[i], q.Append(i, allocator_), (*v)[i], document); + schemaDocument.CreateSchema(&out.schemas[i], q.Append(i, allocator_), (*v)[i], document, id_); out.begin = validatorCount_; validatorCount_ += out.count; } @@ -1129,10 +1401,11 @@ class Schema { #if RAPIDJSON_SCHEMA_USE_INTERNALREGEX template - RegexType* CreatePattern(const ValueType& value) { + RegexType* CreatePattern(const ValueType& value, SchemaDocumentType* sd, const PointerType& p) { if (value.IsString()) { RegexType* r = new (allocator_->Malloc(sizeof(RegexType))) RegexType(value.GetString(), allocator_); if (!r->IsValid()) { + sd->SchemaErrorValue(kSchemaErrorRegexInvalid, p, value.GetString(), value.GetStringLength()); r->~RegexType(); AllocatorType::Free(r); r = 0; @@ -1148,13 +1421,17 @@ class Schema { } #elif RAPIDJSON_SCHEMA_USE_STDREGEX template - RegexType* CreatePattern(const ValueType& value) { - if (value.IsString()) + RegexType* CreatePattern(const ValueType& value, SchemaDocumentType* sd, const PointerType& p) { + if (value.IsString()) { + RegexType *r = static_cast(allocator_->Malloc(sizeof(RegexType))); try { - return new (allocator_->Malloc(sizeof(RegexType))) RegexType(value.GetString(), std::size_t(value.GetStringLength()), std::regex_constants::ECMAScript); + return new (r) RegexType(value.GetString(), std::size_t(value.GetStringLength()), std::regex_constants::ECMAScript); } - catch (const std::regex_error&) { + catch (const std::regex_error& e) { + sd->SchemaErrorValue(kSchemaErrorRegexInvalid, p, value.GetString(), value.GetStringLength()); + AllocatorType::Free(r); } + } return 0; } @@ -1164,7 +1441,9 @@ class Schema { } #else template - RegexType* CreatePattern(const ValueType&) { return 0; } + RegexType* CreatePattern(const ValueType&) { + return 0; + } static bool IsPatternMatch(const RegexType*, const Ch *, SizeType) { return true; } #endif // RAPIDJSON_SCHEMA_USE_STDREGEX @@ -1179,6 +1458,9 @@ class Schema { else if (type == GetNumberString() ) type_ |= (1 << kNumberSchemaType) | (1 << kIntegerSchemaType); } + // Creates parallel validators for allOf, anyOf, oneOf, not and schema dependencies, if required. + // Also creates a hasher for enums and array uniqueness, if required. + // Also a useful place to add type-independent error checks. bool CreateParallelValidator(Context& context) const { if (enum_ || context.arrayUniqueness) context.hasher = context.factory.CreateHasher(); @@ -1186,33 +1468,45 @@ class Schema { if (validatorCount_) { RAPIDJSON_ASSERT(context.validators == 0); context.validators = static_cast(context.factory.MallocState(sizeof(ISchemaValidator*) * validatorCount_)); + std::memset(context.validators, 0, sizeof(ISchemaValidator*) * validatorCount_); context.validatorCount = validatorCount_; + // Always return after first failure for these sub-validators if (allOf_.schemas) - CreateSchemaValidators(context, allOf_); + CreateSchemaValidators(context, allOf_, false); if (anyOf_.schemas) - CreateSchemaValidators(context, anyOf_); - + CreateSchemaValidators(context, anyOf_, false); + if (oneOf_.schemas) - CreateSchemaValidators(context, oneOf_); - + CreateSchemaValidators(context, oneOf_, false); + if (not_) - context.validators[notValidatorIndex_] = context.factory.CreateSchemaValidator(*not_); - + context.validators[notValidatorIndex_] = context.factory.CreateSchemaValidator(*not_, false); + if (hasSchemaDependencies_) { for (SizeType i = 0; i < propertyCount_; i++) if (properties_[i].dependenciesSchema) - context.validators[properties_[i].dependenciesValidatorIndex] = context.factory.CreateSchemaValidator(*properties_[i].dependenciesSchema); + context.validators[properties_[i].dependenciesValidatorIndex] = context.factory.CreateSchemaValidator(*properties_[i].dependenciesSchema, false); } } + // Add any other type-independent checks here + if (readOnly_ && (context.flags & kValidateWriteFlag)) { + context.error_handler.DisallowedWhenWriting(); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorReadOnly); + } + if (writeOnly_ && (context.flags & kValidateReadFlag)) { + context.error_handler.DisallowedWhenReading(); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorWriteOnly); + } + return true; } - void CreateSchemaValidators(Context& context, const SchemaArray& schemas) const { + void CreateSchemaValidators(Context& context, const SchemaArray& schemas, const bool inheritContinueOnErrors) const { for (SizeType i = 0; i < schemas.count; i++) - context.validators[schemas.begin + i] = context.factory.CreateSchemaValidator(*schemas.schemas[i]); + context.validators[schemas.begin + i] = context.factory.CreateSchemaValidator(*schemas.schemas[i], inheritContinueOnErrors); } // O(n) @@ -1220,7 +1514,7 @@ class Schema { SizeType len = name.GetStringLength(); const Ch* str = name.GetString(); for (SizeType index = 0; index < propertyCount_; index++) - if (properties_[index].name.GetStringLength() == len && + if (properties_[index].name.GetStringLength() == len && (std::memcmp(properties_[index].name.GetString(), str, sizeof(Ch) * len) == 0)) { *outIndex = index; @@ -1229,22 +1523,30 @@ class Schema { return false; } + bool CheckBool(Context& context, bool) const { + if (!(type_ & (1 << kBooleanSchemaType))) { + DisallowedType(context, GetBooleanString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorType); + } + return true; + } + bool CheckInt(Context& context, int64_t i) const { if (!(type_ & ((1 << kIntegerSchemaType) | (1 << kNumberSchemaType)))) { DisallowedType(context, GetIntegerString()); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorType); } if (!minimum_.IsNull()) { if (minimum_.IsInt64()) { if (exclusiveMinimum_ ? i <= minimum_.GetInt64() : i < minimum_.GetInt64()) { context.error_handler.BelowMinimum(i, minimum_, exclusiveMinimum_); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetMinimumString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(exclusiveMinimum_ ? kValidateErrorExclusiveMinimum : kValidateErrorMinimum); } } else if (minimum_.IsUint64()) { context.error_handler.BelowMinimum(i, minimum_, exclusiveMinimum_); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetMinimumString()); // i <= max(int64_t) < minimum.GetUint64() + RAPIDJSON_INVALID_KEYWORD_RETURN(exclusiveMinimum_ ? kValidateErrorExclusiveMinimum : kValidateErrorMinimum); // i <= max(int64_t) < minimum.GetUint64() } else if (!CheckDoubleMinimum(context, static_cast(i))) return false; @@ -1254,7 +1556,7 @@ class Schema { if (maximum_.IsInt64()) { if (exclusiveMaximum_ ? i >= maximum_.GetInt64() : i > maximum_.GetInt64()) { context.error_handler.AboveMaximum(i, maximum_, exclusiveMaximum_); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetMaximumString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(exclusiveMaximum_ ? kValidateErrorExclusiveMaximum : kValidateErrorMaximum); } } else if (maximum_.IsUint64()) { } @@ -1267,7 +1569,7 @@ class Schema { if (multipleOf_.IsUint64()) { if (static_cast(i >= 0 ? i : -i) % multipleOf_.GetUint64() != 0) { context.error_handler.NotMultipleOf(i, multipleOf_); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetMultipleOfString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorMultipleOf); } } else if (!CheckDoubleMultipleOf(context, static_cast(i))) @@ -1280,14 +1582,14 @@ class Schema { bool CheckUint(Context& context, uint64_t i) const { if (!(type_ & ((1 << kIntegerSchemaType) | (1 << kNumberSchemaType)))) { DisallowedType(context, GetIntegerString()); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorType); } if (!minimum_.IsNull()) { if (minimum_.IsUint64()) { if (exclusiveMinimum_ ? i <= minimum_.GetUint64() : i < minimum_.GetUint64()) { context.error_handler.BelowMinimum(i, minimum_, exclusiveMinimum_); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetMinimumString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(exclusiveMinimum_ ? kValidateErrorExclusiveMinimum : kValidateErrorMinimum); } } else if (minimum_.IsInt64()) @@ -1300,12 +1602,12 @@ class Schema { if (maximum_.IsUint64()) { if (exclusiveMaximum_ ? i >= maximum_.GetUint64() : i > maximum_.GetUint64()) { context.error_handler.AboveMaximum(i, maximum_, exclusiveMaximum_); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetMaximumString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(exclusiveMaximum_ ? kValidateErrorExclusiveMaximum : kValidateErrorMaximum); } } else if (maximum_.IsInt64()) { context.error_handler.AboveMaximum(i, maximum_, exclusiveMaximum_); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetMaximumString()); // i >= 0 > maximum_ + RAPIDJSON_INVALID_KEYWORD_RETURN(exclusiveMaximum_ ? kValidateErrorExclusiveMaximum : kValidateErrorMaximum); // i >= 0 > maximum_ } else if (!CheckDoubleMaximum(context, static_cast(i))) return false; @@ -1315,7 +1617,7 @@ class Schema { if (multipleOf_.IsUint64()) { if (i % multipleOf_.GetUint64() != 0) { context.error_handler.NotMultipleOf(i, multipleOf_); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetMultipleOfString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorMultipleOf); } } else if (!CheckDoubleMultipleOf(context, static_cast(i))) @@ -1328,7 +1630,7 @@ class Schema { bool CheckDoubleMinimum(Context& context, double d) const { if (exclusiveMinimum_ ? d <= minimum_.GetDouble() : d < minimum_.GetDouble()) { context.error_handler.BelowMinimum(d, minimum_, exclusiveMinimum_); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetMinimumString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(exclusiveMinimum_ ? kValidateErrorExclusiveMinimum : kValidateErrorMinimum); } return true; } @@ -1336,7 +1638,7 @@ class Schema { bool CheckDoubleMaximum(Context& context, double d) const { if (exclusiveMaximum_ ? d >= maximum_.GetDouble() : d > maximum_.GetDouble()) { context.error_handler.AboveMaximum(d, maximum_, exclusiveMaximum_); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetMaximumString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(exclusiveMaximum_ ? kValidateErrorExclusiveMaximum : kValidateErrorMaximum); } return true; } @@ -1347,7 +1649,7 @@ class Schema { double r = a - q * b; if (r > 0.0) { context.error_handler.NotMultipleOf(d, multipleOf_); - RAPIDJSON_INVALID_KEYWORD_RETURN(GetMultipleOfString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorMultipleOf); } return true; } @@ -1381,7 +1683,7 @@ class Schema { struct PatternProperty { PatternProperty() : schema(), pattern() {} - ~PatternProperty() { + ~PatternProperty() { if (pattern) { pattern->~RegexType(); AllocatorType::Free(pattern); @@ -1393,6 +1695,8 @@ class Schema { AllocatorType* allocator_; SValue uri_; + UriType id_; + Specification spec_; PointerType pointer_; const SchemaType* typeless_; uint64_t* enum_; @@ -1435,8 +1739,12 @@ class Schema { SValue multipleOf_; bool exclusiveMinimum_; bool exclusiveMaximum_; - + SizeType defaultValueLength_; + + bool readOnly_; + bool writeOnly_; + bool nullable_; }; template @@ -1478,9 +1786,18 @@ template class IGenericRemoteSchemaDocumentProvider { public: typedef typename SchemaDocumentType::Ch Ch; + typedef typename SchemaDocumentType::ValueType ValueType; + typedef typename SchemaDocumentType::AllocatorType AllocatorType; virtual ~IGenericRemoteSchemaDocumentProvider() {} virtual const SchemaDocumentType* GetRemoteDocument(const Ch* uri, SizeType length) = 0; + virtual const SchemaDocumentType* GetRemoteDocument(const GenericUri uri, Specification& spec) { + // Default implementation just calls through for compatibility + // Following line suppresses unused parameter warning + (void)spec; + // printf("GetRemoteDocument: %d %d\n", spec.draft, spec.oapi); + return GetRemoteDocument(uri.GetBaseString(), uri.GetBaseStringLength()); + } }; /////////////////////////////////////////////////////////////////////////////// @@ -1505,7 +1822,9 @@ class GenericSchemaDocument { typedef typename EncodingType::Ch Ch; typedef internal::Schema SchemaType; typedef GenericPointer PointerType; - typedef GenericValue URIType; + typedef GenericValue GValue; + typedef GenericUri UriType; + typedef GenericStringRef StringRefType; friend class internal::Schema; template friend class GenericSchemaValidator; @@ -1519,46 +1838,53 @@ class GenericSchemaDocument { \param uriLength Length of \c name, in code points. \param remoteProvider An optional remote schema document provider for resolving remote reference. Can be null. \param allocator An optional allocator instance for allocating memory. Can be null. + \param pointer An optional JSON pointer to the start of the schema document + \param spec Optional schema draft or OpenAPI version. Used if no specification in document. Defaults to draft-04. */ explicit GenericSchemaDocument(const ValueType& document, const Ch* uri = 0, SizeType uriLength = 0, - IRemoteSchemaDocumentProviderType* remoteProvider = 0, Allocator* allocator = 0) : + IRemoteSchemaDocumentProviderType* remoteProvider = 0, Allocator* allocator = 0, + const PointerType& pointer = PointerType(), // PR #1393 + const Specification& spec = Specification(kDraft04)) : remoteProvider_(remoteProvider), allocator_(allocator), ownAllocator_(), root_(), typeless_(), schemaMap_(allocator, kInitialSchemaMapSize), - schemaRef_(allocator, kInitialSchemaRefSize) + schemaRef_(allocator, kInitialSchemaRefSize), + spec_(spec), + error_(kObjectType), + currentError_() { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaDocument::GenericSchemaDocument"); if (!allocator_) ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)(); Ch noUri[1] = {0}; uri_.SetString(uri ? uri : noUri, uriLength, *allocator_); + docId_ = UriType(uri_, allocator_); typeless_ = static_cast(allocator_->Malloc(sizeof(SchemaType))); - new (typeless_) SchemaType(this, PointerType(), ValueType(kObjectType).Move(), ValueType(kObjectType).Move(), allocator_); - - // Generate root schema, it will call CreateSchema() to create sub-schemas, - // And call AddRefSchema() if there are $ref. - CreateSchemaRecursive(&root_, PointerType(), document, document); + new (typeless_) SchemaType(this, PointerType(), ValueType(kObjectType).Move(), ValueType(kObjectType).Move(), allocator_, docId_); - // Resolve $ref - while (!schemaRef_.Empty()) { - SchemaRefEntry* refEntry = schemaRef_.template Pop(1); - if (const SchemaType* s = GetSchema(refEntry->target)) { - if (refEntry->schema) - *refEntry->schema = s; - - // Create entry in map if not exist - if (!GetSchema(refEntry->source)) { - new (schemaMap_.template Push()) SchemaEntry(refEntry->source, const_cast(s), false, allocator_); - } - } - else if (refEntry->schema) - *refEntry->schema = typeless_; + // Establish the schema draft or open api version. + // We only ever look for '$schema' or 'swagger' or 'openapi' at the root of the document. + SetSchemaSpecification(document); - refEntry->~SchemaRefEntry(); + // Generate root schema, it will call CreateSchema() to create sub-schemas, + // And call HandleRefSchema() if there are $ref. + // PR #1393 use input pointer if supplied + root_ = typeless_; + if (pointer.GetTokenCount() == 0) { + CreateSchemaRecursive(&root_, pointer, document, document, docId_); + } + else if (const ValueType* v = pointer.Get(document)) { + CreateSchema(&root_, pointer, *v, document, docId_); + } + else { + GenericStringBuffer sb; + pointer.StringifyUriFragment(sb); + SchemaErrorValue(kSchemaErrorStartUnknown, PointerType(), sb.GetString(), static_cast(sb.GetSize() / sizeof(Ch))); } RAPIDJSON_ASSERT(root_ != 0); @@ -1576,7 +1902,11 @@ class GenericSchemaDocument { typeless_(rhs.typeless_), schemaMap_(std::move(rhs.schemaMap_)), schemaRef_(std::move(rhs.schemaRef_)), - uri_(std::move(rhs.uri_)) + uri_(std::move(rhs.uri_)), + docId_(std::move(rhs.docId_)), + spec_(rhs.spec_), + error_(std::move(rhs.error_)), + currentError_(std::move(rhs.currentError_)) { rhs.remoteProvider_ = 0; rhs.allocator_ = 0; @@ -1595,26 +1925,87 @@ class GenericSchemaDocument { Allocator::Free(typeless_); } + // these may contain some allocator data so clear before deleting ownAllocator_ + uri_.SetNull(); + error_.SetNull(); + currentError_.SetNull(); + RAPIDJSON_DELETE(ownAllocator_); } - const URIType& GetURI() const { return uri_; } + const GValue& GetURI() const { return uri_; } + + const Specification& GetSpecification() const { return spec_; } + bool IsSupportedSpecification() const { return spec_.IsSupported(); } + + //! Static method to get the specification of any schema document + // Returns kDraftNone if document is silent + static const Specification GetSpecification(const ValueType& document) { + SchemaDraft draft = GetSchemaDraft(document); + if (draft != kDraftNone) + return Specification(draft); + else { + OpenApiVersion oapi = GetOpenApiVersion(document); + if (oapi != kVersionNone) + return Specification(oapi); + } + return Specification(kDraftNone); + } //! Get the root schema. const SchemaType& GetRoot() const { return *root_; } -private: + //! Gets the error object. + GValue& GetError() { return error_; } + const GValue& GetError() const { return error_; } + + static const StringRefType& GetSchemaErrorKeyword(SchemaErrorCode schemaErrorCode) { + switch (schemaErrorCode) { + case kSchemaErrorStartUnknown: return GetStartUnknownString(); + case kSchemaErrorRefPlainName: return GetRefPlainNameString(); + case kSchemaErrorRefInvalid: return GetRefInvalidString(); + case kSchemaErrorRefPointerInvalid: return GetRefPointerInvalidString(); + case kSchemaErrorRefUnknown: return GetRefUnknownString(); + case kSchemaErrorRefCyclical: return GetRefCyclicalString(); + case kSchemaErrorRefNoRemoteProvider: return GetRefNoRemoteProviderString(); + case kSchemaErrorRefNoRemoteSchema: return GetRefNoRemoteSchemaString(); + case kSchemaErrorRegexInvalid: return GetRegexInvalidString(); + case kSchemaErrorSpecUnknown: return GetSpecUnknownString(); + case kSchemaErrorSpecUnsupported: return GetSpecUnsupportedString(); + case kSchemaErrorSpecIllegal: return GetSpecIllegalString(); + case kSchemaErrorReadOnlyAndWriteOnly: return GetReadOnlyAndWriteOnlyString(); + default: return GetNullString(); + } + } + + //! Default error method + void SchemaError(const SchemaErrorCode code, const PointerType& location) { + currentError_ = GValue(kObjectType); + AddCurrentError(code, location); + } + + //! Method for error with single string value insert + void SchemaErrorValue(const SchemaErrorCode code, const PointerType& location, const Ch* value, SizeType length) { + currentError_ = GValue(kObjectType); + currentError_.AddMember(GetValueString(), GValue(value, length, *allocator_).Move(), *allocator_); + AddCurrentError(code, location); + } + + //! Method for error with invalid pointer + void SchemaErrorPointer(const SchemaErrorCode code, const PointerType& location, const Ch* value, SizeType length, const PointerType& pointer) { + currentError_ = GValue(kObjectType); + currentError_.AddMember(GetValueString(), GValue(value, length, *allocator_).Move(), *allocator_); + currentError_.AddMember(GetOffsetString(), static_cast(pointer.GetParseErrorOffset() / sizeof(Ch)), *allocator_); + AddCurrentError(code, location); + } + + private: //! Prohibit copying GenericSchemaDocument(const GenericSchemaDocument&); //! Prohibit assignment GenericSchemaDocument& operator=(const GenericSchemaDocument&); - struct SchemaRefEntry { - SchemaRefEntry(const PointerType& s, const PointerType& t, const SchemaType** outSchema, Allocator *allocator) : source(s, allocator), target(t, allocator), schema(outSchema) {} - PointerType source; - PointerType target; - const SchemaType** schema; - }; + typedef const PointerType* SchemaRefPtr; // PR #1393 struct SchemaEntry { SchemaEntry(const PointerType& p, SchemaType* s, bool o, Allocator* allocator) : pointer(p, allocator), schema(s), owned(o) {} @@ -1629,79 +2020,361 @@ class GenericSchemaDocument { bool owned; }; - void CreateSchemaRecursive(const SchemaType** schema, const PointerType& pointer, const ValueType& v, const ValueType& document) { - if (schema) - *schema = typeless_; + void AddErrorInstanceLocation(GValue& result, const PointerType& location) { + GenericStringBuffer sb; + location.StringifyUriFragment(sb); + GValue instanceRef(sb.GetString(), static_cast(sb.GetSize() / sizeof(Ch)), *allocator_); + result.AddMember(GetInstanceRefString(), instanceRef, *allocator_); + } + + void AddError(GValue& keyword, GValue& error) { + typename GValue::MemberIterator member = error_.FindMember(keyword); + if (member == error_.MemberEnd()) + error_.AddMember(keyword, error, *allocator_); + else { + if (member->value.IsObject()) { + GValue errors(kArrayType); + errors.PushBack(member->value, *allocator_); + member->value = errors; + } + member->value.PushBack(error, *allocator_); + } + } + void AddCurrentError(const SchemaErrorCode code, const PointerType& location) { + RAPIDJSON_SCHEMA_PRINT(InvalidKeyword, GetSchemaErrorKeyword(code)); + currentError_.AddMember(GetErrorCodeString(), code, *allocator_); + AddErrorInstanceLocation(currentError_, location); + AddError(GValue(GetSchemaErrorKeyword(code)).Move(), currentError_); + } + +#define RAPIDJSON_STRING_(name, ...) \ + static const StringRefType& Get##name##String() {\ + static const Ch s[] = { __VA_ARGS__, '\0' };\ + static const StringRefType v(s, static_cast(sizeof(s) / sizeof(Ch) - 1)); \ + return v;\ + } + + RAPIDJSON_STRING_(InstanceRef, 'i', 'n', 's', 't', 'a', 'n', 'c', 'e', 'R', 'e', 'f') + RAPIDJSON_STRING_(ErrorCode, 'e', 'r', 'r', 'o', 'r', 'C', 'o', 'd', 'e') + RAPIDJSON_STRING_(Value, 'v', 'a', 'l', 'u', 'e') + RAPIDJSON_STRING_(Offset, 'o', 'f', 'f', 's', 'e', 't') + + RAPIDJSON_STRING_(Null, 'n', 'u', 'l', 'l') + RAPIDJSON_STRING_(SpecUnknown, 'S', 'p', 'e', 'c', 'U', 'n', 'k', 'n', 'o', 'w', 'n') + RAPIDJSON_STRING_(SpecUnsupported, 'S', 'p', 'e', 'c', 'U', 'n', 's', 'u', 'p', 'p', 'o', 'r', 't', 'e', 'd') + RAPIDJSON_STRING_(SpecIllegal, 'S', 'p', 'e', 'c', 'I', 'l', 'l', 'e', 'g', 'a', 'l') + RAPIDJSON_STRING_(StartUnknown, 'S', 't', 'a', 'r', 't', 'U', 'n', 'k', 'n', 'o', 'w', 'n') + RAPIDJSON_STRING_(RefPlainName, 'R', 'e', 'f', 'P', 'l', 'a', 'i', 'n', 'N', 'a', 'm', 'e') + RAPIDJSON_STRING_(RefInvalid, 'R', 'e', 'f', 'I', 'n', 'v', 'a', 'l', 'i', 'd') + RAPIDJSON_STRING_(RefPointerInvalid, 'R', 'e', 'f', 'P', 'o', 'i', 'n', 't', 'e', 'r', 'I', 'n', 'v', 'a', 'l', 'i', 'd') + RAPIDJSON_STRING_(RefUnknown, 'R', 'e', 'f', 'U', 'n', 'k', 'n', 'o', 'w', 'n') + RAPIDJSON_STRING_(RefCyclical, 'R', 'e', 'f', 'C', 'y', 'c', 'l', 'i', 'c', 'a', 'l') + RAPIDJSON_STRING_(RefNoRemoteProvider, 'R', 'e', 'f', 'N', 'o', 'R', 'e', 'm', 'o', 't', 'e', 'P', 'r', 'o', 'v', 'i', 'd', 'e', 'r') + RAPIDJSON_STRING_(RefNoRemoteSchema, 'R', 'e', 'f', 'N', 'o', 'R', 'e', 'm', 'o', 't', 'e', 'S', 'c', 'h', 'e', 'm', 'a') + RAPIDJSON_STRING_(ReadOnlyAndWriteOnly, 'R', 'e', 'a', 'd', 'O', 'n', 'l', 'y', 'A', 'n', 'd', 'W', 'r', 'i', 't', 'e', 'O', 'n', 'l', 'y') + RAPIDJSON_STRING_(RegexInvalid, 'R', 'e', 'g', 'e', 'x', 'I', 'n', 'v', 'a', 'l', 'i', 'd') + +#undef RAPIDJSON_STRING_ + + // Static method to get schema draft of any schema document + static SchemaDraft GetSchemaDraft(const ValueType& document) { + static const Ch kDraft03String[] = { 'h', 't', 't', 'p', ':', '/', '/', 'j', 's', 'o', 'n', '-', 's', 'c', 'h', 'e', 'm', 'a', '.', 'o', 'r', 'g', '/', 'd', 'r', 'a', 'f', 't', '-', '0', '3', '/', 's', 'c', 'h', 'e', 'm', 'a', '#', '\0' }; + static const Ch kDraft04String[] = { 'h', 't', 't', 'p', ':', '/', '/', 'j', 's', 'o', 'n', '-', 's', 'c', 'h', 'e', 'm', 'a', '.', 'o', 'r', 'g', '/', 'd', 'r', 'a', 'f', 't', '-', '0', '4', '/', 's', 'c', 'h', 'e', 'm', 'a', '#', '\0' }; + static const Ch kDraft05String[] = { 'h', 't', 't', 'p', ':', '/', '/', 'j', 's', 'o', 'n', '-', 's', 'c', 'h', 'e', 'm', 'a', '.', 'o', 'r', 'g', '/', 'd', 'r', 'a', 'f', 't', '-', '0', '5', '/', 's', 'c', 'h', 'e', 'm', 'a', '#', '\0' }; + static const Ch kDraft06String[] = { 'h', 't', 't', 'p', ':', '/', '/', 'j', 's', 'o', 'n', '-', 's', 'c', 'h', 'e', 'm', 'a', '.', 'o', 'r', 'g', '/', 'd', 'r', 'a', 'f', 't', '-', '0', '6', '/', 's', 'c', 'h', 'e', 'm', 'a', '#', '\0' }; + static const Ch kDraft07String[] = { 'h', 't', 't', 'p', ':', '/', '/', 'j', 's', 'o', 'n', '-', 's', 'c', 'h', 'e', 'm', 'a', '.', 'o', 'r', 'g', '/', 'd', 'r', 'a', 'f', 't', '-', '0', '7', '/', 's', 'c', 'h', 'e', 'm', 'a', '#', '\0' }; + static const Ch kDraft2019_09String[] = { 'h', 't', 't', 'p', 's', ':', '/', '/', 'j', 's', 'o', 'n', '-', 's', 'c', 'h', 'e', 'm', 'a', '.', 'o', 'r', 'g', '/', 'd', 'r', 'a', 'f', 't', '/', '2', '0', '1', '9', '-', '0', '9', '/', 's', 'c', 'h', 'e', 'm', 'a', '\0' }; + static const Ch kDraft2020_12String[] = { 'h', 't', 't', 'p', 's', ':', '/', '/', 'j', 's', 'o', 'n', '-', 's', 'c', 'h', 'e', 'm', 'a', '.', 'o', 'r', 'g', '/', 'd', 'r', 'a', 'f', 't', '/', '2', '0', '2', '0', '-', '1', '2', '/', 's', 'c', 'h', 'e', 'm', 'a', '\0' }; + + if (!document.IsObject()) { + return kDraftNone; + } + + // Get the schema draft from the $schema keyword at the supplied location + typename ValueType::ConstMemberIterator itr = document.FindMember(SchemaType::GetSchemaString()); + if (itr != document.MemberEnd()) { + if (!itr->value.IsString()) return kDraftUnknown; + const UriType draftUri(itr->value); + // Check base uri for match + if (draftUri.Match(UriType(kDraft04String), false)) return kDraft04; + if (draftUri.Match(UriType(kDraft05String), false)) return kDraft05; + if (draftUri.Match(UriType(kDraft06String), false)) return kDraft06; + if (draftUri.Match(UriType(kDraft07String), false)) return kDraft07; + if (draftUri.Match(UriType(kDraft03String), false)) return kDraft03; + if (draftUri.Match(UriType(kDraft2019_09String), false)) return kDraft2019_09; + if (draftUri.Match(UriType(kDraft2020_12String), false)) return kDraft2020_12; + return kDraftUnknown; + } + // $schema not found + return kDraftNone; + } + + + // Get open api version of any schema document + static OpenApiVersion GetOpenApiVersion(const ValueType& document) { + static const Ch kVersion20String[] = { '2', '.', '0', '\0' }; + static const Ch kVersion30String[] = { '3', '.', '0', '.', '\0' }; // ignore patch level + static const Ch kVersion31String[] = { '3', '.', '1', '.', '\0' }; // ignore patch level + static SizeType len = internal::StrLen(kVersion30String); + + if (!document.IsObject()) { + return kVersionNone; + } + + // Get the open api version from the swagger / openapi keyword at the supplied location + typename ValueType::ConstMemberIterator itr = document.FindMember(SchemaType::GetSwaggerString()); + if (itr == document.MemberEnd()) itr = document.FindMember(SchemaType::GetOpenApiString()); + if (itr != document.MemberEnd()) { + if (!itr->value.IsString()) return kVersionUnknown; + const ValueType kVersion20Value(kVersion20String); + if (kVersion20Value == itr->value) return kVersion20; // must match 2.0 exactly + const ValueType kVersion30Value(kVersion30String); + if (itr->value.GetStringLength() > len && kVersion30Value == ValueType(itr->value.GetString(), len)) return kVersion30; // must match 3.0.x + const ValueType kVersion31Value(kVersion31String); + if (itr->value.GetStringLength() > len && kVersion31Value == ValueType(itr->value.GetString(), len)) return kVersion31; // must match 3.1.x + return kVersionUnknown; + } + // swagger or openapi not found + return kVersionNone; + } + + // Get the draft of the schema or the open api version (which implies the draft). + // Report an error if schema draft or open api version not supported or not recognized, or both in document, and carry on. + void SetSchemaSpecification(const ValueType& document) { + // Look for '$schema', 'swagger' or 'openapi' keyword at document root + SchemaDraft docDraft = GetSchemaDraft(document); + OpenApiVersion docOapi = GetOpenApiVersion(document); + // Error if both in document + if (docDraft != kDraftNone && docOapi != kVersionNone) + SchemaError(kSchemaErrorSpecIllegal, PointerType()); + // Use document draft or open api version if present or use spec from constructor + if (docDraft != kDraftNone) + spec_ = Specification(docDraft); + else if (docOapi != kVersionNone) + spec_ = Specification(docOapi); + // Error if draft or version unknown + if (spec_.draft == kDraftUnknown || spec_.oapi == kVersionUnknown) + SchemaError(kSchemaErrorSpecUnknown, PointerType()); + else if (!spec_.IsSupported()) + SchemaError(kSchemaErrorSpecUnsupported, PointerType()); + } + + // Changed by PR #1393 + void CreateSchemaRecursive(const SchemaType** schema, const PointerType& pointer, const ValueType& v, const ValueType& document, const UriType& id) { if (v.GetType() == kObjectType) { - const SchemaType* s = GetSchema(pointer); - if (!s) - CreateSchema(schema, pointer, v, document); + UriType newid = UriType(CreateSchema(schema, pointer, v, document, id), allocator_); for (typename ValueType::ConstMemberIterator itr = v.MemberBegin(); itr != v.MemberEnd(); ++itr) - CreateSchemaRecursive(0, pointer.Append(itr->name, allocator_), itr->value, document); + CreateSchemaRecursive(0, pointer.Append(itr->name, allocator_), itr->value, document, newid); } else if (v.GetType() == kArrayType) for (SizeType i = 0; i < v.Size(); i++) - CreateSchemaRecursive(0, pointer.Append(i, allocator_), v[i], document); + CreateSchemaRecursive(0, pointer.Append(i, allocator_), v[i], document, id); } - void CreateSchema(const SchemaType** schema, const PointerType& pointer, const ValueType& v, const ValueType& document) { + // Changed by PR #1393 + const UriType& CreateSchema(const SchemaType** schema, const PointerType& pointer, const ValueType& v, const ValueType& document, const UriType& id) { RAPIDJSON_ASSERT(pointer.IsValid()); + GenericStringBuffer sb; + pointer.StringifyUriFragment(sb); + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaDocument::CreateSchema", sb.GetString(), id.GetString()); if (v.IsObject()) { - if (!HandleRefSchema(pointer, schema, v, document)) { - SchemaType* s = new (allocator_->Malloc(sizeof(SchemaType))) SchemaType(this, pointer, v, document, allocator_); - new (schemaMap_.template Push()) SchemaEntry(pointer, s, true, allocator_); + if (const SchemaType* sc = GetSchema(pointer)) { + if (schema) + *schema = sc; + AddSchemaRefs(const_cast(sc)); + } + else if (!HandleRefSchema(pointer, schema, v, document, id)) { + // The new schema constructor adds itself and its $ref(s) to schemaMap_ + SchemaType* s = new (allocator_->Malloc(sizeof(SchemaType))) SchemaType(this, pointer, v, document, allocator_, id); if (schema) *schema = s; + return s->GetId(); } } + else { + if (schema) + *schema = typeless_; + AddSchemaRefs(typeless_); + } + return id; } - bool HandleRefSchema(const PointerType& source, const SchemaType** schema, const ValueType& v, const ValueType& document) { - static const Ch kRefString[] = { '$', 'r', 'e', 'f', '\0' }; - static const ValueType kRefValue(kRefString, 4); - - typename ValueType::ConstMemberIterator itr = v.FindMember(kRefValue); + // Changed by PR #1393 + // TODO should this return a UriType& ? + bool HandleRefSchema(const PointerType& source, const SchemaType** schema, const ValueType& v, const ValueType& document, const UriType& id) { + typename ValueType::ConstMemberIterator itr = v.FindMember(SchemaType::GetRefString()); if (itr == v.MemberEnd()) return false; + GenericStringBuffer sb; + source.StringifyUriFragment(sb); + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaDocument::HandleRefSchema", sb.GetString(), id.GetString()); + // Resolve the source pointer to the $ref'ed schema (finally) + new (schemaRef_.template Push()) SchemaRefPtr(&source); + if (itr->value.IsString()) { SizeType len = itr->value.GetStringLength(); - if (len > 0) { - const Ch* s = itr->value.GetString(); - SizeType i = 0; - while (i < len && s[i] != '#') // Find the first # - i++; - - if (i > 0) { // Remote reference, resolve immediately - if (remoteProvider_) { - if (const GenericSchemaDocument* remoteDocument = remoteProvider_->GetRemoteDocument(s, i)) { - PointerType pointer(&s[i], len - i, allocator_); - if (pointer.IsValid()) { - if (const SchemaType* sc = remoteDocument->GetSchema(pointer)) { - if (schema) - *schema = sc; - new (schemaMap_.template Push()) SchemaEntry(source, const_cast(sc), false, allocator_); + if (len == 0) + SchemaError(kSchemaErrorRefInvalid, source); + else { + // First resolve $ref against the in-scope id + UriType scopeId = UriType(id, allocator_); + UriType ref = UriType(itr->value, allocator_).Resolve(scopeId, allocator_); + RAPIDJSON_SCHEMA_PRINT(SchemaIds, id.GetString(), itr->value.GetString(), ref.GetString()); + // See if the resolved $ref minus the fragment matches a resolved id in this document + // Search from the root. Returns the subschema in the document and its absolute JSON pointer. + PointerType basePointer = PointerType(); + const ValueType *base = FindId(document, ref, basePointer, docId_, false); + if (!base) { + // Remote reference - call the remote document provider + if (!remoteProvider_) + SchemaError(kSchemaErrorRefNoRemoteProvider, source); + else { + if (const GenericSchemaDocument* remoteDocument = remoteProvider_->GetRemoteDocument(ref, spec_)) { + const Ch* s = ref.GetFragString(); + len = ref.GetFragStringLength(); + if (len <= 1 || s[1] == '/') { + // JSON pointer fragment, absolute in the remote schema + const PointerType pointer(s, len, allocator_); + if (!pointer.IsValid()) + SchemaErrorPointer(kSchemaErrorRefPointerInvalid, source, s, len, pointer); + else { + // Get the subschema + if (const SchemaType *sc = remoteDocument->GetSchema(pointer)) { + if (schema) + *schema = sc; + AddSchemaRefs(const_cast(sc)); + return true; + } else + SchemaErrorValue(kSchemaErrorRefUnknown, source, ref.GetString(), ref.GetStringLength()); + } + } else + // Plain name fragment, not allowed in remote schema + SchemaErrorValue(kSchemaErrorRefPlainName, source, s, len); + } else + SchemaErrorValue(kSchemaErrorRefNoRemoteSchema, source, ref.GetString(), ref.GetStringLength()); + } + } + else { // Local reference + const Ch* s = ref.GetFragString(); + len = ref.GetFragStringLength(); + if (len <= 1 || s[1] == '/') { + // JSON pointer fragment, relative to the resolved URI + const PointerType relPointer(s, len, allocator_); + if (!relPointer.IsValid()) + SchemaErrorPointer(kSchemaErrorRefPointerInvalid, source, s, len, relPointer); + else { + // Get the subschema + if (const ValueType *pv = relPointer.Get(*base)) { + // Now get the absolute JSON pointer by adding relative to base + PointerType pointer(basePointer, allocator_); + for (SizeType i = 0; i < relPointer.GetTokenCount(); i++) + pointer = pointer.Append(relPointer.GetTokens()[i], allocator_); + if (IsCyclicRef(pointer)) + SchemaErrorValue(kSchemaErrorRefCyclical, source, ref.GetString(), ref.GetStringLength()); + else { + // Call CreateSchema recursively, but first compute the in-scope id for the $ref target as we have jumped there + // TODO: cache pointer <-> id mapping + size_t unresolvedTokenIndex; + scopeId = pointer.GetUri(document, docId_, &unresolvedTokenIndex, allocator_); + CreateSchema(schema, pointer, *pv, document, scopeId); return true; } - } + } else + SchemaErrorValue(kSchemaErrorRefUnknown, source, ref.GetString(), ref.GetStringLength()); } + } else { + // Plain name fragment, relative to the resolved URI + // Not supported in open api 2.0 and 3.0 + PointerType pointer(allocator_); + if (spec_.oapi == kVersion20 || spec_.oapi == kVersion30) + SchemaErrorValue(kSchemaErrorRefPlainName, source, s, len); + // See if the fragment matches an id in this document. + // Search from the base we just established. Returns the subschema in the document and its absolute JSON pointer. + else if (const ValueType *pv = FindId(*base, ref, pointer, UriType(ref.GetBaseString(), ref.GetBaseStringLength(), allocator_), true, basePointer)) { + if (IsCyclicRef(pointer)) + SchemaErrorValue(kSchemaErrorRefCyclical, source, ref.GetString(), ref.GetStringLength()); + else { + // Call CreateSchema recursively, but first compute the in-scope id for the $ref target as we have jumped there + // TODO: cache pointer <-> id mapping + size_t unresolvedTokenIndex; + scopeId = pointer.GetUri(document, docId_, &unresolvedTokenIndex, allocator_); + CreateSchema(schema, pointer, *pv, document, scopeId); + return true; + } + } else + SchemaErrorValue(kSchemaErrorRefUnknown, source, ref.GetString(), ref.GetStringLength()); } } - else if (s[i] == '#') { // Local reference, defer resolution - PointerType pointer(&s[i], len - i, allocator_); - if (pointer.IsValid()) { - if (const ValueType* nv = pointer.Get(document)) - if (HandleRefSchema(source, schema, *nv, document)) - return true; + } + } - new (schemaRef_.template Push()) SchemaRefEntry(source, pointer, schema, allocator_); - return true; - } + // Invalid/Unknown $ref + if (schema) + *schema = typeless_; + AddSchemaRefs(typeless_); + return true; + } + + //! Find the first subschema with a resolved 'id' that matches the specified URI. + // If full specified use all URI else ignore fragment. + // If found, return a pointer to the subschema and its JSON pointer. + // TODO cache pointer <-> id mapping + ValueType* FindId(const ValueType& doc, const UriType& finduri, PointerType& resptr, const UriType& baseuri, bool full, const PointerType& here = PointerType()) const { + SizeType i = 0; + ValueType* resval = 0; + UriType tempuri = UriType(finduri, allocator_); + UriType localuri = UriType(baseuri, allocator_); + if (doc.GetType() == kObjectType) { + // Establish the base URI of this object + typename ValueType::ConstMemberIterator m = doc.FindMember(SchemaType::GetIdString()); + if (m != doc.MemberEnd() && m->value.GetType() == kStringType) { + localuri = UriType(m->value, allocator_).Resolve(baseuri, allocator_); + } + // See if it matches + if (localuri.Match(finduri, full)) { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaDocument::FindId (match)", full ? localuri.GetString() : localuri.GetBaseString()); + resval = const_cast(&doc); + resptr = here; + return resval; + } + // No match, continue looking + for (m = doc.MemberBegin(); m != doc.MemberEnd(); ++m) { + if (m->value.GetType() == kObjectType || m->value.GetType() == kArrayType) { + resval = FindId(m->value, finduri, resptr, localuri, full, here.Append(m->name.GetString(), m->name.GetStringLength(), allocator_)); } + if (resval) break; + } + } else if (doc.GetType() == kArrayType) { + // Continue looking + for (typename ValueType::ConstValueIterator v = doc.Begin(); v != doc.End(); ++v) { + if (v->GetType() == kObjectType || v->GetType() == kArrayType) { + resval = FindId(*v, finduri, resptr, localuri, full, here.Append(i, allocator_)); + } + if (resval) break; + i++; } } + return resval; + } + + // Added by PR #1393 + void AddSchemaRefs(SchemaType* schema) { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaDocument::AddSchemaRefs"); + while (!schemaRef_.Empty()) { + SchemaRefPtr *ref = schemaRef_.template Pop(1); + SchemaEntry *entry = schemaMap_.template Push(); + new (entry) SchemaEntry(**ref, schema, false, allocator_); + } + } + + // Added by PR #1393 + bool IsCyclicRef(const PointerType& pointer) const { + for (const SchemaRefPtr* ref = schemaRef_.template Bottom(); ref != schemaRef_.template End(); ++ref) + if (pointer == **ref) + return true; return false; } @@ -1730,8 +2403,12 @@ class GenericSchemaDocument { const SchemaType* root_; //!< Root schema. SchemaType* typeless_; internal::Stack schemaMap_; // Stores created Pointer -> Schemas - internal::Stack schemaRef_; // Stores Pointer from $ref and schema which holds the $ref - URIType uri_; + internal::Stack schemaRef_; // Stores Pointer(s) from $ref(s) until resolved + GValue uri_; // Schema document URI + UriType docId_; + Specification spec_; + GValue error_; + GValue currentError_; }; //! GenericSchemaDocument using Value type. @@ -1761,8 +2438,7 @@ template < class GenericSchemaValidator : public internal::ISchemaStateFactory, public internal::ISchemaValidator, - public internal::IValidationErrorHandler -{ + public internal::IValidationErrorHandler { public: typedef typename SchemaDocumentType::SchemaType SchemaType; typedef typename SchemaDocumentType::PointerType PointerType; @@ -1795,11 +2471,11 @@ class GenericSchemaValidator : error_(kObjectType), currentError_(), missingDependents_(), - valid_(true) -#if RAPIDJSON_SCHEMA_VERBOSE - , depth_(0) -#endif + valid_(true), + flags_(kValidateDefaultFlags), + depth_(0) { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::GenericSchemaValidator"); } //! Constructor with output handler. @@ -1826,11 +2502,11 @@ class GenericSchemaValidator : error_(kObjectType), currentError_(), missingDependents_(), - valid_(true) -#if RAPIDJSON_SCHEMA_VERBOSE - , depth_(0) -#endif + valid_(true), + flags_(kValidateDefaultFlags), + depth_(0) { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::GenericSchemaValidator (output handler)"); } //! Destructor. @@ -1844,31 +2520,60 @@ class GenericSchemaValidator : while (!schemaStack_.Empty()) PopSchema(); documentStack_.Clear(); + ResetError(); + } + + //! Reset the error state. + void ResetError() { error_.SetObject(); currentError_.SetNull(); missingDependents_.SetNull(); valid_ = true; } - //! Checks whether the current state is valid. - // Implementation of ISchemaValidator - virtual bool IsValid() const { return valid_; } + //! Implementation of ISchemaValidator + void SetValidateFlags(unsigned flags) { + flags_ = flags; + } + virtual unsigned GetValidateFlags() const { + return flags_; + } + + virtual bool IsValid() const { + if (!valid_) return false; + if (GetContinueOnErrors() && !error_.ObjectEmpty()) return false; + return true; + } + //! End of Implementation of ISchemaValidator //! Gets the error object. ValueType& GetError() { return error_; } const ValueType& GetError() const { return error_; } //! Gets the JSON pointer pointed to the invalid schema. + // If reporting all errors, the stack will be empty. PointerType GetInvalidSchemaPointer() const { return schemaStack_.Empty() ? PointerType() : CurrentSchema().GetPointer(); } //! Gets the keyword of invalid schema. + // If reporting all errors, the stack will be empty, so return "errors". const Ch* GetInvalidSchemaKeyword() const { - return schemaStack_.Empty() ? 0 : CurrentContext().invalidKeyword; + if (!schemaStack_.Empty()) return CurrentContext().invalidKeyword; + if (GetContinueOnErrors() && !error_.ObjectEmpty()) return (const Ch*)GetErrorsString(); + return 0; + } + + //! Gets the error code of invalid schema. + // If reporting all errors, the stack will be empty, so return kValidateErrors. + ValidateErrorCode GetInvalidSchemaCode() const { + if (!schemaStack_.Empty()) return CurrentContext().invalidCode; + if (GetContinueOnErrors() && !error_.ObjectEmpty()) return kValidateErrors; + return kValidateErrorNone; } //! Gets the JSON pointer pointed to the invalid value. + // If reporting all errors, the stack will be empty. PointerType GetInvalidDocumentPointer() const { if (documentStack_.Empty()) { return PointerType(); @@ -1879,64 +2584,64 @@ class GenericSchemaValidator : } void NotMultipleOf(int64_t actual, const SValue& expected) { - AddNumberError(SchemaType::GetMultipleOfString(), ValueType(actual).Move(), expected); + AddNumberError(kValidateErrorMultipleOf, ValueType(actual).Move(), expected); } void NotMultipleOf(uint64_t actual, const SValue& expected) { - AddNumberError(SchemaType::GetMultipleOfString(), ValueType(actual).Move(), expected); + AddNumberError(kValidateErrorMultipleOf, ValueType(actual).Move(), expected); } void NotMultipleOf(double actual, const SValue& expected) { - AddNumberError(SchemaType::GetMultipleOfString(), ValueType(actual).Move(), expected); + AddNumberError(kValidateErrorMultipleOf, ValueType(actual).Move(), expected); } void AboveMaximum(int64_t actual, const SValue& expected, bool exclusive) { - AddNumberError(SchemaType::GetMaximumString(), ValueType(actual).Move(), expected, + AddNumberError(exclusive ? kValidateErrorExclusiveMaximum : kValidateErrorMaximum, ValueType(actual).Move(), expected, exclusive ? &SchemaType::GetExclusiveMaximumString : 0); } void AboveMaximum(uint64_t actual, const SValue& expected, bool exclusive) { - AddNumberError(SchemaType::GetMaximumString(), ValueType(actual).Move(), expected, + AddNumberError(exclusive ? kValidateErrorExclusiveMaximum : kValidateErrorMaximum, ValueType(actual).Move(), expected, exclusive ? &SchemaType::GetExclusiveMaximumString : 0); } void AboveMaximum(double actual, const SValue& expected, bool exclusive) { - AddNumberError(SchemaType::GetMaximumString(), ValueType(actual).Move(), expected, + AddNumberError(exclusive ? kValidateErrorExclusiveMaximum : kValidateErrorMaximum, ValueType(actual).Move(), expected, exclusive ? &SchemaType::GetExclusiveMaximumString : 0); } void BelowMinimum(int64_t actual, const SValue& expected, bool exclusive) { - AddNumberError(SchemaType::GetMinimumString(), ValueType(actual).Move(), expected, + AddNumberError(exclusive ? kValidateErrorExclusiveMinimum : kValidateErrorMinimum, ValueType(actual).Move(), expected, exclusive ? &SchemaType::GetExclusiveMinimumString : 0); } void BelowMinimum(uint64_t actual, const SValue& expected, bool exclusive) { - AddNumberError(SchemaType::GetMinimumString(), ValueType(actual).Move(), expected, + AddNumberError(exclusive ? kValidateErrorExclusiveMinimum : kValidateErrorMinimum, ValueType(actual).Move(), expected, exclusive ? &SchemaType::GetExclusiveMinimumString : 0); } void BelowMinimum(double actual, const SValue& expected, bool exclusive) { - AddNumberError(SchemaType::GetMinimumString(), ValueType(actual).Move(), expected, + AddNumberError(exclusive ? kValidateErrorExclusiveMinimum : kValidateErrorMinimum, ValueType(actual).Move(), expected, exclusive ? &SchemaType::GetExclusiveMinimumString : 0); } void TooLong(const Ch* str, SizeType length, SizeType expected) { - AddNumberError(SchemaType::GetMaxLengthString(), + AddNumberError(kValidateErrorMaxLength, ValueType(str, length, GetStateAllocator()).Move(), SValue(expected).Move()); } void TooShort(const Ch* str, SizeType length, SizeType expected) { - AddNumberError(SchemaType::GetMinLengthString(), + AddNumberError(kValidateErrorMinLength, ValueType(str, length, GetStateAllocator()).Move(), SValue(expected).Move()); } void DoesNotMatch(const Ch* str, SizeType length) { currentError_.SetObject(); currentError_.AddMember(GetActualString(), ValueType(str, length, GetStateAllocator()).Move(), GetStateAllocator()); - AddCurrentError(SchemaType::GetPatternString()); + AddCurrentError(kValidateErrorPattern); } void DisallowedItem(SizeType index) { currentError_.SetObject(); currentError_.AddMember(GetDisallowedString(), ValueType(index).Move(), GetStateAllocator()); - AddCurrentError(SchemaType::GetAdditionalItemsString(), true); + AddCurrentError(kValidateErrorAdditionalItems, true); } void TooFewItems(SizeType actualCount, SizeType expectedCount) { - AddNumberError(SchemaType::GetMinItemsString(), + AddNumberError(kValidateErrorMinItems, ValueType(actualCount).Move(), SValue(expectedCount).Move()); } void TooManyItems(SizeType actualCount, SizeType expectedCount) { - AddNumberError(SchemaType::GetMaxItemsString(), + AddNumberError(kValidateErrorMaxItems, ValueType(actualCount).Move(), SValue(expectedCount).Move()); } void DuplicateItems(SizeType index1, SizeType index2) { @@ -1945,15 +2650,15 @@ class GenericSchemaValidator : duplicates.PushBack(index2, GetStateAllocator()); currentError_.SetObject(); currentError_.AddMember(GetDuplicatesString(), duplicates, GetStateAllocator()); - AddCurrentError(SchemaType::GetUniqueItemsString(), true); + AddCurrentError(kValidateErrorUniqueItems, true); } void TooManyProperties(SizeType actualCount, SizeType expectedCount) { - AddNumberError(SchemaType::GetMaxPropertiesString(), + AddNumberError(kValidateErrorMaxProperties, ValueType(actualCount).Move(), SValue(expectedCount).Move()); } void TooFewProperties(SizeType actualCount, SizeType expectedCount) { - AddNumberError(SchemaType::GetMinPropertiesString(), + AddNumberError(kValidateErrorMinProperties, ValueType(actualCount).Move(), SValue(expectedCount).Move()); } void StartMissingProperties() { @@ -1968,7 +2673,7 @@ class GenericSchemaValidator : ValueType error(kObjectType); error.AddMember(GetMissingString(), currentError_, GetStateAllocator()); currentError_ = error; - AddCurrentError(SchemaType::GetRequiredString()); + AddCurrentError(kValidateErrorRequired); return true; } void PropertyViolations(ISchemaValidator** subvalidators, SizeType count) { @@ -1978,7 +2683,7 @@ class GenericSchemaValidator : void DisallowedProperty(const Ch* name, SizeType length) { currentError_.SetObject(); currentError_.AddMember(GetDisallowedString(), ValueType(name, length, GetStateAllocator()).Move(), GetStateAllocator()); - AddCurrentError(SchemaType::GetAdditionalPropertiesString(), true); + AddCurrentError(kValidateErrorAdditionalProperties, true); } void StartDependencyErrors() { @@ -1991,9 +2696,20 @@ class GenericSchemaValidator : missingDependents_.PushBack(ValueType(targetName, GetStateAllocator()).Move(), GetStateAllocator()); } void EndMissingDependentProperties(const SValue& sourceName) { - if (!missingDependents_.Empty()) - currentError_.AddMember(ValueType(sourceName, GetStateAllocator()).Move(), - missingDependents_, GetStateAllocator()); + if (!missingDependents_.Empty()) { + // Create equivalent 'required' error + ValueType error(kObjectType); + ValidateErrorCode code = kValidateErrorRequired; + error.AddMember(GetMissingString(), missingDependents_.Move(), GetStateAllocator()); + AddErrorCode(error, code); + AddErrorInstanceLocation(error, false); + // When appending to a pointer ensure its allocator is used + PointerType schemaRef = GetInvalidSchemaPointer().Append(SchemaType::GetValidateErrorKeyword(kValidateErrorDependencies), &GetInvalidSchemaPointer().GetAllocator()); + AddErrorSchemaLocation(error, schemaRef.Append(sourceName.GetString(), sourceName.GetStringLength(), &GetInvalidSchemaPointer().GetAllocator())); + ValueType wrapper(kObjectType); + wrapper.AddMember(ValueType(SchemaType::GetValidateErrorKeyword(code), GetStateAllocator()).Move(), error, GetStateAllocator()); + currentError_.AddMember(ValueType(sourceName, GetStateAllocator()).Move(), wrapper, GetStateAllocator()); + } } void AddDependencySchemaError(const SValue& sourceName, ISchemaValidator* subvalidator) { currentError_.AddMember(ValueType(sourceName, GetStateAllocator()).Move(), @@ -2005,13 +2721,13 @@ class GenericSchemaValidator : ValueType error(kObjectType); error.AddMember(GetErrorsString(), currentError_, GetStateAllocator()); currentError_ = error; - AddCurrentError(SchemaType::GetDependenciesString()); + AddCurrentError(kValidateErrorDependencies); return true; } - void DisallowedValue() { + void DisallowedValue(const ValidateErrorCode code = kValidateErrorEnum) { currentError_.SetObject(); - AddCurrentError(SchemaType::GetEnumString()); + AddCurrentError(code); } void StartDisallowedType() { currentError_.SetArray(); @@ -2024,22 +2740,40 @@ class GenericSchemaValidator : error.AddMember(GetExpectedString(), currentError_, GetStateAllocator()); error.AddMember(GetActualString(), ValueType(actualType, GetStateAllocator()).Move(), GetStateAllocator()); currentError_ = error; - AddCurrentError(SchemaType::GetTypeString()); + AddCurrentError(kValidateErrorType); } void NotAllOf(ISchemaValidator** subvalidators, SizeType count) { - for (SizeType i = 0; i < count; ++i) { - MergeError(static_cast(subvalidators[i])->GetError()); - } + // Treat allOf like oneOf and anyOf to match https://rapidjson.org/md_doc_schema.html#allOf-anyOf-oneOf + AddErrorArray(kValidateErrorAllOf, subvalidators, count); + //for (SizeType i = 0; i < count; ++i) { + // MergeError(static_cast(subvalidators[i])->GetError()); + //} } void NoneOf(ISchemaValidator** subvalidators, SizeType count) { - AddErrorArray(SchemaType::GetAnyOfString(), subvalidators, count); + AddErrorArray(kValidateErrorAnyOf, subvalidators, count); } void NotOneOf(ISchemaValidator** subvalidators, SizeType count) { - AddErrorArray(SchemaType::GetOneOfString(), subvalidators, count); + AddErrorArray(kValidateErrorOneOf, subvalidators, count); + } + void MultipleOneOf(SizeType index1, SizeType index2) { + ValueType matches(kArrayType); + matches.PushBack(index1, GetStateAllocator()); + matches.PushBack(index2, GetStateAllocator()); + currentError_.SetObject(); + currentError_.AddMember(GetMatchesString(), matches, GetStateAllocator()); + AddCurrentError(kValidateErrorOneOfMatch); } void Disallowed() { currentError_.SetObject(); - AddCurrentError(SchemaType::GetNotString()); + AddCurrentError(kValidateErrorNot); + } + void DisallowedWhenWriting() { + currentError_.SetObject(); + AddCurrentError(kValidateErrorReadOnly); + } + void DisallowedWhenReading() { + currentError_.SetObject(); + AddCurrentError(kValidateErrorWriteOnly); } #define RAPIDJSON_STRING_(name, ...) \ @@ -2056,26 +2790,21 @@ class GenericSchemaValidator : RAPIDJSON_STRING_(Disallowed, 'd', 'i', 's', 'a', 'l', 'l', 'o', 'w', 'e', 'd') RAPIDJSON_STRING_(Missing, 'm', 'i', 's', 's', 'i', 'n', 'g') RAPIDJSON_STRING_(Errors, 'e', 'r', 'r', 'o', 'r', 's') + RAPIDJSON_STRING_(ErrorCode, 'e', 'r', 'r', 'o', 'r', 'C', 'o', 'd', 'e') + RAPIDJSON_STRING_(ErrorMessage, 'e', 'r', 'r', 'o', 'r', 'M', 'e', 's', 's', 'a', 'g', 'e') RAPIDJSON_STRING_(Duplicates, 'd', 'u', 'p', 'l', 'i', 'c', 'a', 't', 'e', 's') + RAPIDJSON_STRING_(Matches, 'm', 'a', 't', 'c', 'h', 'e', 's') #undef RAPIDJSON_STRING_ -#if RAPIDJSON_SCHEMA_VERBOSE -#define RAPIDJSON_SCHEMA_HANDLE_BEGIN_VERBOSE_() \ -RAPIDJSON_MULTILINEMACRO_BEGIN\ - *documentStack_.template Push() = '\0';\ - documentStack_.template Pop(1);\ - internal::PrintInvalidDocument(documentStack_.template Bottom());\ -RAPIDJSON_MULTILINEMACRO_END -#else -#define RAPIDJSON_SCHEMA_HANDLE_BEGIN_VERBOSE_() -#endif - #define RAPIDJSON_SCHEMA_HANDLE_BEGIN_(method, arg1)\ if (!valid_) return false; \ - if (!BeginValue() || !CurrentSchema().method arg1) {\ - RAPIDJSON_SCHEMA_HANDLE_BEGIN_VERBOSE_();\ - return valid_ = false;\ + if ((!BeginValue() && !GetContinueOnErrors()) || (!CurrentSchema().method arg1 && !GetContinueOnErrors())) {\ + *documentStack_.template Push() = '\0';\ + documentStack_.template Pop(1);\ + RAPIDJSON_SCHEMA_PRINT(InvalidDocument, documentStack_.template Bottom());\ + valid_ = false;\ + return valid_;\ } #define RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(method, arg2)\ @@ -2091,7 +2820,8 @@ RAPIDJSON_MULTILINEMACRO_END } #define RAPIDJSON_SCHEMA_HANDLE_END_(method, arg2)\ - return valid_ = EndValue() && (!outputHandler_ || outputHandler_->method arg2) + valid_ = (EndValue() || GetContinueOnErrors()) && (!outputHandler_ || outputHandler_->method arg2);\ + return valid_; #define RAPIDJSON_SCHEMA_HANDLE_VALUE_(method, arg1, arg2) \ RAPIDJSON_SCHEMA_HANDLE_BEGIN_ (method, arg1);\ @@ -2111,51 +2841,69 @@ RAPIDJSON_MULTILINEMACRO_END { RAPIDJSON_SCHEMA_HANDLE_VALUE_(String, (CurrentContext(), str, length, copy), (str, length, copy)); } bool StartObject() { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::StartObject"); RAPIDJSON_SCHEMA_HANDLE_BEGIN_(StartObject, (CurrentContext())); RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(StartObject, ()); - return valid_ = !outputHandler_ || outputHandler_->StartObject(); + valid_ = !outputHandler_ || outputHandler_->StartObject(); + return valid_; } bool Key(const Ch* str, SizeType len, bool copy) { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::Key", str); if (!valid_) return false; AppendToken(str, len); - if (!CurrentSchema().Key(CurrentContext(), str, len, copy)) return valid_ = false; + if (!CurrentSchema().Key(CurrentContext(), str, len, copy) && !GetContinueOnErrors()) { + valid_ = false; + return valid_; + } RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(Key, (str, len, copy)); - return valid_ = !outputHandler_ || outputHandler_->Key(str, len, copy); + valid_ = !outputHandler_ || outputHandler_->Key(str, len, copy); + return valid_; } - bool EndObject(SizeType memberCount) { + bool EndObject(SizeType memberCount) { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::EndObject"); if (!valid_) return false; RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(EndObject, (memberCount)); - if (!CurrentSchema().EndObject(CurrentContext(), memberCount)) return valid_ = false; + if (!CurrentSchema().EndObject(CurrentContext(), memberCount) && !GetContinueOnErrors()) { + valid_ = false; + return valid_; + } RAPIDJSON_SCHEMA_HANDLE_END_(EndObject, (memberCount)); } bool StartArray() { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::StartArray"); RAPIDJSON_SCHEMA_HANDLE_BEGIN_(StartArray, (CurrentContext())); RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(StartArray, ()); - return valid_ = !outputHandler_ || outputHandler_->StartArray(); + valid_ = !outputHandler_ || outputHandler_->StartArray(); + return valid_; } bool EndArray(SizeType elementCount) { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::EndArray"); if (!valid_) return false; RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(EndArray, (elementCount)); - if (!CurrentSchema().EndArray(CurrentContext(), elementCount)) return valid_ = false; + if (!CurrentSchema().EndArray(CurrentContext(), elementCount) && !GetContinueOnErrors()) { + valid_ = false; + return valid_; + } RAPIDJSON_SCHEMA_HANDLE_END_(EndArray, (elementCount)); } -#undef RAPIDJSON_SCHEMA_HANDLE_BEGIN_VERBOSE_ #undef RAPIDJSON_SCHEMA_HANDLE_BEGIN_ #undef RAPIDJSON_SCHEMA_HANDLE_PARALLEL_ #undef RAPIDJSON_SCHEMA_HANDLE_VALUE_ // Implementation of ISchemaStateFactory - virtual ISchemaValidator* CreateSchemaValidator(const SchemaType& root) { - return new (GetStateAllocator().Malloc(sizeof(GenericSchemaValidator))) GenericSchemaValidator(*schemaDocument_, root, documentStack_.template Bottom(), documentStack_.GetSize(), -#if RAPIDJSON_SCHEMA_VERBOSE + virtual ISchemaValidator* CreateSchemaValidator(const SchemaType& root, const bool inheritContinueOnErrors) { + *documentStack_.template Push() = '\0'; + documentStack_.template Pop(1); + ISchemaValidator* sv = new (GetStateAllocator().Malloc(sizeof(GenericSchemaValidator))) GenericSchemaValidator(*schemaDocument_, root, documentStack_.template Bottom(), documentStack_.GetSize(), depth_ + 1, -#endif &GetStateAllocator()); + sv->SetValidateFlags(inheritContinueOnErrors ? GetValidateFlags() : GetValidateFlags() & ~(unsigned)kValidateContinueOnErrorFlag); + return sv; } virtual void DestroySchemaValidator(ISchemaValidator* validator) { @@ -2185,6 +2933,7 @@ RAPIDJSON_MULTILINEMACRO_END virtual void FreeState(void* p) { StateAllocator::Free(p); } + // End of implementation of ISchemaStateFactory private: typedef typename SchemaType::Context Context; @@ -2195,9 +2944,7 @@ RAPIDJSON_MULTILINEMACRO_END const SchemaDocumentType& schemaDocument, const SchemaType& root, const char* basePath, size_t basePathSize, -#if RAPIDJSON_SCHEMA_VERBOSE unsigned depth, -#endif StateAllocator* allocator = 0, size_t schemaStackCapacity = kDefaultSchemaStackCapacity, size_t documentStackCapacity = kDefaultDocumentStackCapacity) @@ -2212,11 +2959,11 @@ RAPIDJSON_MULTILINEMACRO_END error_(kObjectType), currentError_(), missingDependents_(), - valid_(true) -#if RAPIDJSON_SCHEMA_VERBOSE - , depth_(depth) -#endif + valid_(true), + flags_(kValidateDefaultFlags), + depth_(depth) { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::GenericSchemaValidator (internal)", basePath && basePathSize ? basePath : ""); if (basePath && basePathSize) memcpy(documentStack_.template Push(basePathSize), basePath, basePathSize); } @@ -2227,14 +2974,19 @@ RAPIDJSON_MULTILINEMACRO_END return *stateAllocator_; } + bool GetContinueOnErrors() const { + return flags_ & kValidateContinueOnErrorFlag; + } + bool BeginValue() { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::BeginValue"); if (schemaStack_.Empty()) PushSchema(root_); else { if (CurrentContext().inArray) internal::TokenHelper, Ch>::AppendIndexToken(documentStack_, CurrentContext().arrayElementIndex); - if (!CurrentSchema().BeginValue(CurrentContext())) + if (!CurrentSchema().BeginValue(CurrentContext()) && !GetContinueOnErrors()) return false; SizeType count = CurrentContext().patternPropertiesSchemaCount; @@ -2249,8 +3001,9 @@ RAPIDJSON_MULTILINEMACRO_END ISchemaValidator**& va = CurrentContext().patternPropertiesValidators; SizeType& validatorCount = CurrentContext().patternPropertiesValidatorCount; va = static_cast(MallocState(sizeof(ISchemaValidator*) * count)); + std::memset(va, 0, sizeof(ISchemaValidator*) * count); for (SizeType i = 0; i < count; i++) - va[validatorCount++] = CreateSchemaValidator(*sa[i]); + va[validatorCount++] = CreateSchemaValidator(*sa[i], true); // Inherit continueOnError } CurrentContext().arrayUniqueness = valueUniqueness; @@ -2259,32 +3012,36 @@ RAPIDJSON_MULTILINEMACRO_END } bool EndValue() { - if (!CurrentSchema().EndValue(CurrentContext())) + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::EndValue"); + if (!CurrentSchema().EndValue(CurrentContext()) && !GetContinueOnErrors()) return false; -#if RAPIDJSON_SCHEMA_VERBOSE GenericStringBuffer sb; - schemaDocument_->GetPointer(&CurrentSchema()).Stringify(sb); - + schemaDocument_->GetPointer(&CurrentSchema()).StringifyUriFragment(sb); *documentStack_.template Push() = '\0'; documentStack_.template Pop(1); - internal::PrintValidatorPointers(depth_, sb.GetString(), documentStack_.template Bottom()); -#endif - - uint64_t h = CurrentContext().arrayUniqueness ? static_cast(CurrentContext().hasher)->GetHashCode() : 0; + RAPIDJSON_SCHEMA_PRINT(ValidatorPointers, sb.GetString(), documentStack_.template Bottom(), depth_); + void* hasher = CurrentContext().hasher; + uint64_t h = hasher && CurrentContext().arrayUniqueness ? static_cast(hasher)->GetHashCode() : 0; PopSchema(); if (!schemaStack_.Empty()) { Context& context = CurrentContext(); - if (context.valueUniqueness) { + // Only check uniqueness if there is a hasher + if (hasher && context.valueUniqueness) { HashCodeArray* a = static_cast(context.arrayElementHashCodes); if (!a) CurrentContext().arrayElementHashCodes = a = new (GetStateAllocator().Malloc(sizeof(HashCodeArray))) HashCodeArray(kArrayType); for (typename HashCodeArray::ConstValueIterator itr = a->Begin(); itr != a->End(); ++itr) if (itr->GetUint64() == h) { DuplicateItems(static_cast(itr - a->Begin()), a->Size()); - RAPIDJSON_INVALID_KEYWORD_RETURN(SchemaType::GetUniqueItemsString()); + // Cleanup before returning if continuing + if (GetContinueOnErrors()) { + a->PushBack(h, GetStateAllocator()); + while (!documentStack_.Empty() && *documentStack_.template Pop(1) != '/'); + } + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorUniqueItems); } a->PushBack(h, GetStateAllocator()); } @@ -2314,7 +3071,7 @@ RAPIDJSON_MULTILINEMACRO_END } } - RAPIDJSON_FORCEINLINE void PushSchema(const SchemaType& schema) { new (schemaStack_.template Push()) Context(*this, *this, &schema); } + RAPIDJSON_FORCEINLINE void PushSchema(const SchemaType& schema) { new (schemaStack_.template Push()) Context(*this, *this, &schema, flags_); } RAPIDJSON_FORCEINLINE void PopSchema() { Context* c = schemaStack_.template Pop(1); @@ -2325,25 +3082,32 @@ RAPIDJSON_MULTILINEMACRO_END c->~Context(); } - void AddErrorLocation(ValueType& result, bool parent) { + void AddErrorInstanceLocation(ValueType& result, bool parent) { GenericStringBuffer sb; PointerType instancePointer = GetInvalidDocumentPointer(); ((parent && instancePointer.GetTokenCount() > 0) - ? PointerType(instancePointer.GetTokens(), instancePointer.GetTokenCount() - 1) - : instancePointer).StringifyUriFragment(sb); + ? PointerType(instancePointer.GetTokens(), instancePointer.GetTokenCount() - 1) + : instancePointer).StringifyUriFragment(sb); ValueType instanceRef(sb.GetString(), static_cast(sb.GetSize() / sizeof(Ch)), - GetStateAllocator()); + GetStateAllocator()); result.AddMember(GetInstanceRefString(), instanceRef, GetStateAllocator()); - sb.Clear(); - memcpy(sb.Push(CurrentSchema().GetURI().GetStringLength()), - CurrentSchema().GetURI().GetString(), - CurrentSchema().GetURI().GetStringLength() * sizeof(Ch)); - GetInvalidSchemaPointer().StringifyUriFragment(sb); + } + + void AddErrorSchemaLocation(ValueType& result, PointerType schema = PointerType()) { + GenericStringBuffer sb; + SizeType len = CurrentSchema().GetURI().GetStringLength(); + if (len) memcpy(sb.Push(len), CurrentSchema().GetURI().GetString(), len * sizeof(Ch)); + if (schema.GetTokenCount()) schema.StringifyUriFragment(sb); + else GetInvalidSchemaPointer().StringifyUriFragment(sb); ValueType schemaRef(sb.GetString(), static_cast(sb.GetSize() / sizeof(Ch)), GetStateAllocator()); result.AddMember(GetSchemaRefString(), schemaRef, GetStateAllocator()); } + void AddErrorCode(ValueType& result, const ValidateErrorCode code) { + result.AddMember(GetErrorCodeString(), code, GetStateAllocator()); + } + void AddError(ValueType& keyword, ValueType& error) { typename ValueType::MemberIterator member = error_.FindMember(keyword); if (member == error_.MemberEnd()) @@ -2358,9 +3122,11 @@ RAPIDJSON_MULTILINEMACRO_END } } - void AddCurrentError(const typename SchemaType::ValueType& keyword, bool parent = false) { - AddErrorLocation(currentError_, parent); - AddError(ValueType(keyword, GetStateAllocator(), false).Move(), currentError_); + void AddCurrentError(const ValidateErrorCode code, bool parent = false) { + AddErrorCode(currentError_, code); + AddErrorInstanceLocation(currentError_, parent); + AddErrorSchemaLocation(currentError_); + AddError(ValueType(SchemaType::GetValidateErrorKeyword(code), GetStateAllocator(), false).Move(), currentError_); } void MergeError(ValueType& other) { @@ -2369,24 +3135,24 @@ RAPIDJSON_MULTILINEMACRO_END } } - void AddNumberError(const typename SchemaType::ValueType& keyword, ValueType& actual, const SValue& expected, + void AddNumberError(const ValidateErrorCode code, ValueType& actual, const SValue& expected, const typename SchemaType::ValueType& (*exclusive)() = 0) { currentError_.SetObject(); currentError_.AddMember(GetActualString(), actual, GetStateAllocator()); currentError_.AddMember(GetExpectedString(), ValueType(expected, GetStateAllocator()).Move(), GetStateAllocator()); if (exclusive) currentError_.AddMember(ValueType(exclusive(), GetStateAllocator()).Move(), true, GetStateAllocator()); - AddCurrentError(keyword); + AddCurrentError(code); } - void AddErrorArray(const typename SchemaType::ValueType& keyword, + void AddErrorArray(const ValidateErrorCode code, ISchemaValidator** subvalidators, SizeType count) { ValueType errors(kArrayType); for (SizeType i = 0; i < count; ++i) errors.PushBack(static_cast(subvalidators[i])->GetError(), GetStateAllocator()); currentError_.SetObject(); currentError_.AddMember(GetErrorsString(), errors, GetStateAllocator()); - AddCurrentError(keyword); + AddCurrentError(code); } const SchemaType& CurrentSchema() const { return *schemaStack_.template Top()->schema; } @@ -2406,9 +3172,8 @@ RAPIDJSON_MULTILINEMACRO_END ValueType currentError_; ValueType missingDependents_; bool valid_; -#if RAPIDJSON_SCHEMA_VERBOSE + unsigned flags_; unsigned depth_; -#endif }; typedef GenericSchemaValidator SchemaValidator; @@ -2443,7 +3208,7 @@ class SchemaValidatingReader { \param is Input stream. \param sd Schema document. */ - SchemaValidatingReader(InputStream& is, const SchemaDocumentType& sd) : is_(is), sd_(sd), invalidSchemaKeyword_(), error_(kObjectType), isValid_(true) {} + SchemaValidatingReader(InputStream& is, const SchemaDocumentType& sd) : is_(is), sd_(sd), invalidSchemaKeyword_(), invalidSchemaCode_(kValidateErrorNone), error_(kObjectType), isValid_(true) {} template bool operator()(Handler& handler) { @@ -2461,6 +3226,7 @@ class SchemaValidatingReader { else { invalidSchemaPointer_ = validator.GetInvalidSchemaPointer(); invalidSchemaKeyword_ = validator.GetInvalidSchemaKeyword(); + invalidSchemaCode_ = validator.GetInvalidSchemaCode(); invalidDocumentPointer_ = validator.GetInvalidDocumentPointer(); error_.CopyFrom(validator.GetError(), allocator_); } @@ -2474,6 +3240,7 @@ class SchemaValidatingReader { const Ch* GetInvalidSchemaKeyword() const { return invalidSchemaKeyword_; } const PointerType& GetInvalidDocumentPointer() const { return invalidDocumentPointer_; } const ValueType& GetError() const { return error_; } + ValidateErrorCode GetInvalidSchemaCode() const { return invalidSchemaCode_; } private: InputStream& is_; @@ -2483,6 +3250,7 @@ class SchemaValidatingReader { PointerType invalidSchemaPointer_; const Ch* invalidSchemaKeyword_; PointerType invalidDocumentPointer_; + ValidateErrorCode invalidSchemaCode_; StackAllocator allocator_; ValueType error_; bool isValid_; diff --git a/include/common/rapidjson/stream.h b/include/common/rapidjson/stream.h index 7f2643e..1fd7091 100644 --- a/include/common/rapidjson/stream.h +++ b/include/common/rapidjson/stream.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at diff --git a/include/common/rapidjson/stringbuffer.h b/include/common/rapidjson/stringbuffer.h index 4e38b82..82ad3ca 100644 --- a/include/common/rapidjson/stringbuffer.h +++ b/include/common/rapidjson/stringbuffer.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at diff --git a/include/common/rapidjson/uri.h b/include/common/rapidjson/uri.h new file mode 100644 index 0000000..f93e508 --- /dev/null +++ b/include/common/rapidjson/uri.h @@ -0,0 +1,481 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// (C) Copyright IBM Corporation 2021 +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_URI_H_ +#define RAPIDJSON_URI_H_ + +#include "internal/strfunc.h" + +#if defined(__clang__) +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(c++98-compat) +#elif defined(_MSC_VER) +RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated +#endif + +RAPIDJSON_NAMESPACE_BEGIN + +/////////////////////////////////////////////////////////////////////////////// +// GenericUri + +template +class GenericUri { +public: + typedef typename ValueType::Ch Ch; +#if RAPIDJSON_HAS_STDSTRING + typedef std::basic_string String; +#endif + + //! Constructors + GenericUri(Allocator* allocator = 0) : uri_(), base_(), scheme_(), auth_(), path_(), query_(), frag_(), allocator_(allocator), ownAllocator_() { + } + + GenericUri(const Ch* uri, SizeType len, Allocator* allocator = 0) : uri_(), base_(), scheme_(), auth_(), path_(), query_(), frag_(), allocator_(allocator), ownAllocator_() { + Parse(uri, len); + } + + GenericUri(const Ch* uri, Allocator* allocator = 0) : uri_(), base_(), scheme_(), auth_(), path_(), query_(), frag_(), allocator_(allocator), ownAllocator_() { + Parse(uri, internal::StrLen(uri)); + } + + // Use with specializations of GenericValue + template GenericUri(const T& uri, Allocator* allocator = 0) : uri_(), base_(), scheme_(), auth_(), path_(), query_(), frag_(), allocator_(allocator), ownAllocator_() { + const Ch* u = uri.template Get(); // TypeHelper from document.h + Parse(u, internal::StrLen(u)); + } + +#if RAPIDJSON_HAS_STDSTRING + GenericUri(const String& uri, Allocator* allocator = 0) : uri_(), base_(), scheme_(), auth_(), path_(), query_(), frag_(), allocator_(allocator), ownAllocator_() { + Parse(uri.c_str(), internal::StrLen(uri.c_str())); + } +#endif + + //! Copy constructor + GenericUri(const GenericUri& rhs) : uri_(), base_(), scheme_(), auth_(), path_(), query_(), frag_(), allocator_(), ownAllocator_() { + *this = rhs; + } + + //! Copy constructor + GenericUri(const GenericUri& rhs, Allocator* allocator) : uri_(), base_(), scheme_(), auth_(), path_(), query_(), frag_(), allocator_(allocator), ownAllocator_() { + *this = rhs; + } + + //! Destructor. + ~GenericUri() { + Free(); + RAPIDJSON_DELETE(ownAllocator_); + } + + //! Assignment operator + GenericUri& operator=(const GenericUri& rhs) { + if (this != &rhs) { + // Do not delete ownAllocator + Free(); + Allocate(rhs.GetStringLength()); + auth_ = CopyPart(scheme_, rhs.scheme_, rhs.GetSchemeStringLength()); + path_ = CopyPart(auth_, rhs.auth_, rhs.GetAuthStringLength()); + query_ = CopyPart(path_, rhs.path_, rhs.GetPathStringLength()); + frag_ = CopyPart(query_, rhs.query_, rhs.GetQueryStringLength()); + base_ = CopyPart(frag_, rhs.frag_, rhs.GetFragStringLength()); + uri_ = CopyPart(base_, rhs.base_, rhs.GetBaseStringLength()); + CopyPart(uri_, rhs.uri_, rhs.GetStringLength()); + } + return *this; + } + + //! Getters + // Use with specializations of GenericValue + template void Get(T& uri, Allocator& allocator) { + uri.template Set(this->GetString(), allocator); // TypeHelper from document.h + } + + const Ch* GetString() const { return uri_; } + SizeType GetStringLength() const { return uri_ == 0 ? 0 : internal::StrLen(uri_); } + const Ch* GetBaseString() const { return base_; } + SizeType GetBaseStringLength() const { return base_ == 0 ? 0 : internal::StrLen(base_); } + const Ch* GetSchemeString() const { return scheme_; } + SizeType GetSchemeStringLength() const { return scheme_ == 0 ? 0 : internal::StrLen(scheme_); } + const Ch* GetAuthString() const { return auth_; } + SizeType GetAuthStringLength() const { return auth_ == 0 ? 0 : internal::StrLen(auth_); } + const Ch* GetPathString() const { return path_; } + SizeType GetPathStringLength() const { return path_ == 0 ? 0 : internal::StrLen(path_); } + const Ch* GetQueryString() const { return query_; } + SizeType GetQueryStringLength() const { return query_ == 0 ? 0 : internal::StrLen(query_); } + const Ch* GetFragString() const { return frag_; } + SizeType GetFragStringLength() const { return frag_ == 0 ? 0 : internal::StrLen(frag_); } + +#if RAPIDJSON_HAS_STDSTRING + static String Get(const GenericUri& uri) { return String(uri.GetString(), uri.GetStringLength()); } + static String GetBase(const GenericUri& uri) { return String(uri.GetBaseString(), uri.GetBaseStringLength()); } + static String GetScheme(const GenericUri& uri) { return String(uri.GetSchemeString(), uri.GetSchemeStringLength()); } + static String GetAuth(const GenericUri& uri) { return String(uri.GetAuthString(), uri.GetAuthStringLength()); } + static String GetPath(const GenericUri& uri) { return String(uri.GetPathString(), uri.GetPathStringLength()); } + static String GetQuery(const GenericUri& uri) { return String(uri.GetQueryString(), uri.GetQueryStringLength()); } + static String GetFrag(const GenericUri& uri) { return String(uri.GetFragString(), uri.GetFragStringLength()); } +#endif + + //! Equality operators + bool operator==(const GenericUri& rhs) const { + return Match(rhs, true); + } + + bool operator!=(const GenericUri& rhs) const { + return !Match(rhs, true); + } + + bool Match(const GenericUri& uri, bool full = true) const { + Ch* s1; + Ch* s2; + if (full) { + s1 = uri_; + s2 = uri.uri_; + } else { + s1 = base_; + s2 = uri.base_; + } + if (s1 == s2) return true; + if (s1 == 0 || s2 == 0) return false; + return internal::StrCmp(s1, s2) == 0; + } + + //! Resolve this URI against another (base) URI in accordance with URI resolution rules. + // See https://tools.ietf.org/html/rfc3986 + // Use for resolving an id or $ref with an in-scope id. + // Returns a new GenericUri for the resolved URI. + GenericUri Resolve(const GenericUri& baseuri, Allocator* allocator = 0) { + GenericUri resuri; + resuri.allocator_ = allocator; + // Ensure enough space for combining paths + resuri.Allocate(GetStringLength() + baseuri.GetStringLength() + 1); // + 1 for joining slash + + if (!(GetSchemeStringLength() == 0)) { + // Use all of this URI + resuri.auth_ = CopyPart(resuri.scheme_, scheme_, GetSchemeStringLength()); + resuri.path_ = CopyPart(resuri.auth_, auth_, GetAuthStringLength()); + resuri.query_ = CopyPart(resuri.path_, path_, GetPathStringLength()); + resuri.frag_ = CopyPart(resuri.query_, query_, GetQueryStringLength()); + resuri.RemoveDotSegments(); + } else { + // Use the base scheme + resuri.auth_ = CopyPart(resuri.scheme_, baseuri.scheme_, baseuri.GetSchemeStringLength()); + if (!(GetAuthStringLength() == 0)) { + // Use this auth, path, query + resuri.path_ = CopyPart(resuri.auth_, auth_, GetAuthStringLength()); + resuri.query_ = CopyPart(resuri.path_, path_, GetPathStringLength()); + resuri.frag_ = CopyPart(resuri.query_, query_, GetQueryStringLength()); + resuri.RemoveDotSegments(); + } else { + // Use the base auth + resuri.path_ = CopyPart(resuri.auth_, baseuri.auth_, baseuri.GetAuthStringLength()); + if (GetPathStringLength() == 0) { + // Use the base path + resuri.query_ = CopyPart(resuri.path_, baseuri.path_, baseuri.GetPathStringLength()); + if (GetQueryStringLength() == 0) { + // Use the base query + resuri.frag_ = CopyPart(resuri.query_, baseuri.query_, baseuri.GetQueryStringLength()); + } else { + // Use this query + resuri.frag_ = CopyPart(resuri.query_, query_, GetQueryStringLength()); + } + } else { + if (path_[0] == '/') { + // Absolute path - use all of this path + resuri.query_ = CopyPart(resuri.path_, path_, GetPathStringLength()); + resuri.RemoveDotSegments(); + } else { + // Relative path - append this path to base path after base path's last slash + size_t pos = 0; + if (!(baseuri.GetAuthStringLength() == 0) && baseuri.GetPathStringLength() == 0) { + resuri.path_[pos] = '/'; + pos++; + } + size_t lastslashpos = baseuri.GetPathStringLength(); + while (lastslashpos > 0) { + if (baseuri.path_[lastslashpos - 1] == '/') break; + lastslashpos--; + } + std::memcpy(&resuri.path_[pos], baseuri.path_, lastslashpos * sizeof(Ch)); + pos += lastslashpos; + resuri.query_ = CopyPart(&resuri.path_[pos], path_, GetPathStringLength()); + resuri.RemoveDotSegments(); + } + // Use this query + resuri.frag_ = CopyPart(resuri.query_, query_, GetQueryStringLength()); + } + } + } + // Always use this frag + resuri.base_ = CopyPart(resuri.frag_, frag_, GetFragStringLength()); + + // Re-constitute base_ and uri_ + resuri.SetBase(); + resuri.uri_ = resuri.base_ + resuri.GetBaseStringLength() + 1; + resuri.SetUri(); + return resuri; + } + + //! Get the allocator of this GenericUri. + Allocator& GetAllocator() { return *allocator_; } + +private: + // Allocate memory for a URI + // Returns total amount allocated + std::size_t Allocate(std::size_t len) { + // Create own allocator if user did not supply. + if (!allocator_) + ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)(); + + // Allocate one block containing each part of the URI (5) plus base plus full URI, all null terminated. + // Order: scheme, auth, path, query, frag, base, uri + // Note need to set, increment, assign in 3 stages to avoid compiler warning bug. + size_t total = (3 * len + 7) * sizeof(Ch); + scheme_ = static_cast(allocator_->Malloc(total)); + *scheme_ = '\0'; + auth_ = scheme_; + auth_++; + *auth_ = '\0'; + path_ = auth_; + path_++; + *path_ = '\0'; + query_ = path_; + query_++; + *query_ = '\0'; + frag_ = query_; + frag_++; + *frag_ = '\0'; + base_ = frag_; + base_++; + *base_ = '\0'; + uri_ = base_; + uri_++; + *uri_ = '\0'; + return total; + } + + // Free memory for a URI + void Free() { + if (scheme_) { + Allocator::Free(scheme_); + scheme_ = 0; + } + } + + // Parse a URI into constituent scheme, authority, path, query, & fragment parts + // Supports URIs that match regex ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))? as per + // https://tools.ietf.org/html/rfc3986 + void Parse(const Ch* uri, std::size_t len) { + std::size_t start = 0, pos1 = 0, pos2 = 0; + Allocate(len); + + // Look for scheme ([^:/?#]+):)? + if (start < len) { + while (pos1 < len) { + if (uri[pos1] == ':') break; + pos1++; + } + if (pos1 != len) { + while (pos2 < len) { + if (uri[pos2] == '/') break; + if (uri[pos2] == '?') break; + if (uri[pos2] == '#') break; + pos2++; + } + if (pos1 < pos2) { + pos1++; + std::memcpy(scheme_, &uri[start], pos1 * sizeof(Ch)); + scheme_[pos1] = '\0'; + start = pos1; + } + } + } + // Look for auth (//([^/?#]*))? + // Note need to set, increment, assign in 3 stages to avoid compiler warning bug. + auth_ = scheme_ + GetSchemeStringLength(); + auth_++; + *auth_ = '\0'; + if (start < len - 1 && uri[start] == '/' && uri[start + 1] == '/') { + pos2 = start + 2; + while (pos2 < len) { + if (uri[pos2] == '/') break; + if (uri[pos2] == '?') break; + if (uri[pos2] == '#') break; + pos2++; + } + std::memcpy(auth_, &uri[start], (pos2 - start) * sizeof(Ch)); + auth_[pos2 - start] = '\0'; + start = pos2; + } + // Look for path ([^?#]*) + // Note need to set, increment, assign in 3 stages to avoid compiler warning bug. + path_ = auth_ + GetAuthStringLength(); + path_++; + *path_ = '\0'; + if (start < len) { + pos2 = start; + while (pos2 < len) { + if (uri[pos2] == '?') break; + if (uri[pos2] == '#') break; + pos2++; + } + if (start != pos2) { + std::memcpy(path_, &uri[start], (pos2 - start) * sizeof(Ch)); + path_[pos2 - start] = '\0'; + if (path_[0] == '/') + RemoveDotSegments(); // absolute path - normalize + start = pos2; + } + } + // Look for query (\?([^#]*))? + // Note need to set, increment, assign in 3 stages to avoid compiler warning bug. + query_ = path_ + GetPathStringLength(); + query_++; + *query_ = '\0'; + if (start < len && uri[start] == '?') { + pos2 = start + 1; + while (pos2 < len) { + if (uri[pos2] == '#') break; + pos2++; + } + if (start != pos2) { + std::memcpy(query_, &uri[start], (pos2 - start) * sizeof(Ch)); + query_[pos2 - start] = '\0'; + start = pos2; + } + } + // Look for fragment (#(.*))? + // Note need to set, increment, assign in 3 stages to avoid compiler warning bug. + frag_ = query_ + GetQueryStringLength(); + frag_++; + *frag_ = '\0'; + if (start < len && uri[start] == '#') { + std::memcpy(frag_, &uri[start], (len - start) * sizeof(Ch)); + frag_[len - start] = '\0'; + } + + // Re-constitute base_ and uri_ + base_ = frag_ + GetFragStringLength() + 1; + SetBase(); + uri_ = base_ + GetBaseStringLength() + 1; + SetUri(); + } + + // Reconstitute base + void SetBase() { + Ch* next = base_; + std::memcpy(next, scheme_, GetSchemeStringLength() * sizeof(Ch)); + next+= GetSchemeStringLength(); + std::memcpy(next, auth_, GetAuthStringLength() * sizeof(Ch)); + next+= GetAuthStringLength(); + std::memcpy(next, path_, GetPathStringLength() * sizeof(Ch)); + next+= GetPathStringLength(); + std::memcpy(next, query_, GetQueryStringLength() * sizeof(Ch)); + next+= GetQueryStringLength(); + *next = '\0'; + } + + // Reconstitute uri + void SetUri() { + Ch* next = uri_; + std::memcpy(next, base_, GetBaseStringLength() * sizeof(Ch)); + next+= GetBaseStringLength(); + std::memcpy(next, frag_, GetFragStringLength() * sizeof(Ch)); + next+= GetFragStringLength(); + *next = '\0'; + } + + // Copy a part from one GenericUri to another + // Return the pointer to the next part to be copied to + Ch* CopyPart(Ch* to, Ch* from, std::size_t len) { + RAPIDJSON_ASSERT(to != 0); + RAPIDJSON_ASSERT(from != 0); + std::memcpy(to, from, len * sizeof(Ch)); + to[len] = '\0'; + Ch* next = to + len + 1; + return next; + } + + // Remove . and .. segments from the path_ member. + // https://tools.ietf.org/html/rfc3986 + // This is done in place as we are only removing segments. + void RemoveDotSegments() { + std::size_t pathlen = GetPathStringLength(); + std::size_t pathpos = 0; // Position in path_ + std::size_t newpos = 0; // Position in new path_ + + // Loop through each segment in original path_ + while (pathpos < pathlen) { + // Get next segment, bounded by '/' or end + size_t slashpos = 0; + while ((pathpos + slashpos) < pathlen) { + if (path_[pathpos + slashpos] == '/') break; + slashpos++; + } + // Check for .. and . segments + if (slashpos == 2 && path_[pathpos] == '.' && path_[pathpos + 1] == '.') { + // Backup a .. segment in the new path_ + // We expect to find a previously added slash at the end or nothing + RAPIDJSON_ASSERT(newpos == 0 || path_[newpos - 1] == '/'); + size_t lastslashpos = newpos; + // Make sure we don't go beyond the start segment + if (lastslashpos > 1) { + // Find the next to last slash and back up to it + lastslashpos--; + while (lastslashpos > 0) { + if (path_[lastslashpos - 1] == '/') break; + lastslashpos--; + } + // Set the new path_ position + newpos = lastslashpos; + } + } else if (slashpos == 1 && path_[pathpos] == '.') { + // Discard . segment, leaves new path_ unchanged + } else { + // Move any other kind of segment to the new path_ + RAPIDJSON_ASSERT(newpos <= pathpos); + std::memmove(&path_[newpos], &path_[pathpos], slashpos * sizeof(Ch)); + newpos += slashpos; + // Add slash if not at end + if ((pathpos + slashpos) < pathlen) { + path_[newpos] = '/'; + newpos++; + } + } + // Move to next segment + pathpos += slashpos + 1; + } + path_[newpos] = '\0'; + } + + Ch* uri_; // Everything + Ch* base_; // Everything except fragment + Ch* scheme_; // Includes the : + Ch* auth_; // Includes the // + Ch* path_; // Absolute if starts with / + Ch* query_; // Includes the ? + Ch* frag_; // Includes the # + + Allocator* allocator_; //!< The current allocator. It is either user-supplied or equal to ownAllocator_. + Allocator* ownAllocator_; //!< Allocator owned by this Uri. +}; + +//! GenericUri for Value (UTF-8, default allocator). +typedef GenericUri Uri; + +RAPIDJSON_NAMESPACE_END + +#if defined(__clang__) +RAPIDJSON_DIAG_POP +#endif + +#endif // RAPIDJSON_URI_H_ diff --git a/include/common/rapidjson/writer.h b/include/common/rapidjson/writer.h index 49cc0fb..8b38921 100644 --- a/include/common/rapidjson/writer.h +++ b/include/common/rapidjson/writer.h @@ -1,6 +1,6 @@ // Tencent is pleased to support the open source community by making RapidJSON available. // -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. // // Licensed under the MIT License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at @@ -16,6 +16,7 @@ #define RAPIDJSON_WRITER_H_ #include "stream.h" +#include "internal/clzll.h" #include "internal/meta.h" #include "internal/stack.h" #include "internal/strfunc.h" @@ -226,7 +227,7 @@ class Writer { return Key(str.data(), SizeType(str.size())); } #endif - + bool EndObject(SizeType memberCount = 0) { (void)memberCount; RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level)); // not inside an Object @@ -282,6 +283,8 @@ class Writer { os_->Flush(); } + static const size_t kDefaultLevelDepth = 32; + protected: //! Information for each nested level struct Level { @@ -290,8 +293,6 @@ class Writer { bool inArray; //!< true if in array, otherwise in object }; - static const size_t kDefaultLevelDepth = 32; - bool WriteNull() { PutReserve(*os_, 4); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'u'); PutUnsafe(*os_, 'l'); PutUnsafe(*os_, 'l'); return true; @@ -460,8 +461,7 @@ class Writer { PutReserve(*os_, length); GenericStringStream is(json); while (RAPIDJSON_LIKELY(is.Tell() < length)) { - const Ch c = is.Peek(); - RAPIDJSON_ASSERT(c != '\0'); + RAPIDJSON_ASSERT(is.Peek() != '\0'); if (RAPIDJSON_UNLIKELY(!(writeFlags & kWriteValidateEncodingFlag ? Transcoder::Validate(is, *os_) : Transcoder::TranscodeUnsafe(is, *os_)))) @@ -669,19 +669,19 @@ inline bool Writer::ScanWriteUnescapedString(StringStream& is, siz x = vorrq_u8(x, vcltq_u8(s, s3)); x = vrev64q_u8(x); // Rev in 64 - uint64_t low = vgetq_lane_u64(reinterpret_cast(x), 0); // extract - uint64_t high = vgetq_lane_u64(reinterpret_cast(x), 1); // extract + uint64_t low = vgetq_lane_u64(vreinterpretq_u64_u8(x), 0); // extract + uint64_t high = vgetq_lane_u64(vreinterpretq_u64_u8(x), 1); // extract SizeType len = 0; bool escaped = false; if (low == 0) { if (high != 0) { - unsigned lz = (unsigned)__builtin_clzll(high); + uint32_t lz = internal::clzll(high); len = 8 + (lz >> 3); escaped = true; } } else { - unsigned lz = (unsigned)__builtin_clzll(low); + uint32_t lz = internal::clzll(low); len = lz >> 3; escaped = true; } diff --git a/include/common/valhalla/baldr/admin.h b/include/common/valhalla/baldr/admin.h index 329e6f9..fe2cab2 100644 --- a/include/common/valhalla/baldr/admin.h +++ b/include/common/valhalla/baldr/admin.h @@ -1,7 +1,9 @@ #ifndef VALHALLA_BALDR_ADMIN_H_ #define VALHALLA_BALDR_ADMIN_H_ +#include #include +#include #include #include @@ -62,11 +64,11 @@ class Admin { uint32_t country_offset() const; protected: - uint32_t country_offset_; // country name offset - uint32_t state_offset_; // state name offset - char country_iso_[kCountryIso]{}; // country ISO3166-1 - char state_iso_[kStateIso]{}; // state ISO3166-2 - char spare_[3]{}; // spare for byte alignment + uint32_t country_offset_; // country name offset + uint32_t state_offset_; // state name offset + std::array country_iso_{}; // country ISO3166-1 + std::array state_iso_{}; // state ISO3166-2 + char spare_[3]{}; // spare for byte alignment }; } // namespace baldr diff --git a/include/common/valhalla/baldr/connectivity_map.h b/include/common/valhalla/baldr/connectivity_map.h index 26facc7..de6f0bd 100644 --- a/include/common/valhalla/baldr/connectivity_map.h +++ b/include/common/valhalla/baldr/connectivity_map.h @@ -23,6 +23,14 @@ class connectivity_map_t { connectivity_map_t(const boost::property_tree::ptree& pt, const std::shared_ptr& graph_reader = {}); + /** + * Alternative to GetTiles() to query whether a level even exists, e.g. transit.# + * + * @param level the level to query + * @return boolean indicating whether a level even exists + */ + bool level_color_exists(const uint32_t level) const; + /** * Returns the color for the given graphid * @@ -39,8 +47,9 @@ class connectivity_map_t { * @param radius the radius of the circle * @return colors the colors of the tiles that intersect this circle at this level */ - std::unordered_set - get_colors(uint32_t hierarchy_level, const baldr::PathLocation& location, float radius) const; + std::unordered_set get_colors(const baldr::TileLevel& hierarchy_level, + const baldr::PathLocation& location, + float radius) const; /** * Returns the geojson representing the connectivity map diff --git a/include/common/valhalla/baldr/datetime.h b/include/common/valhalla/baldr/datetime.h index 23fbeb1..ebb3fee 100644 --- a/include/common/valhalla/baldr/datetime.h +++ b/include/common/valhalla/baldr/datetime.h @@ -16,8 +16,18 @@ // https://github.com/valhalla/valhalla/pull/3878#issuecomment-1365487437 #define HAS_UNCAUGHT_EXCEPTIONS 1 +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif #include #include +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#pragma GCC diagnostic pop +#endif #include #include diff --git a/include/common/valhalla/baldr/directededge.h b/include/common/valhalla/baldr/directededge.h index 81fe050..1ec4818 100644 --- a/include/common/valhalla/baldr/directededge.h +++ b/include/common/valhalla/baldr/directededge.h @@ -564,6 +564,17 @@ class DirectedEdge { return static_cast(use_); } + /** + * Evaluates a basic set of conditions to determine if this directed edge is a valid potential + * member of a shortcut. This is used while forming and resolving shortcuts. + * @return true if the edge is not a shortcut, not related to transit and not under construction + */ + bool can_form_shortcut() const { + return !is_shortcut() && !bss_connection() && use() != Use::kTransitConnection && + use() != Use::kEgressConnection && use() != Use::kPlatformConnection && + use() != Use::kConstruction; + } + /** * Sets the specialized use type of this edge. * @param use Use of this edge. @@ -1076,6 +1087,29 @@ class DirectedEdge { return superseded_; } +#ifdef _WIN32 + // TODO: Workaround for missing strings.h on Windows. Replace with platform independent + // std::countr_zero in C++20 (see https://en.cppreference.com/w/cpp/numeric/countr_zero). + int ffs(int mask) const { + if (0 == mask) + return 0; + + int idx; + for (idx = 1; !(mask & 1); ++idx) + mask >>= 1; + return idx; + } +#endif + + /** + * Unlike superseded(), this does not return the raw mask but the shortcut index + * that was originally passed to set_superseded(). + * @return Returns the index of the set bit in the superseded mask. + */ + uint32_t superseded_idx() const { + return ffs(superseded_); + } + /** * Set the mask for whether this edge is superseded by a shortcut edge. * Superseded edges can be skipped unless downward transitions are allowed. @@ -1125,6 +1159,20 @@ class DirectedEdge { return bss_connection_; } + /** + * Set the flag indicating whether the edge is lit + * @param lit the edge's lit state + */ + void set_lit(const bool lit); + + /** + * Is the edge lit? + * @return Returns the edge's lit state + */ + bool lit() const { + return lit_; + } + /** * Create a json object representing this edge * @return Returns the json object @@ -1192,7 +1240,8 @@ class DirectedEdge { uint64_t yield_sign_ : 1; // Yield/give way sign at end of the directed edge uint64_t hov_type_ : 1; // if (is_hov_only()==true), this means (HOV2=0, HOV3=1) uint64_t indoor_ : 1; // Is this edge indoor - uint64_t spare4_ : 5; + uint64_t lit_ : 1; // Is the edge lit? + uint64_t spare4_ : 4; // 5th 8-byte word uint64_t turntype_ : 24; // Turn type (see graphconstants.h) diff --git a/include/common/valhalla/baldr/edgeinfo.h b/include/common/valhalla/baldr/edgeinfo.h index 5703440..8cdd19f 100644 --- a/include/common/valhalla/baldr/edgeinfo.h +++ b/include/common/valhalla/baldr/edgeinfo.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -151,6 +152,16 @@ class EdgeInfo { */ std::vector GetNames() const; + /** Convenience method to get the names and route number flags for an edge. + * + * This one does not calculate the types + * Like GetNamesAndTypes but without using memory for the types + * + * @param include_tagged_values Bool indicating whether or not to return the tagged values too + * @return Returns a list (vector) (name, route number flag) pairs + */ + std::vector> GetNames(bool include_tagged_values) const; + /** * Convenience method to get the names for an edge * @param only_pronunciations Bool indicating whether or not to return only the pronunciations @@ -160,13 +171,13 @@ class EdgeInfo { std::vector GetTaggedValues(bool only_pronunciations = false) const; /** - * Convenience method to get the names and route number flags for an edge. + * Convenience method to get the names, route number flags and tag value type for an edge. * @param include_tagged_values Bool indicating whether or not to return the tagged values too * - * @return Returns a list (vector) of name/route number pairs. + * @return Returns a list (vector) of name/route number flags/types tuples. */ - std::vector> GetNamesAndTypes(std::vector& types, - bool include_tagged_names = false) const; + std::vector> + GetNamesAndTypes(bool include_tagged_names = false) const; /** * Convenience method to get tags of the edge. diff --git a/include/common/valhalla/baldr/graphconstants.h b/include/common/valhalla/baldr/graphconstants.h index dbd1227..6108a8a 100644 --- a/include/common/valhalla/baldr/graphconstants.h +++ b/include/common/valhalla/baldr/graphconstants.h @@ -308,6 +308,7 @@ enum class Use : uint8_t { kPedestrianCrossing = 32, // cross walks kElevator = 33, kEscalator = 34, + kPlatform = 35, // Rest/Service Areas kRestArea = 30, @@ -325,9 +326,9 @@ enum class Use : uint8_t { // Transit specific uses. Must be last in the list kRail = 50, // Rail line kBus = 51, // Bus line - kEgressConnection = 52, // Connection to a egress node - kPlatformConnection = 53, // Connection to a platform node - kTransitConnection = 54, // Connection to multi-use transit stop + kEgressConnection = 52, // Connection egress <-> station + kPlatformConnection = 53, // Connection station <-> platform + kTransitConnection = 54, // Connection osm <-> egress }; inline std::string to_string(Use u) { static const std::unordered_map UseStrings = { diff --git a/include/common/valhalla/baldr/graphid.h b/include/common/valhalla/baldr/graphid.h index 74b8724..7d0ff42 100644 --- a/include/common/valhalla/baldr/graphid.h +++ b/include/common/valhalla/baldr/graphid.h @@ -71,6 +71,15 @@ struct GraphId { * @param value all the various bits rolled into one */ explicit GraphId(const uint64_t value) : value(value) { + if (tileid() > kMaxGraphTileId) { + throw std::logic_error("Tile id out of valid range"); + } + if (level() > kMaxGraphHierarchy) { + throw std::logic_error("Level out of valid range"); + } + if (id() > kMaxGraphId) { + throw std::logic_error("Id out of valid range"); + } } /** @@ -94,7 +103,7 @@ struct GraphId { * Gets the tile Id. * @return Returns the tile Id. */ - uint32_t tileid() const { + inline uint32_t tileid() const { return (value & 0x1fffff8) >> 3; } @@ -102,7 +111,7 @@ struct GraphId { * Gets the hierarchy level. * @return Returns the level. */ - uint32_t level() const { + inline uint32_t level() const { return (value & 0x7); } @@ -110,7 +119,7 @@ struct GraphId { * Gets the identifier within the hierarchy level. * @return Returns the unique identifier within the level. */ - uint32_t id() const { + inline uint32_t id() const { return (value & 0x3ffffe000000) >> 25; } @@ -139,6 +148,7 @@ struct GraphId { * @return boolean true if the id is valid */ bool Is_Valid() const { + // TODO: make this strict it should check the tile hierarchy not bit field widths return value != kInvalidGraphId; } @@ -155,7 +165,7 @@ struct GraphId { * Returns a value indicating the tile (level and tile id) of the graph Id. * @return Returns a 32 bit value. */ - uint32_t tile_value() const { + inline uint32_t tile_value() const { return (value & 0x1ffffff); } diff --git a/include/common/valhalla/baldr/graphreader.h b/include/common/valhalla/baldr/graphreader.h index 34dc097..c82526d 100644 --- a/include/common/valhalla/baldr/graphreader.h +++ b/include/common/valhalla/baldr/graphreader.h @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -157,7 +158,8 @@ class FlatTileCache : public TileCache { } inline uint32_t get_index(const GraphId& graphid) const { auto offset = get_offset(graphid); - return offset < cache_indices_.size() ? cache_indices_[offset] : -1; + // using max value to indicate invalid + return offset < cache_indices_.size() ? cache_indices_[offset] : midgard::invalid(); } // The actual cached GraphTile objects diff --git a/include/common/valhalla/baldr/graphtileheader.h b/include/common/valhalla/baldr/graphtileheader.h index 7789cea..41de45f 100644 --- a/include/common/valhalla/baldr/graphtileheader.h +++ b/include/common/valhalla/baldr/graphtileheader.h @@ -1,6 +1,7 @@ #ifndef VALHALLA_BALDR_GRAPHTILEHEADER_H_ #define VALHALLA_BALDR_GRAPHTILEHEADER_H_ +#include #include #include #include @@ -187,7 +188,7 @@ class GraphTileHeader { * @return Returns the version of this tile. */ std::string version() const { - return version_; + return version_.data(); } /** @@ -590,6 +591,7 @@ class GraphTileHeader { } protected: + // TODO when c++20 bitfields can be initialized here // GraphId (tileid and level) of this tile. Data quality metrics. uint64_t graphid_ : 46; uint64_t density_ : 4; @@ -601,13 +603,13 @@ class GraphTileHeader { // TODO: in v4, don't store this its superfluous information, the graphid has all we need // Base lon, lat of the tile - std::pair base_ll_; + std::pair base_ll_ = {0, 0}; // baldr version. - char version_[kMaxVersionSize]; + std::array version_ = {}; // Dataset Id - uint64_t dataset_id_; + uint64_t dataset_id_ = 0; // Record counts (for fixed size records). Node and directed edge have a max of // kMaxGraphId which is 21 bits. @@ -663,36 +665,36 @@ class GraphTileHeader { // the GraphTileHeader structure and order of data within the structure does not change // this should be backwards compatible. Make sure use of bits from spareword* does not // exceed 128 bits. - uint64_t spareword0_; - uint64_t spareword1_; + uint64_t spareword0_ = 0; + uint64_t spareword1_ = 0; // Offsets to beginning of data (for variable size records) - uint32_t complex_restriction_forward_offset_; // Offset to complex restriction list - uint32_t complex_restriction_reverse_offset_; // Offset to complex restriction list - uint32_t edgeinfo_offset_; // Offset to edge info - uint32_t textlist_offset_; // Offset to text list + uint32_t complex_restriction_forward_offset_ = 0; // Offset to complex restriction list + uint32_t complex_restriction_reverse_offset_ = 0; // Offset to complex restriction list + uint32_t edgeinfo_offset_ = 0; // Offset to edge info + uint32_t textlist_offset_ = 0; // Offset to text list // Date the tile was created. Days since pivot date. - uint32_t date_created_; + uint32_t date_created_ = 0; // Offsets for each bin of the 5x5 grid (for search/lookup) - uint32_t bin_offsets_[kBinCount]; + std::array bin_offsets_ = {}; // Offset to beginning of the lane connectivity data - uint32_t lane_connectivity_offset_; + uint32_t lane_connectivity_offset_ = 0; // Offset to the beginning of the predicted speed data - uint32_t predictedspeeds_offset_; + uint32_t predictedspeeds_offset_ = 0; // GraphTile data size in bytes - uint32_t tile_size_; + uint32_t tile_size_ = 0; // Marks the end of this version of the tile with the rest of the slots // being available for growth. If you want to use one of the empty slots, // simply add a uint32_t some_offset_; just above empty_slots_ and decrease // kEmptySlots by 1. Note that you can ONLY add an offset here and NOT a // bitfield or union or anything like that - uint32_t empty_slots_[kEmptySlots]; + std::array empty_slots_ = {}; }; } // namespace baldr diff --git a/include/common/valhalla/baldr/location.h b/include/common/valhalla/baldr/location.h index 7266f61..2e1f566 100644 --- a/include/common/valhalla/baldr/location.h +++ b/include/common/valhalla/baldr/location.h @@ -2,6 +2,7 @@ #define VALHALLA_BALDR_LOCATION_H_ #include +#include #include #include @@ -71,7 +72,7 @@ struct Location { unsigned long radius = 0, const PreferredSide& side = PreferredSide::EITHER, const SearchFilter& search_filter = SearchFilter(), - boost::optional preferred_layer = {}); + std::optional preferred_layer = {}); /** * equality. @@ -89,8 +90,8 @@ struct Location { std::string name_; std::string street_; - boost::optional date_time_; - boost::optional heading_; + std::optional date_time_; + std::optional heading_; // try to find candidates who are reachable from/to this many or more nodes // if a given candidate edge is reachable to/from less than this number of nodes its considered to @@ -111,9 +112,9 @@ struct Location { SearchFilter search_filter_; // coordinates of the location as used for altering the side of street - boost::optional display_latlng_; + std::optional display_latlng_; - boost::optional preferred_layer_; + std::optional preferred_layer_; protected: }; diff --git a/include/common/valhalla/baldr/nodeinfo.h b/include/common/valhalla/baldr/nodeinfo.h index fce922a..15c5fbb 100644 --- a/include/common/valhalla/baldr/nodeinfo.h +++ b/include/common/valhalla/baldr/nodeinfo.h @@ -199,6 +199,16 @@ class NodeInfo { return static_cast(type_); } + /** + * Evaluates a basic set of conditions to determine if this node is eligible for contraction. + * @return true if the node has at least 2 edges and does not represent a fork, gate or toll booth. + */ + bool can_contract() const { + return edge_count() >= 2 && intersection() != IntersectionType::kFork && + type() != NodeType::kGate && type() != NodeType::kTollBooth && + type() != NodeType::kTollGantry && type() != NodeType::kSumpBuster; + } + /** * Set the node type. * @param type node type. @@ -358,11 +368,13 @@ class NodeInfo { /** * Get the connecting way id for a transit stop (stored in headings_ while transit data - * is connected to the road network. + * is connected to the road network). Returns 0 if unset or if used for lon lat * @return Returns the connecting way id for a transit stop. */ uint64_t connecting_wayid() const { - return headings_; + // if the last bit is unset this is a wayid (or unset or headings) for transit in/egress. we + // return 0 for the way id if a connection point (lon, lat) was encoded here instead + return headings_ >> 63 ? 0 : headings_; } /** @@ -371,6 +383,23 @@ class NodeInfo { */ void set_connecting_wayid(const uint64_t wayid); + /** + * Get the connection point location to be used for associating this transit station to the road + * network or an invalid point if it is unset + * @return the connection point or an invalid lon lat + */ + midgard::PointLL connecting_point() const { + // if the last bit is set this is a connection point for transit in/egress + return headings_ >> 63 ? midgard::PointLL(headings_) : midgard::PointLL(); + } + + /** + * Sets the connection point location to be used for associating this transit in/egress to the road + * network + * @param p the location where the in/egress should connect to the road network + */ + void set_connecting_point(const midgard::PointLL& p); + /** * Get the heading of the local edge given its local index. Supports * up to 8 local edges. Headings are stored rounded off to 2 degree @@ -472,9 +501,12 @@ class NodeInfo { uint64_t cash_only_toll_ : 1; // Is this toll cash only? uint64_t spare2_ : 17; - // Headings of up to kMaxLocalEdgeIndex+1 local edges (rounded to nearest 2 degrees) - // for all other levels. Connecting way Id (for transit level) while data build occurs. - // Need to keep this in NodeInfo since it is used in map-matching. + // For not transit levels its the headings of up to kMaxLocalEdgeIndex+1 local edges (rounded to + // nearest 2 degrees)for all other levels. + // Sadly we need to keep this for now because its used in map matching, otherwise we could remove it + // Also for transit levels (while building data only) it can be used for either the connecting way + // id for matching the connection point of the station to the edge or an encoded lon lat pair for + // the exact connection point. If the highest bit is set its a lon lat otherwise its a way id uint64_t headings_; }; diff --git a/include/common/valhalla/baldr/streetname.h b/include/common/valhalla/baldr/streetname.h index 116ccd0..5266117 100644 --- a/include/common/valhalla/baldr/streetname.h +++ b/include/common/valhalla/baldr/streetname.h @@ -2,10 +2,9 @@ #define VALHALLA_BALDR_STREETNAME_H_ #include +#include #include -#include - #include namespace valhalla { @@ -26,7 +25,7 @@ class StreetName { */ StreetName(const std::string& value, const bool is_route_number, - const boost::optional& pronunciation = boost::none); + const std::optional& pronunciation = std::nullopt); virtual ~StreetName(); @@ -42,7 +41,7 @@ class StreetName { * Returns the pronunciation of this street name. * @return the pronunciation of this street name. */ - const boost::optional& pronunciation() const; + const std::optional& pronunciation() const; bool operator==(const StreetName& rhs) const; @@ -63,7 +62,7 @@ class StreetName { protected: std::string value_; bool is_route_number_; - boost::optional pronunciation_; + std::optional pronunciation_; }; } // namespace baldr diff --git a/include/common/valhalla/baldr/streetname_us.h b/include/common/valhalla/baldr/streetname_us.h index 0105663..5272940 100644 --- a/include/common/valhalla/baldr/streetname_us.h +++ b/include/common/valhalla/baldr/streetname_us.h @@ -2,11 +2,10 @@ #define VALHALLA_BALDR_STREETNAME_US_H_ #include +#include #include #include -#include - #include namespace valhalla { @@ -22,7 +21,7 @@ class StreetNameUs : public StreetName { */ StreetNameUs(const std::string& value, const bool is_route_number, - const boost::optional& pronunciation = boost::none); + const std::optional& pronunciation = std::nullopt); std::string GetPreDir() const override; diff --git a/include/common/valhalla/baldr/tilehierarchy.h b/include/common/valhalla/baldr/tilehierarchy.h index 9be7126..c18fcfb 100644 --- a/include/common/valhalla/baldr/tilehierarchy.h +++ b/include/common/valhalla/baldr/tilehierarchy.h @@ -95,6 +95,14 @@ class TileHierarchy { * @return Returns a const reference to the tiling system for this level. */ static const midgard::Tiles& get_tiling(const uint8_t level); + + /** + * Returns the parent (containing tile with lower tile level) of a given tile id + * @param child_tile_id the child tiles graph id + * @return the tile id of the parent tile for the given child tiles id or invalid if already at the + * lowest level + */ + static GraphId parent(const GraphId& child_tile_id); }; } // namespace baldr diff --git a/include/common/valhalla/baldr/time_info.h b/include/common/valhalla/baldr/time_info.h index 69e9da3..20c11d2 100644 --- a/include/common/valhalla/baldr/time_info.h +++ b/include/common/valhalla/baldr/time_info.h @@ -257,6 +257,10 @@ struct TimeInfo { return DateTime::seconds_to_date(local_time, dt::get_tz_db().from_index(timezone_index), false); } + uint32_t day_seconds() const { + return static_cast(second_of_week) % midgard::kSecondsPerDay; + } + // for unit tests bool operator==(const TimeInfo& ti) const { return valid == ti.valid && timezone_index == ti.timezone_index && local_time == ti.local_time && diff --git a/include/common/valhalla/baldr/transitdeparture.h b/include/common/valhalla/baldr/transitdeparture.h index 106eedc..0e7ff88 100644 --- a/include/common/valhalla/baldr/transitdeparture.h +++ b/include/common/valhalla/baldr/transitdeparture.h @@ -35,7 +35,7 @@ class TransitDeparture { * Constructor for a fixed departure time. * @param lineid Unique line Id within the tile * @param tripid Unique trip Id (spans tiles) - * @param routeid Route index within the tile. + * @param routeindex Route index within the tile. * @param blockid Block Id. * @param headsign_offset Offset to headsign within the text/name table. * @param departure_time Departure time (seconds from midnight) @@ -46,7 +46,7 @@ class TransitDeparture { */ TransitDeparture(const uint32_t lineid, const uint32_t tripid, - const uint32_t routeid, + const uint32_t routeindex, const uint32_t blockid, const uint32_t headsign_offset, const uint32_t departure_time, @@ -59,10 +59,10 @@ class TransitDeparture { * Constructor for a frequency based departure. * @param lineid Unique line Id within the tile * @param tripid Unique trip Id (spans tiles) - * @param routeid Route index within the tile. + * @param routeindex Route index within the tile. * @param blockid Block Id. * @param headsign_offset Offset to headsign within the text/name table. - * @param start_time Departure time (seconds from midnight) + * @param departure_time Start time for the frequency (seconds from midnight) * @param end_time End time for departures (seconds from midnight) * @param frequency Seconds between successive departures. * @param elapsed_time Elapsed time to next stop @@ -72,10 +72,10 @@ class TransitDeparture { */ TransitDeparture(const uint32_t lineid, const uint32_t tripid, - const uint32_t routeid, + const uint32_t routeindex, const uint32_t blockid, const uint32_t headsign_offset, - const uint32_t start_time, + const uint32_t departure_time, const uint32_t end_time, const uint32_t frequency, const uint32_t elapsed_time, @@ -110,10 +110,10 @@ class TransitDeparture { /** * Get the route index for this departure. - * @return Returns the internal route Id. + * @return Returns the internal route Index. */ - uint32_t routeid() const { - return routeid_; + uint32_t routeindex() const { + return routeindex_; } /** @@ -199,11 +199,11 @@ class TransitDeparture { bool operator<(const TransitDeparture& other) const; protected: - uint64_t lineid_ : 20; // Line Id - lookup departures by unique line - // Id (which indicates a unique departure / - // arrival stop pair. - uint64_t routeid_ : 12; // Route index. - uint64_t tripid_ : 32; // TripId (internal). + uint64_t lineid_ : 20; // Line Id - lookup departures by unique line + // Id (which indicates a unique departure / + // arrival stop pair. + uint64_t routeindex_ : 12; // Route index. + uint64_t tripid_ : 32; // TripId (internal). uint64_t blockid_ : 20; // Block Id uint64_t schedule_index_ : 12; // Schedule validity index diff --git a/include/common/valhalla/baldr/transitroute.h b/include/common/valhalla/baldr/transitroute.h index b3e114a..bab5f37 100644 --- a/include/common/valhalla/baldr/transitroute.h +++ b/include/common/valhalla/baldr/transitroute.h @@ -35,32 +35,32 @@ class TransitRoute { } /** - * Get the TransitLand one stop Id offset for this route. - * @return Returns the TransitLand one-stop Id offset. + * Get the one stop Id offset for this route. + * @return Returns the one-stop Id offset. */ uint32_t one_stop_offset() const { return one_stop_offset_; } /** - * Get the TransitLand operator one stop Id offset for this route. - * @return Returns the TransitLand operator one-stop Id offset. + * Get the operator one stop Id offset for this route. + * @return Returns the operator one-stop Id offset. */ uint32_t op_by_onestop_id_offset() const { return op_by_onestop_id_offset_; } /** - * Get the TransitLand operator name offset for this route. - * @return Returns the TransitLand operator name offset. + * Get the operator name offset for this route. + * @return Returns the operator name offset. */ uint32_t op_by_name_offset() const { return op_by_name_offset_; } /** - * Get the TransitLand operator website offset for this route. - * @return Returns the TransitLand operator website offset. + * Get the operator website offset for this route. + * @return Returns the operator website offset. */ uint32_t op_by_website_offset() const { return op_by_website_offset_; @@ -119,14 +119,14 @@ class TransitRoute { // Offsets in the text/name list uint64_t route_type_ : 8; // Internal route type - uint64_t one_stop_offset_ : 24; // TransitLand onestop Id for this route. + uint64_t one_stop_offset_ : 24; // onestop Id for this route. uint64_t spare1_ : 32; - uint64_t op_by_onestop_id_offset_ : 24; // TransitLand operated by onestop id. - uint64_t op_by_name_offset_ : 24; // TransitLand operated by name. + uint64_t op_by_onestop_id_offset_ : 24; // operated by onestop id. + uint64_t op_by_name_offset_ : 24; // operated by name. uint64_t spare2_ : 16; - uint64_t op_by_website_offset_ : 24; // TransitLand operated by website. + uint64_t op_by_website_offset_ : 24; // operated by website. uint64_t short_name_offset_ : 24; // Short route name. uint64_t spare3_ : 16; diff --git a/include/common/valhalla/baldr/transitstop.h b/include/common/valhalla/baldr/transitstop.h index 60911c2..ea2cfb7 100644 --- a/include/common/valhalla/baldr/transitstop.h +++ b/include/common/valhalla/baldr/transitstop.h @@ -33,8 +33,8 @@ class TransitStop { } /** - * Get the TransitLand one stop Id offset for the stop. - * @return Returns the TransitLand one stop Id offset. + * Get the one stop Id offset for the stop. + * @return Returns the one stop Id offset. */ uint32_t one_stop_offset() const { return one_stop_offset_; @@ -69,7 +69,7 @@ class TransitStop { } protected: - uint64_t one_stop_offset_ : 24; // TransitLand one stop Id offset. + uint64_t one_stop_offset_ : 24; // one stop Id offset. uint64_t name_offset_ : 24; // Stop name offset in the text/name list. uint64_t generated_ : 1; uint64_t traversability_ : 2; diff --git a/include/common/valhalla/baldr/verbal_text_formatter.h b/include/common/valhalla/baldr/verbal_text_formatter.h index b1f4eae..1ec3319 100644 --- a/include/common/valhalla/baldr/verbal_text_formatter.h +++ b/include/common/valhalla/baldr/verbal_text_formatter.h @@ -4,8 +4,6 @@ #include #include -#include - #include #include diff --git a/include/common/valhalla/baldr/verbal_text_formatter_us.h b/include/common/valhalla/baldr/verbal_text_formatter_us.h index ef2ea4a..b70bf1c 100644 --- a/include/common/valhalla/baldr/verbal_text_formatter_us.h +++ b/include/common/valhalla/baldr/verbal_text_formatter_us.h @@ -6,8 +6,6 @@ #include #include -#include - #include namespace valhalla { diff --git a/include/common/valhalla/baldr/verbal_text_formatter_us_tx.h b/include/common/valhalla/baldr/verbal_text_formatter_us_tx.h index 3785b44..b3f3781 100644 --- a/include/common/valhalla/baldr/verbal_text_formatter_us_tx.h +++ b/include/common/valhalla/baldr/verbal_text_formatter_us_tx.h @@ -5,8 +5,6 @@ #include #include -#include - #include namespace valhalla { diff --git a/include/common/valhalla/loki/worker.h b/include/common/valhalla/loki/worker.h index b6df0a4..c1b24f2 100644 --- a/include/common/valhalla/loki/worker.h +++ b/include/common/valhalla/loki/worker.h @@ -48,12 +48,13 @@ class loki_worker_t : public service_worker_t { void set_interrupt(const std::function* interrupt) override; protected: - void parse_locations( - google::protobuf::RepeatedPtrField* locations, - boost::optional required_exception = valhalla_exception_t{110}); + void parse_locations(google::protobuf::RepeatedPtrField* locations, + std::optional required_exception = valhalla_exception_t{ + 110}); void parse_trace(Api& request); void parse_costing(Api& request, bool allow_none = false); void locations_from_shape(Api& request); + void check_hierarchy_distance(Api& request); void init_locate(Api& request); void init_route(Api& request); @@ -104,6 +105,9 @@ class loki_worker_t : public service_worker_t { unsigned int max_alternates; bool allow_verbose; + // add max_distance_disable_hierarchy_culling + float max_distance_disable_hierarchy_culling; + private: std::string service_name() const override { return "loki"; diff --git a/include/common/valhalla/midgard/point2.h b/include/common/valhalla/midgard/point2.h index 8c7277d..bee8138 100644 --- a/include/common/valhalla/midgard/point2.h +++ b/include/common/valhalla/midgard/point2.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -195,6 +196,15 @@ template class PointXY : public std::pairfirst) + "," + std::to_string(this->second); + } }; using Point2 = PointXY; diff --git a/include/common/valhalla/midgard/pointll.h b/include/common/valhalla/midgard/pointll.h index 4f576c5..80ea089 100644 --- a/include/common/valhalla/midgard/pointll.h +++ b/include/common/valhalla/midgard/pointll.h @@ -37,15 +37,41 @@ template class GeoPoint : public PointXY { */ GeoPoint() : PointXY(INVALID_LL, INVALID_LL) { } - virtual ~GeoPoint() { + /** + * You can encode lon, lat (with 7 digit precision) into 64 bits with the lowest 31 bits for lat and + * upper 32 for lon and 1 extra unused bit for whatever you need.. this constructor throws if the + * values are out of valid lon and lat ranges + * @param encoded + */ + explicit GeoPoint(uint64_t encoded) + : PointXY(static_cast( + (int64_t((encoded >> 31) & ((1ull << 32) - 1)) - 180 * 1e7) * 1e-7), + static_cast( + (int64_t(encoded & ((1ull << 31) - 1)) - 90 * 1e7) * 1e-7)) { } - /** * Parent constructor. Forwards to parent. */ GeoPoint(const PointXY& p) : PointXY(p) { } + virtual ~GeoPoint() { + } + + /** + * cast the lon lat to a 64bit value with 7 decimals places of precision the layout is: + * bitfield { + * lat 31; + * lon 32; + * spare 1; + * } + * @return + */ + explicit operator uint64_t() const { + return (((uint64_t(first * 1e7) + uint64_t(180 * 1e7)) & ((1ull << 32) - 1)) << 31) | + ((uint64_t(second * 1e7) + uint64_t(90 * 1e7)) & ((1ull << 31) - 1)); + } + /** * Get the longitude in degrees. * @return Returns longitude in degrees. @@ -70,6 +96,14 @@ template class GeoPoint : public PointXY { return first != INVALID_LL && second != INVALID_LL; }; + /** + * Checks whether the lon and lat coordinates fall within -180/180 and -90/90 respectively + * @return + */ + bool InRange() const { + return -180 <= first && first <= 180 && -90 <= second && second <= 90; + } + /** * Sets the coordinates to an invalid state */ diff --git a/include/common/valhalla/midgard/util.h b/include/common/valhalla/midgard/util.h index 96e2aa9..a566515 100644 --- a/include/common/valhalla/midgard/util.h +++ b/include/common/valhalla/midgard/util.h @@ -697,5 +697,29 @@ unaligned_read(const void* ptr) { return r; } +/** + * For some variables, an ivalid value needs to be set as: the maximum value it's type can get + * @returns the invalid value of the type + */ +template numeric_t invalid() { + return std::numeric_limits::max(); +} + +/** + * For some variables, an ivalid value needs to be set as: the maximum value it's type can get + * @returns true when the value is invalid + */ +template bool is_invalid(numeric_t value) { + return value == invalid(); +} + +/** + * For some variables, an ivalid value needs to be set as: the maximum value it's type can get + * @returns true when the value is valid + */ +template bool is_valid(numeric_t value) { + return value != invalid(); +} + } // namespace midgard } // namespace valhalla diff --git a/include/common/valhalla/mjolnir/adminbuilder.h b/include/common/valhalla/mjolnir/adminbuilder.h index 425dd19..c63c179 100644 --- a/include/common/valhalla/mjolnir/adminbuilder.h +++ b/include/common/valhalla/mjolnir/adminbuilder.h @@ -11,7 +11,7 @@ namespace valhalla { namespace mjolnir { -void BuildAdminFromPBF(const boost::property_tree::ptree& pt, +bool BuildAdminFromPBF(const boost::property_tree::ptree& pt, const std::vector& input_files); } } // namespace valhalla diff --git a/include/common/valhalla/mjolnir/convert_transit.h b/include/common/valhalla/mjolnir/convert_transit.h index 2066a1b..aeb2540 100644 --- a/include/common/valhalla/mjolnir/convert_transit.h +++ b/include/common/valhalla/mjolnir/convert_transit.h @@ -9,7 +9,9 @@ namespace valhalla { namespace mjolnir { /** - * @brief Grabs protobufs written in fetch_transit and converts them into transit level tiles + * @brief Grabs protobufs written in ingest_transit and converts them into transit level tiles + * Non-transit graph tiles are also required to find locations where to connect the + * transit subgraph (nodes where we can add transit connect edges) * @param pt Property tree containing the hierarchy configuration * and other configuration needed to build transit. * @return std::unordered_set all tiles created diff --git a/include/common/valhalla/mjolnir/ingest_transit.h b/include/common/valhalla/mjolnir/ingest_transit.h index a6416bc..6fa3f98 100644 --- a/include/common/valhalla/mjolnir/ingest_transit.h +++ b/include/common/valhalla/mjolnir/ingest_transit.h @@ -47,16 +47,6 @@ void stitch_transit(const boost::property_tree::ptree& pt, std::list& all_tiles); - } // namespace mjolnir } // namespace valhalla \ No newline at end of file diff --git a/include/common/valhalla/mjolnir/osmway.h b/include/common/valhalla/mjolnir/osmway.h index 4d525e5..ab60575 100644 --- a/include/common/valhalla/mjolnir/osmway.h +++ b/include/common/valhalla/mjolnir/osmway.h @@ -1682,6 +1682,24 @@ struct OSMWay { return level_ref_index_; } + /** + * Sets the lit state + * + * @param lit whether the way is lit. + */ + void set_lit(const bool lit) { + lit_ = lit; + } + + /** + * Get the lit state. + * + * @return bool + */ + bool lit() const { + return lit_; + } + /** * Get the names for the edge info based on the road class. * @param ref updated refs from relations. @@ -1825,7 +1843,8 @@ struct OSMWay { uint16_t use_sidepath_ : 1; uint16_t bike_forward_ : 1; uint16_t bike_backward_ : 1; - uint16_t spare2_ : 4; + bool lit_ : 1; + uint16_t spare2_ : 3; uint16_t nodecount_; diff --git a/include/common/valhalla/mjolnir/transitbuilder.h b/include/common/valhalla/mjolnir/transitbuilder.h index 5c9d4c6..ec15958 100644 --- a/include/common/valhalla/mjolnir/transitbuilder.h +++ b/include/common/valhalla/mjolnir/transitbuilder.h @@ -13,7 +13,18 @@ namespace mjolnir { class TransitBuilder { public: /** - * Add transit information to the graph tiles. + * Add transit information to the graph tiles. At present this is called during the larger tileset + * build. This somewhat simplifies the updates that need to be done on the existing tiles to make + * the connection between the two graphs. Mainly because there are no hierarchies, no spatial + * index, no restrictions. + * + * TODO: rework the tile update methods to be sensitive to hierarchy (transitions), binned edges and + * restrictions. All of these refer to edge or node ids directly, so adding the transit connections + * means we have to update these as well. The easiest approach would be to move the nodes and edges + * to the ends of their respective arrays and update the stuff that references them. This will + * produce small unused/unreferenced holes in those arrays but avoids the problem of having to + * offset all the ids. We could also avoid wasting space by offsetting all the things, we'll have + * to see which is easier than the other * @param pt Property tree containing the hierarchy configuration * and other configuration needed to build transit. */ diff --git a/include/common/valhalla/odin/enhancedtrippath.h b/include/common/valhalla/odin/enhancedtrippath.h index 9211169..9be27de 100644 --- a/include/common/valhalla/odin/enhancedtrippath.h +++ b/include/common/valhalla/odin/enhancedtrippath.h @@ -4,13 +4,12 @@ #include #include #include +#include #include #include #include #include -#include - #include #include #include @@ -713,7 +712,7 @@ class EnhancedTripLeg_Node { uint32_t GetStraightestTraversableIntersectingEdgeTurnDegree(uint32_t from_heading, const TravelMode travel_mode, - boost::optional* use = nullptr); + std::optional* use = nullptr); bool IsStraightestTraversableIntersectingEdgeReversed(uint32_t from_heading, const TravelMode travel_mode); diff --git a/include/common/valhalla/odin/markup_formatter.h b/include/common/valhalla/odin/markup_formatter.h index 0a7ec06..a3fc478 100644 --- a/include/common/valhalla/odin/markup_formatter.h +++ b/include/common/valhalla/odin/markup_formatter.h @@ -1,8 +1,8 @@ #pragma once +#include #include -#include #include #include @@ -37,7 +37,7 @@ class MarkupFormatter { * @param street_name the street name record to format. * @return the street name with phoneme markup if it exists. */ - boost::optional + std::optional FormatPhonemeElement(const std::unique_ptr& street_name) const; /** @@ -46,7 +46,7 @@ class MarkupFormatter { * @param sign the sign record to format. * @return the sign with phoneme markup if it exists. */ - boost::optional FormatPhonemeElement(const Sign& sign) const; + std::optional FormatPhonemeElement(const Sign& sign) const; protected: /** @@ -60,7 +60,7 @@ class MarkupFormatter { void FormatQuotes(std::string& markup_string, valhalla::Pronunciation_Alphabet alphabet) const; std::string FormatPhonemeElement(const std::string& textual_string, - const boost::optional& pronunciation) const; + const std::optional& pronunciation) const; bool markup_enabled_; std::string phoneme_format_; diff --git a/include/common/valhalla/odin/sign.h b/include/common/valhalla/odin/sign.h index b984c7c..5b1dfd6 100644 --- a/include/common/valhalla/odin/sign.h +++ b/include/common/valhalla/odin/sign.h @@ -2,10 +2,9 @@ #define VALHALLA_ODIN_SIGN_H_ #include +#include #include -#include - #include namespace valhalla { @@ -21,7 +20,7 @@ class Sign { */ Sign(const std::string& text, const bool is_route_number, - const boost::optional& pronunciation = boost::none); + const std::optional& pronunciation = std::nullopt); /** * Returns the sign text. @@ -51,7 +50,7 @@ class Sign { * Returns the pronunciation of this sign. * @return the pronunciation of this sign. */ - const boost::optional& pronunciation() const; + const std::optional& pronunciation() const; #ifdef LOGGING_LEVEL_TRACE std::string ToParameterString() const; @@ -63,7 +62,7 @@ class Sign { std::string text_; bool is_route_number_; uint32_t consecutive_count_; - boost::optional pronunciation_; + std::optional pronunciation_; }; } // namespace odin diff --git a/include/common/valhalla/proto_conversions.h b/include/common/valhalla/proto_conversions.h index 3993297..65cecb4 100644 --- a/include/common/valhalla/proto_conversions.h +++ b/include/common/valhalla/proto_conversions.h @@ -284,6 +284,10 @@ inline midgard::PointLL to_ll(const LatLng& ll) { return midgard::PointLL{ll.lng(), ll.lat()}; } +inline midgard::PointLL to_ll(const valhalla::Location& l) { + return midgard::PointLL{l.ll().lng(), l.ll().lat()}; +} + inline void from_ll(valhalla::Location* l, const midgard::PointLL& p) { l->mutable_ll()->set_lat(p.lat()); l->mutable_ll()->set_lng(p.lng()); diff --git a/include/common/valhalla/sif/dynamiccost.h b/include/common/valhalla/sif/dynamiccost.h index 121993a..d93fb1c 100644 --- a/include/common/valhalla/sif/dynamiccost.h +++ b/include/common/valhalla/sif/dynamiccost.h @@ -47,6 +47,25 @@ : range.def))); \ } +/** + * same as above, but for costing options without pbf's awful oneof + * + * @param costing_options pointer to protobuf costing options object + * @param range ranged_default_t object which will check any provided values are in range + * @param json rapidjson value object which should contain user provided costing options + * @param json_key the json key to use to pull a user provided value out of the jsonn + * @param option_name the name of the option will be set on the costing options object + */ + +#define JSON_PBF_RANGED_DEFAULT_V2(costing_options, range, json, json_key, option_name) \ + { \ + costing_options->set_##option_name( \ + range(rapidjson::get(json, json_key, \ + costing_options->option_name() \ + ? costing_options->option_name() \ + : range.def))); \ + } + /** * this macro takes a default value and uses it when no user provided values exist (in json or in pbf) * to set the option on the costing options object @@ -175,15 +194,6 @@ class DynamicCost { */ virtual float GetModeFactor(); - /** - * This method overrides the max_distance with the max_distance_mm per segment - * distance. An example is a pure walking route may have a max distance of - * 10000 meters (10km) but for a multi-modal route a lower limit of 5000 - * meters per segment (e.g. from origin to a transit stop or from the last - * transit stop to the destination). - */ - virtual void UseMaxMultiModalDistance(); - /** * Get the access mode used by this costing method. * @return Returns access mode. @@ -899,6 +909,12 @@ class DynamicCost { */ virtual void set_use_living_streets(float use_living_streets); + /** + * Calculate `lit` costs based on lit preference. + * @param use_lit value of lit preference in range [0; 1] + */ + virtual void set_use_lit(float use_lit); + // Algorithm pass uint32_t pass_; @@ -930,6 +946,7 @@ class DynamicCost { float living_street_factor_; // Avoid living streets factor. float service_factor_; // Avoid service roads factor. float closure_factor_; // Avoid closed edges factor. + float unlit_factor_; // Avoid unlit edges factor. // Transition costs sif::Cost country_crossing_cost_; @@ -1053,6 +1070,9 @@ class DynamicCost { // Get living street factor from costing options. set_use_living_streets(costing_options.use_living_streets()); + // Calculate lit factor from costing options. + set_use_lit(costing_options.use_lit()); + // Penalty and factor to use service roads service_penalty_ = costing_options.service_penalty(); service_factor_ = costing_options.service_factor(); @@ -1171,6 +1191,7 @@ struct BaseCostingOptionsConfig { ranged_default_t use_tracks_; ranged_default_t use_living_streets_; + ranged_default_t use_lit_; ranged_default_t closure_factor_; diff --git a/include/common/valhalla/sif/edgelabel.h b/include/common/valhalla/sif/edgelabel.h index 46308ff..7281f17 100644 --- a/include/common/valhalla/sif/edgelabel.h +++ b/include/common/valhalla/sif/edgelabel.h @@ -12,6 +12,11 @@ namespace valhalla { namespace sif { +constexpr uint32_t kInitialEdgeLabelCountAstar = 2000000; +constexpr uint32_t kInitialEdgeLabelCountBidirAstar = 1000000; +constexpr uint32_t kInitialEdgeLabelCountDijkstras = 4000000; +constexpr uint32_t kInitialEdgeLabelCountBidirDijkstra = 2000000; + /** * Labeling information for shortest path algorithm. Contains cost, * predecessor, current time, and assorted information required during @@ -738,6 +743,7 @@ class MMEdgeLabel : public EdgeLabel { * @param dist Distance meters to the destination * @param mode Mode of travel along this edge. * @param path_distance Accumulated distance. + * @param walking_distance Accumulated walking distance. Used to prune the expansion. * @param tripid Trip Id for a transit edge. * @param prior_stopid Prior transit stop Id. * @param blockid Transit trip block Id. @@ -756,6 +762,7 @@ class MMEdgeLabel : public EdgeLabel { const float dist, const sif::TravelMode mode, const uint32_t path_distance, + const uint32_t walking_distance, const uint32_t tripid, const baldr::GraphId& prior_stopid, const uint32_t blockid, @@ -779,7 +786,8 @@ class MMEdgeLabel : public EdgeLabel { InternalTurn::kNoTurn, path_id), prior_stopid_(prior_stopid), tripid_(tripid), blockid_(blockid), - transit_operator_(transit_operator), has_transit_(has_transit) { + transit_operator_(transit_operator), has_transit_(has_transit), + walking_distance_(walking_distance) { } /** @@ -791,6 +799,7 @@ class MMEdgeLabel : public EdgeLabel { * @param cost True cost (and elapsed time in seconds) to the edge. * @param sortcost Cost for sorting (includes A* heuristic). * @param path_distance Accumulated path distance. + * @param walking_distance Accumulated walking distance. Used to prune the expansion. * @param tripid Trip Id for a transit edge. * @param blockid Transit trip block Id. * @param transition_cost Transition cost @@ -800,6 +809,7 @@ class MMEdgeLabel : public EdgeLabel { const sif::Cost& cost, const float sortcost, const uint32_t path_distance, + const uint32_t walking_distance, const uint32_t tripid, const uint32_t blockid, const Cost& transition_cost, @@ -808,6 +818,7 @@ class MMEdgeLabel : public EdgeLabel { cost_ = cost; sortcost_ = sortcost; path_distance_ = path_distance; + walking_distance_ = walking_distance; tripid_ = tripid; blockid_ = blockid; transition_cost_ = transition_cost; @@ -854,6 +865,13 @@ class MMEdgeLabel : public EdgeLabel { return has_transit_; } + /** + * Return the current walking distance in meters. + */ + uint32_t walking_distance() const { + return walking_distance_; + } + protected: // GraphId of the predecessor transit stop. baldr::GraphId prior_stopid_; @@ -867,6 +885,9 @@ class MMEdgeLabel : public EdgeLabel { uint32_t blockid_ : 21; // Really only needs 20 bits uint32_t transit_operator_ : 10; uint32_t has_transit_ : 1; + + // Accumulated walking distance to prune the expansion + uint32_t walking_distance_; }; } // namespace sif diff --git a/include/common/valhalla/thor/costmatrix.h b/include/common/valhalla/thor/costmatrix.h index 0e62c3c..4d1667f 100644 --- a/include/common/valhalla/thor/costmatrix.h +++ b/include/common/valhalla/thor/costmatrix.h @@ -15,6 +15,8 @@ #include #include #include +#include +#include namespace valhalla { namespace thor { @@ -27,24 +29,6 @@ constexpr float kCostThresholdBicycleDivisor = 56.0f; // 200 km distance threshold will result in a cost threshold of ~3600 (1 hour) constexpr float kCostThresholdPedestrianDivisor = 28.0f; // 200 km distance threshold will result in a cost threshold of ~7200 (2 hours) -constexpr float kMaxCost = 99999999.9999f; - -// Time and Distance structure -struct TimeDistance { - uint32_t time; // Time in seconds - uint32_t dist; // Distance in meters - std::string date_time; - - TimeDistance() : time(0), dist(0), date_time("") { - } - - TimeDistance(const uint32_t secs, const uint32_t meters) : time(secs), dist(meters), date_time("") { - } - - TimeDistance(const uint32_t secs, const uint32_t meters, std::string date_time) - : time(secs), dist(meters), date_time(date_time) { - } -}; /** * Status of a location. Tracks remaining locations to be found @@ -96,7 +80,8 @@ class CostMatrix { * Default constructor. Most internal values are set when a query is made so * the constructor mainly just sets some internals to a default empty value. */ - CostMatrix(); + CostMatrix(const boost::property_tree::ptree& config = {}); + ~CostMatrix(); /** @@ -111,12 +96,14 @@ class CostMatrix { * @return time/distance from origin index to all other locations */ std::vector - SourceToTarget(const google::protobuf::RepeatedPtrField& source_location_list, - const google::protobuf::RepeatedPtrField& target_location_list, + SourceToTarget(google::protobuf::RepeatedPtrField& source_location_list, + google::protobuf::RepeatedPtrField& target_location_list, baldr::GraphReader& graphreader, const sif::mode_costing_t& mode_costing, - const sif::TravelMode mode, - const float max_matrix_distance); + const sif::travel_mode_t mode, + const float max_matrix_distance, + const bool has_time = false, + const bool invariant = false); /** * Clear the temporary information generated during time+distance @@ -134,6 +121,8 @@ class CostMatrix { // Current costing mode std::shared_ptr costing_; + uint32_t max_reserved_labels_count_; + // Number of source and target locations that can be expanded uint32_t source_count_; uint32_t remaining_sources_; @@ -164,6 +153,9 @@ class CostMatrix { // List of best connections found so far std::vector best_connection_; + // when doing timezone differencing a timezone cache speeds up the computation + baldr::DateTime::tz_sys_info_cache_t tz_cache_; + /** * Get the cost threshold based on the current mode and the max arc-length distance * for that mode. @@ -186,7 +178,11 @@ class CostMatrix { * @param n Iteration counter. * @param graphreader Graph reader for accessing routing graph. */ - void ForwardSearch(const uint32_t index, const uint32_t n, baldr::GraphReader& graphreader); + void ForwardSearch(const uint32_t index, + const uint32_t n, + baldr::GraphReader& graphreader, + const baldr::TimeInfo& time_info, + const bool invariant); /** * Check if the edge on the forward search connects to a reached edge @@ -218,7 +214,8 @@ class CostMatrix { * @param sources List of source/origin locations. */ void SetSources(baldr::GraphReader& graphreader, - const google::protobuf::RepeatedPtrField& sources); + const google::protobuf::RepeatedPtrField& sources, + const std::vector& time_infos); /** * Set the target/destination locations. Search expands backwards from @@ -247,6 +244,42 @@ class CostMatrix { const sif::BDEdgeLabel& pred, const uint32_t predindex); + /** + * If time awareness was requested for the CostMatrix algorithm, we need + * to form the paths the sources & targets generated, and recost them to + * update the best connections, before returning the result. + * @param graphreader Graph tile reader + * @param origins The source locations + * @param targets The target locations + * @param time_infos The time info objects for the sources + * @param invariant Whether time is invariant + */ + void RecostPaths(baldr::GraphReader& graphreader, + google::protobuf::RepeatedPtrField& sources, + google::protobuf::RepeatedPtrField& targets, + const std::vector& time_infos, + bool invariant); + + /** + * Sets the date_time on the origin locations. + * + * @param origins the origins (sources or targets) + * @param reader the reader for looking up timezone information + * @returns time info for each location + */ + std::vector + SetOriginTimes(google::protobuf::RepeatedPtrField& origins, + baldr::GraphReader& reader) { + // loop over all locations setting the date time with timezone + std::vector infos; + infos.reserve(origins.size()); + for (auto& origin : origins) { + infos.emplace_back(baldr::TimeInfo::make(origin, reader, &tz_cache_)); + } + + return infos; + }; + /** * Form a time/distance matrix from the results. * @return Returns a time distance matrix among locations. diff --git a/include/common/valhalla/thor/dijkstras.h b/include/common/valhalla/thor/dijkstras.h index a26d0d5..5c82491 100644 --- a/include/common/valhalla/thor/dijkstras.h +++ b/include/common/valhalla/thor/dijkstras.h @@ -102,7 +102,8 @@ class Dijkstras { ComputeMultiModal(google::protobuf::RepeatedPtrField& origin_locations, baldr::GraphReader& graphreader, const sif::mode_costing_t& mode_costing, - const sif::TravelMode mode); + const sif::TravelMode mode, + const valhalla::Options& options); // A child-class must implement this to learn about what nodes were expanded virtual void ExpandingNode(baldr::GraphReader&, @@ -129,8 +130,8 @@ class Dijkstras { uint32_t dow_; uint32_t day_; uint32_t max_transfer_distance_; + uint32_t max_walking_dist_; std::string origin_date_time_; - uint32_t start_time_; std::unordered_map operators_; std::unordered_set processed_tiles_; diff --git a/include/common/valhalla/thor/matrix_common.h b/include/common/valhalla/thor/matrix_common.h index e9ad1f5..e7ecf49 100644 --- a/include/common/valhalla/thor/matrix_common.h +++ b/include/common/valhalla/thor/matrix_common.h @@ -15,15 +15,18 @@ #include #include #include -#include #include #include +#include namespace valhalla { namespace thor { +enum class MatrixType : bool { TimeDist, Cost }; + // Default for time distance matrix is to find all locations constexpr uint32_t kAllLocations = std::numeric_limits::max(); +constexpr float kMaxCost = 99999999.9999f; // Structure to hold information about each destination. struct Destination { @@ -54,6 +57,84 @@ struct Destination { } }; +// Time and Distance structure +struct TimeDistance { + uint32_t time; // Time in seconds + uint32_t dist; // Distance in meters + std::string date_time; + + TimeDistance() : time(0), dist(0), date_time("") { + } + + TimeDistance(const uint32_t secs, const uint32_t meters) : time(secs), dist(meters), date_time("") { + } + + TimeDistance(const uint32_t secs, const uint32_t meters, std::string date_time) + : time(secs), dist(meters), date_time(date_time) { + } +}; + +// Will return a destination's date_time string +inline std::string get_date_time(const std::string& origin_dt, + const uint64_t& origin_tz, + const baldr::GraphId& pred_id, + baldr::GraphReader& reader, + const uint64_t& offset) { + if (origin_dt.empty()) { + return ""; + } else if (!offset) { + return origin_dt; + } + graph_tile_ptr tile = nullptr; + uint32_t dest_tz = 0; + if (pred_id.Is_Valid()) { + // get the timezone of the output location + auto out_nodes = reader.GetDirectedEdgeNodes(pred_id, tile); + dest_tz = reader.GetTimezone(out_nodes.first, tile) || reader.GetTimezone(out_nodes.second, tile); + } + + auto in_epoch = + baldr::DateTime::seconds_since_epoch(origin_dt, + baldr::DateTime::get_tz_db().from_index(origin_tz)); + uint64_t out_epoch = in_epoch + offset; + std::string out_dt = + baldr::DateTime::seconds_to_date(out_epoch, baldr::DateTime::get_tz_db().from_index(dest_tz), + false); + + return out_dt; +} + +// return true if any location had a valid time set +// return false if it doesn't make sense computationally and add warnings accordingly +inline bool check_matrix_time(Api& request, const MatrixType type) { + const auto& options = request.options(); + bool less_sources = options.sources().size() <= options.targets().size(); + + for (const auto& source : options.sources()) { + if (!source.date_time().empty()) { + if (!less_sources && type == MatrixType::TimeDist) { + add_warning(request, 201); + return false; + } + return true; + } + } + for (const auto& target : options.targets()) { + if (!target.date_time().empty()) { + if (less_sources && type == MatrixType::TimeDist) { + add_warning(request, 202); + return false; + } else if (type == MatrixType::Cost) { + add_warning(request, 206); + return false; + } + return true; + } + } + + return false; +} + } // namespace thor } // namespace valhalla diff --git a/include/common/valhalla/thor/multimodal.h b/include/common/valhalla/thor/multimodal.h index 1100324..365e948 100644 --- a/include/common/valhalla/thor/multimodal.h +++ b/include/common/valhalla/thor/multimodal.h @@ -74,8 +74,7 @@ class MultiModalPathAlgorithm : public PathAlgorithm { void Clear() override; protected: - // Current walking distance. - uint32_t walking_distance_; + uint32_t max_walking_dist_; uint32_t max_label_count_; // Max label count to allow sif::TravelMode mode_; // Current travel mode uint8_t travel_type_; // Current travel type diff --git a/include/common/valhalla/thor/timedistancebssmatrix.h b/include/common/valhalla/thor/timedistancebssmatrix.h index 9ad6c2f..7add083 100644 --- a/include/common/valhalla/thor/timedistancebssmatrix.h +++ b/include/common/valhalla/thor/timedistancebssmatrix.h @@ -15,13 +15,10 @@ #include #include #include -#include #include #include #include -constexpr uint64_t kInitialEdgeLabelCount = 500000; - namespace valhalla { namespace thor { @@ -32,7 +29,7 @@ class TimeDistanceBSSMatrix { * Default constructor. Most internal values are set when a query is made so * the constructor mainly just sets some internals to a default empty value. */ - TimeDistanceBSSMatrix(); + TimeDistanceBSSMatrix(const boost::property_tree::ptree& config = {}); /** * Forms a time distance matrix from the set of source locations @@ -57,10 +54,12 @@ class TimeDistanceBSSMatrix { const sif::travel_mode_t /*mode*/, const float max_matrix_distance, const uint32_t matrix_locations = kAllLocations) { + + LOG_INFO("matrix::TimeDistanceBSSMatrix"); + // Set the costings pedestrian_costing_ = mode_costing[static_cast(sif::travel_mode_t::kPedestrian)]; bicycle_costing_ = mode_costing[static_cast(sif::travel_mode_t::kBicycle)]; - edgelabels_.reserve(kInitialEdgeLabelCount); const bool forward_search = source_location_list.size() <= target_location_list.size(); if (forward_search) { @@ -79,6 +78,11 @@ class TimeDistanceBSSMatrix { * matrix construction. */ inline void clear() { + auto reservation = clear_reserved_memory_ ? 0 : max_reserved_labels_count_; + if (edgelabels_.size() > reservation) { + edgelabels_.resize(max_reserved_labels_count_); + edgelabels_.shrink_to_fit(); + } reset(); destinations_.clear(); dest_edges_.clear(); @@ -92,6 +96,9 @@ class TimeDistanceBSSMatrix { // The cost threshold being used for the currently executing query float current_cost_threshold_; + uint32_t max_reserved_labels_count_; + bool clear_reserved_memory_; + // A* heuristic AStarHeuristic pedestrian_astarheuristic_; AStarHeuristic bicycle_astarheuristic_; @@ -121,6 +128,11 @@ class TimeDistanceBSSMatrix { * Reset all origin-specific information */ inline void reset() { + auto reservation = clear_reserved_memory_ ? 0 : max_reserved_labels_count_; + if (edgelabels_.size() > reservation) { + edgelabels_.resize(max_reserved_labels_count_); + edgelabels_.shrink_to_fit(); + } edgelabels_.clear(); // Clear the per-origin information for (auto& dest : destinations_) { diff --git a/include/common/valhalla/thor/timedistancematrix.h b/include/common/valhalla/thor/timedistancematrix.h index d6ab252..63341cc 100644 --- a/include/common/valhalla/thor/timedistancematrix.h +++ b/include/common/valhalla/thor/timedistancematrix.h @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -28,7 +27,7 @@ class TimeDistanceMatrix { * Default constructor. Most internal values are set when a query is made so * the constructor mainly just sets some internals to a default empty value. */ - TimeDistanceMatrix(); + TimeDistanceMatrix(const boost::property_tree::ptree& config = {}); /** * Forms a time distance matrix from the set of source locations @@ -42,6 +41,7 @@ class TimeDistanceMatrix { * @param matrix_locations Number of matrix locations to satisfy a one to many or many to * one request. This allows partial results: e.g. find time/distance * to the closest 20 out of 50 locations). + * @param has_time Whether the request had valid date_time. * @param invariant Whether invariant time was requested. * * @return time/distance from all sources to all targets @@ -55,6 +55,9 @@ class TimeDistanceMatrix { const float max_matrix_distance, const uint32_t matrix_locations = kAllLocations, const bool invariant = false) { + + LOG_INFO("matrix::TimeDistanceMatrix"); + // Set the mode and costing mode_ = mode; costing_ = mode_costing[static_cast(mode_)]; @@ -76,6 +79,11 @@ class TimeDistanceMatrix { * matrix construction. */ inline void clear() { + auto reservation = clear_reserved_memory_ ? 0 : max_reserved_labels_count_; + if (edgelabels_.size() > reservation) { + edgelabels_.resize(max_reserved_labels_count_); + edgelabels_.shrink_to_fit(); + } reset(); destinations_.clear(); dest_edges_.clear(); @@ -89,6 +97,9 @@ class TimeDistanceMatrix { // The cost threshold being used for the currently executing query float current_cost_threshold_; + uint32_t max_reserved_labels_count_; + bool clear_reserved_memory_; + // List of destinations std::vector destinations_; @@ -108,7 +119,7 @@ class TimeDistanceMatrix { // Edge status. Mark edges that are in adjacency list or settled. EdgeStatus edgestatus_; - sif::TravelMode mode_; + sif::travel_mode_t mode_; // when doing timezone differencing a timezone cache speeds up the computation baldr::DateTime::tz_sys_info_cache_t tz_cache_; @@ -117,13 +128,14 @@ class TimeDistanceMatrix { * Reset all origin-specific information */ inline void reset() { - // Clear the edge labels and destination list - edgelabels_.clear(); // Clear the per-origin information for (auto& dest : destinations_) { dest.reset(); } + // Clear the edge labels + edgelabels_.clear(); + // Clear elements from the adjacency list adjacencylist_.clear(); @@ -229,6 +241,7 @@ class TimeDistanceMatrix { const baldr::DirectedEdge* edge, const graph_tile_ptr& tile, const sif::EdgeLabel& pred, + const baldr::TimeInfo& time_info, const uint32_t matrix_locations); /** diff --git a/include/common/valhalla/tyr/serializers.h b/include/common/valhalla/tyr/serializers.h index 34d780f..30cd1b4 100644 --- a/include/common/valhalla/tyr/serializers.h +++ b/include/common/valhalla/tyr/serializers.h @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include namespace valhalla { @@ -32,7 +32,8 @@ std::string serializeDirections(Api& request); */ std::string serializeMatrix(const Api& request, const std::vector& time_distances, - double distance_scale); + double distance_scale, + thor::MatrixType matrix_type); /** * Turn grid data contours into geojson diff --git a/include/common/valhalla/valhalla.h b/include/common/valhalla/valhalla.h index 033e1da..421459f 100644 --- a/include/common/valhalla/valhalla.h +++ b/include/common/valhalla/valhalla.h @@ -1,5 +1,5 @@ #pragma once #define VALHALLA_VERSION_MAJOR 3 -#define VALHALLA_VERSION_MINOR 3 +#define VALHALLA_VERSION_MINOR 4 #define VALHALLA_VERSION_PATCH 0 diff --git a/include/darwin/valhalla/proto/options.pb.cc b/include/darwin/valhalla/proto/options.pb.cc index 745ab34..9acc407 100644 --- a/include/darwin/valhalla/proto/options.pb.cc +++ b/include/darwin/valhalla/proto/options.pb.cc @@ -89,6 +89,8 @@ PROTOBUF_CONSTEXPR Costing_Options::Costing_Options( , /*decltype(_impl_.filter_route_action_)*/0 , /*decltype(_impl_.fixed_speed_)*/0u , /*decltype(_impl_.axle_count_)*/0u + , /*decltype(_impl_.use_lit_)*/0 + , /*decltype(_impl_.disable_hierarchy_pruning_)*/false , /*decltype(_impl_.has_maneuver_penalty_)*/{} , /*decltype(_impl_.has_destination_only_penalty_)*/{} , /*decltype(_impl_.has_gate_cost_)*/{} @@ -226,7 +228,6 @@ PROTOBUF_CONSTEXPR Options::Options( , /*decltype(_impl_.filter_action_)*/0 , /*decltype(_impl_.shape_format_)*/0 , /*decltype(_impl_.reverse_)*/false - , /*decltype(_impl_.matrix_locations_)*/0u , /*decltype(_impl_.has_language_)*/{} , /*decltype(_impl_.has_id_)*/{} , /*decltype(_impl_.has_jsonp_)*/{} @@ -253,6 +254,7 @@ PROTOBUF_CONSTEXPR Options::Options( , /*decltype(_impl_.has_prioritize_bidirectional_)*/{} , /*decltype(_impl_.has_expansion_action_)*/{} , /*decltype(_impl_.has_skip_opposites_)*/{} + , /*decltype(_impl_.has_matrix_locations_)*/{} , /*decltype(_impl_._cached_size_)*/{} , /*decltype(_impl_._oneof_case_)*/{}} {} struct OptionsDefaultTypeInternal { @@ -2106,6 +2108,8 @@ Costing_Options::Costing_Options(const Costing_Options& from) , decltype(_impl_.filter_route_action_){} , decltype(_impl_.fixed_speed_){} , decltype(_impl_.axle_count_){} + , decltype(_impl_.use_lit_){} + , decltype(_impl_.disable_hierarchy_pruning_){} , decltype(_impl_.has_maneuver_penalty_){} , decltype(_impl_.has_destination_only_penalty_){} , decltype(_impl_.has_gate_cost_){} @@ -2183,8 +2187,8 @@ Costing_Options::Costing_Options(const Costing_Options& from) _internal_metadata_.MergeFrom(from._internal_metadata_); ::memcpy(&_impl_.filter_stop_action_, &from._impl_.filter_stop_action_, - static_cast(reinterpret_cast(&_impl_.axle_count_) - - reinterpret_cast(&_impl_.filter_stop_action_)) + sizeof(_impl_.axle_count_)); + static_cast(reinterpret_cast(&_impl_.disable_hierarchy_pruning_) - + reinterpret_cast(&_impl_.filter_stop_action_)) + sizeof(_impl_.disable_hierarchy_pruning_)); clear_has_has_maneuver_penalty(); switch (from.has_maneuver_penalty_case()) { case kManeuverPenalty: { @@ -2922,6 +2926,8 @@ inline void Costing_Options::SharedCtor( , decltype(_impl_.filter_route_action_){0} , decltype(_impl_.fixed_speed_){0u} , decltype(_impl_.axle_count_){0u} + , decltype(_impl_.use_lit_){0} + , decltype(_impl_.disable_hierarchy_pruning_){false} , decltype(_impl_.has_maneuver_penalty_){} , decltype(_impl_.has_destination_only_penalty_){} , decltype(_impl_.has_gate_cost_){} @@ -4328,8 +4334,8 @@ void Costing_Options::Clear() { _impl_.filter_route_ids_.Clear(); _impl_.exclude_edges_.Clear(); ::memset(&_impl_.filter_stop_action_, 0, static_cast( - reinterpret_cast(&_impl_.axle_count_) - - reinterpret_cast(&_impl_.filter_stop_action_)) + sizeof(_impl_.axle_count_)); + reinterpret_cast(&_impl_.disable_hierarchy_pruning_) - + reinterpret_cast(&_impl_.filter_stop_action_)) + sizeof(_impl_.disable_hierarchy_pruning_)); clear_has_maneuver_penalty(); clear_has_destination_only_penalty(); clear_has_gate_cost(); @@ -5090,6 +5096,22 @@ const char* Costing_Options::_InternalParse(const char* ptr, ::_pbi::ParseContex } else goto handle_unusual; continue; + // float use_lit = 82; + case 82: + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 149)) { + _impl_.use_lit_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad(ptr); + ptr += sizeof(float); + } else + goto handle_unusual; + continue; + // bool disable_hierarchy_pruning = 83; + case 83: + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 152)) { + _impl_.disable_hierarchy_pruning_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); + CHK_(ptr); + } else + goto handle_unusual; + continue; default: goto handle_unusual; } // switch @@ -5626,6 +5648,22 @@ uint8_t* Costing_Options::_InternalSerialize( target = ::_pbi::WireFormatLite::WriteUInt32ToArray(81, this->_internal_axle_count(), target); } + // float use_lit = 82; + static_assert(sizeof(uint32_t) == sizeof(float), "Code assumes uint32_t and float are the same size."); + float tmp_use_lit = this->_internal_use_lit(); + uint32_t raw_use_lit; + memcpy(&raw_use_lit, &tmp_use_lit, sizeof(tmp_use_lit)); + if (raw_use_lit != 0) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteFloatToArray(82, this->_internal_use_lit(), target); + } + + // bool disable_hierarchy_pruning = 83; + if (this->_internal_disable_hierarchy_pruning() != 0) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteBoolToArray(83, this->_internal_disable_hierarchy_pruning(), target); + } + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { target = stream->WriteRaw(_internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).data(), static_cast(_internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).size()), target); @@ -5705,6 +5743,20 @@ size_t Costing_Options::ByteSizeLong() const { this->_internal_axle_count()); } + // float use_lit = 82; + static_assert(sizeof(uint32_t) == sizeof(float), "Code assumes uint32_t and float are the same size."); + float tmp_use_lit = this->_internal_use_lit(); + uint32_t raw_use_lit; + memcpy(&raw_use_lit, &tmp_use_lit, sizeof(tmp_use_lit)); + if (raw_use_lit != 0) { + total_size += 2 + 4; + } + + // bool disable_hierarchy_pruning = 83; + if (this->_internal_disable_hierarchy_pruning() != 0) { + total_size += 2 + 1; + } + switch (has_maneuver_penalty_case()) { // float maneuver_penalty = 1; case kManeuverPenalty: { @@ -6481,6 +6533,16 @@ void Costing_Options::MergeFrom(const Costing_Options& from) { if (from._internal_axle_count() != 0) { _this->_internal_set_axle_count(from._internal_axle_count()); } + static_assert(sizeof(uint32_t) == sizeof(float), "Code assumes uint32_t and float are the same size."); + float tmp_use_lit = from._internal_use_lit(); + uint32_t raw_use_lit; + memcpy(&raw_use_lit, &tmp_use_lit, sizeof(tmp_use_lit)); + if (raw_use_lit != 0) { + _this->_internal_set_use_lit(from._internal_use_lit()); + } + if (from._internal_disable_hierarchy_pruning() != 0) { + _this->_internal_set_disable_hierarchy_pruning(from._internal_disable_hierarchy_pruning()); + } switch (from.has_maneuver_penalty_case()) { case kManeuverPenalty: { _this->_internal_set_maneuver_penalty(from._internal_maneuver_penalty()); @@ -7151,8 +7213,8 @@ void Costing_Options::InternalSwap(Costing_Options* other) { _impl_.filter_route_ids_.InternalSwap(&other->_impl_.filter_route_ids_); _impl_.exclude_edges_.InternalSwap(&other->_impl_.exclude_edges_); ::PROTOBUF_NAMESPACE_ID::internal::memswap< - PROTOBUF_FIELD_OFFSET(Costing_Options, _impl_.axle_count_) - + sizeof(Costing_Options::_impl_.axle_count_) + PROTOBUF_FIELD_OFFSET(Costing_Options, _impl_.disable_hierarchy_pruning_) + + sizeof(Costing_Options::_impl_.disable_hierarchy_pruning_) - PROTOBUF_FIELD_OFFSET(Costing_Options, _impl_.filter_stop_action_)>( reinterpret_cast(&_impl_.filter_stop_action_), reinterpret_cast(&other->_impl_.filter_stop_action_)); @@ -7798,7 +7860,6 @@ Options::Options(const Options& from) , decltype(_impl_.filter_action_){} , decltype(_impl_.shape_format_){} , decltype(_impl_.reverse_){} - , decltype(_impl_.matrix_locations_){} , decltype(_impl_.has_language_){} , decltype(_impl_.has_id_){} , decltype(_impl_.has_jsonp_){} @@ -7825,6 +7886,7 @@ Options::Options(const Options& from) , decltype(_impl_.has_prioritize_bidirectional_){} , decltype(_impl_.has_expansion_action_){} , decltype(_impl_.has_skip_opposites_){} + , decltype(_impl_.has_matrix_locations_){} , /*decltype(_impl_._cached_size_)*/{} , /*decltype(_impl_._oneof_case_)*/{}}; @@ -7834,8 +7896,8 @@ Options::Options(const Options& from) _this->_impl_.pbf_field_selector_ = new ::valhalla::PbfFieldSelector(*from._impl_.pbf_field_selector_); } ::memcpy(&_impl_.units_, &from._impl_.units_, - static_cast(reinterpret_cast(&_impl_.matrix_locations_) - - reinterpret_cast(&_impl_.units_)) + sizeof(_impl_.matrix_locations_)); + static_cast(reinterpret_cast(&_impl_.reverse_) - + reinterpret_cast(&_impl_.units_)) + sizeof(_impl_.reverse_)); clear_has_has_language(); switch (from.has_language_case()) { case kLanguage: { @@ -8096,6 +8158,16 @@ Options::Options(const Options& from) break; } } + clear_has_has_matrix_locations(); + switch (from.has_matrix_locations_case()) { + case kMatrixLocations: { + _this->_internal_set_matrix_locations(from._internal_matrix_locations()); + break; + } + case HAS_MATRIX_LOCATIONS_NOT_SET: { + break; + } + } // @@protoc_insertion_point(copy_constructor:valhalla.Options) } @@ -8128,7 +8200,6 @@ inline void Options::SharedCtor( , decltype(_impl_.filter_action_){0} , decltype(_impl_.shape_format_){0} , decltype(_impl_.reverse_){false} - , decltype(_impl_.matrix_locations_){0u} , decltype(_impl_.has_language_){} , decltype(_impl_.has_id_){} , decltype(_impl_.has_jsonp_){} @@ -8155,6 +8226,7 @@ inline void Options::SharedCtor( , decltype(_impl_.has_prioritize_bidirectional_){} , decltype(_impl_.has_expansion_action_){} , decltype(_impl_.has_skip_opposites_){} + , decltype(_impl_.has_matrix_locations_){} , /*decltype(_impl_._cached_size_)*/{} , /*decltype(_impl_._oneof_case_)*/{} }; @@ -8184,6 +8256,7 @@ inline void Options::SharedCtor( clear_has_has_prioritize_bidirectional(); clear_has_has_expansion_action(); clear_has_has_skip_opposites(); + clear_has_has_matrix_locations(); } Options::~Options() { @@ -8289,6 +8362,9 @@ inline void Options::SharedDtor() { if (has_has_skip_opposites()) { clear_has_skip_opposites(); } + if (has_has_matrix_locations()) { + clear_has_matrix_locations(); + } } void Options::SetCachedSize(int size) const { @@ -8659,6 +8735,20 @@ void Options::clear_has_skip_opposites() { _impl_._oneof_case_[25] = HAS_SKIP_OPPOSITES_NOT_SET; } +void Options::clear_has_matrix_locations() { +// @@protoc_insertion_point(one_of_clear_start:valhalla.Options) + switch (has_matrix_locations_case()) { + case kMatrixLocations: { + // No need to clear + break; + } + case HAS_MATRIX_LOCATIONS_NOT_SET: { + break; + } + } + _impl_._oneof_case_[26] = HAS_MATRIX_LOCATIONS_NOT_SET; +} + void Options::Clear() { // @@protoc_insertion_point(message_clear_start:valhalla.Options) @@ -8683,8 +8773,8 @@ void Options::Clear() { } _impl_.pbf_field_selector_ = nullptr; ::memset(&_impl_.units_, 0, static_cast( - reinterpret_cast(&_impl_.matrix_locations_) - - reinterpret_cast(&_impl_.units_)) + sizeof(_impl_.matrix_locations_)); + reinterpret_cast(&_impl_.reverse_) - + reinterpret_cast(&_impl_.units_)) + sizeof(_impl_.reverse_)); clear_has_language(); clear_has_id(); clear_has_jsonp(); @@ -8711,6 +8801,7 @@ void Options::Clear() { clear_has_prioritize_bidirectional(); clear_has_expansion_action(); clear_has_skip_opposites(); + clear_has_matrix_locations(); _internal_metadata_.Clear(); } @@ -9196,7 +9287,7 @@ const char* Options::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) // uint32 matrix_locations = 54; case 54: if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 176)) { - _impl_.matrix_locations_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + _internal_set_matrix_locations(::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr)); CHK_(ptr); } else goto handle_unusual; @@ -9592,7 +9683,7 @@ uint8_t* Options::_InternalSerialize( } // uint32 matrix_locations = 54; - if (this->_internal_matrix_locations() != 0) { + if (_internal_has_matrix_locations()) { target = stream->EnsureSpace(target); target = ::_pbi::WireFormatLite::WriteUInt32ToArray(54, this->_internal_matrix_locations(), target); } @@ -9776,13 +9867,6 @@ size_t Options::ByteSizeLong() const { total_size += 2 + 1; } - // uint32 matrix_locations = 54; - if (this->_internal_matrix_locations() != 0) { - total_size += 2 + - ::_pbi::WireFormatLite::UInt32Size( - this->_internal_matrix_locations()); - } - switch (has_language_case()) { // string language = 2; case kLanguage: { @@ -10058,6 +10142,18 @@ size_t Options::ByteSizeLong() const { break; } } + switch (has_matrix_locations_case()) { + // uint32 matrix_locations = 54; + case kMatrixLocations: { + total_size += 2 + + ::_pbi::WireFormatLite::UInt32Size( + this->_internal_matrix_locations()); + break; + } + case HAS_MATRIX_LOCATIONS_NOT_SET: { + break; + } + } if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { total_size += _internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).size(); } @@ -10125,9 +10221,6 @@ void Options::MergeFrom(const Options& from) { if (from._internal_reverse() != 0) { _this->_internal_set_reverse(from._internal_reverse()); } - if (from._internal_matrix_locations() != 0) { - _this->_internal_set_matrix_locations(from._internal_matrix_locations()); - } switch (from.has_language_case()) { case kLanguage: { _this->_internal_set_language(from._internal_language()); @@ -10362,6 +10455,15 @@ void Options::MergeFrom(const Options& from) { break; } } + switch (from.has_matrix_locations_case()) { + case kMatrixLocations: { + _this->_internal_set_matrix_locations(from._internal_matrix_locations()); + break; + } + case HAS_MATRIX_LOCATIONS_NOT_SET: { + break; + } + } _this->_internal_metadata_.MergeFrom(from._internal_metadata_); } @@ -10392,8 +10494,8 @@ void Options::InternalSwap(Options* other) { _impl_.exclude_polygons_.InternalSwap(&other->_impl_.exclude_polygons_); _impl_.expansion_properties_.InternalSwap(&other->_impl_.expansion_properties_); ::PROTOBUF_NAMESPACE_ID::internal::memswap< - PROTOBUF_FIELD_OFFSET(Options, _impl_.matrix_locations_) - + sizeof(Options::_impl_.matrix_locations_) + PROTOBUF_FIELD_OFFSET(Options, _impl_.reverse_) + + sizeof(Options::_impl_.reverse_) - PROTOBUF_FIELD_OFFSET(Options, _impl_.pbf_field_selector_)>( reinterpret_cast(&_impl_.pbf_field_selector_), reinterpret_cast(&other->_impl_.pbf_field_selector_)); @@ -10423,6 +10525,7 @@ void Options::InternalSwap(Options* other) { swap(_impl_.has_prioritize_bidirectional_, other->_impl_.has_prioritize_bidirectional_); swap(_impl_.has_expansion_action_, other->_impl_.has_expansion_action_); swap(_impl_.has_skip_opposites_, other->_impl_.has_skip_opposites_); + swap(_impl_.has_matrix_locations_, other->_impl_.has_matrix_locations_); swap(_impl_._oneof_case_[0], other->_impl_._oneof_case_[0]); swap(_impl_._oneof_case_[1], other->_impl_._oneof_case_[1]); swap(_impl_._oneof_case_[2], other->_impl_._oneof_case_[2]); @@ -10449,6 +10552,7 @@ void Options::InternalSwap(Options* other) { swap(_impl_._oneof_case_[23], other->_impl_._oneof_case_[23]); swap(_impl_._oneof_case_[24], other->_impl_._oneof_case_[24]); swap(_impl_._oneof_case_[25], other->_impl_._oneof_case_[25]); + swap(_impl_._oneof_case_[26], other->_impl_._oneof_case_[26]); } std::string Options::GetTypeName() const { diff --git a/include/darwin/valhalla/proto/options.pb.h b/include/darwin/valhalla/proto/options.pb.h index d7e6a97..71da067 100644 --- a/include/darwin/valhalla/proto/options.pb.h +++ b/include/darwin/valhalla/proto/options.pb.h @@ -1500,6 +1500,8 @@ class Costing_Options final : kFilterRouteActionFieldNumber = 53, kFixedSpeedFieldNumber = 80, kAxleCountFieldNumber = 81, + kUseLitFieldNumber = 82, + kDisableHierarchyPruningFieldNumber = 83, kManeuverPenaltyFieldNumber = 1, kDestinationOnlyPenaltyFieldNumber = 2, kGateCostFieldNumber = 3, @@ -1708,6 +1710,24 @@ class Costing_Options final : void _internal_set_axle_count(uint32_t value); public: + // float use_lit = 82; + void clear_use_lit(); + float use_lit() const; + void set_use_lit(float value); + private: + float _internal_use_lit() const; + void _internal_set_use_lit(float value); + public: + + // bool disable_hierarchy_pruning = 83; + void clear_disable_hierarchy_pruning(); + bool disable_hierarchy_pruning() const; + void set_disable_hierarchy_pruning(bool value); + private: + bool _internal_disable_hierarchy_pruning() const; + void _internal_set_disable_hierarchy_pruning(bool value); + public: + // float maneuver_penalty = 1; bool has_maneuver_penalty() const; private: @@ -3098,6 +3118,8 @@ class Costing_Options final : int filter_route_action_; uint32_t fixed_speed_; uint32_t axle_count_; + float use_lit_; + bool disable_hierarchy_pruning_; union HasManeuverPenaltyUnion { constexpr HasManeuverPenaltyUnion() : _constinit_{} {} ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized _constinit_; @@ -3933,6 +3955,11 @@ class Options final : HAS_SKIP_OPPOSITES_NOT_SET = 0, }; + enum HasMatrixLocationsCase { + kMatrixLocations = 54, + HAS_MATRIX_LOCATIONS_NOT_SET = 0, + }; + static inline const Options* internal_default_instance() { return reinterpret_cast( &_Options_default_instance_); @@ -4194,7 +4221,6 @@ class Options final : kFilterActionFieldNumber = 33, kShapeFormatFieldNumber = 38, kReverseFieldNumber = 53, - kMatrixLocationsFieldNumber = 54, kLanguageFieldNumber = 2, kIdFieldNumber = 5, kJsonpFieldNumber = 6, @@ -4221,6 +4247,7 @@ class Options final : kPrioritizeBidirectionalFieldNumber = 48, kExpansionActionFieldNumber = 49, kSkipOppositesFieldNumber = 50, + kMatrixLocationsFieldNumber = 54, }; // map costings = 13; int costings_size() const; @@ -4550,15 +4577,6 @@ class Options final : void _internal_set_reverse(bool value); public: - // uint32 matrix_locations = 54; - void clear_matrix_locations(); - uint32_t matrix_locations() const; - void set_matrix_locations(uint32_t value); - private: - uint32_t _internal_matrix_locations() const; - void _internal_set_matrix_locations(uint32_t value); - public: - // string language = 2; bool has_language() const; private: @@ -4922,6 +4940,19 @@ class Options final : void _internal_set_skip_opposites(bool value); public: + // uint32 matrix_locations = 54; + bool has_matrix_locations() const; + private: + bool _internal_has_matrix_locations() const; + public: + void clear_matrix_locations(); + uint32_t matrix_locations() const; + void set_matrix_locations(uint32_t value); + private: + uint32_t _internal_matrix_locations() const; + void _internal_set_matrix_locations(uint32_t value); + public: + void clear_has_language(); HasLanguageCase has_language_case() const; void clear_has_id(); @@ -4974,6 +5005,8 @@ class Options final : HasExpansionActionCase has_expansion_action_case() const; void clear_has_skip_opposites(); HasSkipOppositesCase has_skip_opposites_case() const; + void clear_has_matrix_locations(); + HasMatrixLocationsCase has_matrix_locations_case() const; // @@protoc_insertion_point(class_scope:valhalla.Options) private: class _Internal; @@ -5003,6 +5036,7 @@ class Options final : void set_has_prioritize_bidirectional(); void set_has_expansion_action(); void set_has_skip_opposites(); + void set_has_matrix_locations(); inline bool has_has_language() const; inline void clear_has_has_language(); @@ -5082,6 +5116,9 @@ class Options final : inline bool has_has_skip_opposites() const; inline void clear_has_has_skip_opposites(); + inline bool has_has_matrix_locations() const; + inline void clear_has_has_matrix_locations(); + template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; @@ -5114,7 +5151,6 @@ class Options final : int filter_action_; int shape_format_; bool reverse_; - uint32_t matrix_locations_; union HasLanguageUnion { constexpr HasLanguageUnion() : _constinit_{} {} ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized _constinit_; @@ -5245,8 +5281,13 @@ class Options final : ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized _constinit_; bool skip_opposites_; } has_skip_opposites_; + union HasMatrixLocationsUnion { + constexpr HasMatrixLocationsUnion() : _constinit_{} {} + ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized _constinit_; + uint32_t matrix_locations_; + } has_matrix_locations_; mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - uint32_t _oneof_case_[26]; + uint32_t _oneof_case_[27]; }; union { Impl_ _impl_; }; @@ -8810,6 +8851,46 @@ inline void Costing_Options::set_axle_count(uint32_t value) { // @@protoc_insertion_point(field_set:valhalla.Costing.Options.axle_count) } +// float use_lit = 82; +inline void Costing_Options::clear_use_lit() { + _impl_.use_lit_ = 0; +} +inline float Costing_Options::_internal_use_lit() const { + return _impl_.use_lit_; +} +inline float Costing_Options::use_lit() const { + // @@protoc_insertion_point(field_get:valhalla.Costing.Options.use_lit) + return _internal_use_lit(); +} +inline void Costing_Options::_internal_set_use_lit(float value) { + + _impl_.use_lit_ = value; +} +inline void Costing_Options::set_use_lit(float value) { + _internal_set_use_lit(value); + // @@protoc_insertion_point(field_set:valhalla.Costing.Options.use_lit) +} + +// bool disable_hierarchy_pruning = 83; +inline void Costing_Options::clear_disable_hierarchy_pruning() { + _impl_.disable_hierarchy_pruning_ = false; +} +inline bool Costing_Options::_internal_disable_hierarchy_pruning() const { + return _impl_.disable_hierarchy_pruning_; +} +inline bool Costing_Options::disable_hierarchy_pruning() const { + // @@protoc_insertion_point(field_get:valhalla.Costing.Options.disable_hierarchy_pruning) + return _internal_disable_hierarchy_pruning(); +} +inline void Costing_Options::_internal_set_disable_hierarchy_pruning(bool value) { + + _impl_.disable_hierarchy_pruning_ = value; +} +inline void Costing_Options::set_disable_hierarchy_pruning(bool value) { + _internal_set_disable_hierarchy_pruning(value); + // @@protoc_insertion_point(field_set:valhalla.Costing.Options.disable_hierarchy_pruning) +} + inline bool Costing_Options::has_has_maneuver_penalty() const { return has_maneuver_penalty_case() != HAS_MANEUVER_PENALTY_NOT_SET; } @@ -11667,20 +11748,38 @@ inline void Options::set_reverse(bool value) { } // uint32 matrix_locations = 54; +inline bool Options::_internal_has_matrix_locations() const { + return has_matrix_locations_case() == kMatrixLocations; +} +inline bool Options::has_matrix_locations() const { + return _internal_has_matrix_locations(); +} +inline void Options::set_has_matrix_locations() { + _impl_._oneof_case_[26] = kMatrixLocations; +} inline void Options::clear_matrix_locations() { - _impl_.matrix_locations_ = 0u; + if (_internal_has_matrix_locations()) { + _impl_.has_matrix_locations_.matrix_locations_ = 0u; + clear_has_has_matrix_locations(); + } } inline uint32_t Options::_internal_matrix_locations() const { - return _impl_.matrix_locations_; + if (_internal_has_matrix_locations()) { + return _impl_.has_matrix_locations_.matrix_locations_; + } + return 0u; +} +inline void Options::_internal_set_matrix_locations(uint32_t value) { + if (!_internal_has_matrix_locations()) { + clear_has_matrix_locations(); + set_has_matrix_locations(); + } + _impl_.has_matrix_locations_.matrix_locations_ = value; } inline uint32_t Options::matrix_locations() const { // @@protoc_insertion_point(field_get:valhalla.Options.matrix_locations) return _internal_matrix_locations(); } -inline void Options::_internal_set_matrix_locations(uint32_t value) { - - _impl_.matrix_locations_ = value; -} inline void Options::set_matrix_locations(uint32_t value) { _internal_set_matrix_locations(value); // @@protoc_insertion_point(field_set:valhalla.Options.matrix_locations) @@ -11842,6 +11941,12 @@ inline bool Options::has_has_skip_opposites() const { inline void Options::clear_has_has_skip_opposites() { _impl_._oneof_case_[25] = HAS_SKIP_OPPOSITES_NOT_SET; } +inline bool Options::has_has_matrix_locations() const { + return has_matrix_locations_case() != HAS_MATRIX_LOCATIONS_NOT_SET; +} +inline void Options::clear_has_has_matrix_locations() { + _impl_._oneof_case_[26] = HAS_MATRIX_LOCATIONS_NOT_SET; +} inline Options::HasLanguageCase Options::has_language_case() const { return Options::HasLanguageCase(_impl_._oneof_case_[0]); } @@ -11920,6 +12025,9 @@ inline Options::HasExpansionActionCase Options::has_expansion_action_case() cons inline Options::HasSkipOppositesCase Options::has_skip_opposites_case() const { return Options::HasSkipOppositesCase(_impl_._oneof_case_[25]); } +inline Options::HasMatrixLocationsCase Options::has_matrix_locations_case() const { + return Options::HasMatrixLocationsCase(_impl_._oneof_case_[26]); +} #ifdef __GNUC__ #pragma GCC diagnostic pop #endif // __GNUC__ diff --git a/include/darwin/valhalla/proto/status.pb.cc b/include/darwin/valhalla/proto/status.pb.cc index a7802fb..6e1ad24 100644 --- a/include/darwin/valhalla/proto/status.pb.cc +++ b/include/darwin/valhalla/proto/status.pb.cc @@ -21,13 +21,15 @@ namespace valhalla { PROTOBUF_CONSTEXPR Status::Status( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_.available_actions_)*/{} + , /*decltype(_impl_.version_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}} + , /*decltype(_impl_.tileset_last_modified_)*/0u , /*decltype(_impl_.has_has_tiles_)*/{} , /*decltype(_impl_.has_has_admins_)*/{} , /*decltype(_impl_.has_has_timezones_)*/{} , /*decltype(_impl_.has_has_live_traffic_)*/{} , /*decltype(_impl_.has_bbox_)*/{} - , /*decltype(_impl_.has_version_)*/{} - , /*decltype(_impl_.has_tileset_last_modified_)*/{} + , /*decltype(_impl_.has_has_transit_tiles_)*/{} + , /*decltype(_impl_.has_osm_changeset_)*/{} , /*decltype(_impl_._cached_size_)*/{} , /*decltype(_impl_._oneof_case_)*/{}} {} struct StatusDefaultTypeInternal { @@ -59,17 +61,28 @@ Status::Status(const Status& from) Status* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_.available_actions_){from._impl_.available_actions_} + , decltype(_impl_.version_){} + , decltype(_impl_.tileset_last_modified_){} , decltype(_impl_.has_has_tiles_){} , decltype(_impl_.has_has_admins_){} , decltype(_impl_.has_has_timezones_){} , decltype(_impl_.has_has_live_traffic_){} , decltype(_impl_.has_bbox_){} - , decltype(_impl_.has_version_){} - , decltype(_impl_.has_tileset_last_modified_){} + , decltype(_impl_.has_has_transit_tiles_){} + , decltype(_impl_.has_osm_changeset_){} , /*decltype(_impl_._cached_size_)*/{} , /*decltype(_impl_._oneof_case_)*/{}}; _internal_metadata_.MergeFrom(from._internal_metadata_); + _impl_.version_.InitDefault(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.version_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + if (!from._internal_version().empty()) { + _this->_impl_.version_.Set(from._internal_version(), + _this->GetArenaForAllocation()); + } + _this->_impl_.tileset_last_modified_ = from._impl_.tileset_last_modified_; clear_has_has_has_tiles(); switch (from.has_has_tiles_case()) { case kHasTiles: { @@ -120,23 +133,23 @@ Status::Status(const Status& from) break; } } - clear_has_has_version(); - switch (from.has_version_case()) { - case kVersion: { - _this->_internal_set_version(from._internal_version()); + clear_has_has_has_transit_tiles(); + switch (from.has_has_transit_tiles_case()) { + case kHasTransitTiles: { + _this->_internal_set_has_transit_tiles(from._internal_has_transit_tiles()); break; } - case HAS_VERSION_NOT_SET: { + case HAS_HAS_TRANSIT_TILES_NOT_SET: { break; } } - clear_has_has_tileset_last_modified(); - switch (from.has_tileset_last_modified_case()) { - case kTilesetLastModified: { - _this->_internal_set_tileset_last_modified(from._internal_tileset_last_modified()); + clear_has_has_osm_changeset(); + switch (from.has_osm_changeset_case()) { + case kOsmChangeset: { + _this->_internal_set_osm_changeset(from._internal_osm_changeset()); break; } - case HAS_TILESET_LAST_MODIFIED_NOT_SET: { + case HAS_OSM_CHANGESET_NOT_SET: { break; } } @@ -149,23 +162,29 @@ inline void Status::SharedCtor( (void)is_message_owned; new (&_impl_) Impl_{ decltype(_impl_.available_actions_){arena} + , decltype(_impl_.version_){} + , decltype(_impl_.tileset_last_modified_){0u} , decltype(_impl_.has_has_tiles_){} , decltype(_impl_.has_has_admins_){} , decltype(_impl_.has_has_timezones_){} , decltype(_impl_.has_has_live_traffic_){} , decltype(_impl_.has_bbox_){} - , decltype(_impl_.has_version_){} - , decltype(_impl_.has_tileset_last_modified_){} + , decltype(_impl_.has_has_transit_tiles_){} + , decltype(_impl_.has_osm_changeset_){} , /*decltype(_impl_._cached_size_)*/{} , /*decltype(_impl_._oneof_case_)*/{} }; + _impl_.version_.InitDefault(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.version_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING clear_has_has_has_tiles(); clear_has_has_has_admins(); clear_has_has_has_timezones(); clear_has_has_has_live_traffic(); clear_has_has_bbox(); - clear_has_has_version(); - clear_has_has_tileset_last_modified(); + clear_has_has_has_transit_tiles(); + clear_has_has_osm_changeset(); } Status::~Status() { @@ -180,6 +199,7 @@ Status::~Status() { inline void Status::SharedDtor() { GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); _impl_.available_actions_.~RepeatedPtrField(); + _impl_.version_.Destroy(); if (has_has_has_tiles()) { clear_has_has_tiles(); } @@ -195,11 +215,11 @@ inline void Status::SharedDtor() { if (has_has_bbox()) { clear_has_bbox(); } - if (has_has_version()) { - clear_has_version(); + if (has_has_has_transit_tiles()) { + clear_has_has_transit_tiles(); } - if (has_has_tileset_last_modified()) { - clear_has_tileset_last_modified(); + if (has_has_osm_changeset()) { + clear_has_osm_changeset(); } } @@ -277,32 +297,32 @@ void Status::clear_has_bbox() { _impl_._oneof_case_[4] = HAS_BBOX_NOT_SET; } -void Status::clear_has_version() { +void Status::clear_has_has_transit_tiles() { // @@protoc_insertion_point(one_of_clear_start:valhalla.Status) - switch (has_version_case()) { - case kVersion: { - _impl_.has_version_.version_.Destroy(); + switch (has_has_transit_tiles_case()) { + case kHasTransitTiles: { + // No need to clear break; } - case HAS_VERSION_NOT_SET: { + case HAS_HAS_TRANSIT_TILES_NOT_SET: { break; } } - _impl_._oneof_case_[5] = HAS_VERSION_NOT_SET; + _impl_._oneof_case_[5] = HAS_HAS_TRANSIT_TILES_NOT_SET; } -void Status::clear_has_tileset_last_modified() { +void Status::clear_has_osm_changeset() { // @@protoc_insertion_point(one_of_clear_start:valhalla.Status) - switch (has_tileset_last_modified_case()) { - case kTilesetLastModified: { + switch (has_osm_changeset_case()) { + case kOsmChangeset: { // No need to clear break; } - case HAS_TILESET_LAST_MODIFIED_NOT_SET: { + case HAS_OSM_CHANGESET_NOT_SET: { break; } } - _impl_._oneof_case_[6] = HAS_TILESET_LAST_MODIFIED_NOT_SET; + _impl_._oneof_case_[6] = HAS_OSM_CHANGESET_NOT_SET; } @@ -313,13 +333,15 @@ void Status::Clear() { (void) cached_has_bits; _impl_.available_actions_.Clear(); + _impl_.version_.ClearToEmpty(); + _impl_.tileset_last_modified_ = 0u; clear_has_has_tiles(); clear_has_has_admins(); clear_has_has_timezones(); clear_has_has_live_traffic(); clear_has_bbox(); - clear_has_version(); - clear_has_tileset_last_modified(); + clear_has_has_transit_tiles(); + clear_has_osm_changeset(); _internal_metadata_.Clear(); } @@ -384,7 +406,7 @@ const char* Status::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { // uint32 tileset_last_modified = 7; case 7: if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 56)) { - _internal_set_tileset_last_modified(::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr)); + _impl_.tileset_last_modified_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); CHK_(ptr); } else goto handle_unusual; @@ -404,6 +426,22 @@ const char* Status::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { } else goto handle_unusual; continue; + // bool has_transit_tiles = 9; + case 9: + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 72)) { + _internal_set_has_transit_tiles(::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr)); + CHK_(ptr); + } else + goto handle_unusual; + continue; + // uint64 osm_changeset = 10; + case 10: + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 80)) { + _internal_set_osm_changeset(::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr)); + CHK_(ptr); + } else + goto handle_unusual; + continue; default: goto handle_unusual; } // switch @@ -468,7 +506,7 @@ uint8_t* Status::_InternalSerialize( } // string version = 6; - if (_internal_has_version()) { + if (!this->_internal_version().empty()) { ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( this->_internal_version().data(), static_cast(this->_internal_version().length()), ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, @@ -478,7 +516,7 @@ uint8_t* Status::_InternalSerialize( } // uint32 tileset_last_modified = 7; - if (_internal_has_tileset_last_modified()) { + if (this->_internal_tileset_last_modified() != 0) { target = stream->EnsureSpace(target); target = ::_pbi::WireFormatLite::WriteUInt32ToArray(7, this->_internal_tileset_last_modified(), target); } @@ -493,6 +531,18 @@ uint8_t* Status::_InternalSerialize( target = stream->WriteString(8, s, target); } + // bool has_transit_tiles = 9; + if (_internal_has_has_transit_tiles()) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteBoolToArray(9, this->_internal_has_transit_tiles(), target); + } + + // uint64 osm_changeset = 10; + if (_internal_has_osm_changeset()) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteUInt64ToArray(10, this->_internal_osm_changeset(), target); + } + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { target = stream->WriteRaw(_internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).data(), static_cast(_internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).size()), target); @@ -517,6 +567,18 @@ size_t Status::ByteSizeLong() const { _impl_.available_actions_.Get(i)); } + // string version = 6; + if (!this->_internal_version().empty()) { + total_size += 1 + + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( + this->_internal_version()); + } + + // uint32 tileset_last_modified = 7; + if (this->_internal_tileset_last_modified() != 0) { + total_size += ::_pbi::WireFormatLite::UInt32SizePlusOne(this->_internal_tileset_last_modified()); + } + switch (has_has_tiles_case()) { // bool has_tiles = 1; case kHasTiles: { @@ -569,25 +631,23 @@ size_t Status::ByteSizeLong() const { break; } } - switch (has_version_case()) { - // string version = 6; - case kVersion: { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_version()); + switch (has_has_transit_tiles_case()) { + // bool has_transit_tiles = 9; + case kHasTransitTiles: { + total_size += 1 + 1; break; } - case HAS_VERSION_NOT_SET: { + case HAS_HAS_TRANSIT_TILES_NOT_SET: { break; } } - switch (has_tileset_last_modified_case()) { - // uint32 tileset_last_modified = 7; - case kTilesetLastModified: { - total_size += ::_pbi::WireFormatLite::UInt32SizePlusOne(this->_internal_tileset_last_modified()); + switch (has_osm_changeset_case()) { + // uint64 osm_changeset = 10; + case kOsmChangeset: { + total_size += ::_pbi::WireFormatLite::UInt64SizePlusOne(this->_internal_osm_changeset()); break; } - case HAS_TILESET_LAST_MODIFIED_NOT_SET: { + case HAS_OSM_CHANGESET_NOT_SET: { break; } } @@ -613,6 +673,12 @@ void Status::MergeFrom(const Status& from) { (void) cached_has_bits; _this->_impl_.available_actions_.MergeFrom(from._impl_.available_actions_); + if (!from._internal_version().empty()) { + _this->_internal_set_version(from._internal_version()); + } + if (from._internal_tileset_last_modified() != 0) { + _this->_internal_set_tileset_last_modified(from._internal_tileset_last_modified()); + } switch (from.has_has_tiles_case()) { case kHasTiles: { _this->_internal_set_has_tiles(from._internal_has_tiles()); @@ -658,21 +724,21 @@ void Status::MergeFrom(const Status& from) { break; } } - switch (from.has_version_case()) { - case kVersion: { - _this->_internal_set_version(from._internal_version()); + switch (from.has_has_transit_tiles_case()) { + case kHasTransitTiles: { + _this->_internal_set_has_transit_tiles(from._internal_has_transit_tiles()); break; } - case HAS_VERSION_NOT_SET: { + case HAS_HAS_TRANSIT_TILES_NOT_SET: { break; } } - switch (from.has_tileset_last_modified_case()) { - case kTilesetLastModified: { - _this->_internal_set_tileset_last_modified(from._internal_tileset_last_modified()); + switch (from.has_osm_changeset_case()) { + case kOsmChangeset: { + _this->_internal_set_osm_changeset(from._internal_osm_changeset()); break; } - case HAS_TILESET_LAST_MODIFIED_NOT_SET: { + case HAS_OSM_CHANGESET_NOT_SET: { break; } } @@ -692,15 +758,22 @@ bool Status::IsInitialized() const { void Status::InternalSwap(Status* other) { using std::swap; + auto* lhs_arena = GetArenaForAllocation(); + auto* rhs_arena = other->GetArenaForAllocation(); _internal_metadata_.InternalSwap(&other->_internal_metadata_); _impl_.available_actions_.InternalSwap(&other->_impl_.available_actions_); + ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( + &_impl_.version_, lhs_arena, + &other->_impl_.version_, rhs_arena + ); + swap(_impl_.tileset_last_modified_, other->_impl_.tileset_last_modified_); swap(_impl_.has_has_tiles_, other->_impl_.has_has_tiles_); swap(_impl_.has_has_admins_, other->_impl_.has_has_admins_); swap(_impl_.has_has_timezones_, other->_impl_.has_has_timezones_); swap(_impl_.has_has_live_traffic_, other->_impl_.has_has_live_traffic_); swap(_impl_.has_bbox_, other->_impl_.has_bbox_); - swap(_impl_.has_version_, other->_impl_.has_version_); - swap(_impl_.has_tileset_last_modified_, other->_impl_.has_tileset_last_modified_); + swap(_impl_.has_has_transit_tiles_, other->_impl_.has_has_transit_tiles_); + swap(_impl_.has_osm_changeset_, other->_impl_.has_osm_changeset_); swap(_impl_._oneof_case_[0], other->_impl_._oneof_case_[0]); swap(_impl_._oneof_case_[1], other->_impl_._oneof_case_[1]); swap(_impl_._oneof_case_[2], other->_impl_._oneof_case_[2]); diff --git a/include/darwin/valhalla/proto/status.pb.h b/include/darwin/valhalla/proto/status.pb.h index 08af0a3..0d0bfdf 100644 --- a/include/darwin/valhalla/proto/status.pb.h +++ b/include/darwin/valhalla/proto/status.pb.h @@ -112,14 +112,14 @@ class Status final : HAS_BBOX_NOT_SET = 0, }; - enum HasVersionCase { - kVersion = 6, - HAS_VERSION_NOT_SET = 0, + enum HasHasTransitTilesCase { + kHasTransitTiles = 9, + HAS_HAS_TRANSIT_TILES_NOT_SET = 0, }; - enum HasTilesetLastModifiedCase { - kTilesetLastModified = 7, - HAS_TILESET_LAST_MODIFIED_NOT_SET = 0, + enum HasOsmChangesetCase { + kOsmChangeset = 10, + HAS_OSM_CHANGESET_NOT_SET = 0, }; static inline const Status* internal_default_instance() { @@ -192,13 +192,15 @@ class Status final : enum : int { kAvailableActionsFieldNumber = 8, + kVersionFieldNumber = 6, + kTilesetLastModifiedFieldNumber = 7, kHasTilesFieldNumber = 1, kHasAdminsFieldNumber = 2, kHasTimezonesFieldNumber = 3, kHasLiveTrafficFieldNumber = 4, kBboxFieldNumber = 5, - kVersionFieldNumber = 6, - kTilesetLastModifiedFieldNumber = 7, + kHasTransitTilesFieldNumber = 9, + kOsmChangesetFieldNumber = 10, }; // repeated string available_actions = 8; int available_actions_size() const; @@ -224,6 +226,29 @@ class Status final : std::string* _internal_add_available_actions(); public: + // string version = 6; + void clear_version(); + const std::string& version() const; + template + void set_version(ArgT0&& arg0, ArgT... args); + std::string* mutable_version(); + PROTOBUF_NODISCARD std::string* release_version(); + void set_allocated_version(std::string* version); + private: + const std::string& _internal_version() const; + inline PROTOBUF_ALWAYS_INLINE void _internal_set_version(const std::string& value); + std::string* _internal_mutable_version(); + public: + + // uint32 tileset_last_modified = 7; + void clear_tileset_last_modified(); + uint32_t tileset_last_modified() const; + void set_tileset_last_modified(uint32_t value); + private: + uint32_t _internal_tileset_last_modified() const; + void _internal_set_tileset_last_modified(uint32_t value); + public: + // bool has_tiles = 1; bool has_has_tiles() const; private: @@ -294,35 +319,30 @@ class Status final : std::string* _internal_mutable_bbox(); public: - // string version = 6; - bool has_version() const; + // bool has_transit_tiles = 9; + bool has_has_transit_tiles() const; private: - bool _internal_has_version() const; + bool _internal_has_has_transit_tiles() const; public: - void clear_version(); - const std::string& version() const; - template - void set_version(ArgT0&& arg0, ArgT... args); - std::string* mutable_version(); - PROTOBUF_NODISCARD std::string* release_version(); - void set_allocated_version(std::string* version); + void clear_has_transit_tiles(); + bool has_transit_tiles() const; + void set_has_transit_tiles(bool value); private: - const std::string& _internal_version() const; - inline PROTOBUF_ALWAYS_INLINE void _internal_set_version(const std::string& value); - std::string* _internal_mutable_version(); + bool _internal_has_transit_tiles() const; + void _internal_set_has_transit_tiles(bool value); public: - // uint32 tileset_last_modified = 7; - bool has_tileset_last_modified() const; + // uint64 osm_changeset = 10; + bool has_osm_changeset() const; private: - bool _internal_has_tileset_last_modified() const; + bool _internal_has_osm_changeset() const; public: - void clear_tileset_last_modified(); - uint32_t tileset_last_modified() const; - void set_tileset_last_modified(uint32_t value); + void clear_osm_changeset(); + uint64_t osm_changeset() const; + void set_osm_changeset(uint64_t value); private: - uint32_t _internal_tileset_last_modified() const; - void _internal_set_tileset_last_modified(uint32_t value); + uint64_t _internal_osm_changeset() const; + void _internal_set_osm_changeset(uint64_t value); public: void clear_has_has_tiles(); @@ -335,10 +355,10 @@ class Status final : HasHasLiveTrafficCase has_has_live_traffic_case() const; void clear_has_bbox(); HasBboxCase has_bbox_case() const; - void clear_has_version(); - HasVersionCase has_version_case() const; - void clear_has_tileset_last_modified(); - HasTilesetLastModifiedCase has_tileset_last_modified_case() const; + void clear_has_has_transit_tiles(); + HasHasTransitTilesCase has_has_transit_tiles_case() const; + void clear_has_osm_changeset(); + HasOsmChangesetCase has_osm_changeset_case() const; // @@protoc_insertion_point(class_scope:valhalla.Status) private: class _Internal; @@ -347,8 +367,8 @@ class Status final : void set_has_has_timezones(); void set_has_has_live_traffic(); void set_has_bbox(); - void set_has_version(); - void set_has_tileset_last_modified(); + void set_has_has_transit_tiles(); + void set_has_osm_changeset(); inline bool has_has_has_tiles() const; inline void clear_has_has_has_tiles(); @@ -365,17 +385,19 @@ class Status final : inline bool has_has_bbox() const; inline void clear_has_has_bbox(); - inline bool has_has_version() const; - inline void clear_has_has_version(); + inline bool has_has_has_transit_tiles() const; + inline void clear_has_has_has_transit_tiles(); - inline bool has_has_tileset_last_modified() const; - inline void clear_has_has_tileset_last_modified(); + inline bool has_has_osm_changeset() const; + inline void clear_has_has_osm_changeset(); template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; struct Impl_ { ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField available_actions_; + ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr version_; + uint32_t tileset_last_modified_; union HasHasTilesUnion { constexpr HasHasTilesUnion() : _constinit_{} {} ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized _constinit_; @@ -401,16 +423,16 @@ class Status final : ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized _constinit_; ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr bbox_; } has_bbox_; - union HasVersionUnion { - constexpr HasVersionUnion() : _constinit_{} {} + union HasHasTransitTilesUnion { + constexpr HasHasTransitTilesUnion() : _constinit_{} {} ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized _constinit_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr version_; - } has_version_; - union HasTilesetLastModifiedUnion { - constexpr HasTilesetLastModifiedUnion() : _constinit_{} {} + bool has_transit_tiles_; + } has_has_transit_tiles_; + union HasOsmChangesetUnion { + constexpr HasOsmChangesetUnion() : _constinit_{} {} ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized _constinit_; - uint32_t tileset_last_modified_; - } has_tileset_last_modified_; + uint64_t osm_changeset_; + } has_osm_changeset_; mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; uint32_t _oneof_case_[7]; @@ -659,33 +681,18 @@ inline void Status::set_allocated_bbox(std::string* bbox) { } // string version = 6; -inline bool Status::_internal_has_version() const { - return has_version_case() == kVersion; -} -inline bool Status::has_version() const { - return _internal_has_version(); -} -inline void Status::set_has_version() { - _impl_._oneof_case_[5] = kVersion; -} inline void Status::clear_version() { - if (_internal_has_version()) { - _impl_.has_version_.version_.Destroy(); - clear_has_has_version(); - } + _impl_.version_.ClearToEmpty(); } inline const std::string& Status::version() const { // @@protoc_insertion_point(field_get:valhalla.Status.version) return _internal_version(); } template -inline void Status::set_version(ArgT0&& arg0, ArgT... args) { - if (!_internal_has_version()) { - clear_has_version(); - set_has_version(); - _impl_.has_version_.version_.InitDefault(); - } - _impl_.has_version_.version_.Set( static_cast(arg0), args..., GetArenaForAllocation()); +inline PROTOBUF_ALWAYS_INLINE +void Status::set_version(ArgT0&& arg0, ArgT... args) { + + _impl_.version_.Set(static_cast(arg0), args..., GetArenaForAllocation()); // @@protoc_insertion_point(field_set:valhalla.Status.version) } inline std::string* Status::mutable_version() { @@ -694,80 +701,50 @@ inline std::string* Status::mutable_version() { return _s; } inline const std::string& Status::_internal_version() const { - if (_internal_has_version()) { - return _impl_.has_version_.version_.Get(); - } - return ::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(); + return _impl_.version_.Get(); } inline void Status::_internal_set_version(const std::string& value) { - if (!_internal_has_version()) { - clear_has_version(); - set_has_version(); - _impl_.has_version_.version_.InitDefault(); - } - _impl_.has_version_.version_.Set(value, GetArenaForAllocation()); + + _impl_.version_.Set(value, GetArenaForAllocation()); } inline std::string* Status::_internal_mutable_version() { - if (!_internal_has_version()) { - clear_has_version(); - set_has_version(); - _impl_.has_version_.version_.InitDefault(); - } - return _impl_.has_version_.version_.Mutable( GetArenaForAllocation()); + + return _impl_.version_.Mutable(GetArenaForAllocation()); } inline std::string* Status::release_version() { // @@protoc_insertion_point(field_release:valhalla.Status.version) - if (_internal_has_version()) { - clear_has_has_version(); - return _impl_.has_version_.version_.Release(); - } else { - return nullptr; - } + return _impl_.version_.Release(); } inline void Status::set_allocated_version(std::string* version) { - if (has_has_version()) { - clear_has_version(); - } if (version != nullptr) { - set_has_version(); - _impl_.has_version_.version_.InitAllocated(version, GetArenaForAllocation()); + + } else { + + } + _impl_.version_.SetAllocated(version, GetArenaForAllocation()); +#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + if (_impl_.version_.IsDefault()) { + _impl_.version_.Set("", GetArenaForAllocation()); } +#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING // @@protoc_insertion_point(field_set_allocated:valhalla.Status.version) } // uint32 tileset_last_modified = 7; -inline bool Status::_internal_has_tileset_last_modified() const { - return has_tileset_last_modified_case() == kTilesetLastModified; -} -inline bool Status::has_tileset_last_modified() const { - return _internal_has_tileset_last_modified(); -} -inline void Status::set_has_tileset_last_modified() { - _impl_._oneof_case_[6] = kTilesetLastModified; -} inline void Status::clear_tileset_last_modified() { - if (_internal_has_tileset_last_modified()) { - _impl_.has_tileset_last_modified_.tileset_last_modified_ = 0u; - clear_has_has_tileset_last_modified(); - } + _impl_.tileset_last_modified_ = 0u; } inline uint32_t Status::_internal_tileset_last_modified() const { - if (_internal_has_tileset_last_modified()) { - return _impl_.has_tileset_last_modified_.tileset_last_modified_; - } - return 0u; -} -inline void Status::_internal_set_tileset_last_modified(uint32_t value) { - if (!_internal_has_tileset_last_modified()) { - clear_has_tileset_last_modified(); - set_has_tileset_last_modified(); - } - _impl_.has_tileset_last_modified_.tileset_last_modified_ = value; + return _impl_.tileset_last_modified_; } inline uint32_t Status::tileset_last_modified() const { // @@protoc_insertion_point(field_get:valhalla.Status.tileset_last_modified) return _internal_tileset_last_modified(); } +inline void Status::_internal_set_tileset_last_modified(uint32_t value) { + + _impl_.tileset_last_modified_ = value; +} inline void Status::set_tileset_last_modified(uint32_t value) { _internal_set_tileset_last_modified(value); // @@protoc_insertion_point(field_set:valhalla.Status.tileset_last_modified) @@ -848,6 +825,82 @@ Status::mutable_available_actions() { return &_impl_.available_actions_; } +// bool has_transit_tiles = 9; +inline bool Status::_internal_has_has_transit_tiles() const { + return has_has_transit_tiles_case() == kHasTransitTiles; +} +inline bool Status::has_has_transit_tiles() const { + return _internal_has_has_transit_tiles(); +} +inline void Status::set_has_has_transit_tiles() { + _impl_._oneof_case_[5] = kHasTransitTiles; +} +inline void Status::clear_has_transit_tiles() { + if (_internal_has_has_transit_tiles()) { + _impl_.has_has_transit_tiles_.has_transit_tiles_ = false; + clear_has_has_has_transit_tiles(); + } +} +inline bool Status::_internal_has_transit_tiles() const { + if (_internal_has_has_transit_tiles()) { + return _impl_.has_has_transit_tiles_.has_transit_tiles_; + } + return false; +} +inline void Status::_internal_set_has_transit_tiles(bool value) { + if (!_internal_has_has_transit_tiles()) { + clear_has_has_transit_tiles(); + set_has_has_transit_tiles(); + } + _impl_.has_has_transit_tiles_.has_transit_tiles_ = value; +} +inline bool Status::has_transit_tiles() const { + // @@protoc_insertion_point(field_get:valhalla.Status.has_transit_tiles) + return _internal_has_transit_tiles(); +} +inline void Status::set_has_transit_tiles(bool value) { + _internal_set_has_transit_tiles(value); + // @@protoc_insertion_point(field_set:valhalla.Status.has_transit_tiles) +} + +// uint64 osm_changeset = 10; +inline bool Status::_internal_has_osm_changeset() const { + return has_osm_changeset_case() == kOsmChangeset; +} +inline bool Status::has_osm_changeset() const { + return _internal_has_osm_changeset(); +} +inline void Status::set_has_osm_changeset() { + _impl_._oneof_case_[6] = kOsmChangeset; +} +inline void Status::clear_osm_changeset() { + if (_internal_has_osm_changeset()) { + _impl_.has_osm_changeset_.osm_changeset_ = uint64_t{0u}; + clear_has_has_osm_changeset(); + } +} +inline uint64_t Status::_internal_osm_changeset() const { + if (_internal_has_osm_changeset()) { + return _impl_.has_osm_changeset_.osm_changeset_; + } + return uint64_t{0u}; +} +inline void Status::_internal_set_osm_changeset(uint64_t value) { + if (!_internal_has_osm_changeset()) { + clear_has_osm_changeset(); + set_has_osm_changeset(); + } + _impl_.has_osm_changeset_.osm_changeset_ = value; +} +inline uint64_t Status::osm_changeset() const { + // @@protoc_insertion_point(field_get:valhalla.Status.osm_changeset) + return _internal_osm_changeset(); +} +inline void Status::set_osm_changeset(uint64_t value) { + _internal_set_osm_changeset(value); + // @@protoc_insertion_point(field_set:valhalla.Status.osm_changeset) +} + inline bool Status::has_has_has_tiles() const { return has_has_tiles_case() != HAS_HAS_TILES_NOT_SET; } @@ -878,17 +931,17 @@ inline bool Status::has_has_bbox() const { inline void Status::clear_has_has_bbox() { _impl_._oneof_case_[4] = HAS_BBOX_NOT_SET; } -inline bool Status::has_has_version() const { - return has_version_case() != HAS_VERSION_NOT_SET; +inline bool Status::has_has_has_transit_tiles() const { + return has_has_transit_tiles_case() != HAS_HAS_TRANSIT_TILES_NOT_SET; } -inline void Status::clear_has_has_version() { - _impl_._oneof_case_[5] = HAS_VERSION_NOT_SET; +inline void Status::clear_has_has_has_transit_tiles() { + _impl_._oneof_case_[5] = HAS_HAS_TRANSIT_TILES_NOT_SET; } -inline bool Status::has_has_tileset_last_modified() const { - return has_tileset_last_modified_case() != HAS_TILESET_LAST_MODIFIED_NOT_SET; +inline bool Status::has_has_osm_changeset() const { + return has_osm_changeset_case() != HAS_OSM_CHANGESET_NOT_SET; } -inline void Status::clear_has_has_tileset_last_modified() { - _impl_._oneof_case_[6] = HAS_TILESET_LAST_MODIFIED_NOT_SET; +inline void Status::clear_has_has_osm_changeset() { + _impl_._oneof_case_[6] = HAS_OSM_CHANGESET_NOT_SET; } inline Status::HasHasTilesCase Status::has_has_tiles_case() const { return Status::HasHasTilesCase(_impl_._oneof_case_[0]); @@ -905,11 +958,11 @@ inline Status::HasHasLiveTrafficCase Status::has_has_live_traffic_case() const { inline Status::HasBboxCase Status::has_bbox_case() const { return Status::HasBboxCase(_impl_._oneof_case_[4]); } -inline Status::HasVersionCase Status::has_version_case() const { - return Status::HasVersionCase(_impl_._oneof_case_[5]); +inline Status::HasHasTransitTilesCase Status::has_has_transit_tiles_case() const { + return Status::HasHasTransitTilesCase(_impl_._oneof_case_[5]); } -inline Status::HasTilesetLastModifiedCase Status::has_tileset_last_modified_case() const { - return Status::HasTilesetLastModifiedCase(_impl_._oneof_case_[6]); +inline Status::HasOsmChangesetCase Status::has_osm_changeset_case() const { + return Status::HasOsmChangesetCase(_impl_._oneof_case_[6]); } #ifdef __GNUC__ #pragma GCC diagnostic pop diff --git a/include/darwin/valhalla/proto/transit.pb.cc b/include/darwin/valhalla/proto/transit.pb.cc index 95b0846..7150fe1 100644 --- a/include/darwin/valhalla/proto/transit.pb.cc +++ b/include/darwin/valhalla/proto/transit.pb.cc @@ -30,10 +30,12 @@ PROTOBUF_CONSTEXPR Transit_Node::Transit_Node( , /*decltype(_impl_.lat_)*/0 , /*decltype(_impl_.graphid_)*/uint64_t{0u} , /*decltype(_impl_.prev_type_graphid_)*/uint64_t{0u} - , /*decltype(_impl_.osm_way_id_)*/uint64_t{0u} + , /*decltype(_impl_.osm_connecting_way_id_)*/uint64_t{0u} , /*decltype(_impl_.type_)*/0u , /*decltype(_impl_.wheelchair_boarding_)*/false , /*decltype(_impl_.generated_)*/false + , /*decltype(_impl_.osm_connecting_lon_)*/0 + , /*decltype(_impl_.osm_connecting_lat_)*/0 , /*decltype(_impl_.traversability_)*/0u} {} struct Transit_NodeDefaultTypeInternal { PROTOBUF_CONSTEXPR Transit_NodeDefaultTypeInternal() @@ -253,7 +255,7 @@ class Transit_Node::_Internal { static void set_has_onestop_id(HasBits* has_bits) { (*has_bits)[0] |= 2u; } - static void set_has_osm_way_id(HasBits* has_bits) { + static void set_has_osm_connecting_way_id(HasBits* has_bits) { (*has_bits)[0] |= 128u; } static void set_has_timezone(HasBits* has_bits) { @@ -266,8 +268,14 @@ class Transit_Node::_Internal { (*has_bits)[0] |= 1024u; } static void set_has_traversability(HasBits* has_bits) { + (*has_bits)[0] |= 8192u; + } + static void set_has_osm_connecting_lon(HasBits* has_bits) { (*has_bits)[0] |= 2048u; } + static void set_has_osm_connecting_lat(HasBits* has_bits) { + (*has_bits)[0] |= 4096u; + } }; Transit_Node::Transit_Node(::PROTOBUF_NAMESPACE_ID::Arena* arena, @@ -289,10 +297,12 @@ Transit_Node::Transit_Node(const Transit_Node& from) , decltype(_impl_.lat_){} , decltype(_impl_.graphid_){} , decltype(_impl_.prev_type_graphid_){} - , decltype(_impl_.osm_way_id_){} + , decltype(_impl_.osm_connecting_way_id_){} , decltype(_impl_.type_){} , decltype(_impl_.wheelchair_boarding_){} , decltype(_impl_.generated_){} + , decltype(_impl_.osm_connecting_lon_){} + , decltype(_impl_.osm_connecting_lat_){} , decltype(_impl_.traversability_){}}; _internal_metadata_.MergeFrom(from._internal_metadata_); @@ -340,10 +350,12 @@ inline void Transit_Node::SharedCtor( , decltype(_impl_.lat_){0} , decltype(_impl_.graphid_){uint64_t{0u}} , decltype(_impl_.prev_type_graphid_){uint64_t{0u}} - , decltype(_impl_.osm_way_id_){uint64_t{0u}} + , decltype(_impl_.osm_connecting_way_id_){uint64_t{0u}} , decltype(_impl_.type_){0u} , decltype(_impl_.wheelchair_boarding_){false} , decltype(_impl_.generated_){false} + , decltype(_impl_.osm_connecting_lon_){0} + , decltype(_impl_.osm_connecting_lat_){0} , decltype(_impl_.traversability_){0u} }; _impl_.name_.InitDefault(); @@ -400,10 +412,10 @@ void Transit_Node::Clear() { } if (cached_has_bits & 0x000000f8u) { ::memset(&_impl_.lon_, 0, static_cast( - reinterpret_cast(&_impl_.osm_way_id_) - - reinterpret_cast(&_impl_.lon_)) + sizeof(_impl_.osm_way_id_)); + reinterpret_cast(&_impl_.osm_connecting_way_id_) - + reinterpret_cast(&_impl_.lon_)) + sizeof(_impl_.osm_connecting_way_id_)); } - if (cached_has_bits & 0x00000f00u) { + if (cached_has_bits & 0x00003f00u) { ::memset(&_impl_.type_, 0, static_cast( reinterpret_cast(&_impl_.traversability_) - reinterpret_cast(&_impl_.type_)) + sizeof(_impl_.traversability_)); @@ -419,21 +431,21 @@ const char* Transit_Node::_InternalParse(const char* ptr, ::_pbi::ParseContext* uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { - // optional float lon = 1; + // optional double lon = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 13)) { + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 9)) { _Internal::set_has_lon(&has_bits); - _impl_.lon_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad(ptr); - ptr += sizeof(float); + _impl_.lon_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad(ptr); + ptr += sizeof(double); } else goto handle_unusual; continue; - // optional float lat = 2; + // optional double lat = 2; case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 21)) { + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 17)) { _Internal::set_has_lat(&has_bits); - _impl_.lat_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad(ptr); - ptr += sizeof(float); + _impl_.lat_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad(ptr); + ptr += sizeof(double); } else goto handle_unusual; continue; @@ -482,11 +494,11 @@ const char* Transit_Node::_InternalParse(const char* ptr, ::_pbi::ParseContext* } else goto handle_unusual; continue; - // optional uint64 osm_way_id = 8; + // optional uint64 osm_connecting_way_id = 8; case 8: if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 64)) { - _Internal::set_has_osm_way_id(&has_bits); - _impl_.osm_way_id_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); + _Internal::set_has_osm_connecting_way_id(&has_bits); + _impl_.osm_connecting_way_id_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); CHK_(ptr); } else goto handle_unusual; @@ -527,6 +539,24 @@ const char* Transit_Node::_InternalParse(const char* ptr, ::_pbi::ParseContext* } else goto handle_unusual; continue; + // optional double osm_connecting_lon = 13; + case 13: + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 105)) { + _Internal::set_has_osm_connecting_lon(&has_bits); + _impl_.osm_connecting_lon_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad(ptr); + ptr += sizeof(double); + } else + goto handle_unusual; + continue; + // optional double osm_connecting_lat = 14; + case 14: + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 113)) { + _Internal::set_has_osm_connecting_lat(&has_bits); + _impl_.osm_connecting_lat_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad(ptr); + ptr += sizeof(double); + } else + goto handle_unusual; + continue; default: goto handle_unusual; } // switch @@ -558,16 +588,16 @@ uint8_t* Transit_Node::_InternalSerialize( (void) cached_has_bits; cached_has_bits = _impl_._has_bits_[0]; - // optional float lon = 1; + // optional double lon = 1; if (cached_has_bits & 0x00000008u) { target = stream->EnsureSpace(target); - target = ::_pbi::WireFormatLite::WriteFloatToArray(1, this->_internal_lon(), target); + target = ::_pbi::WireFormatLite::WriteDoubleToArray(1, this->_internal_lon(), target); } - // optional float lat = 2; + // optional double lat = 2; if (cached_has_bits & 0x00000010u) { target = stream->EnsureSpace(target); - target = ::_pbi::WireFormatLite::WriteFloatToArray(2, this->_internal_lat(), target); + target = ::_pbi::WireFormatLite::WriteDoubleToArray(2, this->_internal_lat(), target); } // optional uint32 type = 3; @@ -600,10 +630,10 @@ uint8_t* Transit_Node::_InternalSerialize( 7, this->_internal_onestop_id(), target); } - // optional uint64 osm_way_id = 8; + // optional uint64 osm_connecting_way_id = 8; if (cached_has_bits & 0x00000080u) { target = stream->EnsureSpace(target); - target = ::_pbi::WireFormatLite::WriteUInt64ToArray(8, this->_internal_osm_way_id(), target); + target = ::_pbi::WireFormatLite::WriteUInt64ToArray(8, this->_internal_osm_connecting_way_id(), target); } // optional string timezone = 9; @@ -625,11 +655,23 @@ uint8_t* Transit_Node::_InternalSerialize( } // optional uint32 traversability = 12; - if (cached_has_bits & 0x00000800u) { + if (cached_has_bits & 0x00002000u) { target = stream->EnsureSpace(target); target = ::_pbi::WireFormatLite::WriteUInt32ToArray(12, this->_internal_traversability(), target); } + // optional double osm_connecting_lon = 13; + if (cached_has_bits & 0x00000800u) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteDoubleToArray(13, this->_internal_osm_connecting_lon(), target); + } + + // optional double osm_connecting_lat = 14; + if (cached_has_bits & 0x00001000u) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteDoubleToArray(14, this->_internal_osm_connecting_lat(), target); + } + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { target = stream->WriteRaw(_internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).data(), static_cast(_internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).size()), target); @@ -669,14 +711,14 @@ size_t Transit_Node::ByteSizeLong() const { this->_internal_timezone()); } - // optional float lon = 1; + // optional double lon = 1; if (cached_has_bits & 0x00000008u) { - total_size += 1 + 4; + total_size += 1 + 8; } - // optional float lat = 2; + // optional double lat = 2; if (cached_has_bits & 0x00000010u) { - total_size += 1 + 4; + total_size += 1 + 8; } // optional uint64 graphid = 4; @@ -689,13 +731,13 @@ size_t Transit_Node::ByteSizeLong() const { total_size += ::_pbi::WireFormatLite::UInt64SizePlusOne(this->_internal_prev_type_graphid()); } - // optional uint64 osm_way_id = 8; + // optional uint64 osm_connecting_way_id = 8; if (cached_has_bits & 0x00000080u) { - total_size += ::_pbi::WireFormatLite::UInt64SizePlusOne(this->_internal_osm_way_id()); + total_size += ::_pbi::WireFormatLite::UInt64SizePlusOne(this->_internal_osm_connecting_way_id()); } } - if (cached_has_bits & 0x00000f00u) { + if (cached_has_bits & 0x00003f00u) { // optional uint32 type = 3; if (cached_has_bits & 0x00000100u) { total_size += ::_pbi::WireFormatLite::UInt32SizePlusOne(this->_internal_type()); @@ -711,8 +753,18 @@ size_t Transit_Node::ByteSizeLong() const { total_size += 1 + 1; } - // optional uint32 traversability = 12; + // optional double osm_connecting_lon = 13; if (cached_has_bits & 0x00000800u) { + total_size += 1 + 8; + } + + // optional double osm_connecting_lat = 14; + if (cached_has_bits & 0x00001000u) { + total_size += 1 + 8; + } + + // optional uint32 traversability = 12; + if (cached_has_bits & 0x00002000u) { total_size += ::_pbi::WireFormatLite::UInt32SizePlusOne(this->_internal_traversability()); } @@ -762,11 +814,11 @@ void Transit_Node::MergeFrom(const Transit_Node& from) { _this->_impl_.prev_type_graphid_ = from._impl_.prev_type_graphid_; } if (cached_has_bits & 0x00000080u) { - _this->_impl_.osm_way_id_ = from._impl_.osm_way_id_; + _this->_impl_.osm_connecting_way_id_ = from._impl_.osm_connecting_way_id_; } _this->_impl_._has_bits_[0] |= cached_has_bits; } - if (cached_has_bits & 0x00000f00u) { + if (cached_has_bits & 0x00003f00u) { if (cached_has_bits & 0x00000100u) { _this->_impl_.type_ = from._impl_.type_; } @@ -777,6 +829,12 @@ void Transit_Node::MergeFrom(const Transit_Node& from) { _this->_impl_.generated_ = from._impl_.generated_; } if (cached_has_bits & 0x00000800u) { + _this->_impl_.osm_connecting_lon_ = from._impl_.osm_connecting_lon_; + } + if (cached_has_bits & 0x00001000u) { + _this->_impl_.osm_connecting_lat_ = from._impl_.osm_connecting_lat_; + } + if (cached_has_bits & 0x00002000u) { _this->_impl_.traversability_ = from._impl_.traversability_; } _this->_impl_._has_bits_[0] |= cached_has_bits; diff --git a/include/darwin/valhalla/proto/transit.pb.h b/include/darwin/valhalla/proto/transit.pb.h index 2b16ca7..d3e2436 100644 --- a/include/darwin/valhalla/proto/transit.pb.h +++ b/include/darwin/valhalla/proto/transit.pb.h @@ -215,10 +215,12 @@ class Transit_Node final : kLatFieldNumber = 2, kGraphidFieldNumber = 4, kPrevTypeGraphidFieldNumber = 5, - kOsmWayIdFieldNumber = 8, + kOsmConnectingWayIdFieldNumber = 8, kTypeFieldNumber = 3, kWheelchairBoardingFieldNumber = 10, kGeneratedFieldNumber = 11, + kOsmConnectingLonFieldNumber = 13, + kOsmConnectingLatFieldNumber = 14, kTraversabilityFieldNumber = 12, }; // optional string name = 6; @@ -275,30 +277,30 @@ class Transit_Node final : std::string* _internal_mutable_timezone(); public: - // optional float lon = 1; + // optional double lon = 1; bool has_lon() const; private: bool _internal_has_lon() const; public: void clear_lon(); - float lon() const; - void set_lon(float value); + double lon() const; + void set_lon(double value); private: - float _internal_lon() const; - void _internal_set_lon(float value); + double _internal_lon() const; + void _internal_set_lon(double value); public: - // optional float lat = 2; + // optional double lat = 2; bool has_lat() const; private: bool _internal_has_lat() const; public: void clear_lat(); - float lat() const; - void set_lat(float value); + double lat() const; + void set_lat(double value); private: - float _internal_lat() const; - void _internal_set_lat(float value); + double _internal_lat() const; + void _internal_set_lat(double value); public: // optional uint64 graphid = 4; @@ -327,17 +329,17 @@ class Transit_Node final : void _internal_set_prev_type_graphid(uint64_t value); public: - // optional uint64 osm_way_id = 8; - bool has_osm_way_id() const; + // optional uint64 osm_connecting_way_id = 8; + bool has_osm_connecting_way_id() const; private: - bool _internal_has_osm_way_id() const; + bool _internal_has_osm_connecting_way_id() const; public: - void clear_osm_way_id(); - uint64_t osm_way_id() const; - void set_osm_way_id(uint64_t value); + void clear_osm_connecting_way_id(); + uint64_t osm_connecting_way_id() const; + void set_osm_connecting_way_id(uint64_t value); private: - uint64_t _internal_osm_way_id() const; - void _internal_set_osm_way_id(uint64_t value); + uint64_t _internal_osm_connecting_way_id() const; + void _internal_set_osm_connecting_way_id(uint64_t value); public: // optional uint32 type = 3; @@ -379,6 +381,32 @@ class Transit_Node final : void _internal_set_generated(bool value); public: + // optional double osm_connecting_lon = 13; + bool has_osm_connecting_lon() const; + private: + bool _internal_has_osm_connecting_lon() const; + public: + void clear_osm_connecting_lon(); + double osm_connecting_lon() const; + void set_osm_connecting_lon(double value); + private: + double _internal_osm_connecting_lon() const; + void _internal_set_osm_connecting_lon(double value); + public: + + // optional double osm_connecting_lat = 14; + bool has_osm_connecting_lat() const; + private: + bool _internal_has_osm_connecting_lat() const; + public: + void clear_osm_connecting_lat(); + double osm_connecting_lat() const; + void set_osm_connecting_lat(double value); + private: + double _internal_osm_connecting_lat() const; + void _internal_set_osm_connecting_lat(double value); + public: + // optional uint32 traversability = 12; bool has_traversability() const; private: @@ -405,14 +433,16 @@ class Transit_Node final : ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_; ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr onestop_id_; ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr timezone_; - float lon_; - float lat_; + double lon_; + double lat_; uint64_t graphid_; uint64_t prev_type_graphid_; - uint64_t osm_way_id_; + uint64_t osm_connecting_way_id_; uint32_t type_; bool wheelchair_boarding_; bool generated_; + double osm_connecting_lon_; + double osm_connecting_lat_; uint32_t traversability_; }; union { Impl_ _impl_; }; @@ -1671,7 +1701,7 @@ class Transit final : #endif // __GNUC__ // Transit_Node -// optional float lon = 1; +// optional double lon = 1; inline bool Transit_Node::_internal_has_lon() const { bool value = (_impl_._has_bits_[0] & 0x00000008u) != 0; return value; @@ -1683,23 +1713,23 @@ inline void Transit_Node::clear_lon() { _impl_.lon_ = 0; _impl_._has_bits_[0] &= ~0x00000008u; } -inline float Transit_Node::_internal_lon() const { +inline double Transit_Node::_internal_lon() const { return _impl_.lon_; } -inline float Transit_Node::lon() const { +inline double Transit_Node::lon() const { // @@protoc_insertion_point(field_get:valhalla.mjolnir.Transit.Node.lon) return _internal_lon(); } -inline void Transit_Node::_internal_set_lon(float value) { +inline void Transit_Node::_internal_set_lon(double value) { _impl_._has_bits_[0] |= 0x00000008u; _impl_.lon_ = value; } -inline void Transit_Node::set_lon(float value) { +inline void Transit_Node::set_lon(double value) { _internal_set_lon(value); // @@protoc_insertion_point(field_set:valhalla.mjolnir.Transit.Node.lon) } -// optional float lat = 2; +// optional double lat = 2; inline bool Transit_Node::_internal_has_lat() const { bool value = (_impl_._has_bits_[0] & 0x00000010u) != 0; return value; @@ -1711,18 +1741,18 @@ inline void Transit_Node::clear_lat() { _impl_.lat_ = 0; _impl_._has_bits_[0] &= ~0x00000010u; } -inline float Transit_Node::_internal_lat() const { +inline double Transit_Node::_internal_lat() const { return _impl_.lat_; } -inline float Transit_Node::lat() const { +inline double Transit_Node::lat() const { // @@protoc_insertion_point(field_get:valhalla.mjolnir.Transit.Node.lat) return _internal_lat(); } -inline void Transit_Node::_internal_set_lat(float value) { +inline void Transit_Node::_internal_set_lat(double value) { _impl_._has_bits_[0] |= 0x00000010u; _impl_.lat_ = value; } -inline void Transit_Node::set_lat(float value) { +inline void Transit_Node::set_lat(double value) { _internal_set_lat(value); // @@protoc_insertion_point(field_set:valhalla.mjolnir.Transit.Node.lat) } @@ -1947,32 +1977,32 @@ inline void Transit_Node::set_allocated_onestop_id(std::string* onestop_id) { // @@protoc_insertion_point(field_set_allocated:valhalla.mjolnir.Transit.Node.onestop_id) } -// optional uint64 osm_way_id = 8; -inline bool Transit_Node::_internal_has_osm_way_id() const { +// optional uint64 osm_connecting_way_id = 8; +inline bool Transit_Node::_internal_has_osm_connecting_way_id() const { bool value = (_impl_._has_bits_[0] & 0x00000080u) != 0; return value; } -inline bool Transit_Node::has_osm_way_id() const { - return _internal_has_osm_way_id(); +inline bool Transit_Node::has_osm_connecting_way_id() const { + return _internal_has_osm_connecting_way_id(); } -inline void Transit_Node::clear_osm_way_id() { - _impl_.osm_way_id_ = uint64_t{0u}; +inline void Transit_Node::clear_osm_connecting_way_id() { + _impl_.osm_connecting_way_id_ = uint64_t{0u}; _impl_._has_bits_[0] &= ~0x00000080u; } -inline uint64_t Transit_Node::_internal_osm_way_id() const { - return _impl_.osm_way_id_; +inline uint64_t Transit_Node::_internal_osm_connecting_way_id() const { + return _impl_.osm_connecting_way_id_; } -inline uint64_t Transit_Node::osm_way_id() const { - // @@protoc_insertion_point(field_get:valhalla.mjolnir.Transit.Node.osm_way_id) - return _internal_osm_way_id(); +inline uint64_t Transit_Node::osm_connecting_way_id() const { + // @@protoc_insertion_point(field_get:valhalla.mjolnir.Transit.Node.osm_connecting_way_id) + return _internal_osm_connecting_way_id(); } -inline void Transit_Node::_internal_set_osm_way_id(uint64_t value) { +inline void Transit_Node::_internal_set_osm_connecting_way_id(uint64_t value) { _impl_._has_bits_[0] |= 0x00000080u; - _impl_.osm_way_id_ = value; + _impl_.osm_connecting_way_id_ = value; } -inline void Transit_Node::set_osm_way_id(uint64_t value) { - _internal_set_osm_way_id(value); - // @@protoc_insertion_point(field_set:valhalla.mjolnir.Transit.Node.osm_way_id) +inline void Transit_Node::set_osm_connecting_way_id(uint64_t value) { + _internal_set_osm_connecting_way_id(value); + // @@protoc_insertion_point(field_set:valhalla.mjolnir.Transit.Node.osm_connecting_way_id) } // optional string timezone = 9; @@ -2101,7 +2131,7 @@ inline void Transit_Node::set_generated(bool value) { // optional uint32 traversability = 12; inline bool Transit_Node::_internal_has_traversability() const { - bool value = (_impl_._has_bits_[0] & 0x00000800u) != 0; + bool value = (_impl_._has_bits_[0] & 0x00002000u) != 0; return value; } inline bool Transit_Node::has_traversability() const { @@ -2109,7 +2139,7 @@ inline bool Transit_Node::has_traversability() const { } inline void Transit_Node::clear_traversability() { _impl_.traversability_ = 0u; - _impl_._has_bits_[0] &= ~0x00000800u; + _impl_._has_bits_[0] &= ~0x00002000u; } inline uint32_t Transit_Node::_internal_traversability() const { return _impl_.traversability_; @@ -2119,7 +2149,7 @@ inline uint32_t Transit_Node::traversability() const { return _internal_traversability(); } inline void Transit_Node::_internal_set_traversability(uint32_t value) { - _impl_._has_bits_[0] |= 0x00000800u; + _impl_._has_bits_[0] |= 0x00002000u; _impl_.traversability_ = value; } inline void Transit_Node::set_traversability(uint32_t value) { @@ -2127,6 +2157,62 @@ inline void Transit_Node::set_traversability(uint32_t value) { // @@protoc_insertion_point(field_set:valhalla.mjolnir.Transit.Node.traversability) } +// optional double osm_connecting_lon = 13; +inline bool Transit_Node::_internal_has_osm_connecting_lon() const { + bool value = (_impl_._has_bits_[0] & 0x00000800u) != 0; + return value; +} +inline bool Transit_Node::has_osm_connecting_lon() const { + return _internal_has_osm_connecting_lon(); +} +inline void Transit_Node::clear_osm_connecting_lon() { + _impl_.osm_connecting_lon_ = 0; + _impl_._has_bits_[0] &= ~0x00000800u; +} +inline double Transit_Node::_internal_osm_connecting_lon() const { + return _impl_.osm_connecting_lon_; +} +inline double Transit_Node::osm_connecting_lon() const { + // @@protoc_insertion_point(field_get:valhalla.mjolnir.Transit.Node.osm_connecting_lon) + return _internal_osm_connecting_lon(); +} +inline void Transit_Node::_internal_set_osm_connecting_lon(double value) { + _impl_._has_bits_[0] |= 0x00000800u; + _impl_.osm_connecting_lon_ = value; +} +inline void Transit_Node::set_osm_connecting_lon(double value) { + _internal_set_osm_connecting_lon(value); + // @@protoc_insertion_point(field_set:valhalla.mjolnir.Transit.Node.osm_connecting_lon) +} + +// optional double osm_connecting_lat = 14; +inline bool Transit_Node::_internal_has_osm_connecting_lat() const { + bool value = (_impl_._has_bits_[0] & 0x00001000u) != 0; + return value; +} +inline bool Transit_Node::has_osm_connecting_lat() const { + return _internal_has_osm_connecting_lat(); +} +inline void Transit_Node::clear_osm_connecting_lat() { + _impl_.osm_connecting_lat_ = 0; + _impl_._has_bits_[0] &= ~0x00001000u; +} +inline double Transit_Node::_internal_osm_connecting_lat() const { + return _impl_.osm_connecting_lat_; +} +inline double Transit_Node::osm_connecting_lat() const { + // @@protoc_insertion_point(field_get:valhalla.mjolnir.Transit.Node.osm_connecting_lat) + return _internal_osm_connecting_lat(); +} +inline void Transit_Node::_internal_set_osm_connecting_lat(double value) { + _impl_._has_bits_[0] |= 0x00001000u; + _impl_.osm_connecting_lat_ = value; +} +inline void Transit_Node::set_osm_connecting_lat(double value) { + _internal_set_osm_connecting_lat(value); + // @@protoc_insertion_point(field_set:valhalla.mjolnir.Transit.Node.osm_connecting_lat) +} + // ------------------------------------------------------------------- // Transit_StopPair diff --git a/include/linux/valhalla/proto/options.pb.cc b/include/linux/valhalla/proto/options.pb.cc index 745ab34..9acc407 100644 --- a/include/linux/valhalla/proto/options.pb.cc +++ b/include/linux/valhalla/proto/options.pb.cc @@ -89,6 +89,8 @@ PROTOBUF_CONSTEXPR Costing_Options::Costing_Options( , /*decltype(_impl_.filter_route_action_)*/0 , /*decltype(_impl_.fixed_speed_)*/0u , /*decltype(_impl_.axle_count_)*/0u + , /*decltype(_impl_.use_lit_)*/0 + , /*decltype(_impl_.disable_hierarchy_pruning_)*/false , /*decltype(_impl_.has_maneuver_penalty_)*/{} , /*decltype(_impl_.has_destination_only_penalty_)*/{} , /*decltype(_impl_.has_gate_cost_)*/{} @@ -226,7 +228,6 @@ PROTOBUF_CONSTEXPR Options::Options( , /*decltype(_impl_.filter_action_)*/0 , /*decltype(_impl_.shape_format_)*/0 , /*decltype(_impl_.reverse_)*/false - , /*decltype(_impl_.matrix_locations_)*/0u , /*decltype(_impl_.has_language_)*/{} , /*decltype(_impl_.has_id_)*/{} , /*decltype(_impl_.has_jsonp_)*/{} @@ -253,6 +254,7 @@ PROTOBUF_CONSTEXPR Options::Options( , /*decltype(_impl_.has_prioritize_bidirectional_)*/{} , /*decltype(_impl_.has_expansion_action_)*/{} , /*decltype(_impl_.has_skip_opposites_)*/{} + , /*decltype(_impl_.has_matrix_locations_)*/{} , /*decltype(_impl_._cached_size_)*/{} , /*decltype(_impl_._oneof_case_)*/{}} {} struct OptionsDefaultTypeInternal { @@ -2106,6 +2108,8 @@ Costing_Options::Costing_Options(const Costing_Options& from) , decltype(_impl_.filter_route_action_){} , decltype(_impl_.fixed_speed_){} , decltype(_impl_.axle_count_){} + , decltype(_impl_.use_lit_){} + , decltype(_impl_.disable_hierarchy_pruning_){} , decltype(_impl_.has_maneuver_penalty_){} , decltype(_impl_.has_destination_only_penalty_){} , decltype(_impl_.has_gate_cost_){} @@ -2183,8 +2187,8 @@ Costing_Options::Costing_Options(const Costing_Options& from) _internal_metadata_.MergeFrom(from._internal_metadata_); ::memcpy(&_impl_.filter_stop_action_, &from._impl_.filter_stop_action_, - static_cast(reinterpret_cast(&_impl_.axle_count_) - - reinterpret_cast(&_impl_.filter_stop_action_)) + sizeof(_impl_.axle_count_)); + static_cast(reinterpret_cast(&_impl_.disable_hierarchy_pruning_) - + reinterpret_cast(&_impl_.filter_stop_action_)) + sizeof(_impl_.disable_hierarchy_pruning_)); clear_has_has_maneuver_penalty(); switch (from.has_maneuver_penalty_case()) { case kManeuverPenalty: { @@ -2922,6 +2926,8 @@ inline void Costing_Options::SharedCtor( , decltype(_impl_.filter_route_action_){0} , decltype(_impl_.fixed_speed_){0u} , decltype(_impl_.axle_count_){0u} + , decltype(_impl_.use_lit_){0} + , decltype(_impl_.disable_hierarchy_pruning_){false} , decltype(_impl_.has_maneuver_penalty_){} , decltype(_impl_.has_destination_only_penalty_){} , decltype(_impl_.has_gate_cost_){} @@ -4328,8 +4334,8 @@ void Costing_Options::Clear() { _impl_.filter_route_ids_.Clear(); _impl_.exclude_edges_.Clear(); ::memset(&_impl_.filter_stop_action_, 0, static_cast( - reinterpret_cast(&_impl_.axle_count_) - - reinterpret_cast(&_impl_.filter_stop_action_)) + sizeof(_impl_.axle_count_)); + reinterpret_cast(&_impl_.disable_hierarchy_pruning_) - + reinterpret_cast(&_impl_.filter_stop_action_)) + sizeof(_impl_.disable_hierarchy_pruning_)); clear_has_maneuver_penalty(); clear_has_destination_only_penalty(); clear_has_gate_cost(); @@ -5090,6 +5096,22 @@ const char* Costing_Options::_InternalParse(const char* ptr, ::_pbi::ParseContex } else goto handle_unusual; continue; + // float use_lit = 82; + case 82: + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 149)) { + _impl_.use_lit_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad(ptr); + ptr += sizeof(float); + } else + goto handle_unusual; + continue; + // bool disable_hierarchy_pruning = 83; + case 83: + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 152)) { + _impl_.disable_hierarchy_pruning_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); + CHK_(ptr); + } else + goto handle_unusual; + continue; default: goto handle_unusual; } // switch @@ -5626,6 +5648,22 @@ uint8_t* Costing_Options::_InternalSerialize( target = ::_pbi::WireFormatLite::WriteUInt32ToArray(81, this->_internal_axle_count(), target); } + // float use_lit = 82; + static_assert(sizeof(uint32_t) == sizeof(float), "Code assumes uint32_t and float are the same size."); + float tmp_use_lit = this->_internal_use_lit(); + uint32_t raw_use_lit; + memcpy(&raw_use_lit, &tmp_use_lit, sizeof(tmp_use_lit)); + if (raw_use_lit != 0) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteFloatToArray(82, this->_internal_use_lit(), target); + } + + // bool disable_hierarchy_pruning = 83; + if (this->_internal_disable_hierarchy_pruning() != 0) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteBoolToArray(83, this->_internal_disable_hierarchy_pruning(), target); + } + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { target = stream->WriteRaw(_internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).data(), static_cast(_internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).size()), target); @@ -5705,6 +5743,20 @@ size_t Costing_Options::ByteSizeLong() const { this->_internal_axle_count()); } + // float use_lit = 82; + static_assert(sizeof(uint32_t) == sizeof(float), "Code assumes uint32_t and float are the same size."); + float tmp_use_lit = this->_internal_use_lit(); + uint32_t raw_use_lit; + memcpy(&raw_use_lit, &tmp_use_lit, sizeof(tmp_use_lit)); + if (raw_use_lit != 0) { + total_size += 2 + 4; + } + + // bool disable_hierarchy_pruning = 83; + if (this->_internal_disable_hierarchy_pruning() != 0) { + total_size += 2 + 1; + } + switch (has_maneuver_penalty_case()) { // float maneuver_penalty = 1; case kManeuverPenalty: { @@ -6481,6 +6533,16 @@ void Costing_Options::MergeFrom(const Costing_Options& from) { if (from._internal_axle_count() != 0) { _this->_internal_set_axle_count(from._internal_axle_count()); } + static_assert(sizeof(uint32_t) == sizeof(float), "Code assumes uint32_t and float are the same size."); + float tmp_use_lit = from._internal_use_lit(); + uint32_t raw_use_lit; + memcpy(&raw_use_lit, &tmp_use_lit, sizeof(tmp_use_lit)); + if (raw_use_lit != 0) { + _this->_internal_set_use_lit(from._internal_use_lit()); + } + if (from._internal_disable_hierarchy_pruning() != 0) { + _this->_internal_set_disable_hierarchy_pruning(from._internal_disable_hierarchy_pruning()); + } switch (from.has_maneuver_penalty_case()) { case kManeuverPenalty: { _this->_internal_set_maneuver_penalty(from._internal_maneuver_penalty()); @@ -7151,8 +7213,8 @@ void Costing_Options::InternalSwap(Costing_Options* other) { _impl_.filter_route_ids_.InternalSwap(&other->_impl_.filter_route_ids_); _impl_.exclude_edges_.InternalSwap(&other->_impl_.exclude_edges_); ::PROTOBUF_NAMESPACE_ID::internal::memswap< - PROTOBUF_FIELD_OFFSET(Costing_Options, _impl_.axle_count_) - + sizeof(Costing_Options::_impl_.axle_count_) + PROTOBUF_FIELD_OFFSET(Costing_Options, _impl_.disable_hierarchy_pruning_) + + sizeof(Costing_Options::_impl_.disable_hierarchy_pruning_) - PROTOBUF_FIELD_OFFSET(Costing_Options, _impl_.filter_stop_action_)>( reinterpret_cast(&_impl_.filter_stop_action_), reinterpret_cast(&other->_impl_.filter_stop_action_)); @@ -7798,7 +7860,6 @@ Options::Options(const Options& from) , decltype(_impl_.filter_action_){} , decltype(_impl_.shape_format_){} , decltype(_impl_.reverse_){} - , decltype(_impl_.matrix_locations_){} , decltype(_impl_.has_language_){} , decltype(_impl_.has_id_){} , decltype(_impl_.has_jsonp_){} @@ -7825,6 +7886,7 @@ Options::Options(const Options& from) , decltype(_impl_.has_prioritize_bidirectional_){} , decltype(_impl_.has_expansion_action_){} , decltype(_impl_.has_skip_opposites_){} + , decltype(_impl_.has_matrix_locations_){} , /*decltype(_impl_._cached_size_)*/{} , /*decltype(_impl_._oneof_case_)*/{}}; @@ -7834,8 +7896,8 @@ Options::Options(const Options& from) _this->_impl_.pbf_field_selector_ = new ::valhalla::PbfFieldSelector(*from._impl_.pbf_field_selector_); } ::memcpy(&_impl_.units_, &from._impl_.units_, - static_cast(reinterpret_cast(&_impl_.matrix_locations_) - - reinterpret_cast(&_impl_.units_)) + sizeof(_impl_.matrix_locations_)); + static_cast(reinterpret_cast(&_impl_.reverse_) - + reinterpret_cast(&_impl_.units_)) + sizeof(_impl_.reverse_)); clear_has_has_language(); switch (from.has_language_case()) { case kLanguage: { @@ -8096,6 +8158,16 @@ Options::Options(const Options& from) break; } } + clear_has_has_matrix_locations(); + switch (from.has_matrix_locations_case()) { + case kMatrixLocations: { + _this->_internal_set_matrix_locations(from._internal_matrix_locations()); + break; + } + case HAS_MATRIX_LOCATIONS_NOT_SET: { + break; + } + } // @@protoc_insertion_point(copy_constructor:valhalla.Options) } @@ -8128,7 +8200,6 @@ inline void Options::SharedCtor( , decltype(_impl_.filter_action_){0} , decltype(_impl_.shape_format_){0} , decltype(_impl_.reverse_){false} - , decltype(_impl_.matrix_locations_){0u} , decltype(_impl_.has_language_){} , decltype(_impl_.has_id_){} , decltype(_impl_.has_jsonp_){} @@ -8155,6 +8226,7 @@ inline void Options::SharedCtor( , decltype(_impl_.has_prioritize_bidirectional_){} , decltype(_impl_.has_expansion_action_){} , decltype(_impl_.has_skip_opposites_){} + , decltype(_impl_.has_matrix_locations_){} , /*decltype(_impl_._cached_size_)*/{} , /*decltype(_impl_._oneof_case_)*/{} }; @@ -8184,6 +8256,7 @@ inline void Options::SharedCtor( clear_has_has_prioritize_bidirectional(); clear_has_has_expansion_action(); clear_has_has_skip_opposites(); + clear_has_has_matrix_locations(); } Options::~Options() { @@ -8289,6 +8362,9 @@ inline void Options::SharedDtor() { if (has_has_skip_opposites()) { clear_has_skip_opposites(); } + if (has_has_matrix_locations()) { + clear_has_matrix_locations(); + } } void Options::SetCachedSize(int size) const { @@ -8659,6 +8735,20 @@ void Options::clear_has_skip_opposites() { _impl_._oneof_case_[25] = HAS_SKIP_OPPOSITES_NOT_SET; } +void Options::clear_has_matrix_locations() { +// @@protoc_insertion_point(one_of_clear_start:valhalla.Options) + switch (has_matrix_locations_case()) { + case kMatrixLocations: { + // No need to clear + break; + } + case HAS_MATRIX_LOCATIONS_NOT_SET: { + break; + } + } + _impl_._oneof_case_[26] = HAS_MATRIX_LOCATIONS_NOT_SET; +} + void Options::Clear() { // @@protoc_insertion_point(message_clear_start:valhalla.Options) @@ -8683,8 +8773,8 @@ void Options::Clear() { } _impl_.pbf_field_selector_ = nullptr; ::memset(&_impl_.units_, 0, static_cast( - reinterpret_cast(&_impl_.matrix_locations_) - - reinterpret_cast(&_impl_.units_)) + sizeof(_impl_.matrix_locations_)); + reinterpret_cast(&_impl_.reverse_) - + reinterpret_cast(&_impl_.units_)) + sizeof(_impl_.reverse_)); clear_has_language(); clear_has_id(); clear_has_jsonp(); @@ -8711,6 +8801,7 @@ void Options::Clear() { clear_has_prioritize_bidirectional(); clear_has_expansion_action(); clear_has_skip_opposites(); + clear_has_matrix_locations(); _internal_metadata_.Clear(); } @@ -9196,7 +9287,7 @@ const char* Options::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) // uint32 matrix_locations = 54; case 54: if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 176)) { - _impl_.matrix_locations_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + _internal_set_matrix_locations(::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr)); CHK_(ptr); } else goto handle_unusual; @@ -9592,7 +9683,7 @@ uint8_t* Options::_InternalSerialize( } // uint32 matrix_locations = 54; - if (this->_internal_matrix_locations() != 0) { + if (_internal_has_matrix_locations()) { target = stream->EnsureSpace(target); target = ::_pbi::WireFormatLite::WriteUInt32ToArray(54, this->_internal_matrix_locations(), target); } @@ -9776,13 +9867,6 @@ size_t Options::ByteSizeLong() const { total_size += 2 + 1; } - // uint32 matrix_locations = 54; - if (this->_internal_matrix_locations() != 0) { - total_size += 2 + - ::_pbi::WireFormatLite::UInt32Size( - this->_internal_matrix_locations()); - } - switch (has_language_case()) { // string language = 2; case kLanguage: { @@ -10058,6 +10142,18 @@ size_t Options::ByteSizeLong() const { break; } } + switch (has_matrix_locations_case()) { + // uint32 matrix_locations = 54; + case kMatrixLocations: { + total_size += 2 + + ::_pbi::WireFormatLite::UInt32Size( + this->_internal_matrix_locations()); + break; + } + case HAS_MATRIX_LOCATIONS_NOT_SET: { + break; + } + } if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { total_size += _internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).size(); } @@ -10125,9 +10221,6 @@ void Options::MergeFrom(const Options& from) { if (from._internal_reverse() != 0) { _this->_internal_set_reverse(from._internal_reverse()); } - if (from._internal_matrix_locations() != 0) { - _this->_internal_set_matrix_locations(from._internal_matrix_locations()); - } switch (from.has_language_case()) { case kLanguage: { _this->_internal_set_language(from._internal_language()); @@ -10362,6 +10455,15 @@ void Options::MergeFrom(const Options& from) { break; } } + switch (from.has_matrix_locations_case()) { + case kMatrixLocations: { + _this->_internal_set_matrix_locations(from._internal_matrix_locations()); + break; + } + case HAS_MATRIX_LOCATIONS_NOT_SET: { + break; + } + } _this->_internal_metadata_.MergeFrom(from._internal_metadata_); } @@ -10392,8 +10494,8 @@ void Options::InternalSwap(Options* other) { _impl_.exclude_polygons_.InternalSwap(&other->_impl_.exclude_polygons_); _impl_.expansion_properties_.InternalSwap(&other->_impl_.expansion_properties_); ::PROTOBUF_NAMESPACE_ID::internal::memswap< - PROTOBUF_FIELD_OFFSET(Options, _impl_.matrix_locations_) - + sizeof(Options::_impl_.matrix_locations_) + PROTOBUF_FIELD_OFFSET(Options, _impl_.reverse_) + + sizeof(Options::_impl_.reverse_) - PROTOBUF_FIELD_OFFSET(Options, _impl_.pbf_field_selector_)>( reinterpret_cast(&_impl_.pbf_field_selector_), reinterpret_cast(&other->_impl_.pbf_field_selector_)); @@ -10423,6 +10525,7 @@ void Options::InternalSwap(Options* other) { swap(_impl_.has_prioritize_bidirectional_, other->_impl_.has_prioritize_bidirectional_); swap(_impl_.has_expansion_action_, other->_impl_.has_expansion_action_); swap(_impl_.has_skip_opposites_, other->_impl_.has_skip_opposites_); + swap(_impl_.has_matrix_locations_, other->_impl_.has_matrix_locations_); swap(_impl_._oneof_case_[0], other->_impl_._oneof_case_[0]); swap(_impl_._oneof_case_[1], other->_impl_._oneof_case_[1]); swap(_impl_._oneof_case_[2], other->_impl_._oneof_case_[2]); @@ -10449,6 +10552,7 @@ void Options::InternalSwap(Options* other) { swap(_impl_._oneof_case_[23], other->_impl_._oneof_case_[23]); swap(_impl_._oneof_case_[24], other->_impl_._oneof_case_[24]); swap(_impl_._oneof_case_[25], other->_impl_._oneof_case_[25]); + swap(_impl_._oneof_case_[26], other->_impl_._oneof_case_[26]); } std::string Options::GetTypeName() const { diff --git a/include/linux/valhalla/proto/options.pb.h b/include/linux/valhalla/proto/options.pb.h index 976b3c1..d3357a5 100644 --- a/include/linux/valhalla/proto/options.pb.h +++ b/include/linux/valhalla/proto/options.pb.h @@ -1500,6 +1500,8 @@ class Costing_Options final : kFilterRouteActionFieldNumber = 53, kFixedSpeedFieldNumber = 80, kAxleCountFieldNumber = 81, + kUseLitFieldNumber = 82, + kDisableHierarchyPruningFieldNumber = 83, kManeuverPenaltyFieldNumber = 1, kDestinationOnlyPenaltyFieldNumber = 2, kGateCostFieldNumber = 3, @@ -1708,6 +1710,24 @@ class Costing_Options final : void _internal_set_axle_count(uint32_t value); public: + // float use_lit = 82; + void clear_use_lit(); + float use_lit() const; + void set_use_lit(float value); + private: + float _internal_use_lit() const; + void _internal_set_use_lit(float value); + public: + + // bool disable_hierarchy_pruning = 83; + void clear_disable_hierarchy_pruning(); + bool disable_hierarchy_pruning() const; + void set_disable_hierarchy_pruning(bool value); + private: + bool _internal_disable_hierarchy_pruning() const; + void _internal_set_disable_hierarchy_pruning(bool value); + public: + // float maneuver_penalty = 1; bool has_maneuver_penalty() const; private: @@ -3098,6 +3118,8 @@ class Costing_Options final : int filter_route_action_; uint32_t fixed_speed_; uint32_t axle_count_; + float use_lit_; + bool disable_hierarchy_pruning_; union HasManeuverPenaltyUnion { constexpr HasManeuverPenaltyUnion() : _constinit_{} {} ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized _constinit_; @@ -3933,6 +3955,11 @@ class Options final : HAS_SKIP_OPPOSITES_NOT_SET = 0, }; + enum HasMatrixLocationsCase { + kMatrixLocations = 54, + HAS_MATRIX_LOCATIONS_NOT_SET = 0, + }; + static inline const Options* internal_default_instance() { return reinterpret_cast( &_Options_default_instance_); @@ -4194,7 +4221,6 @@ class Options final : kFilterActionFieldNumber = 33, kShapeFormatFieldNumber = 38, kReverseFieldNumber = 53, - kMatrixLocationsFieldNumber = 54, kLanguageFieldNumber = 2, kIdFieldNumber = 5, kJsonpFieldNumber = 6, @@ -4221,6 +4247,7 @@ class Options final : kPrioritizeBidirectionalFieldNumber = 48, kExpansionActionFieldNumber = 49, kSkipOppositesFieldNumber = 50, + kMatrixLocationsFieldNumber = 54, }; // map costings = 13; int costings_size() const; @@ -4550,15 +4577,6 @@ class Options final : void _internal_set_reverse(bool value); public: - // uint32 matrix_locations = 54; - void clear_matrix_locations(); - uint32_t matrix_locations() const; - void set_matrix_locations(uint32_t value); - private: - uint32_t _internal_matrix_locations() const; - void _internal_set_matrix_locations(uint32_t value); - public: - // string language = 2; bool has_language() const; private: @@ -4922,6 +4940,19 @@ class Options final : void _internal_set_skip_opposites(bool value); public: + // uint32 matrix_locations = 54; + bool has_matrix_locations() const; + private: + bool _internal_has_matrix_locations() const; + public: + void clear_matrix_locations(); + uint32_t matrix_locations() const; + void set_matrix_locations(uint32_t value); + private: + uint32_t _internal_matrix_locations() const; + void _internal_set_matrix_locations(uint32_t value); + public: + void clear_has_language(); HasLanguageCase has_language_case() const; void clear_has_id(); @@ -4974,6 +5005,8 @@ class Options final : HasExpansionActionCase has_expansion_action_case() const; void clear_has_skip_opposites(); HasSkipOppositesCase has_skip_opposites_case() const; + void clear_has_matrix_locations(); + HasMatrixLocationsCase has_matrix_locations_case() const; // @@protoc_insertion_point(class_scope:valhalla.Options) private: class _Internal; @@ -5003,6 +5036,7 @@ class Options final : void set_has_prioritize_bidirectional(); void set_has_expansion_action(); void set_has_skip_opposites(); + void set_has_matrix_locations(); inline bool has_has_language() const; inline void clear_has_has_language(); @@ -5082,6 +5116,9 @@ class Options final : inline bool has_has_skip_opposites() const; inline void clear_has_has_skip_opposites(); + inline bool has_has_matrix_locations() const; + inline void clear_has_has_matrix_locations(); + template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; @@ -5114,7 +5151,6 @@ class Options final : int filter_action_; int shape_format_; bool reverse_; - uint32_t matrix_locations_; union HasLanguageUnion { constexpr HasLanguageUnion() : _constinit_{} {} ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized _constinit_; @@ -5245,8 +5281,13 @@ class Options final : ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized _constinit_; bool skip_opposites_; } has_skip_opposites_; + union HasMatrixLocationsUnion { + constexpr HasMatrixLocationsUnion() : _constinit_{} {} + ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized _constinit_; + uint32_t matrix_locations_; + } has_matrix_locations_; mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - uint32_t _oneof_case_[26]; + uint32_t _oneof_case_[27]; }; union { Impl_ _impl_; }; @@ -8810,6 +8851,46 @@ inline void Costing_Options::set_axle_count(uint32_t value) { // @@protoc_insertion_point(field_set:valhalla.Costing.Options.axle_count) } +// float use_lit = 82; +inline void Costing_Options::clear_use_lit() { + _impl_.use_lit_ = 0; +} +inline float Costing_Options::_internal_use_lit() const { + return _impl_.use_lit_; +} +inline float Costing_Options::use_lit() const { + // @@protoc_insertion_point(field_get:valhalla.Costing.Options.use_lit) + return _internal_use_lit(); +} +inline void Costing_Options::_internal_set_use_lit(float value) { + + _impl_.use_lit_ = value; +} +inline void Costing_Options::set_use_lit(float value) { + _internal_set_use_lit(value); + // @@protoc_insertion_point(field_set:valhalla.Costing.Options.use_lit) +} + +// bool disable_hierarchy_pruning = 83; +inline void Costing_Options::clear_disable_hierarchy_pruning() { + _impl_.disable_hierarchy_pruning_ = false; +} +inline bool Costing_Options::_internal_disable_hierarchy_pruning() const { + return _impl_.disable_hierarchy_pruning_; +} +inline bool Costing_Options::disable_hierarchy_pruning() const { + // @@protoc_insertion_point(field_get:valhalla.Costing.Options.disable_hierarchy_pruning) + return _internal_disable_hierarchy_pruning(); +} +inline void Costing_Options::_internal_set_disable_hierarchy_pruning(bool value) { + + _impl_.disable_hierarchy_pruning_ = value; +} +inline void Costing_Options::set_disable_hierarchy_pruning(bool value) { + _internal_set_disable_hierarchy_pruning(value); + // @@protoc_insertion_point(field_set:valhalla.Costing.Options.disable_hierarchy_pruning) +} + inline bool Costing_Options::has_has_maneuver_penalty() const { return has_maneuver_penalty_case() != HAS_MANEUVER_PENALTY_NOT_SET; } @@ -11667,20 +11748,38 @@ inline void Options::set_reverse(bool value) { } // uint32 matrix_locations = 54; +inline bool Options::_internal_has_matrix_locations() const { + return has_matrix_locations_case() == kMatrixLocations; +} +inline bool Options::has_matrix_locations() const { + return _internal_has_matrix_locations(); +} +inline void Options::set_has_matrix_locations() { + _impl_._oneof_case_[26] = kMatrixLocations; +} inline void Options::clear_matrix_locations() { - _impl_.matrix_locations_ = 0u; + if (_internal_has_matrix_locations()) { + _impl_.has_matrix_locations_.matrix_locations_ = 0u; + clear_has_has_matrix_locations(); + } } inline uint32_t Options::_internal_matrix_locations() const { - return _impl_.matrix_locations_; + if (_internal_has_matrix_locations()) { + return _impl_.has_matrix_locations_.matrix_locations_; + } + return 0u; +} +inline void Options::_internal_set_matrix_locations(uint32_t value) { + if (!_internal_has_matrix_locations()) { + clear_has_matrix_locations(); + set_has_matrix_locations(); + } + _impl_.has_matrix_locations_.matrix_locations_ = value; } inline uint32_t Options::matrix_locations() const { // @@protoc_insertion_point(field_get:valhalla.Options.matrix_locations) return _internal_matrix_locations(); } -inline void Options::_internal_set_matrix_locations(uint32_t value) { - - _impl_.matrix_locations_ = value; -} inline void Options::set_matrix_locations(uint32_t value) { _internal_set_matrix_locations(value); // @@protoc_insertion_point(field_set:valhalla.Options.matrix_locations) @@ -11842,6 +11941,12 @@ inline bool Options::has_has_skip_opposites() const { inline void Options::clear_has_has_skip_opposites() { _impl_._oneof_case_[25] = HAS_SKIP_OPPOSITES_NOT_SET; } +inline bool Options::has_has_matrix_locations() const { + return has_matrix_locations_case() != HAS_MATRIX_LOCATIONS_NOT_SET; +} +inline void Options::clear_has_has_matrix_locations() { + _impl_._oneof_case_[26] = HAS_MATRIX_LOCATIONS_NOT_SET; +} inline Options::HasLanguageCase Options::has_language_case() const { return Options::HasLanguageCase(_impl_._oneof_case_[0]); } @@ -11920,6 +12025,9 @@ inline Options::HasExpansionActionCase Options::has_expansion_action_case() cons inline Options::HasSkipOppositesCase Options::has_skip_opposites_case() const { return Options::HasSkipOppositesCase(_impl_._oneof_case_[25]); } +inline Options::HasMatrixLocationsCase Options::has_matrix_locations_case() const { + return Options::HasMatrixLocationsCase(_impl_._oneof_case_[26]); +} #ifdef __GNUC__ #pragma GCC diagnostic pop #endif // __GNUC__ diff --git a/include/linux/valhalla/proto/status.pb.cc b/include/linux/valhalla/proto/status.pb.cc index a7802fb..6e1ad24 100644 --- a/include/linux/valhalla/proto/status.pb.cc +++ b/include/linux/valhalla/proto/status.pb.cc @@ -21,13 +21,15 @@ namespace valhalla { PROTOBUF_CONSTEXPR Status::Status( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_.available_actions_)*/{} + , /*decltype(_impl_.version_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}} + , /*decltype(_impl_.tileset_last_modified_)*/0u , /*decltype(_impl_.has_has_tiles_)*/{} , /*decltype(_impl_.has_has_admins_)*/{} , /*decltype(_impl_.has_has_timezones_)*/{} , /*decltype(_impl_.has_has_live_traffic_)*/{} , /*decltype(_impl_.has_bbox_)*/{} - , /*decltype(_impl_.has_version_)*/{} - , /*decltype(_impl_.has_tileset_last_modified_)*/{} + , /*decltype(_impl_.has_has_transit_tiles_)*/{} + , /*decltype(_impl_.has_osm_changeset_)*/{} , /*decltype(_impl_._cached_size_)*/{} , /*decltype(_impl_._oneof_case_)*/{}} {} struct StatusDefaultTypeInternal { @@ -59,17 +61,28 @@ Status::Status(const Status& from) Status* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_.available_actions_){from._impl_.available_actions_} + , decltype(_impl_.version_){} + , decltype(_impl_.tileset_last_modified_){} , decltype(_impl_.has_has_tiles_){} , decltype(_impl_.has_has_admins_){} , decltype(_impl_.has_has_timezones_){} , decltype(_impl_.has_has_live_traffic_){} , decltype(_impl_.has_bbox_){} - , decltype(_impl_.has_version_){} - , decltype(_impl_.has_tileset_last_modified_){} + , decltype(_impl_.has_has_transit_tiles_){} + , decltype(_impl_.has_osm_changeset_){} , /*decltype(_impl_._cached_size_)*/{} , /*decltype(_impl_._oneof_case_)*/{}}; _internal_metadata_.MergeFrom(from._internal_metadata_); + _impl_.version_.InitDefault(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.version_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + if (!from._internal_version().empty()) { + _this->_impl_.version_.Set(from._internal_version(), + _this->GetArenaForAllocation()); + } + _this->_impl_.tileset_last_modified_ = from._impl_.tileset_last_modified_; clear_has_has_has_tiles(); switch (from.has_has_tiles_case()) { case kHasTiles: { @@ -120,23 +133,23 @@ Status::Status(const Status& from) break; } } - clear_has_has_version(); - switch (from.has_version_case()) { - case kVersion: { - _this->_internal_set_version(from._internal_version()); + clear_has_has_has_transit_tiles(); + switch (from.has_has_transit_tiles_case()) { + case kHasTransitTiles: { + _this->_internal_set_has_transit_tiles(from._internal_has_transit_tiles()); break; } - case HAS_VERSION_NOT_SET: { + case HAS_HAS_TRANSIT_TILES_NOT_SET: { break; } } - clear_has_has_tileset_last_modified(); - switch (from.has_tileset_last_modified_case()) { - case kTilesetLastModified: { - _this->_internal_set_tileset_last_modified(from._internal_tileset_last_modified()); + clear_has_has_osm_changeset(); + switch (from.has_osm_changeset_case()) { + case kOsmChangeset: { + _this->_internal_set_osm_changeset(from._internal_osm_changeset()); break; } - case HAS_TILESET_LAST_MODIFIED_NOT_SET: { + case HAS_OSM_CHANGESET_NOT_SET: { break; } } @@ -149,23 +162,29 @@ inline void Status::SharedCtor( (void)is_message_owned; new (&_impl_) Impl_{ decltype(_impl_.available_actions_){arena} + , decltype(_impl_.version_){} + , decltype(_impl_.tileset_last_modified_){0u} , decltype(_impl_.has_has_tiles_){} , decltype(_impl_.has_has_admins_){} , decltype(_impl_.has_has_timezones_){} , decltype(_impl_.has_has_live_traffic_){} , decltype(_impl_.has_bbox_){} - , decltype(_impl_.has_version_){} - , decltype(_impl_.has_tileset_last_modified_){} + , decltype(_impl_.has_has_transit_tiles_){} + , decltype(_impl_.has_osm_changeset_){} , /*decltype(_impl_._cached_size_)*/{} , /*decltype(_impl_._oneof_case_)*/{} }; + _impl_.version_.InitDefault(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.version_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING clear_has_has_has_tiles(); clear_has_has_has_admins(); clear_has_has_has_timezones(); clear_has_has_has_live_traffic(); clear_has_has_bbox(); - clear_has_has_version(); - clear_has_has_tileset_last_modified(); + clear_has_has_has_transit_tiles(); + clear_has_has_osm_changeset(); } Status::~Status() { @@ -180,6 +199,7 @@ Status::~Status() { inline void Status::SharedDtor() { GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); _impl_.available_actions_.~RepeatedPtrField(); + _impl_.version_.Destroy(); if (has_has_has_tiles()) { clear_has_has_tiles(); } @@ -195,11 +215,11 @@ inline void Status::SharedDtor() { if (has_has_bbox()) { clear_has_bbox(); } - if (has_has_version()) { - clear_has_version(); + if (has_has_has_transit_tiles()) { + clear_has_has_transit_tiles(); } - if (has_has_tileset_last_modified()) { - clear_has_tileset_last_modified(); + if (has_has_osm_changeset()) { + clear_has_osm_changeset(); } } @@ -277,32 +297,32 @@ void Status::clear_has_bbox() { _impl_._oneof_case_[4] = HAS_BBOX_NOT_SET; } -void Status::clear_has_version() { +void Status::clear_has_has_transit_tiles() { // @@protoc_insertion_point(one_of_clear_start:valhalla.Status) - switch (has_version_case()) { - case kVersion: { - _impl_.has_version_.version_.Destroy(); + switch (has_has_transit_tiles_case()) { + case kHasTransitTiles: { + // No need to clear break; } - case HAS_VERSION_NOT_SET: { + case HAS_HAS_TRANSIT_TILES_NOT_SET: { break; } } - _impl_._oneof_case_[5] = HAS_VERSION_NOT_SET; + _impl_._oneof_case_[5] = HAS_HAS_TRANSIT_TILES_NOT_SET; } -void Status::clear_has_tileset_last_modified() { +void Status::clear_has_osm_changeset() { // @@protoc_insertion_point(one_of_clear_start:valhalla.Status) - switch (has_tileset_last_modified_case()) { - case kTilesetLastModified: { + switch (has_osm_changeset_case()) { + case kOsmChangeset: { // No need to clear break; } - case HAS_TILESET_LAST_MODIFIED_NOT_SET: { + case HAS_OSM_CHANGESET_NOT_SET: { break; } } - _impl_._oneof_case_[6] = HAS_TILESET_LAST_MODIFIED_NOT_SET; + _impl_._oneof_case_[6] = HAS_OSM_CHANGESET_NOT_SET; } @@ -313,13 +333,15 @@ void Status::Clear() { (void) cached_has_bits; _impl_.available_actions_.Clear(); + _impl_.version_.ClearToEmpty(); + _impl_.tileset_last_modified_ = 0u; clear_has_has_tiles(); clear_has_has_admins(); clear_has_has_timezones(); clear_has_has_live_traffic(); clear_has_bbox(); - clear_has_version(); - clear_has_tileset_last_modified(); + clear_has_has_transit_tiles(); + clear_has_osm_changeset(); _internal_metadata_.Clear(); } @@ -384,7 +406,7 @@ const char* Status::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { // uint32 tileset_last_modified = 7; case 7: if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 56)) { - _internal_set_tileset_last_modified(::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr)); + _impl_.tileset_last_modified_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); CHK_(ptr); } else goto handle_unusual; @@ -404,6 +426,22 @@ const char* Status::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { } else goto handle_unusual; continue; + // bool has_transit_tiles = 9; + case 9: + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 72)) { + _internal_set_has_transit_tiles(::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr)); + CHK_(ptr); + } else + goto handle_unusual; + continue; + // uint64 osm_changeset = 10; + case 10: + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 80)) { + _internal_set_osm_changeset(::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr)); + CHK_(ptr); + } else + goto handle_unusual; + continue; default: goto handle_unusual; } // switch @@ -468,7 +506,7 @@ uint8_t* Status::_InternalSerialize( } // string version = 6; - if (_internal_has_version()) { + if (!this->_internal_version().empty()) { ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( this->_internal_version().data(), static_cast(this->_internal_version().length()), ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, @@ -478,7 +516,7 @@ uint8_t* Status::_InternalSerialize( } // uint32 tileset_last_modified = 7; - if (_internal_has_tileset_last_modified()) { + if (this->_internal_tileset_last_modified() != 0) { target = stream->EnsureSpace(target); target = ::_pbi::WireFormatLite::WriteUInt32ToArray(7, this->_internal_tileset_last_modified(), target); } @@ -493,6 +531,18 @@ uint8_t* Status::_InternalSerialize( target = stream->WriteString(8, s, target); } + // bool has_transit_tiles = 9; + if (_internal_has_has_transit_tiles()) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteBoolToArray(9, this->_internal_has_transit_tiles(), target); + } + + // uint64 osm_changeset = 10; + if (_internal_has_osm_changeset()) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteUInt64ToArray(10, this->_internal_osm_changeset(), target); + } + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { target = stream->WriteRaw(_internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).data(), static_cast(_internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).size()), target); @@ -517,6 +567,18 @@ size_t Status::ByteSizeLong() const { _impl_.available_actions_.Get(i)); } + // string version = 6; + if (!this->_internal_version().empty()) { + total_size += 1 + + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( + this->_internal_version()); + } + + // uint32 tileset_last_modified = 7; + if (this->_internal_tileset_last_modified() != 0) { + total_size += ::_pbi::WireFormatLite::UInt32SizePlusOne(this->_internal_tileset_last_modified()); + } + switch (has_has_tiles_case()) { // bool has_tiles = 1; case kHasTiles: { @@ -569,25 +631,23 @@ size_t Status::ByteSizeLong() const { break; } } - switch (has_version_case()) { - // string version = 6; - case kVersion: { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_version()); + switch (has_has_transit_tiles_case()) { + // bool has_transit_tiles = 9; + case kHasTransitTiles: { + total_size += 1 + 1; break; } - case HAS_VERSION_NOT_SET: { + case HAS_HAS_TRANSIT_TILES_NOT_SET: { break; } } - switch (has_tileset_last_modified_case()) { - // uint32 tileset_last_modified = 7; - case kTilesetLastModified: { - total_size += ::_pbi::WireFormatLite::UInt32SizePlusOne(this->_internal_tileset_last_modified()); + switch (has_osm_changeset_case()) { + // uint64 osm_changeset = 10; + case kOsmChangeset: { + total_size += ::_pbi::WireFormatLite::UInt64SizePlusOne(this->_internal_osm_changeset()); break; } - case HAS_TILESET_LAST_MODIFIED_NOT_SET: { + case HAS_OSM_CHANGESET_NOT_SET: { break; } } @@ -613,6 +673,12 @@ void Status::MergeFrom(const Status& from) { (void) cached_has_bits; _this->_impl_.available_actions_.MergeFrom(from._impl_.available_actions_); + if (!from._internal_version().empty()) { + _this->_internal_set_version(from._internal_version()); + } + if (from._internal_tileset_last_modified() != 0) { + _this->_internal_set_tileset_last_modified(from._internal_tileset_last_modified()); + } switch (from.has_has_tiles_case()) { case kHasTiles: { _this->_internal_set_has_tiles(from._internal_has_tiles()); @@ -658,21 +724,21 @@ void Status::MergeFrom(const Status& from) { break; } } - switch (from.has_version_case()) { - case kVersion: { - _this->_internal_set_version(from._internal_version()); + switch (from.has_has_transit_tiles_case()) { + case kHasTransitTiles: { + _this->_internal_set_has_transit_tiles(from._internal_has_transit_tiles()); break; } - case HAS_VERSION_NOT_SET: { + case HAS_HAS_TRANSIT_TILES_NOT_SET: { break; } } - switch (from.has_tileset_last_modified_case()) { - case kTilesetLastModified: { - _this->_internal_set_tileset_last_modified(from._internal_tileset_last_modified()); + switch (from.has_osm_changeset_case()) { + case kOsmChangeset: { + _this->_internal_set_osm_changeset(from._internal_osm_changeset()); break; } - case HAS_TILESET_LAST_MODIFIED_NOT_SET: { + case HAS_OSM_CHANGESET_NOT_SET: { break; } } @@ -692,15 +758,22 @@ bool Status::IsInitialized() const { void Status::InternalSwap(Status* other) { using std::swap; + auto* lhs_arena = GetArenaForAllocation(); + auto* rhs_arena = other->GetArenaForAllocation(); _internal_metadata_.InternalSwap(&other->_internal_metadata_); _impl_.available_actions_.InternalSwap(&other->_impl_.available_actions_); + ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( + &_impl_.version_, lhs_arena, + &other->_impl_.version_, rhs_arena + ); + swap(_impl_.tileset_last_modified_, other->_impl_.tileset_last_modified_); swap(_impl_.has_has_tiles_, other->_impl_.has_has_tiles_); swap(_impl_.has_has_admins_, other->_impl_.has_has_admins_); swap(_impl_.has_has_timezones_, other->_impl_.has_has_timezones_); swap(_impl_.has_has_live_traffic_, other->_impl_.has_has_live_traffic_); swap(_impl_.has_bbox_, other->_impl_.has_bbox_); - swap(_impl_.has_version_, other->_impl_.has_version_); - swap(_impl_.has_tileset_last_modified_, other->_impl_.has_tileset_last_modified_); + swap(_impl_.has_has_transit_tiles_, other->_impl_.has_has_transit_tiles_); + swap(_impl_.has_osm_changeset_, other->_impl_.has_osm_changeset_); swap(_impl_._oneof_case_[0], other->_impl_._oneof_case_[0]); swap(_impl_._oneof_case_[1], other->_impl_._oneof_case_[1]); swap(_impl_._oneof_case_[2], other->_impl_._oneof_case_[2]); diff --git a/include/linux/valhalla/proto/status.pb.h b/include/linux/valhalla/proto/status.pb.h index 58c35f1..1258813 100644 --- a/include/linux/valhalla/proto/status.pb.h +++ b/include/linux/valhalla/proto/status.pb.h @@ -112,14 +112,14 @@ class Status final : HAS_BBOX_NOT_SET = 0, }; - enum HasVersionCase { - kVersion = 6, - HAS_VERSION_NOT_SET = 0, + enum HasHasTransitTilesCase { + kHasTransitTiles = 9, + HAS_HAS_TRANSIT_TILES_NOT_SET = 0, }; - enum HasTilesetLastModifiedCase { - kTilesetLastModified = 7, - HAS_TILESET_LAST_MODIFIED_NOT_SET = 0, + enum HasOsmChangesetCase { + kOsmChangeset = 10, + HAS_OSM_CHANGESET_NOT_SET = 0, }; static inline const Status* internal_default_instance() { @@ -192,13 +192,15 @@ class Status final : enum : int { kAvailableActionsFieldNumber = 8, + kVersionFieldNumber = 6, + kTilesetLastModifiedFieldNumber = 7, kHasTilesFieldNumber = 1, kHasAdminsFieldNumber = 2, kHasTimezonesFieldNumber = 3, kHasLiveTrafficFieldNumber = 4, kBboxFieldNumber = 5, - kVersionFieldNumber = 6, - kTilesetLastModifiedFieldNumber = 7, + kHasTransitTilesFieldNumber = 9, + kOsmChangesetFieldNumber = 10, }; // repeated string available_actions = 8; int available_actions_size() const; @@ -224,6 +226,29 @@ class Status final : std::string* _internal_add_available_actions(); public: + // string version = 6; + void clear_version(); + const std::string& version() const; + template + void set_version(ArgT0&& arg0, ArgT... args); + std::string* mutable_version(); + PROTOBUF_NODISCARD std::string* release_version(); + void set_allocated_version(std::string* version); + private: + const std::string& _internal_version() const; + inline PROTOBUF_ALWAYS_INLINE void _internal_set_version(const std::string& value); + std::string* _internal_mutable_version(); + public: + + // uint32 tileset_last_modified = 7; + void clear_tileset_last_modified(); + uint32_t tileset_last_modified() const; + void set_tileset_last_modified(uint32_t value); + private: + uint32_t _internal_tileset_last_modified() const; + void _internal_set_tileset_last_modified(uint32_t value); + public: + // bool has_tiles = 1; bool has_has_tiles() const; private: @@ -294,35 +319,30 @@ class Status final : std::string* _internal_mutable_bbox(); public: - // string version = 6; - bool has_version() const; + // bool has_transit_tiles = 9; + bool has_has_transit_tiles() const; private: - bool _internal_has_version() const; + bool _internal_has_has_transit_tiles() const; public: - void clear_version(); - const std::string& version() const; - template - void set_version(ArgT0&& arg0, ArgT... args); - std::string* mutable_version(); - PROTOBUF_NODISCARD std::string* release_version(); - void set_allocated_version(std::string* version); + void clear_has_transit_tiles(); + bool has_transit_tiles() const; + void set_has_transit_tiles(bool value); private: - const std::string& _internal_version() const; - inline PROTOBUF_ALWAYS_INLINE void _internal_set_version(const std::string& value); - std::string* _internal_mutable_version(); + bool _internal_has_transit_tiles() const; + void _internal_set_has_transit_tiles(bool value); public: - // uint32 tileset_last_modified = 7; - bool has_tileset_last_modified() const; + // uint64 osm_changeset = 10; + bool has_osm_changeset() const; private: - bool _internal_has_tileset_last_modified() const; + bool _internal_has_osm_changeset() const; public: - void clear_tileset_last_modified(); - uint32_t tileset_last_modified() const; - void set_tileset_last_modified(uint32_t value); + void clear_osm_changeset(); + uint64_t osm_changeset() const; + void set_osm_changeset(uint64_t value); private: - uint32_t _internal_tileset_last_modified() const; - void _internal_set_tileset_last_modified(uint32_t value); + uint64_t _internal_osm_changeset() const; + void _internal_set_osm_changeset(uint64_t value); public: void clear_has_has_tiles(); @@ -335,10 +355,10 @@ class Status final : HasHasLiveTrafficCase has_has_live_traffic_case() const; void clear_has_bbox(); HasBboxCase has_bbox_case() const; - void clear_has_version(); - HasVersionCase has_version_case() const; - void clear_has_tileset_last_modified(); - HasTilesetLastModifiedCase has_tileset_last_modified_case() const; + void clear_has_has_transit_tiles(); + HasHasTransitTilesCase has_has_transit_tiles_case() const; + void clear_has_osm_changeset(); + HasOsmChangesetCase has_osm_changeset_case() const; // @@protoc_insertion_point(class_scope:valhalla.Status) private: class _Internal; @@ -347,8 +367,8 @@ class Status final : void set_has_has_timezones(); void set_has_has_live_traffic(); void set_has_bbox(); - void set_has_version(); - void set_has_tileset_last_modified(); + void set_has_has_transit_tiles(); + void set_has_osm_changeset(); inline bool has_has_has_tiles() const; inline void clear_has_has_has_tiles(); @@ -365,17 +385,19 @@ class Status final : inline bool has_has_bbox() const; inline void clear_has_has_bbox(); - inline bool has_has_version() const; - inline void clear_has_has_version(); + inline bool has_has_has_transit_tiles() const; + inline void clear_has_has_has_transit_tiles(); - inline bool has_has_tileset_last_modified() const; - inline void clear_has_has_tileset_last_modified(); + inline bool has_has_osm_changeset() const; + inline void clear_has_has_osm_changeset(); template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; struct Impl_ { ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField available_actions_; + ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr version_; + uint32_t tileset_last_modified_; union HasHasTilesUnion { constexpr HasHasTilesUnion() : _constinit_{} {} ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized _constinit_; @@ -401,16 +423,16 @@ class Status final : ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized _constinit_; ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr bbox_; } has_bbox_; - union HasVersionUnion { - constexpr HasVersionUnion() : _constinit_{} {} + union HasHasTransitTilesUnion { + constexpr HasHasTransitTilesUnion() : _constinit_{} {} ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized _constinit_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr version_; - } has_version_; - union HasTilesetLastModifiedUnion { - constexpr HasTilesetLastModifiedUnion() : _constinit_{} {} + bool has_transit_tiles_; + } has_has_transit_tiles_; + union HasOsmChangesetUnion { + constexpr HasOsmChangesetUnion() : _constinit_{} {} ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized _constinit_; - uint32_t tileset_last_modified_; - } has_tileset_last_modified_; + uint64_t osm_changeset_; + } has_osm_changeset_; mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; uint32_t _oneof_case_[7]; @@ -659,33 +681,18 @@ inline void Status::set_allocated_bbox(std::string* bbox) { } // string version = 6; -inline bool Status::_internal_has_version() const { - return has_version_case() == kVersion; -} -inline bool Status::has_version() const { - return _internal_has_version(); -} -inline void Status::set_has_version() { - _impl_._oneof_case_[5] = kVersion; -} inline void Status::clear_version() { - if (_internal_has_version()) { - _impl_.has_version_.version_.Destroy(); - clear_has_has_version(); - } + _impl_.version_.ClearToEmpty(); } inline const std::string& Status::version() const { // @@protoc_insertion_point(field_get:valhalla.Status.version) return _internal_version(); } template -inline void Status::set_version(ArgT0&& arg0, ArgT... args) { - if (!_internal_has_version()) { - clear_has_version(); - set_has_version(); - _impl_.has_version_.version_.InitDefault(); - } - _impl_.has_version_.version_.Set( static_cast(arg0), args..., GetArenaForAllocation()); +inline PROTOBUF_ALWAYS_INLINE +void Status::set_version(ArgT0&& arg0, ArgT... args) { + + _impl_.version_.Set(static_cast(arg0), args..., GetArenaForAllocation()); // @@protoc_insertion_point(field_set:valhalla.Status.version) } inline std::string* Status::mutable_version() { @@ -694,80 +701,50 @@ inline std::string* Status::mutable_version() { return _s; } inline const std::string& Status::_internal_version() const { - if (_internal_has_version()) { - return _impl_.has_version_.version_.Get(); - } - return ::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(); + return _impl_.version_.Get(); } inline void Status::_internal_set_version(const std::string& value) { - if (!_internal_has_version()) { - clear_has_version(); - set_has_version(); - _impl_.has_version_.version_.InitDefault(); - } - _impl_.has_version_.version_.Set(value, GetArenaForAllocation()); + + _impl_.version_.Set(value, GetArenaForAllocation()); } inline std::string* Status::_internal_mutable_version() { - if (!_internal_has_version()) { - clear_has_version(); - set_has_version(); - _impl_.has_version_.version_.InitDefault(); - } - return _impl_.has_version_.version_.Mutable( GetArenaForAllocation()); + + return _impl_.version_.Mutable(GetArenaForAllocation()); } inline std::string* Status::release_version() { // @@protoc_insertion_point(field_release:valhalla.Status.version) - if (_internal_has_version()) { - clear_has_has_version(); - return _impl_.has_version_.version_.Release(); - } else { - return nullptr; - } + return _impl_.version_.Release(); } inline void Status::set_allocated_version(std::string* version) { - if (has_has_version()) { - clear_has_version(); - } if (version != nullptr) { - set_has_version(); - _impl_.has_version_.version_.InitAllocated(version, GetArenaForAllocation()); + + } else { + + } + _impl_.version_.SetAllocated(version, GetArenaForAllocation()); +#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + if (_impl_.version_.IsDefault()) { + _impl_.version_.Set("", GetArenaForAllocation()); } +#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING // @@protoc_insertion_point(field_set_allocated:valhalla.Status.version) } // uint32 tileset_last_modified = 7; -inline bool Status::_internal_has_tileset_last_modified() const { - return has_tileset_last_modified_case() == kTilesetLastModified; -} -inline bool Status::has_tileset_last_modified() const { - return _internal_has_tileset_last_modified(); -} -inline void Status::set_has_tileset_last_modified() { - _impl_._oneof_case_[6] = kTilesetLastModified; -} inline void Status::clear_tileset_last_modified() { - if (_internal_has_tileset_last_modified()) { - _impl_.has_tileset_last_modified_.tileset_last_modified_ = 0u; - clear_has_has_tileset_last_modified(); - } + _impl_.tileset_last_modified_ = 0u; } inline uint32_t Status::_internal_tileset_last_modified() const { - if (_internal_has_tileset_last_modified()) { - return _impl_.has_tileset_last_modified_.tileset_last_modified_; - } - return 0u; -} -inline void Status::_internal_set_tileset_last_modified(uint32_t value) { - if (!_internal_has_tileset_last_modified()) { - clear_has_tileset_last_modified(); - set_has_tileset_last_modified(); - } - _impl_.has_tileset_last_modified_.tileset_last_modified_ = value; + return _impl_.tileset_last_modified_; } inline uint32_t Status::tileset_last_modified() const { // @@protoc_insertion_point(field_get:valhalla.Status.tileset_last_modified) return _internal_tileset_last_modified(); } +inline void Status::_internal_set_tileset_last_modified(uint32_t value) { + + _impl_.tileset_last_modified_ = value; +} inline void Status::set_tileset_last_modified(uint32_t value) { _internal_set_tileset_last_modified(value); // @@protoc_insertion_point(field_set:valhalla.Status.tileset_last_modified) @@ -848,6 +825,82 @@ Status::mutable_available_actions() { return &_impl_.available_actions_; } +// bool has_transit_tiles = 9; +inline bool Status::_internal_has_has_transit_tiles() const { + return has_has_transit_tiles_case() == kHasTransitTiles; +} +inline bool Status::has_has_transit_tiles() const { + return _internal_has_has_transit_tiles(); +} +inline void Status::set_has_has_transit_tiles() { + _impl_._oneof_case_[5] = kHasTransitTiles; +} +inline void Status::clear_has_transit_tiles() { + if (_internal_has_has_transit_tiles()) { + _impl_.has_has_transit_tiles_.has_transit_tiles_ = false; + clear_has_has_has_transit_tiles(); + } +} +inline bool Status::_internal_has_transit_tiles() const { + if (_internal_has_has_transit_tiles()) { + return _impl_.has_has_transit_tiles_.has_transit_tiles_; + } + return false; +} +inline void Status::_internal_set_has_transit_tiles(bool value) { + if (!_internal_has_has_transit_tiles()) { + clear_has_has_transit_tiles(); + set_has_has_transit_tiles(); + } + _impl_.has_has_transit_tiles_.has_transit_tiles_ = value; +} +inline bool Status::has_transit_tiles() const { + // @@protoc_insertion_point(field_get:valhalla.Status.has_transit_tiles) + return _internal_has_transit_tiles(); +} +inline void Status::set_has_transit_tiles(bool value) { + _internal_set_has_transit_tiles(value); + // @@protoc_insertion_point(field_set:valhalla.Status.has_transit_tiles) +} + +// uint64 osm_changeset = 10; +inline bool Status::_internal_has_osm_changeset() const { + return has_osm_changeset_case() == kOsmChangeset; +} +inline bool Status::has_osm_changeset() const { + return _internal_has_osm_changeset(); +} +inline void Status::set_has_osm_changeset() { + _impl_._oneof_case_[6] = kOsmChangeset; +} +inline void Status::clear_osm_changeset() { + if (_internal_has_osm_changeset()) { + _impl_.has_osm_changeset_.osm_changeset_ = uint64_t{0u}; + clear_has_has_osm_changeset(); + } +} +inline uint64_t Status::_internal_osm_changeset() const { + if (_internal_has_osm_changeset()) { + return _impl_.has_osm_changeset_.osm_changeset_; + } + return uint64_t{0u}; +} +inline void Status::_internal_set_osm_changeset(uint64_t value) { + if (!_internal_has_osm_changeset()) { + clear_has_osm_changeset(); + set_has_osm_changeset(); + } + _impl_.has_osm_changeset_.osm_changeset_ = value; +} +inline uint64_t Status::osm_changeset() const { + // @@protoc_insertion_point(field_get:valhalla.Status.osm_changeset) + return _internal_osm_changeset(); +} +inline void Status::set_osm_changeset(uint64_t value) { + _internal_set_osm_changeset(value); + // @@protoc_insertion_point(field_set:valhalla.Status.osm_changeset) +} + inline bool Status::has_has_has_tiles() const { return has_has_tiles_case() != HAS_HAS_TILES_NOT_SET; } @@ -878,17 +931,17 @@ inline bool Status::has_has_bbox() const { inline void Status::clear_has_has_bbox() { _impl_._oneof_case_[4] = HAS_BBOX_NOT_SET; } -inline bool Status::has_has_version() const { - return has_version_case() != HAS_VERSION_NOT_SET; +inline bool Status::has_has_has_transit_tiles() const { + return has_has_transit_tiles_case() != HAS_HAS_TRANSIT_TILES_NOT_SET; } -inline void Status::clear_has_has_version() { - _impl_._oneof_case_[5] = HAS_VERSION_NOT_SET; +inline void Status::clear_has_has_has_transit_tiles() { + _impl_._oneof_case_[5] = HAS_HAS_TRANSIT_TILES_NOT_SET; } -inline bool Status::has_has_tileset_last_modified() const { - return has_tileset_last_modified_case() != HAS_TILESET_LAST_MODIFIED_NOT_SET; +inline bool Status::has_has_osm_changeset() const { + return has_osm_changeset_case() != HAS_OSM_CHANGESET_NOT_SET; } -inline void Status::clear_has_has_tileset_last_modified() { - _impl_._oneof_case_[6] = HAS_TILESET_LAST_MODIFIED_NOT_SET; +inline void Status::clear_has_has_osm_changeset() { + _impl_._oneof_case_[6] = HAS_OSM_CHANGESET_NOT_SET; } inline Status::HasHasTilesCase Status::has_has_tiles_case() const { return Status::HasHasTilesCase(_impl_._oneof_case_[0]); @@ -905,11 +958,11 @@ inline Status::HasHasLiveTrafficCase Status::has_has_live_traffic_case() const { inline Status::HasBboxCase Status::has_bbox_case() const { return Status::HasBboxCase(_impl_._oneof_case_[4]); } -inline Status::HasVersionCase Status::has_version_case() const { - return Status::HasVersionCase(_impl_._oneof_case_[5]); +inline Status::HasHasTransitTilesCase Status::has_has_transit_tiles_case() const { + return Status::HasHasTransitTilesCase(_impl_._oneof_case_[5]); } -inline Status::HasTilesetLastModifiedCase Status::has_tileset_last_modified_case() const { - return Status::HasTilesetLastModifiedCase(_impl_._oneof_case_[6]); +inline Status::HasOsmChangesetCase Status::has_osm_changeset_case() const { + return Status::HasOsmChangesetCase(_impl_._oneof_case_[6]); } #ifdef __GNUC__ #pragma GCC diagnostic pop diff --git a/include/linux/valhalla/proto/transit.pb.cc b/include/linux/valhalla/proto/transit.pb.cc index 95b0846..7150fe1 100644 --- a/include/linux/valhalla/proto/transit.pb.cc +++ b/include/linux/valhalla/proto/transit.pb.cc @@ -30,10 +30,12 @@ PROTOBUF_CONSTEXPR Transit_Node::Transit_Node( , /*decltype(_impl_.lat_)*/0 , /*decltype(_impl_.graphid_)*/uint64_t{0u} , /*decltype(_impl_.prev_type_graphid_)*/uint64_t{0u} - , /*decltype(_impl_.osm_way_id_)*/uint64_t{0u} + , /*decltype(_impl_.osm_connecting_way_id_)*/uint64_t{0u} , /*decltype(_impl_.type_)*/0u , /*decltype(_impl_.wheelchair_boarding_)*/false , /*decltype(_impl_.generated_)*/false + , /*decltype(_impl_.osm_connecting_lon_)*/0 + , /*decltype(_impl_.osm_connecting_lat_)*/0 , /*decltype(_impl_.traversability_)*/0u} {} struct Transit_NodeDefaultTypeInternal { PROTOBUF_CONSTEXPR Transit_NodeDefaultTypeInternal() @@ -253,7 +255,7 @@ class Transit_Node::_Internal { static void set_has_onestop_id(HasBits* has_bits) { (*has_bits)[0] |= 2u; } - static void set_has_osm_way_id(HasBits* has_bits) { + static void set_has_osm_connecting_way_id(HasBits* has_bits) { (*has_bits)[0] |= 128u; } static void set_has_timezone(HasBits* has_bits) { @@ -266,8 +268,14 @@ class Transit_Node::_Internal { (*has_bits)[0] |= 1024u; } static void set_has_traversability(HasBits* has_bits) { + (*has_bits)[0] |= 8192u; + } + static void set_has_osm_connecting_lon(HasBits* has_bits) { (*has_bits)[0] |= 2048u; } + static void set_has_osm_connecting_lat(HasBits* has_bits) { + (*has_bits)[0] |= 4096u; + } }; Transit_Node::Transit_Node(::PROTOBUF_NAMESPACE_ID::Arena* arena, @@ -289,10 +297,12 @@ Transit_Node::Transit_Node(const Transit_Node& from) , decltype(_impl_.lat_){} , decltype(_impl_.graphid_){} , decltype(_impl_.prev_type_graphid_){} - , decltype(_impl_.osm_way_id_){} + , decltype(_impl_.osm_connecting_way_id_){} , decltype(_impl_.type_){} , decltype(_impl_.wheelchair_boarding_){} , decltype(_impl_.generated_){} + , decltype(_impl_.osm_connecting_lon_){} + , decltype(_impl_.osm_connecting_lat_){} , decltype(_impl_.traversability_){}}; _internal_metadata_.MergeFrom(from._internal_metadata_); @@ -340,10 +350,12 @@ inline void Transit_Node::SharedCtor( , decltype(_impl_.lat_){0} , decltype(_impl_.graphid_){uint64_t{0u}} , decltype(_impl_.prev_type_graphid_){uint64_t{0u}} - , decltype(_impl_.osm_way_id_){uint64_t{0u}} + , decltype(_impl_.osm_connecting_way_id_){uint64_t{0u}} , decltype(_impl_.type_){0u} , decltype(_impl_.wheelchair_boarding_){false} , decltype(_impl_.generated_){false} + , decltype(_impl_.osm_connecting_lon_){0} + , decltype(_impl_.osm_connecting_lat_){0} , decltype(_impl_.traversability_){0u} }; _impl_.name_.InitDefault(); @@ -400,10 +412,10 @@ void Transit_Node::Clear() { } if (cached_has_bits & 0x000000f8u) { ::memset(&_impl_.lon_, 0, static_cast( - reinterpret_cast(&_impl_.osm_way_id_) - - reinterpret_cast(&_impl_.lon_)) + sizeof(_impl_.osm_way_id_)); + reinterpret_cast(&_impl_.osm_connecting_way_id_) - + reinterpret_cast(&_impl_.lon_)) + sizeof(_impl_.osm_connecting_way_id_)); } - if (cached_has_bits & 0x00000f00u) { + if (cached_has_bits & 0x00003f00u) { ::memset(&_impl_.type_, 0, static_cast( reinterpret_cast(&_impl_.traversability_) - reinterpret_cast(&_impl_.type_)) + sizeof(_impl_.traversability_)); @@ -419,21 +431,21 @@ const char* Transit_Node::_InternalParse(const char* ptr, ::_pbi::ParseContext* uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { - // optional float lon = 1; + // optional double lon = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 13)) { + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 9)) { _Internal::set_has_lon(&has_bits); - _impl_.lon_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad(ptr); - ptr += sizeof(float); + _impl_.lon_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad(ptr); + ptr += sizeof(double); } else goto handle_unusual; continue; - // optional float lat = 2; + // optional double lat = 2; case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 21)) { + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 17)) { _Internal::set_has_lat(&has_bits); - _impl_.lat_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad(ptr); - ptr += sizeof(float); + _impl_.lat_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad(ptr); + ptr += sizeof(double); } else goto handle_unusual; continue; @@ -482,11 +494,11 @@ const char* Transit_Node::_InternalParse(const char* ptr, ::_pbi::ParseContext* } else goto handle_unusual; continue; - // optional uint64 osm_way_id = 8; + // optional uint64 osm_connecting_way_id = 8; case 8: if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 64)) { - _Internal::set_has_osm_way_id(&has_bits); - _impl_.osm_way_id_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); + _Internal::set_has_osm_connecting_way_id(&has_bits); + _impl_.osm_connecting_way_id_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); CHK_(ptr); } else goto handle_unusual; @@ -527,6 +539,24 @@ const char* Transit_Node::_InternalParse(const char* ptr, ::_pbi::ParseContext* } else goto handle_unusual; continue; + // optional double osm_connecting_lon = 13; + case 13: + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 105)) { + _Internal::set_has_osm_connecting_lon(&has_bits); + _impl_.osm_connecting_lon_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad(ptr); + ptr += sizeof(double); + } else + goto handle_unusual; + continue; + // optional double osm_connecting_lat = 14; + case 14: + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 113)) { + _Internal::set_has_osm_connecting_lat(&has_bits); + _impl_.osm_connecting_lat_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad(ptr); + ptr += sizeof(double); + } else + goto handle_unusual; + continue; default: goto handle_unusual; } // switch @@ -558,16 +588,16 @@ uint8_t* Transit_Node::_InternalSerialize( (void) cached_has_bits; cached_has_bits = _impl_._has_bits_[0]; - // optional float lon = 1; + // optional double lon = 1; if (cached_has_bits & 0x00000008u) { target = stream->EnsureSpace(target); - target = ::_pbi::WireFormatLite::WriteFloatToArray(1, this->_internal_lon(), target); + target = ::_pbi::WireFormatLite::WriteDoubleToArray(1, this->_internal_lon(), target); } - // optional float lat = 2; + // optional double lat = 2; if (cached_has_bits & 0x00000010u) { target = stream->EnsureSpace(target); - target = ::_pbi::WireFormatLite::WriteFloatToArray(2, this->_internal_lat(), target); + target = ::_pbi::WireFormatLite::WriteDoubleToArray(2, this->_internal_lat(), target); } // optional uint32 type = 3; @@ -600,10 +630,10 @@ uint8_t* Transit_Node::_InternalSerialize( 7, this->_internal_onestop_id(), target); } - // optional uint64 osm_way_id = 8; + // optional uint64 osm_connecting_way_id = 8; if (cached_has_bits & 0x00000080u) { target = stream->EnsureSpace(target); - target = ::_pbi::WireFormatLite::WriteUInt64ToArray(8, this->_internal_osm_way_id(), target); + target = ::_pbi::WireFormatLite::WriteUInt64ToArray(8, this->_internal_osm_connecting_way_id(), target); } // optional string timezone = 9; @@ -625,11 +655,23 @@ uint8_t* Transit_Node::_InternalSerialize( } // optional uint32 traversability = 12; - if (cached_has_bits & 0x00000800u) { + if (cached_has_bits & 0x00002000u) { target = stream->EnsureSpace(target); target = ::_pbi::WireFormatLite::WriteUInt32ToArray(12, this->_internal_traversability(), target); } + // optional double osm_connecting_lon = 13; + if (cached_has_bits & 0x00000800u) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteDoubleToArray(13, this->_internal_osm_connecting_lon(), target); + } + + // optional double osm_connecting_lat = 14; + if (cached_has_bits & 0x00001000u) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteDoubleToArray(14, this->_internal_osm_connecting_lat(), target); + } + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { target = stream->WriteRaw(_internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).data(), static_cast(_internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).size()), target); @@ -669,14 +711,14 @@ size_t Transit_Node::ByteSizeLong() const { this->_internal_timezone()); } - // optional float lon = 1; + // optional double lon = 1; if (cached_has_bits & 0x00000008u) { - total_size += 1 + 4; + total_size += 1 + 8; } - // optional float lat = 2; + // optional double lat = 2; if (cached_has_bits & 0x00000010u) { - total_size += 1 + 4; + total_size += 1 + 8; } // optional uint64 graphid = 4; @@ -689,13 +731,13 @@ size_t Transit_Node::ByteSizeLong() const { total_size += ::_pbi::WireFormatLite::UInt64SizePlusOne(this->_internal_prev_type_graphid()); } - // optional uint64 osm_way_id = 8; + // optional uint64 osm_connecting_way_id = 8; if (cached_has_bits & 0x00000080u) { - total_size += ::_pbi::WireFormatLite::UInt64SizePlusOne(this->_internal_osm_way_id()); + total_size += ::_pbi::WireFormatLite::UInt64SizePlusOne(this->_internal_osm_connecting_way_id()); } } - if (cached_has_bits & 0x00000f00u) { + if (cached_has_bits & 0x00003f00u) { // optional uint32 type = 3; if (cached_has_bits & 0x00000100u) { total_size += ::_pbi::WireFormatLite::UInt32SizePlusOne(this->_internal_type()); @@ -711,8 +753,18 @@ size_t Transit_Node::ByteSizeLong() const { total_size += 1 + 1; } - // optional uint32 traversability = 12; + // optional double osm_connecting_lon = 13; if (cached_has_bits & 0x00000800u) { + total_size += 1 + 8; + } + + // optional double osm_connecting_lat = 14; + if (cached_has_bits & 0x00001000u) { + total_size += 1 + 8; + } + + // optional uint32 traversability = 12; + if (cached_has_bits & 0x00002000u) { total_size += ::_pbi::WireFormatLite::UInt32SizePlusOne(this->_internal_traversability()); } @@ -762,11 +814,11 @@ void Transit_Node::MergeFrom(const Transit_Node& from) { _this->_impl_.prev_type_graphid_ = from._impl_.prev_type_graphid_; } if (cached_has_bits & 0x00000080u) { - _this->_impl_.osm_way_id_ = from._impl_.osm_way_id_; + _this->_impl_.osm_connecting_way_id_ = from._impl_.osm_connecting_way_id_; } _this->_impl_._has_bits_[0] |= cached_has_bits; } - if (cached_has_bits & 0x00000f00u) { + if (cached_has_bits & 0x00003f00u) { if (cached_has_bits & 0x00000100u) { _this->_impl_.type_ = from._impl_.type_; } @@ -777,6 +829,12 @@ void Transit_Node::MergeFrom(const Transit_Node& from) { _this->_impl_.generated_ = from._impl_.generated_; } if (cached_has_bits & 0x00000800u) { + _this->_impl_.osm_connecting_lon_ = from._impl_.osm_connecting_lon_; + } + if (cached_has_bits & 0x00001000u) { + _this->_impl_.osm_connecting_lat_ = from._impl_.osm_connecting_lat_; + } + if (cached_has_bits & 0x00002000u) { _this->_impl_.traversability_ = from._impl_.traversability_; } _this->_impl_._has_bits_[0] |= cached_has_bits; diff --git a/include/linux/valhalla/proto/transit.pb.h b/include/linux/valhalla/proto/transit.pb.h index a29f1b3..d7f12e2 100644 --- a/include/linux/valhalla/proto/transit.pb.h +++ b/include/linux/valhalla/proto/transit.pb.h @@ -215,10 +215,12 @@ class Transit_Node final : kLatFieldNumber = 2, kGraphidFieldNumber = 4, kPrevTypeGraphidFieldNumber = 5, - kOsmWayIdFieldNumber = 8, + kOsmConnectingWayIdFieldNumber = 8, kTypeFieldNumber = 3, kWheelchairBoardingFieldNumber = 10, kGeneratedFieldNumber = 11, + kOsmConnectingLonFieldNumber = 13, + kOsmConnectingLatFieldNumber = 14, kTraversabilityFieldNumber = 12, }; // optional string name = 6; @@ -275,30 +277,30 @@ class Transit_Node final : std::string* _internal_mutable_timezone(); public: - // optional float lon = 1; + // optional double lon = 1; bool has_lon() const; private: bool _internal_has_lon() const; public: void clear_lon(); - float lon() const; - void set_lon(float value); + double lon() const; + void set_lon(double value); private: - float _internal_lon() const; - void _internal_set_lon(float value); + double _internal_lon() const; + void _internal_set_lon(double value); public: - // optional float lat = 2; + // optional double lat = 2; bool has_lat() const; private: bool _internal_has_lat() const; public: void clear_lat(); - float lat() const; - void set_lat(float value); + double lat() const; + void set_lat(double value); private: - float _internal_lat() const; - void _internal_set_lat(float value); + double _internal_lat() const; + void _internal_set_lat(double value); public: // optional uint64 graphid = 4; @@ -327,17 +329,17 @@ class Transit_Node final : void _internal_set_prev_type_graphid(uint64_t value); public: - // optional uint64 osm_way_id = 8; - bool has_osm_way_id() const; + // optional uint64 osm_connecting_way_id = 8; + bool has_osm_connecting_way_id() const; private: - bool _internal_has_osm_way_id() const; + bool _internal_has_osm_connecting_way_id() const; public: - void clear_osm_way_id(); - uint64_t osm_way_id() const; - void set_osm_way_id(uint64_t value); + void clear_osm_connecting_way_id(); + uint64_t osm_connecting_way_id() const; + void set_osm_connecting_way_id(uint64_t value); private: - uint64_t _internal_osm_way_id() const; - void _internal_set_osm_way_id(uint64_t value); + uint64_t _internal_osm_connecting_way_id() const; + void _internal_set_osm_connecting_way_id(uint64_t value); public: // optional uint32 type = 3; @@ -379,6 +381,32 @@ class Transit_Node final : void _internal_set_generated(bool value); public: + // optional double osm_connecting_lon = 13; + bool has_osm_connecting_lon() const; + private: + bool _internal_has_osm_connecting_lon() const; + public: + void clear_osm_connecting_lon(); + double osm_connecting_lon() const; + void set_osm_connecting_lon(double value); + private: + double _internal_osm_connecting_lon() const; + void _internal_set_osm_connecting_lon(double value); + public: + + // optional double osm_connecting_lat = 14; + bool has_osm_connecting_lat() const; + private: + bool _internal_has_osm_connecting_lat() const; + public: + void clear_osm_connecting_lat(); + double osm_connecting_lat() const; + void set_osm_connecting_lat(double value); + private: + double _internal_osm_connecting_lat() const; + void _internal_set_osm_connecting_lat(double value); + public: + // optional uint32 traversability = 12; bool has_traversability() const; private: @@ -405,14 +433,16 @@ class Transit_Node final : ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_; ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr onestop_id_; ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr timezone_; - float lon_; - float lat_; + double lon_; + double lat_; uint64_t graphid_; uint64_t prev_type_graphid_; - uint64_t osm_way_id_; + uint64_t osm_connecting_way_id_; uint32_t type_; bool wheelchair_boarding_; bool generated_; + double osm_connecting_lon_; + double osm_connecting_lat_; uint32_t traversability_; }; union { Impl_ _impl_; }; @@ -1671,7 +1701,7 @@ class Transit final : #endif // __GNUC__ // Transit_Node -// optional float lon = 1; +// optional double lon = 1; inline bool Transit_Node::_internal_has_lon() const { bool value = (_impl_._has_bits_[0] & 0x00000008u) != 0; return value; @@ -1683,23 +1713,23 @@ inline void Transit_Node::clear_lon() { _impl_.lon_ = 0; _impl_._has_bits_[0] &= ~0x00000008u; } -inline float Transit_Node::_internal_lon() const { +inline double Transit_Node::_internal_lon() const { return _impl_.lon_; } -inline float Transit_Node::lon() const { +inline double Transit_Node::lon() const { // @@protoc_insertion_point(field_get:valhalla.mjolnir.Transit.Node.lon) return _internal_lon(); } -inline void Transit_Node::_internal_set_lon(float value) { +inline void Transit_Node::_internal_set_lon(double value) { _impl_._has_bits_[0] |= 0x00000008u; _impl_.lon_ = value; } -inline void Transit_Node::set_lon(float value) { +inline void Transit_Node::set_lon(double value) { _internal_set_lon(value); // @@protoc_insertion_point(field_set:valhalla.mjolnir.Transit.Node.lon) } -// optional float lat = 2; +// optional double lat = 2; inline bool Transit_Node::_internal_has_lat() const { bool value = (_impl_._has_bits_[0] & 0x00000010u) != 0; return value; @@ -1711,18 +1741,18 @@ inline void Transit_Node::clear_lat() { _impl_.lat_ = 0; _impl_._has_bits_[0] &= ~0x00000010u; } -inline float Transit_Node::_internal_lat() const { +inline double Transit_Node::_internal_lat() const { return _impl_.lat_; } -inline float Transit_Node::lat() const { +inline double Transit_Node::lat() const { // @@protoc_insertion_point(field_get:valhalla.mjolnir.Transit.Node.lat) return _internal_lat(); } -inline void Transit_Node::_internal_set_lat(float value) { +inline void Transit_Node::_internal_set_lat(double value) { _impl_._has_bits_[0] |= 0x00000010u; _impl_.lat_ = value; } -inline void Transit_Node::set_lat(float value) { +inline void Transit_Node::set_lat(double value) { _internal_set_lat(value); // @@protoc_insertion_point(field_set:valhalla.mjolnir.Transit.Node.lat) } @@ -1947,32 +1977,32 @@ inline void Transit_Node::set_allocated_onestop_id(std::string* onestop_id) { // @@protoc_insertion_point(field_set_allocated:valhalla.mjolnir.Transit.Node.onestop_id) } -// optional uint64 osm_way_id = 8; -inline bool Transit_Node::_internal_has_osm_way_id() const { +// optional uint64 osm_connecting_way_id = 8; +inline bool Transit_Node::_internal_has_osm_connecting_way_id() const { bool value = (_impl_._has_bits_[0] & 0x00000080u) != 0; return value; } -inline bool Transit_Node::has_osm_way_id() const { - return _internal_has_osm_way_id(); +inline bool Transit_Node::has_osm_connecting_way_id() const { + return _internal_has_osm_connecting_way_id(); } -inline void Transit_Node::clear_osm_way_id() { - _impl_.osm_way_id_ = uint64_t{0u}; +inline void Transit_Node::clear_osm_connecting_way_id() { + _impl_.osm_connecting_way_id_ = uint64_t{0u}; _impl_._has_bits_[0] &= ~0x00000080u; } -inline uint64_t Transit_Node::_internal_osm_way_id() const { - return _impl_.osm_way_id_; +inline uint64_t Transit_Node::_internal_osm_connecting_way_id() const { + return _impl_.osm_connecting_way_id_; } -inline uint64_t Transit_Node::osm_way_id() const { - // @@protoc_insertion_point(field_get:valhalla.mjolnir.Transit.Node.osm_way_id) - return _internal_osm_way_id(); +inline uint64_t Transit_Node::osm_connecting_way_id() const { + // @@protoc_insertion_point(field_get:valhalla.mjolnir.Transit.Node.osm_connecting_way_id) + return _internal_osm_connecting_way_id(); } -inline void Transit_Node::_internal_set_osm_way_id(uint64_t value) { +inline void Transit_Node::_internal_set_osm_connecting_way_id(uint64_t value) { _impl_._has_bits_[0] |= 0x00000080u; - _impl_.osm_way_id_ = value; + _impl_.osm_connecting_way_id_ = value; } -inline void Transit_Node::set_osm_way_id(uint64_t value) { - _internal_set_osm_way_id(value); - // @@protoc_insertion_point(field_set:valhalla.mjolnir.Transit.Node.osm_way_id) +inline void Transit_Node::set_osm_connecting_way_id(uint64_t value) { + _internal_set_osm_connecting_way_id(value); + // @@protoc_insertion_point(field_set:valhalla.mjolnir.Transit.Node.osm_connecting_way_id) } // optional string timezone = 9; @@ -2101,7 +2131,7 @@ inline void Transit_Node::set_generated(bool value) { // optional uint32 traversability = 12; inline bool Transit_Node::_internal_has_traversability() const { - bool value = (_impl_._has_bits_[0] & 0x00000800u) != 0; + bool value = (_impl_._has_bits_[0] & 0x00002000u) != 0; return value; } inline bool Transit_Node::has_traversability() const { @@ -2109,7 +2139,7 @@ inline bool Transit_Node::has_traversability() const { } inline void Transit_Node::clear_traversability() { _impl_.traversability_ = 0u; - _impl_._has_bits_[0] &= ~0x00000800u; + _impl_._has_bits_[0] &= ~0x00002000u; } inline uint32_t Transit_Node::_internal_traversability() const { return _impl_.traversability_; @@ -2119,7 +2149,7 @@ inline uint32_t Transit_Node::traversability() const { return _internal_traversability(); } inline void Transit_Node::_internal_set_traversability(uint32_t value) { - _impl_._has_bits_[0] |= 0x00000800u; + _impl_._has_bits_[0] |= 0x00002000u; _impl_.traversability_ = value; } inline void Transit_Node::set_traversability(uint32_t value) { @@ -2127,6 +2157,62 @@ inline void Transit_Node::set_traversability(uint32_t value) { // @@protoc_insertion_point(field_set:valhalla.mjolnir.Transit.Node.traversability) } +// optional double osm_connecting_lon = 13; +inline bool Transit_Node::_internal_has_osm_connecting_lon() const { + bool value = (_impl_._has_bits_[0] & 0x00000800u) != 0; + return value; +} +inline bool Transit_Node::has_osm_connecting_lon() const { + return _internal_has_osm_connecting_lon(); +} +inline void Transit_Node::clear_osm_connecting_lon() { + _impl_.osm_connecting_lon_ = 0; + _impl_._has_bits_[0] &= ~0x00000800u; +} +inline double Transit_Node::_internal_osm_connecting_lon() const { + return _impl_.osm_connecting_lon_; +} +inline double Transit_Node::osm_connecting_lon() const { + // @@protoc_insertion_point(field_get:valhalla.mjolnir.Transit.Node.osm_connecting_lon) + return _internal_osm_connecting_lon(); +} +inline void Transit_Node::_internal_set_osm_connecting_lon(double value) { + _impl_._has_bits_[0] |= 0x00000800u; + _impl_.osm_connecting_lon_ = value; +} +inline void Transit_Node::set_osm_connecting_lon(double value) { + _internal_set_osm_connecting_lon(value); + // @@protoc_insertion_point(field_set:valhalla.mjolnir.Transit.Node.osm_connecting_lon) +} + +// optional double osm_connecting_lat = 14; +inline bool Transit_Node::_internal_has_osm_connecting_lat() const { + bool value = (_impl_._has_bits_[0] & 0x00001000u) != 0; + return value; +} +inline bool Transit_Node::has_osm_connecting_lat() const { + return _internal_has_osm_connecting_lat(); +} +inline void Transit_Node::clear_osm_connecting_lat() { + _impl_.osm_connecting_lat_ = 0; + _impl_._has_bits_[0] &= ~0x00001000u; +} +inline double Transit_Node::_internal_osm_connecting_lat() const { + return _impl_.osm_connecting_lat_; +} +inline double Transit_Node::osm_connecting_lat() const { + // @@protoc_insertion_point(field_get:valhalla.mjolnir.Transit.Node.osm_connecting_lat) + return _internal_osm_connecting_lat(); +} +inline void Transit_Node::_internal_set_osm_connecting_lat(double value) { + _impl_._has_bits_[0] |= 0x00001000u; + _impl_.osm_connecting_lat_ = value; +} +inline void Transit_Node::set_osm_connecting_lat(double value) { + _internal_set_osm_connecting_lat(value); + // @@protoc_insertion_point(field_set:valhalla.mjolnir.Transit.Node.osm_connecting_lat) +} + // ------------------------------------------------------------------- // Transit_StopPair diff --git a/include/windows/valhalla/proto/options.pb.cc b/include/windows/valhalla/proto/options.pb.cc index 745ab34..9acc407 100644 --- a/include/windows/valhalla/proto/options.pb.cc +++ b/include/windows/valhalla/proto/options.pb.cc @@ -89,6 +89,8 @@ PROTOBUF_CONSTEXPR Costing_Options::Costing_Options( , /*decltype(_impl_.filter_route_action_)*/0 , /*decltype(_impl_.fixed_speed_)*/0u , /*decltype(_impl_.axle_count_)*/0u + , /*decltype(_impl_.use_lit_)*/0 + , /*decltype(_impl_.disable_hierarchy_pruning_)*/false , /*decltype(_impl_.has_maneuver_penalty_)*/{} , /*decltype(_impl_.has_destination_only_penalty_)*/{} , /*decltype(_impl_.has_gate_cost_)*/{} @@ -226,7 +228,6 @@ PROTOBUF_CONSTEXPR Options::Options( , /*decltype(_impl_.filter_action_)*/0 , /*decltype(_impl_.shape_format_)*/0 , /*decltype(_impl_.reverse_)*/false - , /*decltype(_impl_.matrix_locations_)*/0u , /*decltype(_impl_.has_language_)*/{} , /*decltype(_impl_.has_id_)*/{} , /*decltype(_impl_.has_jsonp_)*/{} @@ -253,6 +254,7 @@ PROTOBUF_CONSTEXPR Options::Options( , /*decltype(_impl_.has_prioritize_bidirectional_)*/{} , /*decltype(_impl_.has_expansion_action_)*/{} , /*decltype(_impl_.has_skip_opposites_)*/{} + , /*decltype(_impl_.has_matrix_locations_)*/{} , /*decltype(_impl_._cached_size_)*/{} , /*decltype(_impl_._oneof_case_)*/{}} {} struct OptionsDefaultTypeInternal { @@ -2106,6 +2108,8 @@ Costing_Options::Costing_Options(const Costing_Options& from) , decltype(_impl_.filter_route_action_){} , decltype(_impl_.fixed_speed_){} , decltype(_impl_.axle_count_){} + , decltype(_impl_.use_lit_){} + , decltype(_impl_.disable_hierarchy_pruning_){} , decltype(_impl_.has_maneuver_penalty_){} , decltype(_impl_.has_destination_only_penalty_){} , decltype(_impl_.has_gate_cost_){} @@ -2183,8 +2187,8 @@ Costing_Options::Costing_Options(const Costing_Options& from) _internal_metadata_.MergeFrom(from._internal_metadata_); ::memcpy(&_impl_.filter_stop_action_, &from._impl_.filter_stop_action_, - static_cast(reinterpret_cast(&_impl_.axle_count_) - - reinterpret_cast(&_impl_.filter_stop_action_)) + sizeof(_impl_.axle_count_)); + static_cast(reinterpret_cast(&_impl_.disable_hierarchy_pruning_) - + reinterpret_cast(&_impl_.filter_stop_action_)) + sizeof(_impl_.disable_hierarchy_pruning_)); clear_has_has_maneuver_penalty(); switch (from.has_maneuver_penalty_case()) { case kManeuverPenalty: { @@ -2922,6 +2926,8 @@ inline void Costing_Options::SharedCtor( , decltype(_impl_.filter_route_action_){0} , decltype(_impl_.fixed_speed_){0u} , decltype(_impl_.axle_count_){0u} + , decltype(_impl_.use_lit_){0} + , decltype(_impl_.disable_hierarchy_pruning_){false} , decltype(_impl_.has_maneuver_penalty_){} , decltype(_impl_.has_destination_only_penalty_){} , decltype(_impl_.has_gate_cost_){} @@ -4328,8 +4334,8 @@ void Costing_Options::Clear() { _impl_.filter_route_ids_.Clear(); _impl_.exclude_edges_.Clear(); ::memset(&_impl_.filter_stop_action_, 0, static_cast( - reinterpret_cast(&_impl_.axle_count_) - - reinterpret_cast(&_impl_.filter_stop_action_)) + sizeof(_impl_.axle_count_)); + reinterpret_cast(&_impl_.disable_hierarchy_pruning_) - + reinterpret_cast(&_impl_.filter_stop_action_)) + sizeof(_impl_.disable_hierarchy_pruning_)); clear_has_maneuver_penalty(); clear_has_destination_only_penalty(); clear_has_gate_cost(); @@ -5090,6 +5096,22 @@ const char* Costing_Options::_InternalParse(const char* ptr, ::_pbi::ParseContex } else goto handle_unusual; continue; + // float use_lit = 82; + case 82: + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 149)) { + _impl_.use_lit_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad(ptr); + ptr += sizeof(float); + } else + goto handle_unusual; + continue; + // bool disable_hierarchy_pruning = 83; + case 83: + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 152)) { + _impl_.disable_hierarchy_pruning_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); + CHK_(ptr); + } else + goto handle_unusual; + continue; default: goto handle_unusual; } // switch @@ -5626,6 +5648,22 @@ uint8_t* Costing_Options::_InternalSerialize( target = ::_pbi::WireFormatLite::WriteUInt32ToArray(81, this->_internal_axle_count(), target); } + // float use_lit = 82; + static_assert(sizeof(uint32_t) == sizeof(float), "Code assumes uint32_t and float are the same size."); + float tmp_use_lit = this->_internal_use_lit(); + uint32_t raw_use_lit; + memcpy(&raw_use_lit, &tmp_use_lit, sizeof(tmp_use_lit)); + if (raw_use_lit != 0) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteFloatToArray(82, this->_internal_use_lit(), target); + } + + // bool disable_hierarchy_pruning = 83; + if (this->_internal_disable_hierarchy_pruning() != 0) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteBoolToArray(83, this->_internal_disable_hierarchy_pruning(), target); + } + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { target = stream->WriteRaw(_internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).data(), static_cast(_internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).size()), target); @@ -5705,6 +5743,20 @@ size_t Costing_Options::ByteSizeLong() const { this->_internal_axle_count()); } + // float use_lit = 82; + static_assert(sizeof(uint32_t) == sizeof(float), "Code assumes uint32_t and float are the same size."); + float tmp_use_lit = this->_internal_use_lit(); + uint32_t raw_use_lit; + memcpy(&raw_use_lit, &tmp_use_lit, sizeof(tmp_use_lit)); + if (raw_use_lit != 0) { + total_size += 2 + 4; + } + + // bool disable_hierarchy_pruning = 83; + if (this->_internal_disable_hierarchy_pruning() != 0) { + total_size += 2 + 1; + } + switch (has_maneuver_penalty_case()) { // float maneuver_penalty = 1; case kManeuverPenalty: { @@ -6481,6 +6533,16 @@ void Costing_Options::MergeFrom(const Costing_Options& from) { if (from._internal_axle_count() != 0) { _this->_internal_set_axle_count(from._internal_axle_count()); } + static_assert(sizeof(uint32_t) == sizeof(float), "Code assumes uint32_t and float are the same size."); + float tmp_use_lit = from._internal_use_lit(); + uint32_t raw_use_lit; + memcpy(&raw_use_lit, &tmp_use_lit, sizeof(tmp_use_lit)); + if (raw_use_lit != 0) { + _this->_internal_set_use_lit(from._internal_use_lit()); + } + if (from._internal_disable_hierarchy_pruning() != 0) { + _this->_internal_set_disable_hierarchy_pruning(from._internal_disable_hierarchy_pruning()); + } switch (from.has_maneuver_penalty_case()) { case kManeuverPenalty: { _this->_internal_set_maneuver_penalty(from._internal_maneuver_penalty()); @@ -7151,8 +7213,8 @@ void Costing_Options::InternalSwap(Costing_Options* other) { _impl_.filter_route_ids_.InternalSwap(&other->_impl_.filter_route_ids_); _impl_.exclude_edges_.InternalSwap(&other->_impl_.exclude_edges_); ::PROTOBUF_NAMESPACE_ID::internal::memswap< - PROTOBUF_FIELD_OFFSET(Costing_Options, _impl_.axle_count_) - + sizeof(Costing_Options::_impl_.axle_count_) + PROTOBUF_FIELD_OFFSET(Costing_Options, _impl_.disable_hierarchy_pruning_) + + sizeof(Costing_Options::_impl_.disable_hierarchy_pruning_) - PROTOBUF_FIELD_OFFSET(Costing_Options, _impl_.filter_stop_action_)>( reinterpret_cast(&_impl_.filter_stop_action_), reinterpret_cast(&other->_impl_.filter_stop_action_)); @@ -7798,7 +7860,6 @@ Options::Options(const Options& from) , decltype(_impl_.filter_action_){} , decltype(_impl_.shape_format_){} , decltype(_impl_.reverse_){} - , decltype(_impl_.matrix_locations_){} , decltype(_impl_.has_language_){} , decltype(_impl_.has_id_){} , decltype(_impl_.has_jsonp_){} @@ -7825,6 +7886,7 @@ Options::Options(const Options& from) , decltype(_impl_.has_prioritize_bidirectional_){} , decltype(_impl_.has_expansion_action_){} , decltype(_impl_.has_skip_opposites_){} + , decltype(_impl_.has_matrix_locations_){} , /*decltype(_impl_._cached_size_)*/{} , /*decltype(_impl_._oneof_case_)*/{}}; @@ -7834,8 +7896,8 @@ Options::Options(const Options& from) _this->_impl_.pbf_field_selector_ = new ::valhalla::PbfFieldSelector(*from._impl_.pbf_field_selector_); } ::memcpy(&_impl_.units_, &from._impl_.units_, - static_cast(reinterpret_cast(&_impl_.matrix_locations_) - - reinterpret_cast(&_impl_.units_)) + sizeof(_impl_.matrix_locations_)); + static_cast(reinterpret_cast(&_impl_.reverse_) - + reinterpret_cast(&_impl_.units_)) + sizeof(_impl_.reverse_)); clear_has_has_language(); switch (from.has_language_case()) { case kLanguage: { @@ -8096,6 +8158,16 @@ Options::Options(const Options& from) break; } } + clear_has_has_matrix_locations(); + switch (from.has_matrix_locations_case()) { + case kMatrixLocations: { + _this->_internal_set_matrix_locations(from._internal_matrix_locations()); + break; + } + case HAS_MATRIX_LOCATIONS_NOT_SET: { + break; + } + } // @@protoc_insertion_point(copy_constructor:valhalla.Options) } @@ -8128,7 +8200,6 @@ inline void Options::SharedCtor( , decltype(_impl_.filter_action_){0} , decltype(_impl_.shape_format_){0} , decltype(_impl_.reverse_){false} - , decltype(_impl_.matrix_locations_){0u} , decltype(_impl_.has_language_){} , decltype(_impl_.has_id_){} , decltype(_impl_.has_jsonp_){} @@ -8155,6 +8226,7 @@ inline void Options::SharedCtor( , decltype(_impl_.has_prioritize_bidirectional_){} , decltype(_impl_.has_expansion_action_){} , decltype(_impl_.has_skip_opposites_){} + , decltype(_impl_.has_matrix_locations_){} , /*decltype(_impl_._cached_size_)*/{} , /*decltype(_impl_._oneof_case_)*/{} }; @@ -8184,6 +8256,7 @@ inline void Options::SharedCtor( clear_has_has_prioritize_bidirectional(); clear_has_has_expansion_action(); clear_has_has_skip_opposites(); + clear_has_has_matrix_locations(); } Options::~Options() { @@ -8289,6 +8362,9 @@ inline void Options::SharedDtor() { if (has_has_skip_opposites()) { clear_has_skip_opposites(); } + if (has_has_matrix_locations()) { + clear_has_matrix_locations(); + } } void Options::SetCachedSize(int size) const { @@ -8659,6 +8735,20 @@ void Options::clear_has_skip_opposites() { _impl_._oneof_case_[25] = HAS_SKIP_OPPOSITES_NOT_SET; } +void Options::clear_has_matrix_locations() { +// @@protoc_insertion_point(one_of_clear_start:valhalla.Options) + switch (has_matrix_locations_case()) { + case kMatrixLocations: { + // No need to clear + break; + } + case HAS_MATRIX_LOCATIONS_NOT_SET: { + break; + } + } + _impl_._oneof_case_[26] = HAS_MATRIX_LOCATIONS_NOT_SET; +} + void Options::Clear() { // @@protoc_insertion_point(message_clear_start:valhalla.Options) @@ -8683,8 +8773,8 @@ void Options::Clear() { } _impl_.pbf_field_selector_ = nullptr; ::memset(&_impl_.units_, 0, static_cast( - reinterpret_cast(&_impl_.matrix_locations_) - - reinterpret_cast(&_impl_.units_)) + sizeof(_impl_.matrix_locations_)); + reinterpret_cast(&_impl_.reverse_) - + reinterpret_cast(&_impl_.units_)) + sizeof(_impl_.reverse_)); clear_has_language(); clear_has_id(); clear_has_jsonp(); @@ -8711,6 +8801,7 @@ void Options::Clear() { clear_has_prioritize_bidirectional(); clear_has_expansion_action(); clear_has_skip_opposites(); + clear_has_matrix_locations(); _internal_metadata_.Clear(); } @@ -9196,7 +9287,7 @@ const char* Options::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) // uint32 matrix_locations = 54; case 54: if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 176)) { - _impl_.matrix_locations_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + _internal_set_matrix_locations(::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr)); CHK_(ptr); } else goto handle_unusual; @@ -9592,7 +9683,7 @@ uint8_t* Options::_InternalSerialize( } // uint32 matrix_locations = 54; - if (this->_internal_matrix_locations() != 0) { + if (_internal_has_matrix_locations()) { target = stream->EnsureSpace(target); target = ::_pbi::WireFormatLite::WriteUInt32ToArray(54, this->_internal_matrix_locations(), target); } @@ -9776,13 +9867,6 @@ size_t Options::ByteSizeLong() const { total_size += 2 + 1; } - // uint32 matrix_locations = 54; - if (this->_internal_matrix_locations() != 0) { - total_size += 2 + - ::_pbi::WireFormatLite::UInt32Size( - this->_internal_matrix_locations()); - } - switch (has_language_case()) { // string language = 2; case kLanguage: { @@ -10058,6 +10142,18 @@ size_t Options::ByteSizeLong() const { break; } } + switch (has_matrix_locations_case()) { + // uint32 matrix_locations = 54; + case kMatrixLocations: { + total_size += 2 + + ::_pbi::WireFormatLite::UInt32Size( + this->_internal_matrix_locations()); + break; + } + case HAS_MATRIX_LOCATIONS_NOT_SET: { + break; + } + } if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { total_size += _internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).size(); } @@ -10125,9 +10221,6 @@ void Options::MergeFrom(const Options& from) { if (from._internal_reverse() != 0) { _this->_internal_set_reverse(from._internal_reverse()); } - if (from._internal_matrix_locations() != 0) { - _this->_internal_set_matrix_locations(from._internal_matrix_locations()); - } switch (from.has_language_case()) { case kLanguage: { _this->_internal_set_language(from._internal_language()); @@ -10362,6 +10455,15 @@ void Options::MergeFrom(const Options& from) { break; } } + switch (from.has_matrix_locations_case()) { + case kMatrixLocations: { + _this->_internal_set_matrix_locations(from._internal_matrix_locations()); + break; + } + case HAS_MATRIX_LOCATIONS_NOT_SET: { + break; + } + } _this->_internal_metadata_.MergeFrom(from._internal_metadata_); } @@ -10392,8 +10494,8 @@ void Options::InternalSwap(Options* other) { _impl_.exclude_polygons_.InternalSwap(&other->_impl_.exclude_polygons_); _impl_.expansion_properties_.InternalSwap(&other->_impl_.expansion_properties_); ::PROTOBUF_NAMESPACE_ID::internal::memswap< - PROTOBUF_FIELD_OFFSET(Options, _impl_.matrix_locations_) - + sizeof(Options::_impl_.matrix_locations_) + PROTOBUF_FIELD_OFFSET(Options, _impl_.reverse_) + + sizeof(Options::_impl_.reverse_) - PROTOBUF_FIELD_OFFSET(Options, _impl_.pbf_field_selector_)>( reinterpret_cast(&_impl_.pbf_field_selector_), reinterpret_cast(&other->_impl_.pbf_field_selector_)); @@ -10423,6 +10525,7 @@ void Options::InternalSwap(Options* other) { swap(_impl_.has_prioritize_bidirectional_, other->_impl_.has_prioritize_bidirectional_); swap(_impl_.has_expansion_action_, other->_impl_.has_expansion_action_); swap(_impl_.has_skip_opposites_, other->_impl_.has_skip_opposites_); + swap(_impl_.has_matrix_locations_, other->_impl_.has_matrix_locations_); swap(_impl_._oneof_case_[0], other->_impl_._oneof_case_[0]); swap(_impl_._oneof_case_[1], other->_impl_._oneof_case_[1]); swap(_impl_._oneof_case_[2], other->_impl_._oneof_case_[2]); @@ -10449,6 +10552,7 @@ void Options::InternalSwap(Options* other) { swap(_impl_._oneof_case_[23], other->_impl_._oneof_case_[23]); swap(_impl_._oneof_case_[24], other->_impl_._oneof_case_[24]); swap(_impl_._oneof_case_[25], other->_impl_._oneof_case_[25]); + swap(_impl_._oneof_case_[26], other->_impl_._oneof_case_[26]); } std::string Options::GetTypeName() const { diff --git a/include/windows/valhalla/proto/options.pb.h b/include/windows/valhalla/proto/options.pb.h index fc8e39e..e37860c 100644 --- a/include/windows/valhalla/proto/options.pb.h +++ b/include/windows/valhalla/proto/options.pb.h @@ -1500,6 +1500,8 @@ class Costing_Options final : kFilterRouteActionFieldNumber = 53, kFixedSpeedFieldNumber = 80, kAxleCountFieldNumber = 81, + kUseLitFieldNumber = 82, + kDisableHierarchyPruningFieldNumber = 83, kManeuverPenaltyFieldNumber = 1, kDestinationOnlyPenaltyFieldNumber = 2, kGateCostFieldNumber = 3, @@ -1708,6 +1710,24 @@ class Costing_Options final : void _internal_set_axle_count(uint32_t value); public: + // float use_lit = 82; + void clear_use_lit(); + float use_lit() const; + void set_use_lit(float value); + private: + float _internal_use_lit() const; + void _internal_set_use_lit(float value); + public: + + // bool disable_hierarchy_pruning = 83; + void clear_disable_hierarchy_pruning(); + bool disable_hierarchy_pruning() const; + void set_disable_hierarchy_pruning(bool value); + private: + bool _internal_disable_hierarchy_pruning() const; + void _internal_set_disable_hierarchy_pruning(bool value); + public: + // float maneuver_penalty = 1; bool has_maneuver_penalty() const; private: @@ -3098,6 +3118,8 @@ class Costing_Options final : int filter_route_action_; uint32_t fixed_speed_; uint32_t axle_count_; + float use_lit_; + bool disable_hierarchy_pruning_; union HasManeuverPenaltyUnion { constexpr HasManeuverPenaltyUnion() : _constinit_{} {} ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized _constinit_; @@ -3933,6 +3955,11 @@ class Options final : HAS_SKIP_OPPOSITES_NOT_SET = 0, }; + enum HasMatrixLocationsCase { + kMatrixLocations = 54, + HAS_MATRIX_LOCATIONS_NOT_SET = 0, + }; + static inline const Options* internal_default_instance() { return reinterpret_cast( &_Options_default_instance_); @@ -4194,7 +4221,6 @@ class Options final : kFilterActionFieldNumber = 33, kShapeFormatFieldNumber = 38, kReverseFieldNumber = 53, - kMatrixLocationsFieldNumber = 54, kLanguageFieldNumber = 2, kIdFieldNumber = 5, kJsonpFieldNumber = 6, @@ -4221,6 +4247,7 @@ class Options final : kPrioritizeBidirectionalFieldNumber = 48, kExpansionActionFieldNumber = 49, kSkipOppositesFieldNumber = 50, + kMatrixLocationsFieldNumber = 54, }; // map costings = 13; int costings_size() const; @@ -4550,15 +4577,6 @@ class Options final : void _internal_set_reverse(bool value); public: - // uint32 matrix_locations = 54; - void clear_matrix_locations(); - uint32_t matrix_locations() const; - void set_matrix_locations(uint32_t value); - private: - uint32_t _internal_matrix_locations() const; - void _internal_set_matrix_locations(uint32_t value); - public: - // string language = 2; bool has_language() const; private: @@ -4922,6 +4940,19 @@ class Options final : void _internal_set_skip_opposites(bool value); public: + // uint32 matrix_locations = 54; + bool has_matrix_locations() const; + private: + bool _internal_has_matrix_locations() const; + public: + void clear_matrix_locations(); + uint32_t matrix_locations() const; + void set_matrix_locations(uint32_t value); + private: + uint32_t _internal_matrix_locations() const; + void _internal_set_matrix_locations(uint32_t value); + public: + void clear_has_language(); HasLanguageCase has_language_case() const; void clear_has_id(); @@ -4974,6 +5005,8 @@ class Options final : HasExpansionActionCase has_expansion_action_case() const; void clear_has_skip_opposites(); HasSkipOppositesCase has_skip_opposites_case() const; + void clear_has_matrix_locations(); + HasMatrixLocationsCase has_matrix_locations_case() const; // @@protoc_insertion_point(class_scope:valhalla.Options) private: class _Internal; @@ -5003,6 +5036,7 @@ class Options final : void set_has_prioritize_bidirectional(); void set_has_expansion_action(); void set_has_skip_opposites(); + void set_has_matrix_locations(); inline bool has_has_language() const; inline void clear_has_has_language(); @@ -5082,6 +5116,9 @@ class Options final : inline bool has_has_skip_opposites() const; inline void clear_has_has_skip_opposites(); + inline bool has_has_matrix_locations() const; + inline void clear_has_has_matrix_locations(); + template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; @@ -5114,7 +5151,6 @@ class Options final : int filter_action_; int shape_format_; bool reverse_; - uint32_t matrix_locations_; union HasLanguageUnion { constexpr HasLanguageUnion() : _constinit_{} {} ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized _constinit_; @@ -5245,8 +5281,13 @@ class Options final : ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized _constinit_; bool skip_opposites_; } has_skip_opposites_; + union HasMatrixLocationsUnion { + constexpr HasMatrixLocationsUnion() : _constinit_{} {} + ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized _constinit_; + uint32_t matrix_locations_; + } has_matrix_locations_; mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - uint32_t _oneof_case_[26]; + uint32_t _oneof_case_[27]; }; union { Impl_ _impl_; }; @@ -8810,6 +8851,46 @@ inline void Costing_Options::set_axle_count(uint32_t value) { // @@protoc_insertion_point(field_set:valhalla.Costing.Options.axle_count) } +// float use_lit = 82; +inline void Costing_Options::clear_use_lit() { + _impl_.use_lit_ = 0; +} +inline float Costing_Options::_internal_use_lit() const { + return _impl_.use_lit_; +} +inline float Costing_Options::use_lit() const { + // @@protoc_insertion_point(field_get:valhalla.Costing.Options.use_lit) + return _internal_use_lit(); +} +inline void Costing_Options::_internal_set_use_lit(float value) { + + _impl_.use_lit_ = value; +} +inline void Costing_Options::set_use_lit(float value) { + _internal_set_use_lit(value); + // @@protoc_insertion_point(field_set:valhalla.Costing.Options.use_lit) +} + +// bool disable_hierarchy_pruning = 83; +inline void Costing_Options::clear_disable_hierarchy_pruning() { + _impl_.disable_hierarchy_pruning_ = false; +} +inline bool Costing_Options::_internal_disable_hierarchy_pruning() const { + return _impl_.disable_hierarchy_pruning_; +} +inline bool Costing_Options::disable_hierarchy_pruning() const { + // @@protoc_insertion_point(field_get:valhalla.Costing.Options.disable_hierarchy_pruning) + return _internal_disable_hierarchy_pruning(); +} +inline void Costing_Options::_internal_set_disable_hierarchy_pruning(bool value) { + + _impl_.disable_hierarchy_pruning_ = value; +} +inline void Costing_Options::set_disable_hierarchy_pruning(bool value) { + _internal_set_disable_hierarchy_pruning(value); + // @@protoc_insertion_point(field_set:valhalla.Costing.Options.disable_hierarchy_pruning) +} + inline bool Costing_Options::has_has_maneuver_penalty() const { return has_maneuver_penalty_case() != HAS_MANEUVER_PENALTY_NOT_SET; } @@ -11667,20 +11748,38 @@ inline void Options::set_reverse(bool value) { } // uint32 matrix_locations = 54; +inline bool Options::_internal_has_matrix_locations() const { + return has_matrix_locations_case() == kMatrixLocations; +} +inline bool Options::has_matrix_locations() const { + return _internal_has_matrix_locations(); +} +inline void Options::set_has_matrix_locations() { + _impl_._oneof_case_[26] = kMatrixLocations; +} inline void Options::clear_matrix_locations() { - _impl_.matrix_locations_ = 0u; + if (_internal_has_matrix_locations()) { + _impl_.has_matrix_locations_.matrix_locations_ = 0u; + clear_has_has_matrix_locations(); + } } inline uint32_t Options::_internal_matrix_locations() const { - return _impl_.matrix_locations_; + if (_internal_has_matrix_locations()) { + return _impl_.has_matrix_locations_.matrix_locations_; + } + return 0u; +} +inline void Options::_internal_set_matrix_locations(uint32_t value) { + if (!_internal_has_matrix_locations()) { + clear_has_matrix_locations(); + set_has_matrix_locations(); + } + _impl_.has_matrix_locations_.matrix_locations_ = value; } inline uint32_t Options::matrix_locations() const { // @@protoc_insertion_point(field_get:valhalla.Options.matrix_locations) return _internal_matrix_locations(); } -inline void Options::_internal_set_matrix_locations(uint32_t value) { - - _impl_.matrix_locations_ = value; -} inline void Options::set_matrix_locations(uint32_t value) { _internal_set_matrix_locations(value); // @@protoc_insertion_point(field_set:valhalla.Options.matrix_locations) @@ -11842,6 +11941,12 @@ inline bool Options::has_has_skip_opposites() const { inline void Options::clear_has_has_skip_opposites() { _impl_._oneof_case_[25] = HAS_SKIP_OPPOSITES_NOT_SET; } +inline bool Options::has_has_matrix_locations() const { + return has_matrix_locations_case() != HAS_MATRIX_LOCATIONS_NOT_SET; +} +inline void Options::clear_has_has_matrix_locations() { + _impl_._oneof_case_[26] = HAS_MATRIX_LOCATIONS_NOT_SET; +} inline Options::HasLanguageCase Options::has_language_case() const { return Options::HasLanguageCase(_impl_._oneof_case_[0]); } @@ -11920,6 +12025,9 @@ inline Options::HasExpansionActionCase Options::has_expansion_action_case() cons inline Options::HasSkipOppositesCase Options::has_skip_opposites_case() const { return Options::HasSkipOppositesCase(_impl_._oneof_case_[25]); } +inline Options::HasMatrixLocationsCase Options::has_matrix_locations_case() const { + return Options::HasMatrixLocationsCase(_impl_._oneof_case_[26]); +} #ifdef __GNUC__ #pragma GCC diagnostic pop #endif // __GNUC__ diff --git a/include/windows/valhalla/proto/status.pb.cc b/include/windows/valhalla/proto/status.pb.cc index a7802fb..6e1ad24 100644 --- a/include/windows/valhalla/proto/status.pb.cc +++ b/include/windows/valhalla/proto/status.pb.cc @@ -21,13 +21,15 @@ namespace valhalla { PROTOBUF_CONSTEXPR Status::Status( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_.available_actions_)*/{} + , /*decltype(_impl_.version_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}} + , /*decltype(_impl_.tileset_last_modified_)*/0u , /*decltype(_impl_.has_has_tiles_)*/{} , /*decltype(_impl_.has_has_admins_)*/{} , /*decltype(_impl_.has_has_timezones_)*/{} , /*decltype(_impl_.has_has_live_traffic_)*/{} , /*decltype(_impl_.has_bbox_)*/{} - , /*decltype(_impl_.has_version_)*/{} - , /*decltype(_impl_.has_tileset_last_modified_)*/{} + , /*decltype(_impl_.has_has_transit_tiles_)*/{} + , /*decltype(_impl_.has_osm_changeset_)*/{} , /*decltype(_impl_._cached_size_)*/{} , /*decltype(_impl_._oneof_case_)*/{}} {} struct StatusDefaultTypeInternal { @@ -59,17 +61,28 @@ Status::Status(const Status& from) Status* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_.available_actions_){from._impl_.available_actions_} + , decltype(_impl_.version_){} + , decltype(_impl_.tileset_last_modified_){} , decltype(_impl_.has_has_tiles_){} , decltype(_impl_.has_has_admins_){} , decltype(_impl_.has_has_timezones_){} , decltype(_impl_.has_has_live_traffic_){} , decltype(_impl_.has_bbox_){} - , decltype(_impl_.has_version_){} - , decltype(_impl_.has_tileset_last_modified_){} + , decltype(_impl_.has_has_transit_tiles_){} + , decltype(_impl_.has_osm_changeset_){} , /*decltype(_impl_._cached_size_)*/{} , /*decltype(_impl_._oneof_case_)*/{}}; _internal_metadata_.MergeFrom(from._internal_metadata_); + _impl_.version_.InitDefault(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.version_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + if (!from._internal_version().empty()) { + _this->_impl_.version_.Set(from._internal_version(), + _this->GetArenaForAllocation()); + } + _this->_impl_.tileset_last_modified_ = from._impl_.tileset_last_modified_; clear_has_has_has_tiles(); switch (from.has_has_tiles_case()) { case kHasTiles: { @@ -120,23 +133,23 @@ Status::Status(const Status& from) break; } } - clear_has_has_version(); - switch (from.has_version_case()) { - case kVersion: { - _this->_internal_set_version(from._internal_version()); + clear_has_has_has_transit_tiles(); + switch (from.has_has_transit_tiles_case()) { + case kHasTransitTiles: { + _this->_internal_set_has_transit_tiles(from._internal_has_transit_tiles()); break; } - case HAS_VERSION_NOT_SET: { + case HAS_HAS_TRANSIT_TILES_NOT_SET: { break; } } - clear_has_has_tileset_last_modified(); - switch (from.has_tileset_last_modified_case()) { - case kTilesetLastModified: { - _this->_internal_set_tileset_last_modified(from._internal_tileset_last_modified()); + clear_has_has_osm_changeset(); + switch (from.has_osm_changeset_case()) { + case kOsmChangeset: { + _this->_internal_set_osm_changeset(from._internal_osm_changeset()); break; } - case HAS_TILESET_LAST_MODIFIED_NOT_SET: { + case HAS_OSM_CHANGESET_NOT_SET: { break; } } @@ -149,23 +162,29 @@ inline void Status::SharedCtor( (void)is_message_owned; new (&_impl_) Impl_{ decltype(_impl_.available_actions_){arena} + , decltype(_impl_.version_){} + , decltype(_impl_.tileset_last_modified_){0u} , decltype(_impl_.has_has_tiles_){} , decltype(_impl_.has_has_admins_){} , decltype(_impl_.has_has_timezones_){} , decltype(_impl_.has_has_live_traffic_){} , decltype(_impl_.has_bbox_){} - , decltype(_impl_.has_version_){} - , decltype(_impl_.has_tileset_last_modified_){} + , decltype(_impl_.has_has_transit_tiles_){} + , decltype(_impl_.has_osm_changeset_){} , /*decltype(_impl_._cached_size_)*/{} , /*decltype(_impl_._oneof_case_)*/{} }; + _impl_.version_.InitDefault(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.version_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING clear_has_has_has_tiles(); clear_has_has_has_admins(); clear_has_has_has_timezones(); clear_has_has_has_live_traffic(); clear_has_has_bbox(); - clear_has_has_version(); - clear_has_has_tileset_last_modified(); + clear_has_has_has_transit_tiles(); + clear_has_has_osm_changeset(); } Status::~Status() { @@ -180,6 +199,7 @@ Status::~Status() { inline void Status::SharedDtor() { GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); _impl_.available_actions_.~RepeatedPtrField(); + _impl_.version_.Destroy(); if (has_has_has_tiles()) { clear_has_has_tiles(); } @@ -195,11 +215,11 @@ inline void Status::SharedDtor() { if (has_has_bbox()) { clear_has_bbox(); } - if (has_has_version()) { - clear_has_version(); + if (has_has_has_transit_tiles()) { + clear_has_has_transit_tiles(); } - if (has_has_tileset_last_modified()) { - clear_has_tileset_last_modified(); + if (has_has_osm_changeset()) { + clear_has_osm_changeset(); } } @@ -277,32 +297,32 @@ void Status::clear_has_bbox() { _impl_._oneof_case_[4] = HAS_BBOX_NOT_SET; } -void Status::clear_has_version() { +void Status::clear_has_has_transit_tiles() { // @@protoc_insertion_point(one_of_clear_start:valhalla.Status) - switch (has_version_case()) { - case kVersion: { - _impl_.has_version_.version_.Destroy(); + switch (has_has_transit_tiles_case()) { + case kHasTransitTiles: { + // No need to clear break; } - case HAS_VERSION_NOT_SET: { + case HAS_HAS_TRANSIT_TILES_NOT_SET: { break; } } - _impl_._oneof_case_[5] = HAS_VERSION_NOT_SET; + _impl_._oneof_case_[5] = HAS_HAS_TRANSIT_TILES_NOT_SET; } -void Status::clear_has_tileset_last_modified() { +void Status::clear_has_osm_changeset() { // @@protoc_insertion_point(one_of_clear_start:valhalla.Status) - switch (has_tileset_last_modified_case()) { - case kTilesetLastModified: { + switch (has_osm_changeset_case()) { + case kOsmChangeset: { // No need to clear break; } - case HAS_TILESET_LAST_MODIFIED_NOT_SET: { + case HAS_OSM_CHANGESET_NOT_SET: { break; } } - _impl_._oneof_case_[6] = HAS_TILESET_LAST_MODIFIED_NOT_SET; + _impl_._oneof_case_[6] = HAS_OSM_CHANGESET_NOT_SET; } @@ -313,13 +333,15 @@ void Status::Clear() { (void) cached_has_bits; _impl_.available_actions_.Clear(); + _impl_.version_.ClearToEmpty(); + _impl_.tileset_last_modified_ = 0u; clear_has_has_tiles(); clear_has_has_admins(); clear_has_has_timezones(); clear_has_has_live_traffic(); clear_has_bbox(); - clear_has_version(); - clear_has_tileset_last_modified(); + clear_has_has_transit_tiles(); + clear_has_osm_changeset(); _internal_metadata_.Clear(); } @@ -384,7 +406,7 @@ const char* Status::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { // uint32 tileset_last_modified = 7; case 7: if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 56)) { - _internal_set_tileset_last_modified(::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr)); + _impl_.tileset_last_modified_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); CHK_(ptr); } else goto handle_unusual; @@ -404,6 +426,22 @@ const char* Status::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { } else goto handle_unusual; continue; + // bool has_transit_tiles = 9; + case 9: + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 72)) { + _internal_set_has_transit_tiles(::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr)); + CHK_(ptr); + } else + goto handle_unusual; + continue; + // uint64 osm_changeset = 10; + case 10: + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 80)) { + _internal_set_osm_changeset(::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr)); + CHK_(ptr); + } else + goto handle_unusual; + continue; default: goto handle_unusual; } // switch @@ -468,7 +506,7 @@ uint8_t* Status::_InternalSerialize( } // string version = 6; - if (_internal_has_version()) { + if (!this->_internal_version().empty()) { ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( this->_internal_version().data(), static_cast(this->_internal_version().length()), ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, @@ -478,7 +516,7 @@ uint8_t* Status::_InternalSerialize( } // uint32 tileset_last_modified = 7; - if (_internal_has_tileset_last_modified()) { + if (this->_internal_tileset_last_modified() != 0) { target = stream->EnsureSpace(target); target = ::_pbi::WireFormatLite::WriteUInt32ToArray(7, this->_internal_tileset_last_modified(), target); } @@ -493,6 +531,18 @@ uint8_t* Status::_InternalSerialize( target = stream->WriteString(8, s, target); } + // bool has_transit_tiles = 9; + if (_internal_has_has_transit_tiles()) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteBoolToArray(9, this->_internal_has_transit_tiles(), target); + } + + // uint64 osm_changeset = 10; + if (_internal_has_osm_changeset()) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteUInt64ToArray(10, this->_internal_osm_changeset(), target); + } + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { target = stream->WriteRaw(_internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).data(), static_cast(_internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).size()), target); @@ -517,6 +567,18 @@ size_t Status::ByteSizeLong() const { _impl_.available_actions_.Get(i)); } + // string version = 6; + if (!this->_internal_version().empty()) { + total_size += 1 + + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( + this->_internal_version()); + } + + // uint32 tileset_last_modified = 7; + if (this->_internal_tileset_last_modified() != 0) { + total_size += ::_pbi::WireFormatLite::UInt32SizePlusOne(this->_internal_tileset_last_modified()); + } + switch (has_has_tiles_case()) { // bool has_tiles = 1; case kHasTiles: { @@ -569,25 +631,23 @@ size_t Status::ByteSizeLong() const { break; } } - switch (has_version_case()) { - // string version = 6; - case kVersion: { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_version()); + switch (has_has_transit_tiles_case()) { + // bool has_transit_tiles = 9; + case kHasTransitTiles: { + total_size += 1 + 1; break; } - case HAS_VERSION_NOT_SET: { + case HAS_HAS_TRANSIT_TILES_NOT_SET: { break; } } - switch (has_tileset_last_modified_case()) { - // uint32 tileset_last_modified = 7; - case kTilesetLastModified: { - total_size += ::_pbi::WireFormatLite::UInt32SizePlusOne(this->_internal_tileset_last_modified()); + switch (has_osm_changeset_case()) { + // uint64 osm_changeset = 10; + case kOsmChangeset: { + total_size += ::_pbi::WireFormatLite::UInt64SizePlusOne(this->_internal_osm_changeset()); break; } - case HAS_TILESET_LAST_MODIFIED_NOT_SET: { + case HAS_OSM_CHANGESET_NOT_SET: { break; } } @@ -613,6 +673,12 @@ void Status::MergeFrom(const Status& from) { (void) cached_has_bits; _this->_impl_.available_actions_.MergeFrom(from._impl_.available_actions_); + if (!from._internal_version().empty()) { + _this->_internal_set_version(from._internal_version()); + } + if (from._internal_tileset_last_modified() != 0) { + _this->_internal_set_tileset_last_modified(from._internal_tileset_last_modified()); + } switch (from.has_has_tiles_case()) { case kHasTiles: { _this->_internal_set_has_tiles(from._internal_has_tiles()); @@ -658,21 +724,21 @@ void Status::MergeFrom(const Status& from) { break; } } - switch (from.has_version_case()) { - case kVersion: { - _this->_internal_set_version(from._internal_version()); + switch (from.has_has_transit_tiles_case()) { + case kHasTransitTiles: { + _this->_internal_set_has_transit_tiles(from._internal_has_transit_tiles()); break; } - case HAS_VERSION_NOT_SET: { + case HAS_HAS_TRANSIT_TILES_NOT_SET: { break; } } - switch (from.has_tileset_last_modified_case()) { - case kTilesetLastModified: { - _this->_internal_set_tileset_last_modified(from._internal_tileset_last_modified()); + switch (from.has_osm_changeset_case()) { + case kOsmChangeset: { + _this->_internal_set_osm_changeset(from._internal_osm_changeset()); break; } - case HAS_TILESET_LAST_MODIFIED_NOT_SET: { + case HAS_OSM_CHANGESET_NOT_SET: { break; } } @@ -692,15 +758,22 @@ bool Status::IsInitialized() const { void Status::InternalSwap(Status* other) { using std::swap; + auto* lhs_arena = GetArenaForAllocation(); + auto* rhs_arena = other->GetArenaForAllocation(); _internal_metadata_.InternalSwap(&other->_internal_metadata_); _impl_.available_actions_.InternalSwap(&other->_impl_.available_actions_); + ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( + &_impl_.version_, lhs_arena, + &other->_impl_.version_, rhs_arena + ); + swap(_impl_.tileset_last_modified_, other->_impl_.tileset_last_modified_); swap(_impl_.has_has_tiles_, other->_impl_.has_has_tiles_); swap(_impl_.has_has_admins_, other->_impl_.has_has_admins_); swap(_impl_.has_has_timezones_, other->_impl_.has_has_timezones_); swap(_impl_.has_has_live_traffic_, other->_impl_.has_has_live_traffic_); swap(_impl_.has_bbox_, other->_impl_.has_bbox_); - swap(_impl_.has_version_, other->_impl_.has_version_); - swap(_impl_.has_tileset_last_modified_, other->_impl_.has_tileset_last_modified_); + swap(_impl_.has_has_transit_tiles_, other->_impl_.has_has_transit_tiles_); + swap(_impl_.has_osm_changeset_, other->_impl_.has_osm_changeset_); swap(_impl_._oneof_case_[0], other->_impl_._oneof_case_[0]); swap(_impl_._oneof_case_[1], other->_impl_._oneof_case_[1]); swap(_impl_._oneof_case_[2], other->_impl_._oneof_case_[2]); diff --git a/include/windows/valhalla/proto/status.pb.h b/include/windows/valhalla/proto/status.pb.h index 9edcf08..fb2f9be 100644 --- a/include/windows/valhalla/proto/status.pb.h +++ b/include/windows/valhalla/proto/status.pb.h @@ -112,14 +112,14 @@ class Status final : HAS_BBOX_NOT_SET = 0, }; - enum HasVersionCase { - kVersion = 6, - HAS_VERSION_NOT_SET = 0, + enum HasHasTransitTilesCase { + kHasTransitTiles = 9, + HAS_HAS_TRANSIT_TILES_NOT_SET = 0, }; - enum HasTilesetLastModifiedCase { - kTilesetLastModified = 7, - HAS_TILESET_LAST_MODIFIED_NOT_SET = 0, + enum HasOsmChangesetCase { + kOsmChangeset = 10, + HAS_OSM_CHANGESET_NOT_SET = 0, }; static inline const Status* internal_default_instance() { @@ -192,13 +192,15 @@ class Status final : enum : int { kAvailableActionsFieldNumber = 8, + kVersionFieldNumber = 6, + kTilesetLastModifiedFieldNumber = 7, kHasTilesFieldNumber = 1, kHasAdminsFieldNumber = 2, kHasTimezonesFieldNumber = 3, kHasLiveTrafficFieldNumber = 4, kBboxFieldNumber = 5, - kVersionFieldNumber = 6, - kTilesetLastModifiedFieldNumber = 7, + kHasTransitTilesFieldNumber = 9, + kOsmChangesetFieldNumber = 10, }; // repeated string available_actions = 8; int available_actions_size() const; @@ -224,6 +226,29 @@ class Status final : std::string* _internal_add_available_actions(); public: + // string version = 6; + void clear_version(); + const std::string& version() const; + template + void set_version(ArgT0&& arg0, ArgT... args); + std::string* mutable_version(); + PROTOBUF_NODISCARD std::string* release_version(); + void set_allocated_version(std::string* version); + private: + const std::string& _internal_version() const; + inline PROTOBUF_ALWAYS_INLINE void _internal_set_version(const std::string& value); + std::string* _internal_mutable_version(); + public: + + // uint32 tileset_last_modified = 7; + void clear_tileset_last_modified(); + uint32_t tileset_last_modified() const; + void set_tileset_last_modified(uint32_t value); + private: + uint32_t _internal_tileset_last_modified() const; + void _internal_set_tileset_last_modified(uint32_t value); + public: + // bool has_tiles = 1; bool has_has_tiles() const; private: @@ -294,35 +319,30 @@ class Status final : std::string* _internal_mutable_bbox(); public: - // string version = 6; - bool has_version() const; + // bool has_transit_tiles = 9; + bool has_has_transit_tiles() const; private: - bool _internal_has_version() const; + bool _internal_has_has_transit_tiles() const; public: - void clear_version(); - const std::string& version() const; - template - void set_version(ArgT0&& arg0, ArgT... args); - std::string* mutable_version(); - PROTOBUF_NODISCARD std::string* release_version(); - void set_allocated_version(std::string* version); + void clear_has_transit_tiles(); + bool has_transit_tiles() const; + void set_has_transit_tiles(bool value); private: - const std::string& _internal_version() const; - inline PROTOBUF_ALWAYS_INLINE void _internal_set_version(const std::string& value); - std::string* _internal_mutable_version(); + bool _internal_has_transit_tiles() const; + void _internal_set_has_transit_tiles(bool value); public: - // uint32 tileset_last_modified = 7; - bool has_tileset_last_modified() const; + // uint64 osm_changeset = 10; + bool has_osm_changeset() const; private: - bool _internal_has_tileset_last_modified() const; + bool _internal_has_osm_changeset() const; public: - void clear_tileset_last_modified(); - uint32_t tileset_last_modified() const; - void set_tileset_last_modified(uint32_t value); + void clear_osm_changeset(); + uint64_t osm_changeset() const; + void set_osm_changeset(uint64_t value); private: - uint32_t _internal_tileset_last_modified() const; - void _internal_set_tileset_last_modified(uint32_t value); + uint64_t _internal_osm_changeset() const; + void _internal_set_osm_changeset(uint64_t value); public: void clear_has_has_tiles(); @@ -335,10 +355,10 @@ class Status final : HasHasLiveTrafficCase has_has_live_traffic_case() const; void clear_has_bbox(); HasBboxCase has_bbox_case() const; - void clear_has_version(); - HasVersionCase has_version_case() const; - void clear_has_tileset_last_modified(); - HasTilesetLastModifiedCase has_tileset_last_modified_case() const; + void clear_has_has_transit_tiles(); + HasHasTransitTilesCase has_has_transit_tiles_case() const; + void clear_has_osm_changeset(); + HasOsmChangesetCase has_osm_changeset_case() const; // @@protoc_insertion_point(class_scope:valhalla.Status) private: class _Internal; @@ -347,8 +367,8 @@ class Status final : void set_has_has_timezones(); void set_has_has_live_traffic(); void set_has_bbox(); - void set_has_version(); - void set_has_tileset_last_modified(); + void set_has_has_transit_tiles(); + void set_has_osm_changeset(); inline bool has_has_has_tiles() const; inline void clear_has_has_has_tiles(); @@ -365,17 +385,19 @@ class Status final : inline bool has_has_bbox() const; inline void clear_has_has_bbox(); - inline bool has_has_version() const; - inline void clear_has_has_version(); + inline bool has_has_has_transit_tiles() const; + inline void clear_has_has_has_transit_tiles(); - inline bool has_has_tileset_last_modified() const; - inline void clear_has_has_tileset_last_modified(); + inline bool has_has_osm_changeset() const; + inline void clear_has_has_osm_changeset(); template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; struct Impl_ { ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField available_actions_; + ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr version_; + uint32_t tileset_last_modified_; union HasHasTilesUnion { constexpr HasHasTilesUnion() : _constinit_{} {} ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized _constinit_; @@ -401,16 +423,16 @@ class Status final : ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized _constinit_; ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr bbox_; } has_bbox_; - union HasVersionUnion { - constexpr HasVersionUnion() : _constinit_{} {} + union HasHasTransitTilesUnion { + constexpr HasHasTransitTilesUnion() : _constinit_{} {} ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized _constinit_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr version_; - } has_version_; - union HasTilesetLastModifiedUnion { - constexpr HasTilesetLastModifiedUnion() : _constinit_{} {} + bool has_transit_tiles_; + } has_has_transit_tiles_; + union HasOsmChangesetUnion { + constexpr HasOsmChangesetUnion() : _constinit_{} {} ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized _constinit_; - uint32_t tileset_last_modified_; - } has_tileset_last_modified_; + uint64_t osm_changeset_; + } has_osm_changeset_; mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; uint32_t _oneof_case_[7]; @@ -659,33 +681,18 @@ inline void Status::set_allocated_bbox(std::string* bbox) { } // string version = 6; -inline bool Status::_internal_has_version() const { - return has_version_case() == kVersion; -} -inline bool Status::has_version() const { - return _internal_has_version(); -} -inline void Status::set_has_version() { - _impl_._oneof_case_[5] = kVersion; -} inline void Status::clear_version() { - if (_internal_has_version()) { - _impl_.has_version_.version_.Destroy(); - clear_has_has_version(); - } + _impl_.version_.ClearToEmpty(); } inline const std::string& Status::version() const { // @@protoc_insertion_point(field_get:valhalla.Status.version) return _internal_version(); } template -inline void Status::set_version(ArgT0&& arg0, ArgT... args) { - if (!_internal_has_version()) { - clear_has_version(); - set_has_version(); - _impl_.has_version_.version_.InitDefault(); - } - _impl_.has_version_.version_.Set( static_cast(arg0), args..., GetArenaForAllocation()); +inline PROTOBUF_ALWAYS_INLINE +void Status::set_version(ArgT0&& arg0, ArgT... args) { + + _impl_.version_.Set(static_cast(arg0), args..., GetArenaForAllocation()); // @@protoc_insertion_point(field_set:valhalla.Status.version) } inline std::string* Status::mutable_version() { @@ -694,80 +701,50 @@ inline std::string* Status::mutable_version() { return _s; } inline const std::string& Status::_internal_version() const { - if (_internal_has_version()) { - return _impl_.has_version_.version_.Get(); - } - return ::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(); + return _impl_.version_.Get(); } inline void Status::_internal_set_version(const std::string& value) { - if (!_internal_has_version()) { - clear_has_version(); - set_has_version(); - _impl_.has_version_.version_.InitDefault(); - } - _impl_.has_version_.version_.Set(value, GetArenaForAllocation()); + + _impl_.version_.Set(value, GetArenaForAllocation()); } inline std::string* Status::_internal_mutable_version() { - if (!_internal_has_version()) { - clear_has_version(); - set_has_version(); - _impl_.has_version_.version_.InitDefault(); - } - return _impl_.has_version_.version_.Mutable( GetArenaForAllocation()); + + return _impl_.version_.Mutable(GetArenaForAllocation()); } inline std::string* Status::release_version() { // @@protoc_insertion_point(field_release:valhalla.Status.version) - if (_internal_has_version()) { - clear_has_has_version(); - return _impl_.has_version_.version_.Release(); - } else { - return nullptr; - } + return _impl_.version_.Release(); } inline void Status::set_allocated_version(std::string* version) { - if (has_has_version()) { - clear_has_version(); - } if (version != nullptr) { - set_has_version(); - _impl_.has_version_.version_.InitAllocated(version, GetArenaForAllocation()); + + } else { + + } + _impl_.version_.SetAllocated(version, GetArenaForAllocation()); +#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + if (_impl_.version_.IsDefault()) { + _impl_.version_.Set("", GetArenaForAllocation()); } +#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING // @@protoc_insertion_point(field_set_allocated:valhalla.Status.version) } // uint32 tileset_last_modified = 7; -inline bool Status::_internal_has_tileset_last_modified() const { - return has_tileset_last_modified_case() == kTilesetLastModified; -} -inline bool Status::has_tileset_last_modified() const { - return _internal_has_tileset_last_modified(); -} -inline void Status::set_has_tileset_last_modified() { - _impl_._oneof_case_[6] = kTilesetLastModified; -} inline void Status::clear_tileset_last_modified() { - if (_internal_has_tileset_last_modified()) { - _impl_.has_tileset_last_modified_.tileset_last_modified_ = 0u; - clear_has_has_tileset_last_modified(); - } + _impl_.tileset_last_modified_ = 0u; } inline uint32_t Status::_internal_tileset_last_modified() const { - if (_internal_has_tileset_last_modified()) { - return _impl_.has_tileset_last_modified_.tileset_last_modified_; - } - return 0u; -} -inline void Status::_internal_set_tileset_last_modified(uint32_t value) { - if (!_internal_has_tileset_last_modified()) { - clear_has_tileset_last_modified(); - set_has_tileset_last_modified(); - } - _impl_.has_tileset_last_modified_.tileset_last_modified_ = value; + return _impl_.tileset_last_modified_; } inline uint32_t Status::tileset_last_modified() const { // @@protoc_insertion_point(field_get:valhalla.Status.tileset_last_modified) return _internal_tileset_last_modified(); } +inline void Status::_internal_set_tileset_last_modified(uint32_t value) { + + _impl_.tileset_last_modified_ = value; +} inline void Status::set_tileset_last_modified(uint32_t value) { _internal_set_tileset_last_modified(value); // @@protoc_insertion_point(field_set:valhalla.Status.tileset_last_modified) @@ -848,6 +825,82 @@ Status::mutable_available_actions() { return &_impl_.available_actions_; } +// bool has_transit_tiles = 9; +inline bool Status::_internal_has_has_transit_tiles() const { + return has_has_transit_tiles_case() == kHasTransitTiles; +} +inline bool Status::has_has_transit_tiles() const { + return _internal_has_has_transit_tiles(); +} +inline void Status::set_has_has_transit_tiles() { + _impl_._oneof_case_[5] = kHasTransitTiles; +} +inline void Status::clear_has_transit_tiles() { + if (_internal_has_has_transit_tiles()) { + _impl_.has_has_transit_tiles_.has_transit_tiles_ = false; + clear_has_has_has_transit_tiles(); + } +} +inline bool Status::_internal_has_transit_tiles() const { + if (_internal_has_has_transit_tiles()) { + return _impl_.has_has_transit_tiles_.has_transit_tiles_; + } + return false; +} +inline void Status::_internal_set_has_transit_tiles(bool value) { + if (!_internal_has_has_transit_tiles()) { + clear_has_has_transit_tiles(); + set_has_has_transit_tiles(); + } + _impl_.has_has_transit_tiles_.has_transit_tiles_ = value; +} +inline bool Status::has_transit_tiles() const { + // @@protoc_insertion_point(field_get:valhalla.Status.has_transit_tiles) + return _internal_has_transit_tiles(); +} +inline void Status::set_has_transit_tiles(bool value) { + _internal_set_has_transit_tiles(value); + // @@protoc_insertion_point(field_set:valhalla.Status.has_transit_tiles) +} + +// uint64 osm_changeset = 10; +inline bool Status::_internal_has_osm_changeset() const { + return has_osm_changeset_case() == kOsmChangeset; +} +inline bool Status::has_osm_changeset() const { + return _internal_has_osm_changeset(); +} +inline void Status::set_has_osm_changeset() { + _impl_._oneof_case_[6] = kOsmChangeset; +} +inline void Status::clear_osm_changeset() { + if (_internal_has_osm_changeset()) { + _impl_.has_osm_changeset_.osm_changeset_ = uint64_t{0u}; + clear_has_has_osm_changeset(); + } +} +inline uint64_t Status::_internal_osm_changeset() const { + if (_internal_has_osm_changeset()) { + return _impl_.has_osm_changeset_.osm_changeset_; + } + return uint64_t{0u}; +} +inline void Status::_internal_set_osm_changeset(uint64_t value) { + if (!_internal_has_osm_changeset()) { + clear_has_osm_changeset(); + set_has_osm_changeset(); + } + _impl_.has_osm_changeset_.osm_changeset_ = value; +} +inline uint64_t Status::osm_changeset() const { + // @@protoc_insertion_point(field_get:valhalla.Status.osm_changeset) + return _internal_osm_changeset(); +} +inline void Status::set_osm_changeset(uint64_t value) { + _internal_set_osm_changeset(value); + // @@protoc_insertion_point(field_set:valhalla.Status.osm_changeset) +} + inline bool Status::has_has_has_tiles() const { return has_has_tiles_case() != HAS_HAS_TILES_NOT_SET; } @@ -878,17 +931,17 @@ inline bool Status::has_has_bbox() const { inline void Status::clear_has_has_bbox() { _impl_._oneof_case_[4] = HAS_BBOX_NOT_SET; } -inline bool Status::has_has_version() const { - return has_version_case() != HAS_VERSION_NOT_SET; +inline bool Status::has_has_has_transit_tiles() const { + return has_has_transit_tiles_case() != HAS_HAS_TRANSIT_TILES_NOT_SET; } -inline void Status::clear_has_has_version() { - _impl_._oneof_case_[5] = HAS_VERSION_NOT_SET; +inline void Status::clear_has_has_has_transit_tiles() { + _impl_._oneof_case_[5] = HAS_HAS_TRANSIT_TILES_NOT_SET; } -inline bool Status::has_has_tileset_last_modified() const { - return has_tileset_last_modified_case() != HAS_TILESET_LAST_MODIFIED_NOT_SET; +inline bool Status::has_has_osm_changeset() const { + return has_osm_changeset_case() != HAS_OSM_CHANGESET_NOT_SET; } -inline void Status::clear_has_has_tileset_last_modified() { - _impl_._oneof_case_[6] = HAS_TILESET_LAST_MODIFIED_NOT_SET; +inline void Status::clear_has_has_osm_changeset() { + _impl_._oneof_case_[6] = HAS_OSM_CHANGESET_NOT_SET; } inline Status::HasHasTilesCase Status::has_has_tiles_case() const { return Status::HasHasTilesCase(_impl_._oneof_case_[0]); @@ -905,11 +958,11 @@ inline Status::HasHasLiveTrafficCase Status::has_has_live_traffic_case() const { inline Status::HasBboxCase Status::has_bbox_case() const { return Status::HasBboxCase(_impl_._oneof_case_[4]); } -inline Status::HasVersionCase Status::has_version_case() const { - return Status::HasVersionCase(_impl_._oneof_case_[5]); +inline Status::HasHasTransitTilesCase Status::has_has_transit_tiles_case() const { + return Status::HasHasTransitTilesCase(_impl_._oneof_case_[5]); } -inline Status::HasTilesetLastModifiedCase Status::has_tileset_last_modified_case() const { - return Status::HasTilesetLastModifiedCase(_impl_._oneof_case_[6]); +inline Status::HasOsmChangesetCase Status::has_osm_changeset_case() const { + return Status::HasOsmChangesetCase(_impl_._oneof_case_[6]); } #ifdef __GNUC__ #pragma GCC diagnostic pop diff --git a/include/windows/valhalla/proto/transit.pb.cc b/include/windows/valhalla/proto/transit.pb.cc index 95b0846..7150fe1 100644 --- a/include/windows/valhalla/proto/transit.pb.cc +++ b/include/windows/valhalla/proto/transit.pb.cc @@ -30,10 +30,12 @@ PROTOBUF_CONSTEXPR Transit_Node::Transit_Node( , /*decltype(_impl_.lat_)*/0 , /*decltype(_impl_.graphid_)*/uint64_t{0u} , /*decltype(_impl_.prev_type_graphid_)*/uint64_t{0u} - , /*decltype(_impl_.osm_way_id_)*/uint64_t{0u} + , /*decltype(_impl_.osm_connecting_way_id_)*/uint64_t{0u} , /*decltype(_impl_.type_)*/0u , /*decltype(_impl_.wheelchair_boarding_)*/false , /*decltype(_impl_.generated_)*/false + , /*decltype(_impl_.osm_connecting_lon_)*/0 + , /*decltype(_impl_.osm_connecting_lat_)*/0 , /*decltype(_impl_.traversability_)*/0u} {} struct Transit_NodeDefaultTypeInternal { PROTOBUF_CONSTEXPR Transit_NodeDefaultTypeInternal() @@ -253,7 +255,7 @@ class Transit_Node::_Internal { static void set_has_onestop_id(HasBits* has_bits) { (*has_bits)[0] |= 2u; } - static void set_has_osm_way_id(HasBits* has_bits) { + static void set_has_osm_connecting_way_id(HasBits* has_bits) { (*has_bits)[0] |= 128u; } static void set_has_timezone(HasBits* has_bits) { @@ -266,8 +268,14 @@ class Transit_Node::_Internal { (*has_bits)[0] |= 1024u; } static void set_has_traversability(HasBits* has_bits) { + (*has_bits)[0] |= 8192u; + } + static void set_has_osm_connecting_lon(HasBits* has_bits) { (*has_bits)[0] |= 2048u; } + static void set_has_osm_connecting_lat(HasBits* has_bits) { + (*has_bits)[0] |= 4096u; + } }; Transit_Node::Transit_Node(::PROTOBUF_NAMESPACE_ID::Arena* arena, @@ -289,10 +297,12 @@ Transit_Node::Transit_Node(const Transit_Node& from) , decltype(_impl_.lat_){} , decltype(_impl_.graphid_){} , decltype(_impl_.prev_type_graphid_){} - , decltype(_impl_.osm_way_id_){} + , decltype(_impl_.osm_connecting_way_id_){} , decltype(_impl_.type_){} , decltype(_impl_.wheelchair_boarding_){} , decltype(_impl_.generated_){} + , decltype(_impl_.osm_connecting_lon_){} + , decltype(_impl_.osm_connecting_lat_){} , decltype(_impl_.traversability_){}}; _internal_metadata_.MergeFrom(from._internal_metadata_); @@ -340,10 +350,12 @@ inline void Transit_Node::SharedCtor( , decltype(_impl_.lat_){0} , decltype(_impl_.graphid_){uint64_t{0u}} , decltype(_impl_.prev_type_graphid_){uint64_t{0u}} - , decltype(_impl_.osm_way_id_){uint64_t{0u}} + , decltype(_impl_.osm_connecting_way_id_){uint64_t{0u}} , decltype(_impl_.type_){0u} , decltype(_impl_.wheelchair_boarding_){false} , decltype(_impl_.generated_){false} + , decltype(_impl_.osm_connecting_lon_){0} + , decltype(_impl_.osm_connecting_lat_){0} , decltype(_impl_.traversability_){0u} }; _impl_.name_.InitDefault(); @@ -400,10 +412,10 @@ void Transit_Node::Clear() { } if (cached_has_bits & 0x000000f8u) { ::memset(&_impl_.lon_, 0, static_cast( - reinterpret_cast(&_impl_.osm_way_id_) - - reinterpret_cast(&_impl_.lon_)) + sizeof(_impl_.osm_way_id_)); + reinterpret_cast(&_impl_.osm_connecting_way_id_) - + reinterpret_cast(&_impl_.lon_)) + sizeof(_impl_.osm_connecting_way_id_)); } - if (cached_has_bits & 0x00000f00u) { + if (cached_has_bits & 0x00003f00u) { ::memset(&_impl_.type_, 0, static_cast( reinterpret_cast(&_impl_.traversability_) - reinterpret_cast(&_impl_.type_)) + sizeof(_impl_.traversability_)); @@ -419,21 +431,21 @@ const char* Transit_Node::_InternalParse(const char* ptr, ::_pbi::ParseContext* uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { - // optional float lon = 1; + // optional double lon = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 13)) { + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 9)) { _Internal::set_has_lon(&has_bits); - _impl_.lon_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad(ptr); - ptr += sizeof(float); + _impl_.lon_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad(ptr); + ptr += sizeof(double); } else goto handle_unusual; continue; - // optional float lat = 2; + // optional double lat = 2; case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 21)) { + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 17)) { _Internal::set_has_lat(&has_bits); - _impl_.lat_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad(ptr); - ptr += sizeof(float); + _impl_.lat_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad(ptr); + ptr += sizeof(double); } else goto handle_unusual; continue; @@ -482,11 +494,11 @@ const char* Transit_Node::_InternalParse(const char* ptr, ::_pbi::ParseContext* } else goto handle_unusual; continue; - // optional uint64 osm_way_id = 8; + // optional uint64 osm_connecting_way_id = 8; case 8: if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 64)) { - _Internal::set_has_osm_way_id(&has_bits); - _impl_.osm_way_id_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); + _Internal::set_has_osm_connecting_way_id(&has_bits); + _impl_.osm_connecting_way_id_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); CHK_(ptr); } else goto handle_unusual; @@ -527,6 +539,24 @@ const char* Transit_Node::_InternalParse(const char* ptr, ::_pbi::ParseContext* } else goto handle_unusual; continue; + // optional double osm_connecting_lon = 13; + case 13: + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 105)) { + _Internal::set_has_osm_connecting_lon(&has_bits); + _impl_.osm_connecting_lon_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad(ptr); + ptr += sizeof(double); + } else + goto handle_unusual; + continue; + // optional double osm_connecting_lat = 14; + case 14: + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 113)) { + _Internal::set_has_osm_connecting_lat(&has_bits); + _impl_.osm_connecting_lat_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad(ptr); + ptr += sizeof(double); + } else + goto handle_unusual; + continue; default: goto handle_unusual; } // switch @@ -558,16 +588,16 @@ uint8_t* Transit_Node::_InternalSerialize( (void) cached_has_bits; cached_has_bits = _impl_._has_bits_[0]; - // optional float lon = 1; + // optional double lon = 1; if (cached_has_bits & 0x00000008u) { target = stream->EnsureSpace(target); - target = ::_pbi::WireFormatLite::WriteFloatToArray(1, this->_internal_lon(), target); + target = ::_pbi::WireFormatLite::WriteDoubleToArray(1, this->_internal_lon(), target); } - // optional float lat = 2; + // optional double lat = 2; if (cached_has_bits & 0x00000010u) { target = stream->EnsureSpace(target); - target = ::_pbi::WireFormatLite::WriteFloatToArray(2, this->_internal_lat(), target); + target = ::_pbi::WireFormatLite::WriteDoubleToArray(2, this->_internal_lat(), target); } // optional uint32 type = 3; @@ -600,10 +630,10 @@ uint8_t* Transit_Node::_InternalSerialize( 7, this->_internal_onestop_id(), target); } - // optional uint64 osm_way_id = 8; + // optional uint64 osm_connecting_way_id = 8; if (cached_has_bits & 0x00000080u) { target = stream->EnsureSpace(target); - target = ::_pbi::WireFormatLite::WriteUInt64ToArray(8, this->_internal_osm_way_id(), target); + target = ::_pbi::WireFormatLite::WriteUInt64ToArray(8, this->_internal_osm_connecting_way_id(), target); } // optional string timezone = 9; @@ -625,11 +655,23 @@ uint8_t* Transit_Node::_InternalSerialize( } // optional uint32 traversability = 12; - if (cached_has_bits & 0x00000800u) { + if (cached_has_bits & 0x00002000u) { target = stream->EnsureSpace(target); target = ::_pbi::WireFormatLite::WriteUInt32ToArray(12, this->_internal_traversability(), target); } + // optional double osm_connecting_lon = 13; + if (cached_has_bits & 0x00000800u) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteDoubleToArray(13, this->_internal_osm_connecting_lon(), target); + } + + // optional double osm_connecting_lat = 14; + if (cached_has_bits & 0x00001000u) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteDoubleToArray(14, this->_internal_osm_connecting_lat(), target); + } + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { target = stream->WriteRaw(_internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).data(), static_cast(_internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).size()), target); @@ -669,14 +711,14 @@ size_t Transit_Node::ByteSizeLong() const { this->_internal_timezone()); } - // optional float lon = 1; + // optional double lon = 1; if (cached_has_bits & 0x00000008u) { - total_size += 1 + 4; + total_size += 1 + 8; } - // optional float lat = 2; + // optional double lat = 2; if (cached_has_bits & 0x00000010u) { - total_size += 1 + 4; + total_size += 1 + 8; } // optional uint64 graphid = 4; @@ -689,13 +731,13 @@ size_t Transit_Node::ByteSizeLong() const { total_size += ::_pbi::WireFormatLite::UInt64SizePlusOne(this->_internal_prev_type_graphid()); } - // optional uint64 osm_way_id = 8; + // optional uint64 osm_connecting_way_id = 8; if (cached_has_bits & 0x00000080u) { - total_size += ::_pbi::WireFormatLite::UInt64SizePlusOne(this->_internal_osm_way_id()); + total_size += ::_pbi::WireFormatLite::UInt64SizePlusOne(this->_internal_osm_connecting_way_id()); } } - if (cached_has_bits & 0x00000f00u) { + if (cached_has_bits & 0x00003f00u) { // optional uint32 type = 3; if (cached_has_bits & 0x00000100u) { total_size += ::_pbi::WireFormatLite::UInt32SizePlusOne(this->_internal_type()); @@ -711,8 +753,18 @@ size_t Transit_Node::ByteSizeLong() const { total_size += 1 + 1; } - // optional uint32 traversability = 12; + // optional double osm_connecting_lon = 13; if (cached_has_bits & 0x00000800u) { + total_size += 1 + 8; + } + + // optional double osm_connecting_lat = 14; + if (cached_has_bits & 0x00001000u) { + total_size += 1 + 8; + } + + // optional uint32 traversability = 12; + if (cached_has_bits & 0x00002000u) { total_size += ::_pbi::WireFormatLite::UInt32SizePlusOne(this->_internal_traversability()); } @@ -762,11 +814,11 @@ void Transit_Node::MergeFrom(const Transit_Node& from) { _this->_impl_.prev_type_graphid_ = from._impl_.prev_type_graphid_; } if (cached_has_bits & 0x00000080u) { - _this->_impl_.osm_way_id_ = from._impl_.osm_way_id_; + _this->_impl_.osm_connecting_way_id_ = from._impl_.osm_connecting_way_id_; } _this->_impl_._has_bits_[0] |= cached_has_bits; } - if (cached_has_bits & 0x00000f00u) { + if (cached_has_bits & 0x00003f00u) { if (cached_has_bits & 0x00000100u) { _this->_impl_.type_ = from._impl_.type_; } @@ -777,6 +829,12 @@ void Transit_Node::MergeFrom(const Transit_Node& from) { _this->_impl_.generated_ = from._impl_.generated_; } if (cached_has_bits & 0x00000800u) { + _this->_impl_.osm_connecting_lon_ = from._impl_.osm_connecting_lon_; + } + if (cached_has_bits & 0x00001000u) { + _this->_impl_.osm_connecting_lat_ = from._impl_.osm_connecting_lat_; + } + if (cached_has_bits & 0x00002000u) { _this->_impl_.traversability_ = from._impl_.traversability_; } _this->_impl_._has_bits_[0] |= cached_has_bits; diff --git a/include/windows/valhalla/proto/transit.pb.h b/include/windows/valhalla/proto/transit.pb.h index da84db2..2a1b19c 100644 --- a/include/windows/valhalla/proto/transit.pb.h +++ b/include/windows/valhalla/proto/transit.pb.h @@ -215,10 +215,12 @@ class Transit_Node final : kLatFieldNumber = 2, kGraphidFieldNumber = 4, kPrevTypeGraphidFieldNumber = 5, - kOsmWayIdFieldNumber = 8, + kOsmConnectingWayIdFieldNumber = 8, kTypeFieldNumber = 3, kWheelchairBoardingFieldNumber = 10, kGeneratedFieldNumber = 11, + kOsmConnectingLonFieldNumber = 13, + kOsmConnectingLatFieldNumber = 14, kTraversabilityFieldNumber = 12, }; // optional string name = 6; @@ -275,30 +277,30 @@ class Transit_Node final : std::string* _internal_mutable_timezone(); public: - // optional float lon = 1; + // optional double lon = 1; bool has_lon() const; private: bool _internal_has_lon() const; public: void clear_lon(); - float lon() const; - void set_lon(float value); + double lon() const; + void set_lon(double value); private: - float _internal_lon() const; - void _internal_set_lon(float value); + double _internal_lon() const; + void _internal_set_lon(double value); public: - // optional float lat = 2; + // optional double lat = 2; bool has_lat() const; private: bool _internal_has_lat() const; public: void clear_lat(); - float lat() const; - void set_lat(float value); + double lat() const; + void set_lat(double value); private: - float _internal_lat() const; - void _internal_set_lat(float value); + double _internal_lat() const; + void _internal_set_lat(double value); public: // optional uint64 graphid = 4; @@ -327,17 +329,17 @@ class Transit_Node final : void _internal_set_prev_type_graphid(uint64_t value); public: - // optional uint64 osm_way_id = 8; - bool has_osm_way_id() const; + // optional uint64 osm_connecting_way_id = 8; + bool has_osm_connecting_way_id() const; private: - bool _internal_has_osm_way_id() const; + bool _internal_has_osm_connecting_way_id() const; public: - void clear_osm_way_id(); - uint64_t osm_way_id() const; - void set_osm_way_id(uint64_t value); + void clear_osm_connecting_way_id(); + uint64_t osm_connecting_way_id() const; + void set_osm_connecting_way_id(uint64_t value); private: - uint64_t _internal_osm_way_id() const; - void _internal_set_osm_way_id(uint64_t value); + uint64_t _internal_osm_connecting_way_id() const; + void _internal_set_osm_connecting_way_id(uint64_t value); public: // optional uint32 type = 3; @@ -379,6 +381,32 @@ class Transit_Node final : void _internal_set_generated(bool value); public: + // optional double osm_connecting_lon = 13; + bool has_osm_connecting_lon() const; + private: + bool _internal_has_osm_connecting_lon() const; + public: + void clear_osm_connecting_lon(); + double osm_connecting_lon() const; + void set_osm_connecting_lon(double value); + private: + double _internal_osm_connecting_lon() const; + void _internal_set_osm_connecting_lon(double value); + public: + + // optional double osm_connecting_lat = 14; + bool has_osm_connecting_lat() const; + private: + bool _internal_has_osm_connecting_lat() const; + public: + void clear_osm_connecting_lat(); + double osm_connecting_lat() const; + void set_osm_connecting_lat(double value); + private: + double _internal_osm_connecting_lat() const; + void _internal_set_osm_connecting_lat(double value); + public: + // optional uint32 traversability = 12; bool has_traversability() const; private: @@ -405,14 +433,16 @@ class Transit_Node final : ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_; ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr onestop_id_; ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr timezone_; - float lon_; - float lat_; + double lon_; + double lat_; uint64_t graphid_; uint64_t prev_type_graphid_; - uint64_t osm_way_id_; + uint64_t osm_connecting_way_id_; uint32_t type_; bool wheelchair_boarding_; bool generated_; + double osm_connecting_lon_; + double osm_connecting_lat_; uint32_t traversability_; }; union { Impl_ _impl_; }; @@ -1671,7 +1701,7 @@ class Transit final : #endif // __GNUC__ // Transit_Node -// optional float lon = 1; +// optional double lon = 1; inline bool Transit_Node::_internal_has_lon() const { bool value = (_impl_._has_bits_[0] & 0x00000008u) != 0; return value; @@ -1683,23 +1713,23 @@ inline void Transit_Node::clear_lon() { _impl_.lon_ = 0; _impl_._has_bits_[0] &= ~0x00000008u; } -inline float Transit_Node::_internal_lon() const { +inline double Transit_Node::_internal_lon() const { return _impl_.lon_; } -inline float Transit_Node::lon() const { +inline double Transit_Node::lon() const { // @@protoc_insertion_point(field_get:valhalla.mjolnir.Transit.Node.lon) return _internal_lon(); } -inline void Transit_Node::_internal_set_lon(float value) { +inline void Transit_Node::_internal_set_lon(double value) { _impl_._has_bits_[0] |= 0x00000008u; _impl_.lon_ = value; } -inline void Transit_Node::set_lon(float value) { +inline void Transit_Node::set_lon(double value) { _internal_set_lon(value); // @@protoc_insertion_point(field_set:valhalla.mjolnir.Transit.Node.lon) } -// optional float lat = 2; +// optional double lat = 2; inline bool Transit_Node::_internal_has_lat() const { bool value = (_impl_._has_bits_[0] & 0x00000010u) != 0; return value; @@ -1711,18 +1741,18 @@ inline void Transit_Node::clear_lat() { _impl_.lat_ = 0; _impl_._has_bits_[0] &= ~0x00000010u; } -inline float Transit_Node::_internal_lat() const { +inline double Transit_Node::_internal_lat() const { return _impl_.lat_; } -inline float Transit_Node::lat() const { +inline double Transit_Node::lat() const { // @@protoc_insertion_point(field_get:valhalla.mjolnir.Transit.Node.lat) return _internal_lat(); } -inline void Transit_Node::_internal_set_lat(float value) { +inline void Transit_Node::_internal_set_lat(double value) { _impl_._has_bits_[0] |= 0x00000010u; _impl_.lat_ = value; } -inline void Transit_Node::set_lat(float value) { +inline void Transit_Node::set_lat(double value) { _internal_set_lat(value); // @@protoc_insertion_point(field_set:valhalla.mjolnir.Transit.Node.lat) } @@ -1947,32 +1977,32 @@ inline void Transit_Node::set_allocated_onestop_id(std::string* onestop_id) { // @@protoc_insertion_point(field_set_allocated:valhalla.mjolnir.Transit.Node.onestop_id) } -// optional uint64 osm_way_id = 8; -inline bool Transit_Node::_internal_has_osm_way_id() const { +// optional uint64 osm_connecting_way_id = 8; +inline bool Transit_Node::_internal_has_osm_connecting_way_id() const { bool value = (_impl_._has_bits_[0] & 0x00000080u) != 0; return value; } -inline bool Transit_Node::has_osm_way_id() const { - return _internal_has_osm_way_id(); +inline bool Transit_Node::has_osm_connecting_way_id() const { + return _internal_has_osm_connecting_way_id(); } -inline void Transit_Node::clear_osm_way_id() { - _impl_.osm_way_id_ = uint64_t{0u}; +inline void Transit_Node::clear_osm_connecting_way_id() { + _impl_.osm_connecting_way_id_ = uint64_t{0u}; _impl_._has_bits_[0] &= ~0x00000080u; } -inline uint64_t Transit_Node::_internal_osm_way_id() const { - return _impl_.osm_way_id_; +inline uint64_t Transit_Node::_internal_osm_connecting_way_id() const { + return _impl_.osm_connecting_way_id_; } -inline uint64_t Transit_Node::osm_way_id() const { - // @@protoc_insertion_point(field_get:valhalla.mjolnir.Transit.Node.osm_way_id) - return _internal_osm_way_id(); +inline uint64_t Transit_Node::osm_connecting_way_id() const { + // @@protoc_insertion_point(field_get:valhalla.mjolnir.Transit.Node.osm_connecting_way_id) + return _internal_osm_connecting_way_id(); } -inline void Transit_Node::_internal_set_osm_way_id(uint64_t value) { +inline void Transit_Node::_internal_set_osm_connecting_way_id(uint64_t value) { _impl_._has_bits_[0] |= 0x00000080u; - _impl_.osm_way_id_ = value; + _impl_.osm_connecting_way_id_ = value; } -inline void Transit_Node::set_osm_way_id(uint64_t value) { - _internal_set_osm_way_id(value); - // @@protoc_insertion_point(field_set:valhalla.mjolnir.Transit.Node.osm_way_id) +inline void Transit_Node::set_osm_connecting_way_id(uint64_t value) { + _internal_set_osm_connecting_way_id(value); + // @@protoc_insertion_point(field_set:valhalla.mjolnir.Transit.Node.osm_connecting_way_id) } // optional string timezone = 9; @@ -2101,7 +2131,7 @@ inline void Transit_Node::set_generated(bool value) { // optional uint32 traversability = 12; inline bool Transit_Node::_internal_has_traversability() const { - bool value = (_impl_._has_bits_[0] & 0x00000800u) != 0; + bool value = (_impl_._has_bits_[0] & 0x00002000u) != 0; return value; } inline bool Transit_Node::has_traversability() const { @@ -2109,7 +2139,7 @@ inline bool Transit_Node::has_traversability() const { } inline void Transit_Node::clear_traversability() { _impl_.traversability_ = 0u; - _impl_._has_bits_[0] &= ~0x00000800u; + _impl_._has_bits_[0] &= ~0x00002000u; } inline uint32_t Transit_Node::_internal_traversability() const { return _impl_.traversability_; @@ -2119,7 +2149,7 @@ inline uint32_t Transit_Node::traversability() const { return _internal_traversability(); } inline void Transit_Node::_internal_set_traversability(uint32_t value) { - _impl_._has_bits_[0] |= 0x00000800u; + _impl_._has_bits_[0] |= 0x00002000u; _impl_.traversability_ = value; } inline void Transit_Node::set_traversability(uint32_t value) { @@ -2127,6 +2157,62 @@ inline void Transit_Node::set_traversability(uint32_t value) { // @@protoc_insertion_point(field_set:valhalla.mjolnir.Transit.Node.traversability) } +// optional double osm_connecting_lon = 13; +inline bool Transit_Node::_internal_has_osm_connecting_lon() const { + bool value = (_impl_._has_bits_[0] & 0x00000800u) != 0; + return value; +} +inline bool Transit_Node::has_osm_connecting_lon() const { + return _internal_has_osm_connecting_lon(); +} +inline void Transit_Node::clear_osm_connecting_lon() { + _impl_.osm_connecting_lon_ = 0; + _impl_._has_bits_[0] &= ~0x00000800u; +} +inline double Transit_Node::_internal_osm_connecting_lon() const { + return _impl_.osm_connecting_lon_; +} +inline double Transit_Node::osm_connecting_lon() const { + // @@protoc_insertion_point(field_get:valhalla.mjolnir.Transit.Node.osm_connecting_lon) + return _internal_osm_connecting_lon(); +} +inline void Transit_Node::_internal_set_osm_connecting_lon(double value) { + _impl_._has_bits_[0] |= 0x00000800u; + _impl_.osm_connecting_lon_ = value; +} +inline void Transit_Node::set_osm_connecting_lon(double value) { + _internal_set_osm_connecting_lon(value); + // @@protoc_insertion_point(field_set:valhalla.mjolnir.Transit.Node.osm_connecting_lon) +} + +// optional double osm_connecting_lat = 14; +inline bool Transit_Node::_internal_has_osm_connecting_lat() const { + bool value = (_impl_._has_bits_[0] & 0x00001000u) != 0; + return value; +} +inline bool Transit_Node::has_osm_connecting_lat() const { + return _internal_has_osm_connecting_lat(); +} +inline void Transit_Node::clear_osm_connecting_lat() { + _impl_.osm_connecting_lat_ = 0; + _impl_._has_bits_[0] &= ~0x00001000u; +} +inline double Transit_Node::_internal_osm_connecting_lat() const { + return _impl_.osm_connecting_lat_; +} +inline double Transit_Node::osm_connecting_lat() const { + // @@protoc_insertion_point(field_get:valhalla.mjolnir.Transit.Node.osm_connecting_lat) + return _internal_osm_connecting_lat(); +} +inline void Transit_Node::_internal_set_osm_connecting_lat(double value) { + _impl_._has_bits_[0] |= 0x00001000u; + _impl_.osm_connecting_lat_ = value; +} +inline void Transit_Node::set_osm_connecting_lat(double value) { + _internal_set_osm_connecting_lat(value); + // @@protoc_insertion_point(field_set:valhalla.mjolnir.Transit.Node.osm_connecting_lat) +} + // ------------------------------------------------------------------- // Transit_StopPair diff --git a/lib/darwin/libvalhalla.a b/lib/darwin/libvalhalla.a index 679ae51..1371449 100644 Binary files a/lib/darwin/libvalhalla.a and b/lib/darwin/libvalhalla.a differ diff --git a/lib/linux/libvalhalla.a b/lib/linux/libvalhalla.a index 9581ce0..a53de60 100644 Binary files a/lib/linux/libvalhalla.a and b/lib/linux/libvalhalla.a differ diff --git a/lib/windows/valhalla.lib b/lib/windows/valhalla.lib index 65494b0..f70ce73 100644 Binary files a/lib/windows/valhalla.lib and b/lib/windows/valhalla.lib differ diff --git a/pyproject.toml b/pyproject.toml index 78dce61..fa2315e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,6 +23,7 @@ exclude = ''' | '*build' | __pycache__ | '*.toml' + )/ ''' diff --git a/scripts/build_mac.sh b/scripts/build_mac.sh index e055fbd..fa90c0b 100755 --- a/scripts/build_mac.sh +++ b/scripts/build_mac.sh @@ -11,8 +11,8 @@ git apply ../upstream_patches/* popd # TODO: the env var can be omitted once geos 3.11 is released: https://github.com/libgeos/geos/issues/500 -cmake -B upstream/build -S upstream/ -DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 -DENABLE_CCACHE=OFF -DBUILD_SHARED_LIBS=OFF -DENABLE_BENCHMARKS=OFF -DENABLE_PYTHON_BINDINGS=ON -DENABLE_TESTS=OFF -DENABLE_TOOLS=OFF -DENABLE_DATA_TOOLS=OFF -DENABLE_SERVICES=OFF -DENABLE_HTTP=OFF -DENABLE_CCACHE=OFF -DCMAKE_BUILD_TYPE=Release -cmake --build upstream/build -- -j$(sysctl -n hw.logicalcpu) +cmake -B upstream/build -S upstream/ -DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 -DENABLE_CCACHE=OFF -DBUILD_SHARED_LIBS=OFF -DENABLE_BENCHMARKS=OFF -DENABLE_PYTHON_BINDINGS=ON -DENABLE_TESTS=OFF -DENABLE_TOOLS=OFF -DENABLE_DATA_TOOLS=OFF -DENABLE_SERVICES=OFF -DENABLE_HTTP=OFF -DENABLE_CCACHE=OFF -DCMAKE_BUILD_TYPE=Release || exit 1 +cmake --build upstream/build -- -j$(sysctl -n hw.logicalcpu) || exit 1 rm -r include/darwin/* rm -r lib/darwin diff --git a/setup.cfg b/setup.cfg index 1fad3ea..a914c5b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -4,4 +4,4 @@ ignore = E203,E266,E501,E731,W503,F403,E722,F405 per-file-ignores = __init__.py:F401 max-complexity = 15 max-line-length = 105 -exclude = .*,__pycache__,*build,dist,wheelhouse,valhalla/valhalla_build_config.py +exclude = .*,__pycache__,*build,dist,wheelhouse,valhalla/valhalla_build_config.py,valhalla/__version__.py diff --git a/upstream b/upstream index ea7d44a..cbabe7c 160000 --- a/upstream +++ b/upstream @@ -1 +1 @@ -Subproject commit ea7d44af37c47fcf0cb186e7ba0f9f77e96f202a +Subproject commit cbabe7cfbad2225090e4c006c778f1f0a7b3ec4e diff --git a/valhalla/__init__.py b/valhalla/__init__.py index f506e95..3f54fa9 100644 --- a/valhalla/__init__.py +++ b/valhalla/__init__.py @@ -3,4 +3,4 @@ from ._valhalla import * from .__version__ import __version__ -__valhalla_commit__ = "b5ce7c418" +__valhalla_commit__ = "cbabe7cfb" diff --git a/valhalla/valhalla_build_config.py b/valhalla/valhalla_build_config.py index e771fc3..68ce3da 100644 --- a/valhalla/valhalla_build_config.py +++ b/valhalla/valhalla_build_config.py @@ -1,10 +1,19 @@ #!/usr/bin/env python3 from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter -from distutils.util import strtobool import json from typing import List, Union +def strtobool(value): + lower = str(value).lower() + if lower in {"y", "yes", "t", "true", "on", "1"}: + return True + elif lower in {"n", "no", "f", "false", "off", "0"}: + return False + else: + raise ValueError('"{}" is not a valid bool value'.format(value)) + + class Optional: def __init__(self, t=None): self.type = t @@ -12,517 +21,531 @@ def __init__(self, t=None): # global default configuration config = { - 'mjolnir': { - 'max_cache_size': 1000000000, - 'id_table_size': 1300000000, - 'use_lru_mem_cache': False, - 'lru_mem_cache_hard_control': False, - 'use_simple_mem_cache': False, - 'user_agent': Optional(str), - 'tile_url': Optional(str), - 'tile_url_gz': Optional(bool), - 'concurrency': Optional(int), - 'tile_dir': '/data/valhalla', - 'tile_extract': '/data/valhalla/tiles.tar', - 'traffic_extract': '/data/valhalla/traffic.tar', - 'incident_dir': Optional(str), - 'incident_log': Optional(str), - 'shortcut_caching': Optional(bool), - 'admin': '/data/valhalla/admin.sqlite', - 'timezone': '/data/valhalla/tz_world.sqlite', - 'transit_dir': '/data/valhalla/transit', - 'transit_feeds_dir': '/data/valhalla/transit_feeds', - 'transit_bounding_box': Optional(str), - 'hierarchy': True, - 'shortcuts': True, - 'include_driveways': True, - 'include_construction': False, - 'include_bicycle': True, - 'include_pedestrian': True, - 'include_driving': True, - 'import_bike_share_stations': False, - 'global_synchronized_cache': False, - 'max_concurrent_reader_users': 1, - 'reclassify_links': True, - 'default_speeds_config': Optional(str), - 'data_processing': { - 'infer_internal_intersections': True, - 'infer_turn_channels': True, - 'apply_country_overrides': True, - 'use_admin_db': True, - 'use_direction_on_ways': False, - 'allow_alt_name': False, - 'use_urban_tag': False, - 'use_rest_area': False, - 'scan_tar': False, - }, - 'logging': {'type': 'std_out', 'color': True, 'file_name': 'path_to_some_file.log'}, + "mjolnir": { + "max_cache_size": 1000000000, + "id_table_size": 1300000000, + "use_lru_mem_cache": False, + "lru_mem_cache_hard_control": False, + "use_simple_mem_cache": False, + "user_agent": Optional(str), + "tile_url": Optional(str), + "tile_url_gz": Optional(bool), + "concurrency": Optional(int), + "tile_dir": "/data/valhalla", + "tile_extract": "/data/valhalla/tiles.tar", + "traffic_extract": "/data/valhalla/traffic.tar", + "incident_dir": Optional(str), + "incident_log": Optional(str), + "shortcut_caching": Optional(bool), + "admin": "/data/valhalla/admin.sqlite", + "timezone": "/data/valhalla/tz_world.sqlite", + "transit_dir": "/data/valhalla/transit", + "transit_feeds_dir": "/data/valhalla/transit_feeds", + "transit_bounding_box": Optional(str), + "transit_pbf_limit": 20000, + "hierarchy": True, + "shortcuts": True, + "include_platforms": False, + "include_driveways": True, + "include_construction": False, + "include_bicycle": True, + "include_pedestrian": True, + "include_driving": True, + "import_bike_share_stations": False, + "global_synchronized_cache": False, + "max_concurrent_reader_users": 1, + "reclassify_links": True, + "default_speeds_config": Optional(str), + "data_processing": { + "infer_internal_intersections": True, + "infer_turn_channels": True, + "apply_country_overrides": True, + "use_admin_db": True, + "use_direction_on_ways": False, + "allow_alt_name": False, + "use_urban_tag": False, + "use_rest_area": False, + "scan_tar": False, + }, + "logging": {"type": "std_out", "color": True, "file_name": "path_to_some_file.log"}, }, - 'additional_data': {'elevation': '/data/valhalla/elevation/', 'elevation_url': Optional(str)}, - 'loki': { - 'actions': [ - 'locate', - 'route', - 'height', - 'sources_to_targets', - 'optimized_route', - 'isochrone', - 'trace_route', - 'trace_attributes', - 'transit_available', - 'expansion', - 'centroid', - 'status', + "additional_data": {"elevation": "/data/valhalla/elevation/", "elevation_url": Optional(str)}, + "loki": { + "actions": [ + "locate", + "route", + "height", + "sources_to_targets", + "optimized_route", + "isochrone", + "trace_route", + "trace_attributes", + "transit_available", + "expansion", + "centroid", + "status", ], - 'use_connectivity': True, - 'service_defaults': { - 'radius': 0, - 'minimum_reachability': 50, - 'search_cutoff': 35000, - 'node_snap_tolerance': 5, - 'street_side_tolerance': 5, - 'street_side_max_distance': 1000, - 'heading_tolerance': 60, - }, - 'logging': { - 'type': 'std_out', - 'color': True, - 'file_name': 'path_to_some_file.log', - 'long_request': 100.0, - }, - 'service': {'proxy': 'ipc:///tmp/loki'}, + "use_connectivity": True, + "service_defaults": { + "radius": 0, + "minimum_reachability": 50, + "search_cutoff": 35000, + "node_snap_tolerance": 5, + "street_side_tolerance": 5, + "street_side_max_distance": 1000, + "heading_tolerance": 60, + }, + "logging": { + "type": "std_out", + "color": True, + "file_name": "path_to_some_file.log", + "long_request": 100.0, + }, + "service": {"proxy": "ipc:///tmp/loki"}, }, - 'thor': { - 'logging': { - 'type': 'std_out', - 'color': True, - 'file_name': 'path_to_some_file.log', - 'long_request': 110.0, - }, - 'source_to_target_algorithm': 'select_optimal', - 'service': {'proxy': 'ipc:///tmp/thor'}, - 'max_reserved_labels_count': 1000000, - 'clear_reserved_memory': False, - 'extended_search': False, + "thor": { + "logging": { + "type": "std_out", + "color": True, + "file_name": "path_to_some_file.log", + "long_request": 110.0, + }, + "source_to_target_algorithm": "select_optimal", + "service": {"proxy": "ipc:///tmp/thor"}, + "max_reserved_labels_count_astar": 2000000, + "max_reserved_labels_count_bidir_astar": 1000000, + "max_reserved_labels_count_dijkstras": 4000000, + "max_reserved_labels_count_bidir_dijkstras": 2000000, + "clear_reserved_memory": False, + "extended_search": False, }, - 'odin': { - 'logging': {'type': 'std_out', 'color': True, 'file_name': 'path_to_some_file.log'}, - 'service': {'proxy': 'ipc:///tmp/odin'}, - 'markup_formatter': { - 'markup_enabled': False, - 'phoneme_format': ' (phoneme>//)', + "odin": { + "logging": {"type": "std_out", "color": True, "file_name": "path_to_some_file.log"}, + "service": {"proxy": "ipc:///tmp/odin"}, + "markup_formatter": { + "markup_enabled": False, + "phoneme_format": " (phoneme>//)", }, }, - 'meili': { - 'mode': 'auto', - 'customizable': [ - 'mode', - 'search_radius', - 'turn_penalty_factor', - 'gps_accuracy', - 'interpolation_distance', - 'sigma_z', - 'beta', - 'max_route_distance_factor', - 'max_route_time_factor', + "meili": { + "mode": "auto", + "customizable": [ + "mode", + "search_radius", + "turn_penalty_factor", + "gps_accuracy", + "interpolation_distance", + "sigma_z", + "beta", + "max_route_distance_factor", + "max_route_time_factor", ], - 'verbose': False, - 'default': { - 'sigma_z': 4.07, - 'gps_accuracy': 5.0, - 'beta': 3, - 'max_route_distance_factor': 5, - 'max_route_time_factor': 5, - 'max_search_radius': 100, - 'breakage_distance': 2000, - 'interpolation_distance': 10, - 'search_radius': 50, - 'geometry': False, - 'route': True, - 'turn_penalty_factor': 0, - }, - 'auto': {'turn_penalty_factor': 200, 'search_radius': 50}, - 'pedestrian': {'turn_penalty_factor': 100, 'search_radius': 50}, - 'bicycle': {'turn_penalty_factor': 140}, - 'multimodal': {'turn_penalty_factor': 70}, - 'logging': {'type': 'std_out', 'color': True, 'file_name': 'path_to_some_file.log'}, - 'service': {'proxy': 'ipc:///tmp/meili'}, - 'grid': {'size': 500, 'cache_size': 100240}, + "verbose": False, + "default": { + "sigma_z": 4.07, + "gps_accuracy": 5.0, + "beta": 3, + "max_route_distance_factor": 5, + "max_route_time_factor": 5, + "max_search_radius": 100, + "breakage_distance": 2000, + "interpolation_distance": 10, + "search_radius": 50, + "geometry": False, + "route": True, + "turn_penalty_factor": 0, + }, + "auto": {"turn_penalty_factor": 200, "search_radius": 50}, + "pedestrian": {"turn_penalty_factor": 100, "search_radius": 50}, + "bicycle": {"turn_penalty_factor": 140}, + "multimodal": {"turn_penalty_factor": 70}, + "logging": {"type": "std_out", "color": True, "file_name": "path_to_some_file.log"}, + "service": {"proxy": "ipc:///tmp/meili"}, + "grid": {"size": 500, "cache_size": 100240}, }, - 'httpd': { - 'service': { - 'listen': 'tcp://*:8002', - 'loopback': 'ipc:///tmp/loopback', - 'interrupt': 'ipc:///tmp/interrupt', - 'drain_seconds': 28, - 'shutdown_seconds': 1, + "httpd": { + "service": { + "listen": "tcp://*:8002", + "loopback": "ipc:///tmp/loopback", + "interrupt": "ipc:///tmp/interrupt", + "drain_seconds": 28, + "shutdown_seconds": 1, + "timeout_seconds": -1, } }, - 'service_limits': { - 'auto': { - 'max_distance': 5000000.0, - 'max_locations': 20, - 'max_matrix_distance': 400000.0, - 'max_matrix_location_pairs': 2500, - }, - 'bus': { - 'max_distance': 5000000.0, - 'max_locations': 50, - 'max_matrix_distance': 400000.0, - 'max_matrix_location_pairs': 2500, - }, - 'taxi': { - 'max_distance': 5000000.0, - 'max_locations': 20, - 'max_matrix_distance': 400000.0, - 'max_matrix_location_pairs': 2500, - }, - 'pedestrian': { - 'max_distance': 250000.0, - 'max_locations': 50, - 'max_matrix_distance': 200000.0, - 'max_matrix_location_pairs': 2500, - 'min_transit_walking_distance': 1, - 'max_transit_walking_distance': 10000, - }, - 'motor_scooter': { - 'max_distance': 500000.0, - 'max_locations': 50, - 'max_matrix_distance': 200000.0, - 'max_matrix_location_pairs': 2500, - }, - 'motorcycle': { - 'max_distance': 500000.0, - 'max_locations': 50, - 'max_matrix_distance': 200000.0, - 'max_matrix_location_pairs': 2500, - }, - 'bicycle': { - 'max_distance': 500000.0, - 'max_locations': 50, - 'max_matrix_distance': 200000.0, - 'max_matrix_location_pairs': 2500, - }, - 'multimodal': { - 'max_distance': 500000.0, - 'max_locations': 50, - 'max_matrix_distance': 0.0, - 'max_matrix_location_pairs': 0, - }, - 'status': {'allow_verbose': False}, - 'transit': { - 'max_distance': 500000.0, - 'max_locations': 50, - 'max_matrix_distance': 200000.0, - 'max_matrix_location_pairs': 2500, - }, - 'truck': { - 'max_distance': 5000000.0, - 'max_locations': 20, - 'max_matrix_distance': 400000.0, - 'max_matrix_location_pairs': 2500, - }, - 'skadi': {'max_shape': 750000, 'min_resample': 10.0}, - 'isochrone': { - 'max_contours': 4, - 'max_time_contour': 120, - 'max_distance': 25000.0, - 'max_locations': 1, - 'max_distance_contour': 200, - }, - 'trace': { - 'max_distance': 200000.0, - 'max_gps_accuracy': 100.0, - 'max_search_radius': 100.0, - 'max_shape': 16000, - 'max_alternates': 3, - 'max_alternates_shape': 100, - }, - 'bikeshare': { - 'max_distance': 500000.0, - 'max_locations': 50, - 'max_matrix_distance': 200000.0, - 'max_matrix_location_pairs': 2500, - }, - 'centroid': {'max_distance': 200000.0, 'max_locations': 5}, - 'max_exclude_locations': 50, - 'max_reachability': 100, - 'max_radius': 200, - 'max_timedep_distance': 500000, - 'max_timedep_distance_matrix': 0, - 'max_alternates': 2, - 'max_exclude_polygons_length': 10000, + "service_limits": { + "auto": { + "max_distance": 5000000.0, + "max_locations": 20, + "max_matrix_distance": 400000.0, + "max_matrix_location_pairs": 2500, + }, + "bus": { + "max_distance": 5000000.0, + "max_locations": 50, + "max_matrix_distance": 400000.0, + "max_matrix_location_pairs": 2500, + }, + "taxi": { + "max_distance": 5000000.0, + "max_locations": 20, + "max_matrix_distance": 400000.0, + "max_matrix_location_pairs": 2500, + }, + "pedestrian": { + "max_distance": 250000.0, + "max_locations": 50, + "max_matrix_distance": 200000.0, + "max_matrix_location_pairs": 2500, + "min_transit_walking_distance": 1, + "max_transit_walking_distance": 10000, + }, + "motor_scooter": { + "max_distance": 500000.0, + "max_locations": 50, + "max_matrix_distance": 200000.0, + "max_matrix_location_pairs": 2500, + }, + "motorcycle": { + "max_distance": 500000.0, + "max_locations": 50, + "max_matrix_distance": 200000.0, + "max_matrix_location_pairs": 2500, + }, + "bicycle": { + "max_distance": 500000.0, + "max_locations": 50, + "max_matrix_distance": 200000.0, + "max_matrix_location_pairs": 2500, + }, + "multimodal": { + "max_distance": 500000.0, + "max_locations": 50, + "max_matrix_distance": 0.0, + "max_matrix_location_pairs": 0, + }, + "status": {"allow_verbose": False}, + "transit": { + "max_distance": 500000.0, + "max_locations": 50, + "max_matrix_distance": 200000.0, + "max_matrix_location_pairs": 2500, + }, + "truck": { + "max_distance": 5000000.0, + "max_locations": 20, + "max_matrix_distance": 400000.0, + "max_matrix_location_pairs": 2500, + }, + "skadi": {"max_shape": 750000, "min_resample": 10.0}, + "isochrone": { + "max_contours": 4, + "max_time_contour": 120, + "max_distance": 25000.0, + "max_locations": 1, + "max_distance_contour": 200, + }, + "trace": { + "max_distance": 200000.0, + "max_gps_accuracy": 100.0, + "max_search_radius": 100.0, + "max_shape": 16000, + "max_alternates": 3, + "max_alternates_shape": 100, + }, + "bikeshare": { + "max_distance": 500000.0, + "max_locations": 50, + "max_matrix_distance": 200000.0, + "max_matrix_location_pairs": 2500, + }, + "centroid": {"max_distance": 200000.0, "max_locations": 5}, + "max_exclude_locations": 50, + "max_reachability": 100, + "max_radius": 200, + "max_timedep_distance": 500000, + "max_timedep_distance_matrix": 0, + "max_alternates": 2, + "max_exclude_polygons_length": 10000, + "max_distance_disable_hierarchy_culling": 0, }, - 'statsd': { - 'host': Optional(str), - 'port': 8125, - 'prefix': 'valhalla', - 'batch_size': Optional(int), - 'tags': Optional(list), + "statsd": { + "host": Optional(str), + "port": 8125, + "prefix": "valhalla", + "batch_size": Optional(int), + "tags": Optional(list), }, } help_text = { - 'mjolnir': { - 'max_cache_size': 'Number of bytes per thread used to store tile data in memory', - 'id_table_size': 'Value controls the initial size of the Id table', - 'use_lru_mem_cache': 'Use memory cache with LRU eviction policy', - 'lru_mem_cache_hard_control': 'Use hard memory limit control for LRU memory cache (i.e. on every put) - never allow overcommit', - 'use_simple_mem_cache': 'Use memory cache within a simple hash map the clears all tiles when overcommitted', - 'user_agent': 'User-Agent http header to request single tiles', - 'tile_url': 'Http location to read tiles from if they are not found in the tile_dir, e.g.: http://your_valhalla_tile_server_host:8000/some/Optional/path/{tilePath}?some=Optional&query=params. Valhalla will look for the {tilePath} portion of the url and fill this out with a given tile path when it make a request for that tile', - 'tile_url_gz': 'Whether or not to request for compressed tiles', - 'concurrency': 'How many threads to use in the concurrent parts of tile building', - 'tile_dir': 'Location to read/write tiles to/from', - 'tile_extract': 'Location to read tiles from tar', - 'traffic_extract': 'Location to read traffic from tar', - 'incident_dir': 'Location to read incident tiles from', - 'incident_log': 'Location to read change events of incident tiles', - 'shortcut_caching': 'Precaches the superceded edges of all shortcuts in the graph. Defaults to false', - 'admin': 'Location of sqlite file holding admin polygons created with valhalla_build_admins', - 'timezone': 'Location of sqlite file holding timezone information created with valhalla_build_timezones', - 'transit_dir': 'Location of intermediate transit tiles created with valhalla_build_transit', - 'transit_feeds_dir': 'Location of GTFS transit feeds', - 'transit_bounding_box': 'Add comma separated bounding box values to only download transit data inside the given bounding box', - 'hierarchy': 'bool indicating whether road hierarchy is to be built - default to True', - 'shortcuts': 'bool indicating whether shortcuts are to be built - default to True', - 'include_driveways': 'bool indicating whether private driveways are included - default to True', - 'include_construction': 'bool indicating where roads under construction are included - default to False', - 'include_bicycle': 'bool indicating whether cycling only ways are included - default to True', - 'include_pedestrian': 'bool indicating whether pedestrian only ways are included - default to True', - 'include_driving': 'bool indicating whether driving only ways are included - default to True', - 'import_bike_share_stations': 'bool indicating whether importing bike share stations(BSS). Set to True when using multimodal - default to False', - 'global_synchronized_cache': 'bool indicating whether global_synchronized_cache is used - default to False', - 'max_concurrent_reader_users': 'number of threads in the threadpool which can be used to fetch tiles over the network via curl', - 'reclassify_links': 'bool indicating whether or not to reclassify links - reclassifies ramps based on the lowest class connecting road', - 'default_speeds_config': 'a path indicating the json config file which graph enhancer will use to set the speeds of edges in the graph based on their geographic location (state/country), density (urban/rural), road class, road use (form of way)', - 'data_processing': { - 'infer_internal_intersections': 'bool indicating whether or not to infer internal intersections during the graph enhancer phase or use the internal_intersection key from the pbf', - 'infer_turn_channels': 'bool indicating whether or not to infer turn channels during the graph enhancer phase or use the turn_channel key from the pbf', - 'apply_country_overrides': 'bool indicating whether or not to apply country overrides during the graph enhancer phase', - 'use_admin_db': 'bool indicating whether or not to use the administrative database during the graph enhancer phase or use the admin keys from the pbf that are set on the node', - 'use_direction_on_ways': 'bool indicating whether or not to process the direction key on the ways or utilize the guidance relation tags during the parsing phase', - 'allow_alt_name': 'bool indicating whether or not to process the alt_name key on the ways during the parsing phase', - 'use_urban_tag': 'bool indicating whether or not to use the urban area tag on the ways or to utilize the getDensity function within the graph enhancer phase', - 'use_rest_area': 'bool indicating whether or not to use the rest/service area tag on the ways', - 'scan_tar': 'bool indicating whether or not to pre-scan the tar ball(s) when loading an extract with an index file, to warm up the OS page cache.', - }, - 'logging': { - 'type': 'Type of logger either std_out or file', - 'color': 'User colored log level in std_out logger', - 'file_name': 'Output log file for the file logger', + "mjolnir": { + "max_cache_size": "Number of bytes per thread used to store tile data in memory", + "id_table_size": "Value controls the initial size of the Id table", + "use_lru_mem_cache": "Use memory cache with LRU eviction policy", + "lru_mem_cache_hard_control": "Use hard memory limit control for LRU memory cache (i.e. on every put) - never allow overcommit", + "use_simple_mem_cache": "Use memory cache within a simple hash map the clears all tiles when overcommitted", + "user_agent": "User-Agent http header to request single tiles", + "tile_url": "Http location to read tiles from if they are not found in the tile_dir, e.g.: http://your_valhalla_tile_server_host:8000/some/Optional/path/{tilePath}?some=Optional&query=params. Valhalla will look for the {tilePath} portion of the url and fill this out with a given tile path when it make a request for that tile", + "tile_url_gz": "Whether or not to request for compressed tiles", + "concurrency": "How many threads to use in the concurrent parts of tile building", + "tile_dir": "Location to read/write tiles to/from", + "tile_extract": "Location to read tiles from tar", + "traffic_extract": "Location to read traffic from tar", + "incident_dir": "Location to read incident tiles from", + "incident_log": "Location to read change events of incident tiles", + "shortcut_caching": "Precaches the superceded edges of all shortcuts in the graph. Defaults to false", + "admin": "Location of sqlite file holding admin polygons created with valhalla_build_admins", + "timezone": "Location of sqlite file holding timezone information created with valhalla_build_timezones", + "transit_dir": "Location of intermediate transit tiles created with valhalla_build_transit", + "transit_feeds_dir": "Location of GTFS transit feeds", + "transit_bounding_box": "Add comma separated bounding box values to only download transit data inside the given bounding box", + "transit_pbf_limit": "Limit individual PBF files to this many trips (needed for PBF's stupid size limit)", + "hierarchy": "bool indicating whether road hierarchy is to be built - default to True", + "shortcuts": "bool indicating whether shortcuts are to be built - default to True", + "include_platforms": "bool indicating whether to include highway=platform - default to False", + "include_driveways": "bool indicating whether private driveways are included - default to True", + "include_construction": "bool indicating where roads under construction are included - default to False", + "include_bicycle": "bool indicating whether cycling only ways are included - default to True", + "include_pedestrian": "bool indicating whether pedestrian only ways are included - default to True", + "include_driving": "bool indicating whether driving only ways are included - default to True", + "import_bike_share_stations": "bool indicating whether importing bike share stations(BSS). Set to True when using multimodal - default to False", + "global_synchronized_cache": "bool indicating whether global_synchronized_cache is used - default to False", + "max_concurrent_reader_users": "number of threads in the threadpool which can be used to fetch tiles over the network via curl", + "reclassify_links": "bool indicating whether or not to reclassify links - reclassifies ramps based on the lowest class connecting road", + "default_speeds_config": "a path indicating the json config file which graph enhancer will use to set the speeds of edges in the graph based on their geographic location (state/country), density (urban/rural), road class, road use (form of way)", + "data_processing": { + "infer_internal_intersections": "bool indicating whether or not to infer internal intersections during the graph enhancer phase or use the internal_intersection key from the pbf", + "infer_turn_channels": "bool indicating whether or not to infer turn channels during the graph enhancer phase or use the turn_channel key from the pbf", + "apply_country_overrides": "bool indicating whether or not to apply country overrides during the graph enhancer phase", + "use_admin_db": "bool indicating whether or not to use the administrative database during the graph enhancer phase or use the admin keys from the pbf that are set on the node", + "use_direction_on_ways": "bool indicating whether or not to process the direction key on the ways or utilize the guidance relation tags during the parsing phase", + "allow_alt_name": "bool indicating whether or not to process the alt_name key on the ways during the parsing phase", + "use_urban_tag": "bool indicating whether or not to use the urban area tag on the ways or to utilize the getDensity function within the graph enhancer phase", + "use_rest_area": "bool indicating whether or not to use the rest/service area tag on the ways", + "scan_tar": "bool indicating whether or not to pre-scan the tar ball(s) when loading an extract with an index file, to warm up the OS page cache.", + }, + "logging": { + "type": "Type of logger either std_out or file", + "color": "User colored log level in std_out logger", + "file_name": "Output log file for the file logger", }, }, - 'additional_data': { - 'elevation': 'Location of elevation tiles', - 'elevation_url': 'Http location to read elevations from. this address is used if elevation tiles were not found in the elevation directory. Ex.: http://:/some/Optional/path/{tilePath}?some=Optional&query=params. Valhalla will look for the {tilePath} portion of the url and fill this out with an elevation path when it makes a request for that particular elevation', + "additional_data": { + "elevation": "Location of elevation tiles", + "elevation_url": "Http location to read elevations from. this address is used if elevation tiles were not found in the elevation directory. Ex.: http://:/some/Optional/path/{tilePath}?some=Optional&query=params. Valhalla will look for the {tilePath} portion of the url and fill this out with an elevation path when it makes a request for that particular elevation", }, - 'loki': { - 'actions': 'Comma separated list of allowable actions for the service, one or more of: locate, route, height, optimized_route, isochrone, trace_route, trace_attributes, transit_available, expansion, centroid, status', - 'use_connectivity': 'a boolean value to know whether or not to construct the connectivity maps', - 'service_defaults': { - 'radius': 'Default radius to apply to incoming locations should one not be supplied', - 'minimum_reachability': 'Default minimum reachability to apply to incoming locations should one not be supplied', - 'search_cutoff': 'The cutoff at which we will assume the input is too far away from civilisation to be worth correlating to the nearest graph elements', - 'node_snap_tolerance': 'During edge correlation this is the tolerance used to determine whether or not to snap to the intersection rather than along the street, if the snap location is within this distance from the intersection the intersection is used instead', - 'street_side_tolerance': 'If your input coordinate is less than this tolerance away from the edge centerline then we set your side of street to none otherwise your side of street will be left or right depending on direction of travel', - 'street_side_max_distance': 'The max distance in meters that the input coordinates or display ll can be from the edge centerline for them to be used for determining the side of street. Beyond this distance the side of street is set to none', - 'heading_tolerance': 'When a heading is supplied, this is the tolerance around that heading with which we determine whether an edges heading is similar enough to match the supplied heading', - }, - 'logging': { - 'type': 'Type of logger either std_out or file', - 'color': 'User colored log level in std_out logger', - 'file_name': 'Output log file for the file logger', - 'long_request': 'Value used in processing to determine whether it took too long', - }, - 'service': {'proxy': 'IPC linux domain socket file location'}, + "loki": { + "actions": "Comma separated list of allowable actions for the service, one or more of: locate, route, height, optimized_route, isochrone, trace_route, trace_attributes, transit_available, expansion, centroid, status", + "use_connectivity": "a boolean value to know whether or not to construct the connectivity maps", + "service_defaults": { + "radius": "Default radius to apply to incoming locations should one not be supplied", + "minimum_reachability": "Default minimum reachability to apply to incoming locations should one not be supplied", + "search_cutoff": "The cutoff at which we will assume the input is too far away from civilisation to be worth correlating to the nearest graph elements", + "node_snap_tolerance": "During edge correlation this is the tolerance used to determine whether or not to snap to the intersection rather than along the street, if the snap location is within this distance from the intersection the intersection is used instead", + "street_side_tolerance": "If your input coordinate is less than this tolerance away from the edge centerline then we set your side of street to none otherwise your side of street will be left or right depending on direction of travel", + "street_side_max_distance": "The max distance in meters that the input coordinates or display ll can be from the edge centerline for them to be used for determining the side of street. Beyond this distance the side of street is set to none", + "heading_tolerance": "When a heading is supplied, this is the tolerance around that heading with which we determine whether an edges heading is similar enough to match the supplied heading", + }, + "logging": { + "type": "Type of logger either std_out or file", + "color": "User colored log level in std_out logger", + "file_name": "Output log file for the file logger", + "long_request": "Value used in processing to determine whether it took too long", + }, + "service": {"proxy": "IPC linux domain socket file location"}, }, - 'thor': { - 'logging': { - 'type': 'Type of logger either std_out or file', - 'color': 'User colored log level in std_out logger', - 'file_name': 'Output log file for the file logger', - 'long_request': 'Value used in processing to determine whether it took too long', - }, - 'source_to_target_algorithm': 'TODO: which matrix algorithm should be used', - 'service': {'proxy': 'IPC linux domain socket file location'}, - 'max_reserved_labels_count': 'Maximum capacity that allowed to keep reserved in path algorithm.', - 'clear_reserved_memory': 'If True clean reserved memory in path algorithms', - 'extended_search': 'If True and 1 side of the bidirectional search is exhausted, causes the other side to continue if the starting location of that side began on a not_thru or closed edge', + "thor": { + "logging": { + "type": "Type of logger either std_out or file", + "color": "User colored log level in std_out logger", + "file_name": "Output log file for the file logger", + "long_request": "Value used in processing to determine whether it took too long", + }, + "source_to_target_algorithm": "TODO: which matrix algorithm should be used", + "service": {"proxy": "IPC linux domain socket file location"}, + "max_reserved_labels_count_astar": "Maximum capacity allowed to keep reserved for unidirectional A*.", + "max_reserved_labels_count_bidir_astar": "Maximum capacity allowed to keep reserved for bidirectional A*.", + "max_reserved_labels_count_dijkstras": "Maximum capacity allowed to keep reserved for unidirectional Dijkstras.", + "max_reserved_labels_count_bidir_dijkstras": "Maximum capacity allowed to keep reserved for bidirectional Dijkstras.", + "clear_reserved_memory": "If True clean reserved memory in path algorithms", + "extended_search": "If True and 1 side of the bidirectional search is exhausted, causes the other side to continue if the starting location of that side began on a not_thru or closed edge", }, - 'odin': { - 'logging': { - 'type': 'Type of logger either std_out or file', - 'color': 'User colored log level in std_out logger', - 'file_name': 'Output log file for the file logger', + "odin": { + "logging": { + "type": "Type of logger either std_out or file", + "color": "User colored log level in std_out logger", + "file_name": "Output log file for the file logger", }, - 'service': {'proxy': 'IPC linux domain socket file location'}, - 'markup_formatter': { - 'markup_enabled': 'Boolean flag to use markup formatting', - 'phoneme_format': 'The phoneme format string that will be used by street names and signs', + "service": {"proxy": "IPC linux domain socket file location"}, + "markup_formatter": { + "markup_enabled": "Boolean flag to use markup formatting", + "phoneme_format": "The phoneme format string that will be used by street names and signs", }, }, - 'meili': { - 'mode': 'Specify the default transport mode', - 'customizable': 'Specify which parameters are allowed to be customized by URL query parameters', - 'verbose': 'Control verbose output for debugging', - 'default': { - 'sigma_z': 'A non-negative value to specify the GPS accuracy (the variance of the normal distribution) of an incoming GPS sequence. It is also used to weight emission costs of measurements', - 'gps_accuracy': 'TODO: ', - 'beta': 'A non-negative emprical value to weight the transition cost of two successive candidates', - 'max_route_distance_factor': 'A non-negative value used to limit the routing search range which is the distance to next measurement multiplied by this factor', - 'max_route_time_factor': 'A non-negative value used to limit the routing search range which is the time to the next measurement multiplied by this factor', - 'breakage_distance': 'A non-negative value. If two successive measurements are far than this distance, then connectivity in between will not be considered', - 'max_search_radius': 'A non-negative value specifying the maximum radius in meters about a given point to search for candidate edges for routing', - 'interpolation_distance': 'If two successive measurements are closer than this distance, then the later one will be interpolated into the matched route', - 'search_radius': 'A non-negative value to specify the search radius (in meters) within which to search road candidates for each measurement', - 'geometry': 'TODO: ', - 'route': 'TODO: ', - 'turn_penalty_factor': 'A non-negative value to penalize turns from one road segment to next', - }, - 'auto': { - 'turn_penalty_factor': 'A non-negative value to penalize turns from one road segment to next', - 'search_radius': 'A non-negative value to specify the search radius (in meters) within which to search road candidates for each measurement', - }, - 'pedestrian': { - 'turn_penalty_factor': 'A non-negative value to penalize turns from one road segment to next', - 'search_radius': 'A non-negative value to specify the search radius (in meters) within which to search road candidates for each measurement', - }, - 'bicycle': { - 'turn_penalty_factor': 'A non-negative value to penalize turns from one road segment to next' - }, - 'multimodal': { - 'turn_penalty_factor': 'A non-negative value to penalize turns from one road segment to next' - }, - 'logging': { - 'type': 'Type of logger either std_out or file', - 'color': 'User colored log level in std_out logger', - 'file_name': 'Output log file for the file logger', - }, - 'service': {'proxy': 'IPC linux domain socket file location'}, - 'grid': { - 'size': 'TODO: Resolution of the grid used in finding match candidates', - 'cache_size': 'TODO: number of grids to keep in cache', + "meili": { + "mode": "Specify the default transport mode", + "customizable": "Specify which parameters are allowed to be customized by URL query parameters", + "verbose": "Control verbose output for debugging", + "default": { + "sigma_z": "A non-negative value to specify the GPS accuracy (the variance of the normal distribution) of an incoming GPS sequence. It is also used to weight emission costs of measurements", + "gps_accuracy": "TODO: ", + "beta": "A non-negative emprical value to weight the transition cost of two successive candidates", + "max_route_distance_factor": "A non-negative value used to limit the routing search range which is the distance to next measurement multiplied by this factor", + "max_route_time_factor": "A non-negative value used to limit the routing search range which is the time to the next measurement multiplied by this factor", + "breakage_distance": "A non-negative value. If two successive measurements are far than this distance, then connectivity in between will not be considered", + "max_search_radius": "A non-negative value specifying the maximum radius in meters about a given point to search for candidate edges for routing", + "interpolation_distance": "If two successive measurements are closer than this distance, then the later one will be interpolated into the matched route", + "search_radius": "A non-negative value to specify the search radius (in meters) within which to search road candidates for each measurement", + "geometry": "TODO: ", + "route": "TODO: ", + "turn_penalty_factor": "A non-negative value to penalize turns from one road segment to next", + }, + "auto": { + "turn_penalty_factor": "A non-negative value to penalize turns from one road segment to next", + "search_radius": "A non-negative value to specify the search radius (in meters) within which to search road candidates for each measurement", + }, + "pedestrian": { + "turn_penalty_factor": "A non-negative value to penalize turns from one road segment to next", + "search_radius": "A non-negative value to specify the search radius (in meters) within which to search road candidates for each measurement", + }, + "bicycle": { + "turn_penalty_factor": "A non-negative value to penalize turns from one road segment to next" + }, + "multimodal": { + "turn_penalty_factor": "A non-negative value to penalize turns from one road segment to next" + }, + "logging": { + "type": "Type of logger either std_out or file", + "color": "User colored log level in std_out logger", + "file_name": "Output log file for the file logger", + }, + "service": {"proxy": "IPC linux domain socket file location"}, + "grid": { + "size": "TODO: Resolution of the grid used in finding match candidates", + "cache_size": "TODO: number of grids to keep in cache", }, }, - 'httpd': { - 'service': { - 'listen': 'The protocol, host location and port your service will bind to', - 'loopback': 'IPC linux domain socket file location used to communicate results back to the client', - 'interrupt': 'IPC linux domain socket file location used to cancel work in progress', - 'drain_seconds': 'How long to wait for currently running threads to finish before signaling them to shutdown', - 'shutdown_seconds': 'How long to wait for currently running threads to quit before exiting the process', + "httpd": { + "service": { + "listen": "The protocol, host location and port your service will bind to", + "loopback": "IPC linux domain socket file location used to communicate results back to the client", + "interrupt": "IPC linux domain socket file location used to cancel work in progress", + "drain_seconds": "How long to wait for currently running threads to finish before signaling them to shutdown", + "shutdown_seconds": "How long to wait for currently running threads to quit before exiting the process", + "timeout_seconds": "How long to wait for a single request to finish before timing it out (defaults to infinite)", } }, - 'service_limits': { - 'auto': { - 'max_distance': 'Maximum b-line distance between all locations in meters', - 'max_locations': 'Maximum number of input locations', - 'max_matrix_distance': 'Maximum b-line distance between 2 most distant locations in meters for a matrix', - 'max_matrix_location_pairs': 'Maximum number of routes computed with the matrix, e.g. 2500 = 50:50 or 1:2500', - }, - 'bus': { - 'max_distance': 'Maximum b-line distance between all locations in meters', - 'max_locations': 'Maximum number of input locations', - 'max_matrix_distance': 'Maximum b-line distance between 2 most distant locations in meters for a matrix', - 'max_matrix_location_pairs': 'Maximum number of routes computed with the matrix, e.g. 2500 = 50:50 or 1:2500', - }, - 'taxi': { - 'max_distance': 'Maximum b-line distance between all locations in meters', - 'max_locations': 'Maximum number of input locations', - 'max_matrix_distance': 'Maximum b-line distance between 2 most distant locations in meters for a matrix', - 'max_matrix_location_pairs': 'Maximum number of routes computed with the matrix, e.g. 2500 = 50:50 or 1:2500', - }, - 'pedestrian': { - 'max_distance': 'Maximum b-line distance between all locations in meters', - 'max_locations': 'Maximum number of input locations', - 'max_matrix_distance': 'Maximum b-line distance between 2 most distant locations in meters for a matrix', - 'max_matrix_location_pairs': 'Maximum number of routes computed with the matrix, e.g. 2500 = 50:50 or 1:2500', - 'min_transit_walking_distance': 'TODO: minimum distance you must walk to a station', - 'max_transit_walking_distance': 'Maximum distance allowed for walking when using transit', - }, - 'motor_scooter': { - 'max_distance': 'Maximum b-line distance between all locations in meters', - 'max_locations': 'Maximum number of input locations', - 'max_matrix_distance': 'Maximum b-line distance between 2 most distant locations in meters for a matrix', - 'max_matrix_location_pairs': 'Maximum number of routes computed with the matrix, e.g. 2500 = 50:50 or 1:2500', - }, - 'motorcycle': { - 'max_distance': 'Maximum b-line distance between all locations in meters', - 'max_locations': 'Maximum number of input locations', - 'max_matrix_distance': 'Maximum b-line distance between 2 most distant locations in meters for a matrix', - 'max_matrix_location_pairs': 'Maximum number of routes computed with the matrix, e.g. 2500 = 50:50 or 1:2500', - }, - 'bicycle': { - 'max_distance': 'Maximum b-line distance between all locations in meters', - 'max_locations': 'Maximum number of input locations', - 'max_matrix_distance': 'Maximum b-line distance between 2 most distant locations in meters for a matrix', - 'max_matrix_location_pairs': 'Maximum number of routes computed with the matrix, e.g. 2500 = 50:50 or 1:2500', - }, - 'multimodal': { - 'max_distance': 'Maximum b-line distance between all locations in meters', - 'max_locations': 'Maximum number of input locations', - 'max_matrix_distance': 'Maximum b-line distance between 2 most distant locations in meters for a matrix', - 'max_matrix_location_pairs': 'Maximum number of routes computed with the matrix, e.g. 2500 = 50:50 or 1:2500', - }, - 'status': { - 'allow_verbose': 'Allow verbose output for the /status endpoint, which can be computationally expensive' - }, - 'transit': { - 'max_distance': 'Maximum b-line distance between all locations in meters', - 'max_locations': 'Maximum number of input locations', - 'max_matrix_distance': 'Maximum b-line distance between 2 most distant locations in meters for a matrix', - 'max_matrix_location_pairs': 'Maximum number of routes computed with the matrix, e.g. 2500 = 50:50 or 1:2500', - }, - 'truck': { - 'max_distance': 'Maximum b-line distance between all locations in meters', - 'max_locations': 'Maximum number of input locations', - 'max_matrix_distance': 'Maximum b-line distance between 2 most distant locations in meters for a matrix', - 'max_matrix_location_pairs': 'Maximum number of routes computed with the matrix, e.g. 2500 = 50:50 or 1:2500', - }, - 'skadi': { - 'max_shape': 'Maximum number of input shapes', - 'min_resample': 'Smalled resampling distance to allow in meters', - }, - 'isochrone': { - 'max_contours': 'Maximum number of input contours to allow', - 'max_time_contour': 'Maximum time value for any one contour in minutes', - 'max_distance': 'Maximum b-line distance between all locations in meters', - 'max_locations': 'Maximum number of input locations', - 'max_distance_contour': 'Maximum distance value for any one contour in kilometers', - }, - 'trace': { - 'max_distance': 'Maximum input shape distance in meters', - 'max_gps_accuracy': 'Maximum input gps accuracy in meters', - 'max_search_radius': 'Maximum upper bounds of the search radius in meters', - 'max_shape': 'Maximum number of input shape points', - 'max_alternates': 'Maximum number of alternate map matching', - 'max_alternates_shape': 'Maximum number of input shape points when requesting multiple paths', - }, - 'bikeshare': { - 'max_distance': 'Maximum b-line distance between all locations in meters', - 'max_locations': 'Maximum number of input locations', - 'max_matrix_distance': 'Maximum b-line distance between 2 most distant locations in meters for a matrix', - 'max_matrix_location_pairs': 'Maximum number of routes computed with the matrix, e.g. 2500 = 50:50 or 1:2500', - }, - 'centroid': { - 'max_distance': 'Maximum b-line distance between any pair of locations in meters', - 'max_locations': 'Maximum number of input locations, 127 is a hard limit and cannot be increased in config', - }, - 'max_exclude_locations': 'Maximum number of avoid locations to allow in a request', - 'max_reachability': 'Maximum reachability (number of nodes reachable) allowed on any one location', - 'max_radius': 'Maximum radius in meters allowed on any one location', - 'max_timedep_distance': 'Maximum b-line distance between locations to allow a time-dependent route', - 'max_timedep_distance_matrix': 'Maximum b-line distance between 2 most distant locations in meters to allow a time-dependent matrix', - 'max_alternates': 'Maximum number of alternate routes to allow in a request', - 'max_exclude_polygons_length': 'Maximum total perimeter of all exclude_polygons in meters', + "service_limits": { + "auto": { + "max_distance": "Maximum b-line distance between all locations in meters", + "max_locations": "Maximum number of input locations", + "max_matrix_distance": "Maximum b-line distance between 2 most distant locations in meters for a matrix", + "max_matrix_location_pairs": "Maximum number of routes computed with the matrix, e.g. 2500 = 50:50 or 1:2500", + }, + "bus": { + "max_distance": "Maximum b-line distance between all locations in meters", + "max_locations": "Maximum number of input locations", + "max_matrix_distance": "Maximum b-line distance between 2 most distant locations in meters for a matrix", + "max_matrix_location_pairs": "Maximum number of routes computed with the matrix, e.g. 2500 = 50:50 or 1:2500", + }, + "taxi": { + "max_distance": "Maximum b-line distance between all locations in meters", + "max_locations": "Maximum number of input locations", + "max_matrix_distance": "Maximum b-line distance between 2 most distant locations in meters for a matrix", + "max_matrix_location_pairs": "Maximum number of routes computed with the matrix, e.g. 2500 = 50:50 or 1:2500", + }, + "pedestrian": { + "max_distance": "Maximum b-line distance between all locations in meters", + "max_locations": "Maximum number of input locations", + "max_matrix_distance": "Maximum b-line distance between 2 most distant locations in meters for a matrix", + "max_matrix_location_pairs": "Maximum number of routes computed with the matrix, e.g. 2500 = 50:50 or 1:2500", + "min_transit_walking_distance": "Minimum distance you must walk to the egress of to a station", + "max_transit_walking_distance": "Maximum distance allowed for walking when using transit", + }, + "motor_scooter": { + "max_distance": "Maximum b-line distance between all locations in meters", + "max_locations": "Maximum number of input locations", + "max_matrix_distance": "Maximum b-line distance between 2 most distant locations in meters for a matrix", + "max_matrix_location_pairs": "Maximum number of routes computed with the matrix, e.g. 2500 = 50:50 or 1:2500", + }, + "motorcycle": { + "max_distance": "Maximum b-line distance between all locations in meters", + "max_locations": "Maximum number of input locations", + "max_matrix_distance": "Maximum b-line distance between 2 most distant locations in meters for a matrix", + "max_matrix_location_pairs": "Maximum number of routes computed with the matrix, e.g. 2500 = 50:50 or 1:2500", + }, + "bicycle": { + "max_distance": "Maximum b-line distance between all locations in meters", + "max_locations": "Maximum number of input locations", + "max_matrix_distance": "Maximum b-line distance between 2 most distant locations in meters for a matrix", + "max_matrix_location_pairs": "Maximum number of routes computed with the matrix, e.g. 2500 = 50:50 or 1:2500", + }, + "multimodal": { + "max_distance": "Maximum b-line distance between all locations in meters", + "max_locations": "Maximum number of input locations", + "max_matrix_distance": "Maximum b-line distance between 2 most distant locations in meters for a matrix", + "max_matrix_location_pairs": "Maximum number of routes computed with the matrix, e.g. 2500 = 50:50 or 1:2500", + }, + "status": { + "allow_verbose": "Allow verbose output for the /status endpoint, which can be computationally expensive" + }, + "transit": { + "max_distance": "Maximum b-line distance between all locations in meters", + "max_locations": "Maximum number of input locations", + "max_matrix_distance": "Maximum b-line distance between 2 most distant locations in meters for a matrix", + "max_matrix_location_pairs": "Maximum number of routes computed with the matrix, e.g. 2500 = 50:50 or 1:2500", + }, + "truck": { + "max_distance": "Maximum b-line distance between all locations in meters", + "max_locations": "Maximum number of input locations", + "max_matrix_distance": "Maximum b-line distance between 2 most distant locations in meters for a matrix", + "max_matrix_location_pairs": "Maximum number of routes computed with the matrix, e.g. 2500 = 50:50 or 1:2500", + }, + "skadi": { + "max_shape": "Maximum number of input shapes", + "min_resample": "Smalled resampling distance to allow in meters", + }, + "isochrone": { + "max_contours": "Maximum number of input contours to allow", + "max_time_contour": "Maximum time value for any one contour in minutes", + "max_distance": "Maximum b-line distance between all locations in meters", + "max_locations": "Maximum number of input locations", + "max_distance_contour": "Maximum distance value for any one contour in kilometers", + }, + "trace": { + "max_distance": "Maximum input shape distance in meters", + "max_gps_accuracy": "Maximum input gps accuracy in meters", + "max_search_radius": "Maximum upper bounds of the search radius in meters", + "max_shape": "Maximum number of input shape points", + "max_alternates": "Maximum number of alternate map matching", + "max_alternates_shape": "Maximum number of input shape points when requesting multiple paths", + }, + "bikeshare": { + "max_distance": "Maximum b-line distance between all locations in meters", + "max_locations": "Maximum number of input locations", + "max_matrix_distance": "Maximum b-line distance between 2 most distant locations in meters for a matrix", + "max_matrix_location_pairs": "Maximum number of routes computed with the matrix, e.g. 2500 = 50:50 or 1:2500", + }, + "centroid": { + "max_distance": "Maximum b-line distance between any pair of locations in meters", + "max_locations": "Maximum number of input locations, 127 is a hard limit and cannot be increased in config", + }, + "max_exclude_locations": "Maximum number of avoid locations to allow in a request", + "max_reachability": "Maximum reachability (number of nodes reachable) allowed on any one location", + "max_radius": "Maximum radius in meters allowed on any one location", + "max_timedep_distance": "Maximum b-line distance between locations to allow a time-dependent route", + "max_timedep_distance_matrix": "Maximum b-line distance between 2 most distant locations in meters to allow a time-dependent matrix", + "max_alternates": "Maximum number of alternate routes to allow in a request", + "max_exclude_polygons_length": "Maximum total perimeter of all exclude_polygons in meters", + "max_distance_disable_hierarchy_culling": "Maximum search distance allowed with hierarchy culling disabled", }, - 'statsd': { - 'host': 'The statsd host address', - 'port': 'The statsd port', - 'prefix': 'The statsd prefix to use for each metric', - 'batch_size': 'Approximate maximum size in bytes of each batch of stats to send to statsd', - 'tags': 'List of tags to include with each metric', + "statsd": { + "host": "The statsd host address", + "port": "The statsd port", + "prefix": "The statsd prefix to use for each metric", + "batch_size": "Approximate maximum size in bytes of each batch of stats to send to statsd", + "tags": "List of tags to include with each metric", }, } @@ -542,10 +565,10 @@ def add_leaf_args( if isinstance(tree, dict): for k in tree: v = tree[k] - add_leaf_args('\0'.join([path, k]) if len(path) else k, v, leaves_, parser_, help) + add_leaf_args("\0".join([path, k]) if len(path) else k, v, leaves_, parser_, help) # we've reached a leaf else: - keys = path.split('\0') + keys = path.split("\0") h = help for k in keys: h = h[k] @@ -556,13 +579,13 @@ def add_leaf_args( if isinstance(tree, Optional): t = tree.type elif isinstance(tree, list): - t = lambda arg: arg.split(',') + t = lambda arg: arg.split(",") elif isinstance(tree, bool): t = lambda arg: bool(strtobool(arg)) else: t = type(tree) - arg = '--' + path.replace('_', '-').replace('\0', '-') + arg = "--" + path.replace("_", "-").replace("\0", "-") parser_.add_argument(arg, type=t, help=h, default=tree) leaves_.append(path) @@ -570,11 +593,11 @@ def add_leaf_args( def override_config(args_: dict, leaves_: list, config_: dict): """override the defaults given what was passed""" for leaf in leaves_: - keys = leaf.split('\0') + keys = leaf.split("\0") v = config_ for k in keys[:-1]: v = v[k] - v[keys[-1]] = args_.get(leaf.replace('\0', '_')) + v[keys[-1]] = args_.get(leaf.replace("\0", "_")) if isinstance(v[keys[-1]], type(Optional())): del v[keys[-1]] @@ -582,12 +605,12 @@ def override_config(args_: dict, leaves_: list, config_: dict): # set up available program options leaves = [] parser = ArgumentParser( - description='Generate valhalla configuration', formatter_class=ArgumentDefaultsHelpFormatter + description="Generate valhalla configuration", formatter_class=ArgumentDefaultsHelpFormatter ) -add_leaf_args('', config, leaves, parser, help_text) +add_leaf_args("", config, leaves, parser, help_text) # entry point to program -if __name__ == '__main__': +if __name__ == "__main__": # TODO: add argument to set base path and use in all other path based values args = parser.parse_args() @@ -595,4 +618,4 @@ def override_config(args_: dict, leaves_: list, config_: dict): override_config(args.__dict__, leaves, config) # show the config - print(json.dumps(config, sort_keys=True, indent=2, separators=(',', ': '))) + print(json.dumps(config, sort_keys=True, indent=2, separators=(",", ": ")))