Skip to content

Commit

Permalink
Add "taocpp_json" package (ruslo#1906)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjoe authored and ruslo committed Jul 2, 2019
1 parent 0ef4012 commit 20ba56a
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmake/configs/default.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ hunter_default_version(stormlib VERSION 9.21-p1)
hunter_default_version(sugar VERSION 1.3.0)
hunter_default_version(szip VERSION 2.1.0-p1)
hunter_default_version(tacopie VERSION 3.2.0-h1)
hunter_default_version(taocpp-json VERSION 1.0.0-beta.11-e0895587)
hunter_default_version(tcl VERSION core8.6.8)
hunter_default_version(termcolor VERSION 1.0.0)
hunter_default_version(thread-pool-cpp VERSION 1.1.0)
Expand Down
31 changes: 31 additions & 0 deletions cmake/projects/taocpp-json/hunter.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# !!! DO NOT PLACE HEADER GUARDS HERE !!!

include(hunter_add_version)
include(hunter_cacheable)
include(hunter_cmake_args)
include(hunter_download)
include(hunter_pick_scheme)

hunter_add_version(
PACKAGE_NAME
taocpp-json
VERSION
1.0.0-beta.11-e0895587
URL
"https://github.com/taocpp/json/archive/e08955875acc5853d31aa5ccd4b918726d20847f.zip"
SHA1
916357f4325fa15de32ba15f3b78e89d6308b920
)

hunter_cmake_args(
taocpp-json
CMAKE_ARGS
TAOCPP_JSON_BUILD_TESTS=OFF
TAOCPP_JSON_BUILD_EXAMPLES=OFF
)

hunter_pick_scheme(DEFAULT url_sha1_cmake)
hunter_cacheable(taocpp-json)
hunter_download(
PACKAGE_NAME taocpp-json
)
21 changes: 21 additions & 0 deletions docs/packages/pkg/taocpp-json.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.. spelling::

taocpp
json

.. index::
single: unsorted ; taocpp-json

.. _pkg.taocpp-json:

taocpp-json
===========

- `Official <https://github.com/taocpp/json>`__
- `Example <https://github.com/ruslo/hunter/blob/master/examples/taocpp-json/CMakeLists.txt>`__
- Added by `Jörg-Christian Böhme <https://github.com/BJoe>`__ (`pr-1906 <https://github.com/ruslo/hunter/pull/1906>`__)

.. literalinclude:: /../examples/taocpp-json/CMakeLists.txt
:language: cmake
:start-after: # DOCUMENTATION_START {
:end-before: # DOCUMENTATION_END }
18 changes: 18 additions & 0 deletions examples/taocpp-json/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2016-2018, Ruslan Baratov
# All rights reserved.

cmake_minimum_required(VERSION 3.2)

# Emulate HunterGate:
# * https://github.com/hunter-packages/gate
include("../common.cmake")

project(taocpp-json)

# DOCUMENTATION_START {
hunter_add_package(taocpp-json)
find_package(taocpp-json REQUIRED)

add_executable(boo boo.cpp)
target_link_libraries(boo PUBLIC taocpp::json)
# DOCUMENTATION_END }
56 changes: 56 additions & 0 deletions examples/taocpp-json/boo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) 2018-2019 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/json/

#include <cstddef>
#include <limits>
#include <stdexcept>
#include <string>
#include <utility>

#include <tao/json/value.hpp>

#include <tao/json/events/discard.hpp>
#include <tao/json/events/from_value.hpp>

namespace tao::json
{
template< typename Consumer, std::uint64_t Min, std::uint64_t Max >
struct validate_integer
: public Consumer
{
static_assert( Max >= Min );
static_assert( Max <= std::uint64_t( ( std::numeric_limits< std::int64_t >::max )() ), "Max may not be larger than 2^63-1" );

using Consumer::Consumer;

void number( const std::int64_t v )
{
if( ( v < std::int64_t( Min ) ) || ( v > std::int64_t( Max ) ) ) {
throw std::runtime_error( "integer range violated: " + std::to_string( v ) ); // NOLINT
}
Consumer::number( v );
}

void number( const std::uint64_t v )
{
if( ( v < Min ) || ( v > Max ) ) {
throw std::runtime_error( "unsigned range violated: " + std::to_string( v ) ); // NOLINT
}
Consumer::number( v );
}

void number( const double v ) noexcept( noexcept( std::declval< Consumer >().number( v ) ) )
{
Consumer::number( v );
}
};

} // namespace tao::json

int main( int /*unused*/, char** /*unused*/ )
{
tao::json::value v = { { "a", 20 }, { "b", 30 } };
tao::json::validate_integer< tao::json::events::discard, 10, 40 > consumer;
tao::json::events::from_value( consumer, v );
return 0;
}

0 comments on commit 20ba56a

Please sign in to comment.