Skip to content

Commit

Permalink
Merge pull request #441 from beached/v3
Browse files Browse the repository at this point in the history
Smaller pull size for non-testing builds
  • Loading branch information
beached authored Aug 21, 2024
2 parents 1cb3753 + 18255b9 commit eefff34
Show file tree
Hide file tree
Showing 90 changed files with 298 additions and 3,204,163 deletions.
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
cmake_minimum_required( VERSION 3.14 )

project( "daw-json-link"
VERSION "3.27.1"
VERSION "3.28.1"
DESCRIPTION "Static JSON parsing in C++"
HOMEPAGE_URL "https://github.com/beached/daw_json_link"
LANGUAGES C CXX )
Expand Down Expand Up @@ -177,6 +177,14 @@ install( FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
install( DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION include/ )

if( DAW_ENABLE_TESTING )
FetchContent_Declare(
daw_json_link_test_data
GIT_REPOSITORY https://github.com/beached/daw_json_link_test_data.git
GIT_TAG release
GIT_SHALLOW 1
SOURCE_DIR ${PROJECT_SOURCE_DIR}/test_data
)
FetchContent_MakeAvailable(daw_json_link_test_data)
enable_testing()
add_subdirectory( tests )
endif()
Expand Down
2 changes: 2 additions & 0 deletions extern/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ else()
FetchContent_Declare(
daw_header_libraries
GIT_REPOSITORY https://github.com/beached/header_libraries.git
GIT_SHALLOW 1
GIT_TAG master
)
endif()

FetchContent_Declare(
daw_utf_range
GIT_REPOSITORY https://github.com/beached/utf_range.git
GIT_SHALLOW 1
GIT_TAG v2.2.5
)

Expand Down
6 changes: 3 additions & 3 deletions include/daw/json/concepts/daw_container_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ namespace daw::json {
} // namespace container_detect

template<typename T>
struct container_traits<
T, std::enable_if_t<container_detect::is_container_v<T>>>
: std::true_type {};
DAW_JSON_REQUIRES( container_detect::is_container_v<T> )
struct container_traits<T DAW_JSON_ENABLEIF_S(
container_detect::is_container_v<T> )> : std::true_type {};

template<typename T, std::size_t N>
struct container_traits<std::array<T, N>> : std::true_type {
Expand Down
2 changes: 1 addition & 1 deletion include/daw/json/concepts/daw_container_traits_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ namespace daw::json {
template<typename, typename = void>
struct container_traits : std::false_type {};
} // namespace concepts
} // namespace DAW_JSON_VER
} // namespace DAW_JSON_VER
} // namespace daw::json
46 changes: 25 additions & 21 deletions include/daw/json/concepts/daw_nullable_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ namespace daw::json {
return opt;
}

template<typename... Args,
std::enable_if_t<
nullable_impl::is_nullable_value_type_constructible_v<
value_type, Args...>,
std::nullptr_t> = nullptr>
template<typename... Args DAW_JSON_ENABLEIF(
nullable_impl::is_nullable_value_type_constructible_v<value_type,
Args...> )>
DAW_JSON_REQUIRES(
nullable_impl::is_nullable_value_type_constructible_v<value_type,
Args...> )
DAW_JSON_CPP23_STATIC_CALL_OP constexpr nullable_type
operator( )( construct_nullable_with_value_t,
Args &&...args ) DAW_JSON_CPP23_STATIC_CALL_OP_CONST
Expand Down Expand Up @@ -105,11 +106,12 @@ namespace daw::json {
return opt;
}

template<typename... Args,
std::enable_if_t<
nullable_impl::is_nullable_value_type_constructible_v<
value_type, Args...>,
std::nullptr_t> = nullptr>
template<typename... Args DAW_JSON_ENABLEIF(
nullable_impl::is_nullable_value_type_constructible_v<value_type,
Args...> )>
DAW_JSON_REQUIRES(
nullable_impl::is_nullable_value_type_constructible_v<value_type,
Args...> )
DAW_JSON_CPP23_STATIC_CALL_OP constexpr nullable_type
operator( )( construct_nullable_with_value_t,
Args &&...args ) DAW_JSON_CPP23_STATIC_CALL_OP_CONST
Expand Down Expand Up @@ -170,11 +172,12 @@ namespace daw::json {
return opt;
}

