Skip to content

Commit

Permalink
Merge pull request #430 from beached/v3
Browse files Browse the repository at this point in the history
Small bugfixes
  • Loading branch information
beached authored Jul 1, 2024
2 parents 0ba03e0 + 94c7380 commit b56176d
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 5 deletions.
2 changes: 1 addition & 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.24.0"
VERSION "3.24.1"
DESCRIPTION "Static JSON parsing in C++"
HOMEPAGE_URL "https://github.com/beached/daw_json_link"
LANGUAGES C CXX )
Expand Down
2 changes: 1 addition & 1 deletion extern/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ endif()
FetchContent_Declare(
daw_utf_range
GIT_REPOSITORY https://github.com/beached/utf_range.git
GIT_TAG v2.2.4
GIT_TAG v2.2.5
)

FetchContent_MakeAvailable( daw_header_libraries daw_utf_range )
Expand Down
2 changes: 1 addition & 1 deletion include/daw/json/impl/daw_json_assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace daw::json {
namespace json_details {
[[noreturn]] DAW_ATTRIB_NOINLINE inline void
handle_error( json_exception &&jex ) {
daw_json_error_handler( std::move( jex ), daw_json_error_handler_data );
daw_json_error_handler.get( )( std::move( jex ), daw_json_error_handler_data );
DAW_UNREACHABLE( );
}
} // namespace json_details
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
![logo image](docs/images/json_link_logo_128.png)
# DAW JSON Link v3
# JSON Link v3

## Content
* [Intro](#intro)
Expand Down Expand Up @@ -53,7 +53,7 @@
## Intro
###### [Top](#content)

The DAW JSON Link library is a high performance, no allocation, C++ JSON Library supporting:
The JSON Link library is a high performance, no allocation, C++ JSON Library supporting:
* Direct parsing of JSON to your own data structures via simple declarative mappings
* Earlier error reporting of unexpected data and errors
* Low memory requirement, parser requires a small amount of stack but does not allocate itself.
Expand Down
6 changes: 6 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,12 @@ target_link_libraries( issue_421_test PRIVATE json_test )
#add_dependencies( ci_tests issue_421_test )
#add_dependencies( full issue_421_test )

add_executable( issue_428_test EXCLUDE_FROM_ALL src/issue_428_test.cpp )
target_link_libraries( issue_428_test PRIVATE json_test )
#add_test( NAME issue_428_test COMMAND issue_428_test WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/test_data/" )
#add_dependencies( ci_tests issue_428_test )
#add_dependencies( full issue_428_test )

add_executable( multi_tu_test src/multi_tu_p0_test.cpp src/multi_tu_p1_test.cpp )
target_link_libraries( multi_tu_test json_test )
add_test( NAME multi_tu_test_test COMMAND multi_tu_test )
Expand Down
89 changes: 89 additions & 0 deletions tests/src/issue_428_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright (c) Darrell Wright
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/beached/daw_json_link
//

#include <daw/json/daw_json_link.h>

#include <iostream>
#include <type_traits>
#include <vector>

template<class Key, class T>
struct vector_map {
using value_type = std::pair<Key, T>;
using vector_type = std::vector<value_type>;
using reference = typename vector_type::reference;
using const_reference = typename vector_type::const_reference;
using iterator = typename vector_type::iterator;
using const_iterator = typename vector_type::const_iterator;

private:
vector_type data_;

public:
vector_map( ) = default;

template<typename Container,
std::enable_if_t<
not std::is_same_v<vector_map, daw::remove_cvref_t<Container>>,
std::nullptr_t> = nullptr>
vector_map( Container &&values ) {
for( auto &&v : values ) {}
}

template<class... Args>
std::pair<iterator, bool> emplace( Args &&...args ) {
data_.emplace_back( std::make_pair( std::forward<Args>( args )... ) );
return std::make_pair( data_.end( ) - 1, true );
}
};

template<typename class_type>
struct map_builder {
constexpr class_type operator( )( ) const {
static_assert( std::is_same_v<int, class_type> );
return class_type{ };
}

template<typename T>
constexpr class_type operator( )( T &&v ) const {
static_assert( std::is_same_v<int, class_type> );
return class_type( v );
}

template<typename Iter>
constexpr class_type operator( )( Iter first, Iter last ) const {
static_assert( std::is_same_v<int, class_type> );
class_type ans;
while( first != last ) {
auto [k, v] = *first;
ans.emplace( k, v );
++first;
}
return ans;
}
};

namespace daw::json {
template<class Key, class T>
struct json_data_contract<vector_map<Key, T>> {
using class_type = vector_map<Key, T>;

//using constructor_t = map_builder<class_type>;
using type = json_type_alias<
json_key_value_no_name<class_type, Key, T, map_builder<class_type>>>;
};
} // namespace daw::json

void json_test( std::string_view data_view ) {
auto obj = daw::json::from_json<vector_map<std::string, int>>( data_view );
auto obj_json = daw::json::to_json(
obj, daw::json::options::output_flags<
daw::json::options::SerializationFormat::Pretty> );

std::cout << obj_json.c_str( ) << std::endl;
}

0 comments on commit b56176d

Please sign in to comment.