DAW JSON Link
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 
11 #include <daw/json/impl/version.h>
12 
15 
16 #include <daw/daw_algorithm.h>
17 #include <daw/daw_character_traits.h>
18 
19 #include <iostream>
20 
21 namespace daw::json {
22  inline namespace DAW_JSON_VER {
23  namespace concepts {
25  template<typename T>
26  DAW_JSON_REQUIRES( std::is_base_of_v<std::ostream, T> )
27  struct writable_output_trait<T DAW_JSON_ENABLEIF_S(
28  std::is_base_of_v<std::ostream, T> )> : std::true_type {
29 
30  template<typename... StringViews>
31  static inline void write( std::ostream &os,
32  StringViews const &...svs ) {
33  static_assert( sizeof...( StringViews ) > 0 );
34  constexpr auto writer = []( std::ostream &o,
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 inline 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.
#define DAW_JSON_ENABLEIF_S(...)
#define DAW_JSON_CPP23_STATIC_CALL_OP
This is in addition to the parse policy. Always do a full name match instead of sometimes relying on ...
Customization point traits.
DAW_JSON_REQUIRES(boost::describe::has_describe_members< T >::value and use_boost_describe_v< T >) struct json_data_contract< T >
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.
Definition: version.h:25