template<typename... Args,
std::enable_if_t<
nullable_impl::is_nullable_value_type_constructible_v<
value_type, Args...>,
std::nullptr_t> = nullptr>
template<typename... Args DAW_JSON_ENABLEIF(
nullable_impl::is_nullable_value_type_constructible_v<value_type,
Args...> )>
DAW_JSON_REQUIRES(
nullable_impl::is_nullable_value_type_constructible_v<value_type,
Args...> )
DAW_JSON_CPP23_STATIC_CALL_OP constexpr nullable_type
operator( )( construct_nullable_with_value_t,
Args &&...args ) DAW_JSON_CPP23_STATIC_CALL_OP_CONST
Expand Down Expand Up @@ -227,11 +230,12 @@ namespace daw::json {
return ptr;
}

template<typename... Args,
std::enable_if_t<
nullable_impl::is_nullable_value_type_constructible_v<
value_type, Args...>,
std::nullptr_t> = nullptr>
template<typename... Args DAW_JSON_ENABLEIF(
nullable_impl::is_nullable_value_type_constructible_v<value_type,
Args...> )>
DAW_JSON_REQUIRES(
nullable_impl::is_nullable_value_type_constructible_v<value_type,
Args...> )
DAW_JSON_CPP23_STATIC_CALL_OP constexpr nullable_type
operator( )( construct_nullable_with_value_t,
Args &&...args ) DAW_JSON_CPP23_STATIC_CALL_OP_CONST
Expand Down Expand Up @@ -265,7 +269,7 @@ namespace daw::json {
}
};
} // namespace concepts
} // namespace DAW_JSON_VER
} // namespace DAW_JSON_VER
} // namespace daw::json
#if defined( DAW_HAS_AGG_PAREN_INIT )
#undef DAW_HAS_AGG_PAREN_INIT
Expand Down
11 changes: 6 additions & 5 deletions include/daw/json/concepts/daw_nullable_value_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ namespace daw::json {
return value_type{ };
}
/// @brief Return an empty nullable type
template<typename... Args,
std::enable_if_t<
nullable_impl::is_nullable_value_type_constructible_v<
nullable_type, Args...>,
std::nullptr_t> = nullptr>
template<typename... Args DAW_JSON_ENABLEIF(
nullable_impl::is_nullable_value_type_constructible_v<nullable_type,
Args...> )>
DAW_JSON_REQUIRES(
nullable_impl::is_nullable_value_type_constructible_v<nullable_type,
Args...> )
DAW_JSON_CPP23_STATIC_CALL_OP constexpr nullable_type
operator( )( construct_nullable_with_empty_t,
Args &&...args ) DAW_JSON_CPP23_STATIC_CALL_OP_CONST
Expand Down
37 changes: 22 additions & 15 deletions include/daw/json/concepts/daw_writable_output_basics.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <daw/json/impl/version.h>

