Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7761788
Add parse_into
pdimov Oct 21, 2022
76c234b
Add example/parse_into_canada.cpp
pdimov Oct 6, 2021
4c628ae
Add null_handler
pdimov Oct 6, 2021
62af0a0
parse_into header cleanup
grisumbras Oct 19, 2022
56fcb09
reusing existing conversion components
grisumbras Oct 21, 2022
ef6e310
parse_into supports described enums
grisumbras Jul 28, 2023
7133184
parse_into supports optionals
grisumbras Jul 28, 2023
71a6521
extend parse_into API, document it
grisumbras Jul 29, 2023
8e6283a
internal docs for parse_into machinery
grisumbras Aug 11, 2023
9565c71
refactor parse_into tuple handler
grisumbras Aug 13, 2023
b540696
error_code is first argument for parse_into nested handlers' functions
grisumbras Aug 12, 2023
98b85ad
parse_into tuple support works on C++11
grisumbras Aug 15, 2023
7b26a34
parse_into supports variants
grisumbras Aug 6, 2023
10ef306
test/parse_into.cpp requires /bigobj on msvc
grisumbras Aug 15, 2023
9859866
parse_into supports std::array
grisumbras Aug 21, 2023
53b99c8
Add example/parse_into_citm_catalog.cpp
pdimov Oct 7, 2021
4f4396e
test parse_into error reporting
grisumbras Aug 23, 2023
aaa4e7f
add tuple size checking for parse_into
grisumbras Aug 27, 2023
c1b7174
add array size checking for parse_into
grisumbras Aug 27, 2023
f5b9709
add struct member count checking for parse_into
grisumbras Aug 27, 2023
a3821ce
increase parse_into coverage
grisumbras Aug 24, 2023
60bf345
remove unnecessary parameters
grisumbras Sep 9, 2023
34284c3
avoid unnecessary allocations for strings
grisumbras Sep 11, 2023
f144f38
document direct parsing
grisumbras Sep 9, 2023
75981e7
parse_into clears sequences before filling them
grisumbras Sep 30, 2023
e19edde
parse_into clears strings before filling them
grisumbras Oct 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add null_handler
  • Loading branch information
pdimov authored and grisumbras committed Oct 9, 2023
commit 4c628ae36a8711fb0a04f2c2384a8ccd62c770ec
36 changes: 36 additions & 0 deletions include/boost/json/detail/parse_into.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,41 @@ template<class V, class P> class bool_handler: public handler_error_base<error::
}
};

// null_handler

template<class V, class P> class null_handler: public handler_error_base<error::not_null>
{
private:

V * value_;
P * parent_;

public:

null_handler( null_handler const& ) = delete;
null_handler& operator=( null_handler const& ) = delete;

public:

null_handler( V* v, P* p ): value_( v ), parent_( p )
{
}

bool on_null( error_code& )
{
*value_ = {};

parent_->signal_value();
return true;
}

bool on_array_end( std::size_t, error_code& )
{
parent_->signal_end();
return true;
}
};

// forward declarations

template<class V, class P> class sequence_handler;
Expand Down Expand Up @@ -317,6 +352,7 @@ template<class T> struct is_described_struct<T, decltype((void)boost::describe::

template<class V, class P> using get_handler = boost::mp11::mp_cond<

std::is_same<V, std::nullptr_t>, null_handler<V, P>,
std::is_same<V, bool>, bool_handler<V, P>,
std::is_integral<V>, integral_handler<V, P>,
std::is_floating_point<V>, floating_point_handler<V, P>,
Expand Down
8 changes: 8 additions & 0 deletions test/parse_into.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ class parse_into_test
BOOST_TEST( !ec.failed() ) && BOOST_TEST( t1 == t2 );
}

void testNull()
{
testParseInto( nullptr );
}

void testBoolean()
{
testParseInto( false );
Expand Down Expand Up @@ -107,6 +112,8 @@ class parse_into_test

void testSequence()
{
testParseInto<std::vector<std::nullptr_t>>( { nullptr, nullptr } );

testParseInto< std::vector<bool> >( {} );
testParseInto< std::vector<bool> >( { true, false } );

Expand Down Expand Up @@ -176,6 +183,7 @@ class parse_into_test

void run()
{
testNull();
testBoolean();
testIntegral();
testFloatingPoint();
Expand Down