Libosmium  2.10.3
Fast and flexible C++ library for working with OpenStreetMap data
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
delta.hpp
Go to the documentation of this file.
1 #ifndef OSMIUM_UTIL_DELTA_HPP
2 #define OSMIUM_UTIL_DELTA_HPP
3 
4 /*
5 
6 This file is part of Osmium (http://osmcode.org/libosmium).
7 
8 Copyright 2013-2016 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 <cstdint>
37 #include <type_traits>
38 #include <utility>
39 
40 #include <osmium/util/cast.hpp>
41 
42 namespace osmium {
43 
44  namespace util {
45 
49  template <typename TValue, typename TDelta = int64_t>
50  class DeltaEncode {
51 
52  "DeltaEncode value type must be some integer");
53 
54  "DeltaEncode delta type must be some signed integer");
55 
56  TValue m_value;
57 
58  public:
59 
60  using value_type = TValue;
61  using delta_type = TDelta;
62 
63  explicit DeltaEncode(TValue value = 0) :
64  m_value(value) {
65  }
66 
67  void clear() noexcept {
68  m_value = 0;
69  }
70 
71  TValue value() const noexcept {
72  return m_value;
73  }
74 
75  TDelta update(TValue new_value) noexcept {
76  using std::swap;
77  swap(m_value, new_value);
78  return static_cast_with_assert<TDelta>(m_value) -
79  static_cast_with_assert<TDelta>(new_value);
80  }
81 
82  }; // class DeltaEncode
83 
87  template <typename TValue, typename TDelta = int64_t>
88  class DeltaDecode {
89 
90  "DeltaDecode value type must be some integer");
91 
92  "DeltaDecode delta type must be some signed integer");
93 
94  TValue m_value;
95 
96  public:
97 
98  using value_type = TValue;
99  using delta_type = TDelta;
100 
102  m_value(0) {
103  }
104 
105  void clear() noexcept {
106  m_value = 0;
107  }
108 
109  TValue update(TDelta delta) noexcept {
110  m_value = static_cast_with_assert<TValue>(
111  static_cast_with_assert<TDelta>(m_value) + delta);
112  return m_value;
113  }
114 
115  }; // class DeltaDecode
116 
117  } // namespace util
118 
119 } // namespace osmium
120 
121 #endif // OSMIUM_UTIL_DELTA_HPP
DeltaEncode(TValue value=0)
Definition: delta.hpp:63
TDelta delta_type
Definition: delta.hpp:61
TValue m_value
Definition: delta.hpp:94
TDelta update(TValue new_value) noexcept
Definition: delta.hpp:75
Definition: delta.hpp:88
void swap(Buffer &lhs, Buffer &rhs)
Definition: buffer.hpp:761
TValue value_type
Definition: delta.hpp:98
TValue m_value
Definition: delta.hpp:56
Namespace for everything in the Osmium library.
Definition: assembler.hpp:73
Definition: delta.hpp:50
TValue update(TDelta delta) noexcept
Definition: delta.hpp:109
TValue value_type
Definition: delta.hpp:60
TValue value() const noexcept
Definition: delta.hpp:71
void clear() noexcept
Definition: delta.hpp:105
void clear() noexcept
Definition: delta.hpp:67
TDelta delta_type
Definition: delta.hpp:99
DeltaDecode()
Definition: delta.hpp:101