detail/stream.hpp
100.0% Lines (101/101)
100.0% List of functions (34/34)
Functions (34)
Function
Calls
Lines
Branches
Blocks
boost::json::detail::const_stream::const_stream(char const*, unsigned long)
:27
35719x
100.0%
–
100.0%
boost::json::detail::const_stream::remain() const
:43
64866x
100.0%
–
100.0%
boost::json::detail::const_stream::data() const
:49
62244x
100.0%
–
100.0%
boost::json::detail::const_stream::operator bool() const
:54
31451934x
100.0%
–
100.0%
boost::json::detail::const_stream::operator*() const
:61
31417505x
100.0%
–
75.0%
boost::json::detail::const_stream::operator++()
:69
31417505x
100.0%
–
75.0%
boost::json::detail::const_stream::skip(unsigned long)
:77
26559x
100.0%
–
75.0%
boost::json::detail::local_const_stream::local_const_stream(boost::json::detail::const_stream&)
:98
44285x
100.0%
–
100.0%
boost::json::detail::local_const_stream::~local_const_stream()
:105
44285x
100.0%
–
100.0%
boost::json::detail::const_stream_wrapper::const_stream_wrapper(char const*&, char const*)
:128
4794062x
100.0%
–
100.0%
boost::json::detail::const_stream_wrapper::operator++()
:136
63384959x
100.0%
–
100.0%
boost::json::detail::const_stream_wrapper::operator+=(unsigned long)
:141
2046839x
100.0%
–
100.0%
boost::json::detail::const_stream_wrapper::operator=(char const*)
:146
7322858x
100.0%
–
100.0%
boost::json::detail::const_stream_wrapper::operator*() const
:151
70856167x
100.0%
–
100.0%
boost::json::detail::const_stream_wrapper::operator bool() const
:156
76831743x
100.0%
–
100.0%
boost::json::detail::const_stream_wrapper::begin() const
:161
20797775x
100.0%
–
100.0%
boost::json::detail::const_stream_wrapper::end() const
:166
4865457x
100.0%
–
100.0%
boost::json::detail::const_stream_wrapper::remain() const
:171
2135882x
100.0%
–
100.0%
boost::json::detail::const_stream_wrapper::remain(char const*) const
:176
3071x
100.0%
–
100.0%
boost::json::detail::const_stream_wrapper::used(char const*) const
:181
2314817x
100.0%
–
100.0%
boost::json::detail::clipped_const_stream::clipped_const_stream(char const*&, char const*)
:193
13678x
100.0%
–
100.0%
boost::json::detail::clipped_const_stream::operator bool() const
:211
68643x
100.0%
–
100.0%
boost::json::detail::clipped_const_stream::remain() const
:216
11688x
100.0%
–
100.0%
boost::json::detail::clipped_const_stream::clip(unsigned long)
:227
15663x
100.0%
–
100.0%
boost::json::detail::stream::stream(char*, unsigned long)
:247
32982x
100.0%
–
100.0%
boost::json::detail::stream::used(char*) const
:256
32980x
100.0%
–
100.0%
boost::json::detail::stream::remain() const
:263
90553x
100.0%
–
100.0%
boost::json::detail::stream::data()
:269
2956x
100.0%
–
100.0%
boost::json::detail::stream::operator bool() const
:274
31623944x
100.0%
–
100.0%
boost::json::detail::stream::append(char const*, unsigned long)
:298
32736x
100.0%
–
75.0%
boost::json::detail::stream::append(char)
:309
31554204x
100.0%
–
67.0%
boost::json::detail::stream::advance(unsigned long)
:316
2956x
100.0%
–
75.0%
boost::json::detail::local_stream::local_stream(boost::json::detail::stream&)
:330
84495x
100.0%
–
100.0%
boost::json::detail::local_stream::~local_stream()
:337
84495x
100.0%
–
100.0%
| Line | TLA | Hits | Source Code |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) | ||
| 3 | // | ||
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
| 6 | // | ||
| 7 | // Official repository: https://github.com/boostorg/json | ||
| 8 | // | ||
| 9 | |||
| 10 | #ifndef BOOST_JSON_DETAIL_STREAM_HPP | ||
| 11 | #define BOOST_JSON_DETAIL_STREAM_HPP | ||
| 12 | |||
| 13 | namespace boost { | ||
| 14 | namespace json { | ||
| 15 | namespace detail { | ||
| 16 | |||
| 17 | class const_stream | ||
| 18 | { | ||
| 19 | friend class local_const_stream; | ||
| 20 | |||
| 21 | char const* p_; | ||
| 22 | char const* end_; | ||
| 23 | |||
| 24 | public: | ||
| 25 | const_stream() = default; | ||
| 26 | |||
| 27 | 35719x | const_stream( | |
| 28 | char const* data, | ||
| 29 | std::size_t size) noexcept | ||
| 30 | 35719x | : p_(data) | |
| 31 | 35719x | , end_(data + size) | |
| 32 | { | ||
| 33 | 35719x | } | |
| 34 | |||
| 35 | size_t | ||
| 36 | used(char const* begin) const noexcept | ||
| 37 | { | ||
| 38 | return static_cast< | ||
| 39 | size_t>(p_ - begin); | ||
| 40 | } | ||
| 41 | |||
| 42 | size_t | ||
| 43 | 64866x | remain() const noexcept | |
| 44 | { | ||
| 45 | 64866x | return end_ - p_; | |
| 46 | } | ||
| 47 | |||
| 48 | char const* | ||
| 49 | 62244x | data() const noexcept | |
| 50 | { | ||
| 51 | 62244x | return p_; | |
| 52 | } | ||
| 53 | |||
| 54 | 31451934x | operator bool() const noexcept | |
| 55 | { | ||
| 56 | 31451934x | return p_ < end_; | |
| 57 | } | ||
| 58 | |||
| 59 | // unchecked | ||
| 60 | char | ||
| 61 | 31417505x | operator*() const noexcept | |
| 62 | { | ||
| 63 | 31417505x | BOOST_ASSERT(p_ < end_); | |
| 64 | 31417505x | return *p_; | |
| 65 | } | ||
| 66 | |||
| 67 | // unchecked | ||
| 68 | const_stream& | ||
| 69 | 31417505x | operator++() noexcept | |
| 70 | { | ||
| 71 | 31417505x | BOOST_ASSERT(p_ < end_); | |
| 72 | 31417505x | ++p_; | |
| 73 | 31417505x | return *this; | |
| 74 | } | ||
| 75 | |||
| 76 | void | ||
| 77 | 26559x | skip(std::size_t n) noexcept | |
| 78 | { | ||
| 79 | 26559x | BOOST_ASSERT(n <= remain()); | |
| 80 | 26559x | p_ += n; | |
| 81 | 26559x | } | |
| 82 | |||
| 83 | void | ||
| 84 | skip_to(const char* p) noexcept | ||
| 85 | { | ||
| 86 | BOOST_ASSERT(p <= end_ && p >= p_); | ||
| 87 | p_ = p; | ||
| 88 | } | ||
| 89 | }; | ||
| 90 | |||
| 91 | class local_const_stream | ||
| 92 | : public const_stream | ||
| 93 | { | ||
| 94 | const_stream& src_; | ||
| 95 | |||
| 96 | public: | ||
| 97 | explicit | ||
| 98 | 44285x | local_const_stream( | |
| 99 | const_stream& src) noexcept | ||
| 100 | 44285x | : const_stream(src) | |
| 101 | 44285x | , src_(src) | |
| 102 | { | ||
| 103 | 44285x | } | |
| 104 | |||
| 105 | 44285x | ~local_const_stream() | |
| 106 | { | ||
| 107 | 44285x | src_.p_ = p_; | |
| 108 | 44285x | } | |
| 109 | |||
| 110 | void | ||
| 111 | clip(std::size_t n) noexcept | ||
| 112 | { | ||
| 113 | if(static_cast<std::size_t>( | ||
| 114 | src_.end_ - p_) > n) | ||
| 115 | end_ = p_ + n; | ||
| 116 | else | ||
| 117 | end_ = src_.end_; | ||
| 118 | } | ||
| 119 | }; | ||
| 120 | |||
| 121 | class const_stream_wrapper | ||
| 122 | { | ||
| 123 | const char*& p_; | ||
| 124 | const char* const end_; | ||
| 125 | |||
| 126 | friend class clipped_const_stream; | ||
| 127 | public: | ||
| 128 | 4794062x | const_stream_wrapper( | |
| 129 | const char*& p, | ||
| 130 | const char* end) | ||
| 131 | 4794062x | : p_(p) | |
| 132 | 4794062x | , end_(end) | |
| 133 | { | ||
| 134 | 4794062x | } | |
| 135 | |||
| 136 | 63384959x | void operator++() noexcept | |
| 137 | { | ||
| 138 | 63384959x | ++p_; | |
| 139 | 63384959x | } | |
| 140 | |||
| 141 | 2046839x | void operator+=(std::size_t n) noexcept | |
| 142 | { | ||
| 143 | 2046839x | p_ += n; | |
| 144 | 2046839x | } | |
| 145 | |||
| 146 | 7322858x | void operator=(const char* p) noexcept | |
| 147 | { | ||
| 148 | 7322858x | p_ = p; | |
| 149 | 7322858x | } | |
| 150 | |||
| 151 | 70856167x | char operator*() const noexcept | |
| 152 | { | ||
| 153 | 70856167x | return *p_; | |
| 154 | } | ||
| 155 | |||
| 156 | 76831743x | operator bool() const noexcept | |
| 157 | { | ||
| 158 | 76831743x | return p_ < end_; | |
| 159 | } | ||
| 160 | |||
| 161 | 20797775x | const char* begin() const noexcept | |
| 162 | { | ||
| 163 | 20797775x | return p_; | |
| 164 | } | ||
| 165 | |||
| 166 | 4865457x | const char* end() const noexcept | |
| 167 | { | ||
| 168 | 4865457x | return end_; | |
| 169 | } | ||
| 170 | |||
| 171 | 2135882x | std::size_t remain() const noexcept | |
| 172 | { | ||
| 173 | 2135882x | return end_ - p_; | |
| 174 | } | ||
| 175 | |||
| 176 | 3071x | std::size_t remain(const char* p) const noexcept | |
| 177 | { | ||
| 178 | 3071x | return end_ - p; | |
| 179 | } | ||
| 180 | |||
| 181 | 2314817x | std::size_t used(const char* p) const noexcept | |
| 182 | { | ||
| 183 | 2314817x | return p_ - p; | |
| 184 | } | ||
| 185 | }; | ||
| 186 | |||
| 187 | class clipped_const_stream | ||
| 188 | : public const_stream_wrapper | ||
| 189 | { | ||
| 190 | const char* clip_; | ||
| 191 | |||
| 192 | public: | ||
| 193 | 13678x | clipped_const_stream( | |
| 194 | const char*& p, | ||
| 195 | const char* end) | ||
| 196 | 13678x | : const_stream_wrapper(p, end) | |
| 197 | 13678x | , clip_(end) | |
| 198 | { | ||
| 199 | 13678x | } | |
| 200 | |||
| 201 | void operator=(const char* p) | ||
| 202 | { | ||
| 203 | p_ = p; | ||
| 204 | } | ||
| 205 | |||
| 206 | const char* end() const noexcept | ||
| 207 | { | ||
| 208 | return clip_; | ||
| 209 | } | ||
| 210 | |||
| 211 | 68643x | operator bool() const noexcept | |
| 212 | { | ||
| 213 | 68643x | return p_ < clip_; | |
| 214 | } | ||
| 215 | |||
| 216 | 11688x | std::size_t remain() const noexcept | |
| 217 | { | ||
| 218 | 11688x | return clip_ - p_; | |
| 219 | } | ||
| 220 | |||
| 221 | std::size_t remain(const char* p) const noexcept | ||
| 222 | { | ||
| 223 | return clip_ - p; | ||
| 224 | } | ||
| 225 | |||
| 226 | void | ||
| 227 | 15663x | clip(std::size_t n) noexcept | |
| 228 | { | ||
| 229 | 15663x | if(static_cast<std::size_t>( | |
| 230 | 15663x | end_ - p_) > n) | |
| 231 | 37x | clip_ = p_ + n; | |
| 232 | else | ||
| 233 | 15626x | clip_ = end_; | |
| 234 | 15663x | } | |
| 235 | }; | ||
| 236 | |||
| 237 | //-------------------------------------- | ||
| 238 | |||
| 239 | class stream | ||
| 240 | { | ||
| 241 | friend class local_stream; | ||
| 242 | |||
| 243 | char* p_; | ||
| 244 | char* end_; | ||
| 245 | |||
| 246 | public: | ||
| 247 | 32982x | stream( | |
| 248 | char* data, | ||
| 249 | std::size_t size) noexcept | ||
| 250 | 32982x | : p_(data) | |
| 251 | 32982x | , end_(data + size) | |
| 252 | { | ||
| 253 | 32982x | } | |
| 254 | |||
| 255 | size_t | ||
| 256 | 32980x | used(char* begin) const noexcept | |
| 257 | { | ||
| 258 | return static_cast< | ||
| 259 | 32980x | size_t>(p_ - begin); | |
| 260 | } | ||
| 261 | |||
| 262 | size_t | ||
| 263 | 90553x | remain() const noexcept | |
| 264 | { | ||
| 265 | 90553x | return end_ - p_; | |
| 266 | } | ||
| 267 | |||
| 268 | char* | ||
| 269 | 2956x | data() noexcept | |
| 270 | { | ||
| 271 | 2956x | return p_; | |
| 272 | } | ||
| 273 | |||
| 274 | 31623944x | operator bool() const noexcept | |
| 275 | { | ||
| 276 | 31623944x | return p_ < end_; | |
| 277 | } | ||
| 278 | |||
| 279 | // unchecked | ||
| 280 | char& | ||
| 281 | operator*() noexcept | ||
| 282 | { | ||
| 283 | BOOST_ASSERT(p_ < end_); | ||
| 284 | return *p_; | ||
| 285 | } | ||
| 286 | |||
| 287 | // unchecked | ||
| 288 | stream& | ||
| 289 | operator++() noexcept | ||
| 290 | { | ||
| 291 | BOOST_ASSERT(p_ < end_); | ||
| 292 | ++p_; | ||
| 293 | return *this; | ||
| 294 | } | ||
| 295 | |||
| 296 | // unchecked | ||
| 297 | void | ||
| 298 | 32736x | append( | |
| 299 | char const* src, | ||
| 300 | std::size_t n) noexcept | ||
| 301 | { | ||
| 302 | 32736x | BOOST_ASSERT(remain() >= n); | |
| 303 | 32736x | std::memcpy(p_, src, n); | |
| 304 | 32736x | p_ += n; | |
| 305 | 32736x | } | |
| 306 | |||
| 307 | // unchecked | ||
| 308 | void | ||
| 309 | 31554204x | append(char c) noexcept | |
| 310 | { | ||
| 311 | 31554204x | BOOST_ASSERT(p_ < end_); | |
| 312 | 31554204x | *p_++ = c; | |
| 313 | 31554204x | } | |
| 314 | |||
| 315 | void | ||
| 316 | 2956x | advance(std::size_t n) noexcept | |
| 317 | { | ||
| 318 | 2956x | BOOST_ASSERT(remain() >= n); | |
| 319 | 2956x | p_ += n; | |
| 320 | 2956x | } | |
| 321 | }; | ||
| 322 | |||
| 323 | class local_stream | ||
| 324 | : public stream | ||
| 325 | { | ||
| 326 | stream& src_; | ||
| 327 | |||
| 328 | public: | ||
| 329 | explicit | ||
| 330 | 84495x | local_stream( | |
| 331 | stream& src) | ||
| 332 | 84495x | : stream(src) | |
| 333 | 84495x | , src_(src) | |
| 334 | { | ||
| 335 | 84495x | } | |
| 336 | |||
| 337 | 84495x | ~local_stream() | |
| 338 | { | ||
| 339 | 84495x | src_.p_ = p_; | |
| 340 | 84495x | } | |
| 341 | }; | ||
| 342 | |||
| 343 | } // detail | ||
| 344 | } // namespace json | ||
| 345 | } // namespace boost | ||
| 346 | |||
| 347 | #endif | ||
| 348 |