DAW JSON Link
Loading...
Searching...
No Matches
daw_writable_output_cstdio.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_string_view.h>
19
20#include <cstdio>
21
22namespace daw::json {
23 inline namespace DAW_JSON_VER {
24 namespace concepts {
26 template<>
27 struct writable_output_trait<std::FILE *> : std::true_type {
28
29 template<typename... StringViews>
30 static inline void write( std::FILE *fp, StringViews const &...svs ) {
31 static_assert( sizeof...( StringViews ) > 0 );
32 constexpr auto writer = []( std::FILE *f,
34 if( sv.empty( ) ) {
35 return 0;
36 }
37 auto ret = std::fwrite( sv.data( ), 1, sv.size( ), f );
38 daw_json_ensure( ret == sv.size( ),
39 daw::json::ErrorReason::OutputError );
40 return 1;
41 };
42 ( (void)writer( fp, svs ), ... );
43 }
44
45 static inline void put( std::FILE *f, char c ) {
46 auto ret = std::fputc( c, f );
47 daw_json_ensure( ret == c, daw::json::ErrorReason::OutputError );
48 }
49 };
50 } // namespace concepts
51 } // namespace DAW_JSON_VER
52} // namespace daw::json
#define daw_json_ensure(Bool,...)
Ensure that Bool is true. If false pass rest of args to daw_json_error.
#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