1 #ifndef OSMIUM_INDEX_INDEX_HPP 2 #define OSMIUM_INDEX_INDEX_HPP 3 4 /* 5 6 This file is part of Osmium (https://osmcode.org/libosmium). 7 8 Copyright 2013-2021 Jochen Topf <jochen@topf.org> and others (see README). 9 10 Boost Software License - Version 1.0 - August 17th, 2003 11 12 Permission is hereby granted, free of charge, to any person or organization 13 obtaining a copy of the software and accompanying documentation covered by 14 this license (the "Software") to use, reproduce, display, distribute, 15 execute, and transmit the Software, and to prepare derivative works of the 16 Software, and to permit third-parties to whom the Software is furnished to 17 do so, all subject to the following: 18 19 The copyright notices in the Software and this entire statement, including 20 the above license grant, this restriction and the following disclaimer, 21 must be included in all copies of the Software, in whole or in part, and 22 all derivative works of the Software, unless such copies or derivative 23 works are solely in the form of machine-executable object code generated by 24 a source language processor. 25 26 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 29 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 30 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 31 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 32 DEALINGS IN THE SOFTWARE. 33 34 */ 35 36 #include <cstddef> 37 #include <cstdint> 38 #include <limits> 39 #include <stdexcept> 40 #include <string> 41 42 namespace osmium { 43 44 /** 45 * Exception signaling that an element could not be 46 * found in an index. 47 */ 48 struct not_found : public std::runtime_error { 49 not_foundosmium::not_found50 explicit not_found(const std::string& what) : 51 std::runtime_error(what) { 52 } 53 not_foundosmium::not_found54 explicit not_found(const char* what) : 55 std::runtime_error(what) { 56 } 57 not_foundosmium::not_found58 explicit not_found(uint64_t id) : 59 std::runtime_error(std::string{"id "} + std::to_string(id) + " not found") { 60 } 61 62 }; // struct not_found 63 64 /** 65 * @brief Indexing of OSM data, Locations, etc. 66 */ 67 namespace index { 68 69 /** 70 * Some of the index classes need an "empty" value that can 71 * never appear in real data. This function must return this 72 * empty value for any class used as a value in an index. 73 * The default implementation returns a default constructed 74 * object, but it can be specialized. 75 */ 76 template <typename T> empty_value()77 inline constexpr T empty_value() { 78 return T{}; 79 } 80 81 /** 82 * The size_t value in indexes is usually used for offsets 83 * into a buffer or file. It is unlikely that we ever need 84 * the full range, so the max value is a good "empty" value. 85 */ 86 template <> empty_value()87 inline constexpr size_t empty_value<size_t>() { 88 return std::numeric_limits<size_t>::max(); 89 } 90 91 } // namespace index 92 93 } // namespace osmium 94 95 #endif // OSMIUM_INDEX_INDEX_HPP 96