#include "daw/json/daw_json_switches.h"
#include "daw/json/impl/daw_json_assert.h"
#include "daw_writable_output_fwd.h"
#include "impl/daw_writable_output_details.h"
Expand All @@ -25,11 +26,13 @@ namespace daw::json {
namespace concepts {
/// @brief Specialization for character pointer
template<typename T>
DAW_JSON_REQUIRES(
writeable_output_details::is_char_sized_character_v<T> or
writeable_output_details::is_byte_type_v<T> )
struct writable_output_trait<
T *, std::enable_if_t<(
writeable_output_details::is_char_sized_character_v<T> or
writeable_output_details::is_byte_type_v<T> )>>
: std::true_type {
T * DAW_JSON_ENABLEIF_S(
writeable_output_details::is_char_sized_character_v<T> or
writeable_output_details::is_byte_type_v<T> )> : std::true_type {

template<typename... StringViews>
static constexpr void write( T *&ptr, StringViews const &...svs ) {
Expand All @@ -55,9 +58,11 @@ namespace daw::json {

/// @brief Specialization for a span to a buffer with a fixed size
template<typename T>
DAW_JSON_REQUIRES( writeable_output_details::is_span_like_range_v<
T, typename T::value_type> )
struct writable_output_trait<
T, std::enable_if_t<writeable_output_details::is_span_like_range_v<
T, typename T::value_type>>> : std::true_type {
T DAW_JSON_ENABLEIF_S( writeable_output_details::is_span_like_range_v<
T, typename T::value_type> )> : std::true_type {
using CharT = typename T::value_type;

template<typename... StringViews>
Expand Down Expand Up @@ -85,13 +90,14 @@ namespace daw::json {
}
};

/// @brief Specialization for a resizable continain like vector/string
/// @brief Specialization for a resizable container like vector/string
template<typename Container>
struct writable_output_trait<
Container, std::enable_if_t<
writeable_output_details::is_string_like_writable_output_v<
Container, typename Container::value_type>>>
: std::true_type {
DAW_JSON_REQUIRES(
writeable_output_details::is_string_like_writable_output_v<
Container, typename Container::value_type> )
struct writable_output_trait<Container DAW_JSON_ENABLEIF_S(
writeable_output_details::is_string_like_writable_output_v<
Container, typename Container::value_type> )> : std::true_type {
using CharT = typename Container::value_type;

template<typename... StringViews>
Expand Down Expand Up @@ -120,9 +126,10 @@ namespace daw::json {

/// @brief Specialization for output iterators
template<typename T>
struct writable_output_trait<
T, std::enable_if_t<
writeable_output_details::is_writable_output_iterator_v<T>>>
DAW_JSON_REQUIRES(
writeable_output_details::is_writable_output_iterator_v<T> )
struct writable_output_trait<T DAW_JSON_ENABLEIF_S(
writeable_output_details::is_writable_output_iterator_v<T> )>
: std::true_type {

template<typename... StringViews>
Expand Down
6 changes: 3 additions & 3 deletions include/daw/json/concepts/daw_writable_output_ostream.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ namespace daw::json {
namespace concepts {
/// @brief Specialization for ostream &
template<typename T>
struct writable_output_trait<
T, std::enable_if_t<std::is_base_of_v<std::ostream, T>>>
: std::true_type {
DAW_JSON_REQUIRES( std::is_base_of_v<std::ostream, T> )
struct writable_output_trait<T DAW_JSON_ENABLEIF_S(
std::is_base_of_v<std::ostream, T> )> : std::true_type {

template<typename... StringViews>
static inline void write( std::ostream &os,
Expand Down
42 changes: 22 additions & 20 deletions include/daw/json/daw_json_apply.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ namespace daw::json {
/// @param callable The callable used to evaluate the parsed values.
/// @return The result of calling Callable
template<typename Signature = use_default, typename String,
typename Callable,
std::enable_if_t<json_details::has_call_operator<Callable>,
std::nullptr_t> = nullptr>
typename Callable DAW_JSON_ENABLEIF(
json_details::has_call_operator<Callable> )>
DAW_JSON_REQUIRES( json_details::has_call_operator<Callable> )
constexpr auto json_apply( String &&json_doc, Callable &&callable ) {
return json_details::json_apply_impl<Signature>( DAW_FWD( callable ),
DAW_FWD( json_doc ) );
Expand All @@ -83,9 +83,9 @@ namespace daw::json {
/// @param callable The callable used to evaluate the parsed values.
/// @return The result of calling Callable
template<typename Signature = use_default, typename String,
typename Callable,
std::enable_if_t<json_details::has_call_operator<Callable>,
std::nullptr_t> = nullptr>
typename Callable DAW_JSON_ENABLEIF(
json_details::has_call_operator<Callable> )>
DAW_JSON_REQUIRES( json_details::has_call_operator<Callable> )
constexpr auto json_apply( String &&json_doc, std::string_view json_path,
Callable &&callable ) {
return json_details::json_apply_impl<Signature>(
Expand All @@ -107,13 +107,14 @@ namespace daw::json {
/// @param callable The callable used to evaluate the parsed values.
/// @return The result of calling Callable
template<typename Signature = use_default, typename String,
auto... PolicyFlags, typename Callable,
std::enable_if_t<json_details::has_call_operator<Callable>,
std::nullptr_t> = nullptr>
constexpr auto
json_apply( String &&json_doc, std::string_view json_path,
daw::json::options::parse_flags_t<PolicyFlags...> flags,
Callable &&callable ) {
auto... PolicyFlags,
typename Callable DAW_JSON_ENABLEIF(
json_details::has_call_operator<Callable> )>
DAW_JSON_REQUIRES( json_details::has_call_operator<Callable> )
constexpr auto json_apply(
String &&json_doc, std::string_view json_path,
daw::json::options::parse_flags_t<PolicyFlags...> flags,
Callable &&callable ) {
return json_details::json_apply_impl<Signature>(
DAW_FWD( callable ), DAW_FWD( json_doc ), json_path, flags );
}
Expand All @@ -132,13 +133,14 @@ namespace daw::json {
/// @param callable The callable used to evaluate the parsed values.
/// @return The result of calling Callable
template<typename Signature = use_default, typename String,
auto... PolicyFlags, typename Callable,
std::enable_if_t<json_details::has_call_operator<Callable>,
std::nullptr_t> = nullptr>
constexpr auto
json_apply( String &&json_doc,
daw::json::options::parse_flags_t<PolicyFlags...> flags,
Callable &&callable ) {
auto... PolicyFlags,
typename Callable DAW_JSON_ENABLEIF(
json_details::has_call_operator<Callable> )>
DAW_JSON_REQUIRES( json_details::has_call_operator<Callable> )
constexpr auto json_apply(
String &&json_doc,
daw::json::options::parse_flags_t<PolicyFlags...> flags,
Callable &&callable ) {
return json_details::json_apply_impl<Signature>(
DAW_FWD( callable ), DAW_FWD( json_doc ), flags );
}
Expand Down
23 changes: 11 additions & 12 deletions include/daw/json/daw_json_default_constuctor_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,18 @@ namespace daw::json {
struct default_constructor {
using i_am_the_default_default_constructor_type = void;

template<typename... Args,
std::enable_if_t<std::is_constructible_v<T, Args...>,
std::nullptr_t> = nullptr>
template<typename... Args DAW_JSON_ENABLEIF(
std::is_constructible_v<T, Args...> )>
DAW_JSON_REQUIRES( std::is_constructible_v<T, Args...> )
[[nodiscard]] DAW_ATTRIB_INLINE DAW_JSON_CPP23_STATIC_CALL_OP constexpr T
operator( )( Args &&...args ) DAW_JSON_CPP23_STATIC_CALL_OP_CONST {

return T( DAW_FWD( args )... );
}

template<
typename... Args,
std::enable_if_t<json_details::should_list_construct_v<T, Args...>,
std::nullptr_t> = nullptr>
template<typename... Args DAW_JSON_ENABLEIF(
json_details::should_list_construct_v<T, Args...> )>
DAW_JSON_REQUIRES( json_details::should_list_construct_v<T, Args...> )
[[nodiscard]] DAW_ATTRIB_INLINE DAW_JSON_CPP23_STATIC_CALL_OP constexpr T
operator( )( Args &&...args ) DAW_JSON_CPP23_STATIC_CALL_OP_CONST
noexcept( std::is_nothrow_constructible_v<T, Args...> ) {
Expand All @@ -70,11 +69,11 @@ namespace daw::json {
};

template<typename T>
struct nullable_constructor<
T,
std::enable_if_t<( concepts::nullable_impl::is_list_constructible_v<T> and
not concepts::is_nullable_value_v<T> )>>
: default_constructor<T> {
DAW_JSON_REQUIRES( concepts::nullable_impl::is_list_constructible_v<T> and
not concepts::is_nullable_value_v<T> )
struct nullable_constructor<T DAW_JSON_ENABLEIF_S(
concepts::nullable_impl::is_list_constructible_v<T> and
not concepts::is_nullable_value_v<T> )> : default_constructor<T> {
/// used for types like string_view that have an empty state
using default_constructor<T>::operator( );
[[nodiscard]] DAW_ATTRIB_INLINE DAW_JSON_CPP23_STATIC_CALL_OP constexpr T
Expand Down
23 changes: 13 additions & 10 deletions include/daw/json/daw_json_iostream.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,27 @@ namespace daw::json {
inline constexpr bool is_container_opted_into_json_iostreams_v<
Container, std::void_t<typename Container::value_type>> =
is_opted_into_json_iostreams_v<typename Container::value_type>;

} // namespace json_details
} // namespace DAW_JSON_VER
} // namespace DAW_JSON_VER
} // namespace daw::json

/// @brief An opt in ostream interface for types that have JSON mappings.
template<typename T>
auto operator<<( std::ostream &os, T const &value ) -> std::enable_if_t<
daw::json::json_details::is_opted_into_json_iostreams_v<T>, std::ostream &> {

template<typename T DAW_JSON_ENABLEIF(
daw::json::json_details::is_opted_into_json_iostreams_v<T> )>
DAW_JSON_REQUIRES( daw::json::json_details::is_opted_into_json_iostreams_v<T> )
std::ostream &operator<<( std::ostream &os, T const &value ) {
return daw::json::to_json( value, os );
}

/// @brief An opt in ostream interface for containers of types that have JSON
/// mappings.
template<typename Container>
auto operator<<( std::ostream &os, Container const &c ) -> std::enable_if_t<
daw::json::json_details::is_container_opted_into_json_iostreams_v<Container>,
std::ostream &> {

template<typename Container DAW_JSON_ENABLEIF(
daw::json::json_details::is_container_opted_into_json_iostreams_v<
Container> )>
DAW_JSON_REQUIRES(
daw::json::json_details::is_container_opted_into_json_iostreams_v<Container> )
std::ostream &
operator<<( std::ostream &os, Container const &c ) {
return daw::json::to_json_array( c, os );
}
Loading

0 comments on commit eefff34

Please sign in to comment.