Coverage Report

Created: 2026-01-17 06:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/jsoncons/include/jsoncons_ext/bson/bson_reader.hpp
Line
Count
Source
1
// Copyright 2013-2026 Daniel Parker
2
// Distributed under the Boost license, Version 1.0.
3
// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4
5
// See https://github.com/danielaparker/jsoncons for latest version
6
7
#ifndef JSONCONS_EXT_BSON_BSON_READER_HPP
8
#define JSONCONS_EXT_BSON_BSON_READER_HPP
9
10
#include <cstddef>
11
#include <memory>
12
#include <system_error>
13
#include <utility> // std::move
14
15
#include <jsoncons/config/compiler_support.hpp>
16
#include <jsoncons/json_exception.hpp>
17
#include <jsoncons/json_visitor.hpp>
18
#include <jsoncons/source.hpp>
19
#include <jsoncons_ext/bson/bson_parser.hpp>
20
21
namespace jsoncons { 
22
namespace bson {
23
24
template <typename Source,typename TempAlloc =std::allocator<char>>
25
class basic_bson_reader 
26
{
27
    basic_bson_parser<Source,TempAlloc> parser_;
28
    json_visitor& visitor_;
29
public:
30
    template <typename Sourceable>
31
    basic_bson_reader(Sourceable&& source, 
32
                      json_visitor& visitor, 
33
                      const TempAlloc& temp_alloc)
34
       : basic_bson_reader(std::forward<Sourceable>(source),
35
                           visitor,
36
                           bson_decode_options(),
37
                           temp_alloc)
38
    {
39
    }
40
41
    template <typename Sourceable>
42
    basic_bson_reader(Sourceable&& source, 
43
                      json_visitor& visitor, 
44
                      const bson_decode_options& options = bson_decode_options(),
45
                      const TempAlloc& temp_alloc=TempAlloc())
46
9.21k
       : parser_(std::forward<Sourceable>(source), options, temp_alloc),
47
9.21k
         visitor_(visitor)
48
9.21k
    {
49
9.21k
    }
jsoncons::bson::basic_bson_reader<jsoncons::stream_source<unsigned char, std::__1::allocator<unsigned char> >, std::__1::allocator<char> >::basic_bson_reader<std::__1::basic_istringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >&>(std::__1::basic_istringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, jsoncons::basic_json_visitor<char>&, jsoncons::bson::bson_decode_options const&, std::__1::allocator<char> const&)
Line
Count
Source
46
4.70k
       : parser_(std::forward<Sourceable>(source), options, temp_alloc),
47
4.70k
         visitor_(visitor)
48
4.70k
    {
49
4.70k
    }
jsoncons::bson::basic_bson_reader<jsoncons::stream_source<unsigned char, std::__1::allocator<unsigned char> >, std::__1::allocator<char> >::basic_bson_reader<std::__1::basic_istream<char, std::__1::char_traits<char> >&>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, jsoncons::basic_json_visitor<char>&, jsoncons::bson::bson_decode_options const&, std::__1::allocator<char> const&)
Line
Count
Source
46
4.50k
       : parser_(std::forward<Sourceable>(source), options, temp_alloc),
47
4.50k
         visitor_(visitor)
48
4.50k
    {
49
4.50k
    }
50
51
    void read()
52
    {
53
        std::error_code ec;
54
        read(ec);
55
        if (JSONCONS_UNLIKELY(ec))
56
        {
57
            JSONCONS_THROW(ser_error(ec,line(),column()));
58
        }
59
    }
60
61
    void read(std::error_code& ec)
62
9.21k
    {
63
9.21k
        parser_.reset();
64
9.21k
        parser_.parse(visitor_, ec);
65
9.21k
        if (JSONCONS_UNLIKELY(ec))
66
9.18k
        {
67
9.18k
            return;
68
9.18k
        }
69
9.21k
    }
70
71
    std::size_t line() const
72
4.49k
    {
73
4.49k
        return parser_.line();
74
4.49k
    }
75
76
    std::size_t column() const
77
4.49k
    {
78
4.49k
        return parser_.column();
79
4.49k
    }
80
};
81
82
using bson_stream_reader = basic_bson_reader<jsoncons::binary_stream_source>;
83
using bson_bytes_reader = basic_bson_reader<jsoncons::bytes_source>;
84
85
} // namespace bson
86
} // namespace jsoncons
87
88
#endif // JSONCONS_EXT_BSON_BSON_READER_HPP