DAW JSON Link
Loading...
Searching...
No Matches
daw_writable_output_ostream.h
Go to the documentation of this file.
1// Copyright (c) Darrell Wright
2//
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
5//
6// Official repository: https://github.com/beached/daw_json_link
7//
8
9#pragma once
10
12
15
16#include <daw/daw_algorithm.h>
17#include <daw/daw_character_traits.h>
18#include <daw/daw_enable_requires.h>
19
20#include <iostream>
21
22namespace daw::json {
23 inline namespace DAW_JSON_VER {
24 namespace concepts {
26 template<typename T>
27 DAW_REQUIRES( std::is_base_of_v<std::ostream, T> )
28 struct writable_output_trait<T DAW_ENABLEIF_S(
29 std::is_base_of_v<std::ostream, T> )> : std::true_type {
30
31 template<typename... StringViews>
32 static void write( std::ostream &os, StringViews const &...svs ) {
33 static_assert( sizeof...( StringViews ) > 0 );
34 DAW_CPP23_STATIC_LOCAL constexpr auto writer =
35 []( std::ostream &o, auto sv ) DAW_JSON_CPP23_STATIC_CALL_OP {
36 if( sv.empty( ) ) {
37 return 0;
38 }
39 o.write( sv.data( ), static_cast<std::streamsize>( sv.size( ) ) );
40 daw_json_ensure( static_cast<bool>( o ),
41 daw::json::ErrorReason::OutputError );
42 return 1;
43 };
44 ( (void)writer( os, svs ), ... );
45 }
46
47 static void put( std::ostream &os, char c ) {
48 os.put( c );
49 daw_json_ensure( static_cast<bool>( os ),
50 daw::json::ErrorReason::OutputError );
51 }
52 };
53 } // namespace concepts
54 } // namespace DAW_JSON_VER
55} // namespace daw::json
#define daw_json_ensure(Bool,...)
Ensure that Bool is true. If false pass rest of args to daw_json_error.
DAW_REQUIRES(daw::json::json_details::is_container_opted_into_json_iostreams_v< Container >) std
An opt in ostream interface for containers of types that have JSON mappings.
#define DAW_JSON_CPP23_STATIC_CALL_OP
Customization point traits.
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.
Definition version.h:20