#ifndef seafire__representation__traits_hxx_ #define seafire__representation__traits_hxx_ #include #include #include #include #include #include #include #include #include namespace seafire::representation::traits { // has_entity_tag // template> struct has_entity_tag : std::false_type {}; template struct has_entity_tag< R, std::void_t< decltype( protocol::rfc7232::entity_tag_t{ std::declval< common::traits::remove_optional_t().etag())> >() } ) > > : std::true_type {}; template constexpr bool has_entity_tag_v{has_entity_tag::value}; // has_last_modified // template> struct has_last_modified : std::false_type {}; template struct has_last_modified< R, std::void_t< decltype( std::chrono::system_clock::time_point{ std::declval< common::traits::remove_optional_t().last_modified())> >() } ) > > : std::true_type {}; template constexpr bool has_last_modified_v{has_last_modified::value}; // ============================================================================= // input representation. // template< typename R, typename = std::void_t<> > struct is_input_representation : std::false_type {}; template struct is_input_representation< M, std::void_t< decltype( bool{ M::can_accept_input( std::declval() ) } ), decltype( M{ std::declval< decltype( M::read_from( std::declval>(), std::declval() ) ) >() } ) > > : std::true_type { }; template struct is_input_representation< std::variant > : std::bool_constant< (is_input_representation::value && ...) > { }; template constexpr bool is_input_representation_v{is_input_representation::value}; template struct is_variant_input_representation : std::false_type {}; template struct is_variant_input_representation< std::variant > : is_input_representation> { }; template constexpr bool is_variant_input_representation_v{is_variant_input_representation::value}; template struct input_representation_traits { // TODO: DO. }; // ============================================================================= // (output) representation. // // is_basic_representation // template< typename R, typename = std::void_t<> > struct is_basic_representation : std::false_type {}; template struct is_basic_representation< R, std::void_t< decltype( protocol::media_type_t{ std::declval().type() } ), decltype( std::declval().write_to(std::declval()) ) > > : std::true_type {}; template constexpr bool is_basic_representation_v{ is_basic_representation::value }; // is_content_negotiable_representation // template> struct is_content_negotiable_representation : std::false_type {}; template struct is_content_negotiable_representation< R, std::void_t< // check that r::is_accepted(protocol::media_type_t) is valid. // decltype( bool{ R::is_accepted( std::declval>() ) } ), // check that r{}.select(protocol::media_type_t) is valid. // decltype( std::declval().select( std::declval>() ) ) > > : std::bool_constant< is_basic_representation_v< // check that the type of the return value of r{}.select(...) is a representation. // decltype( std::declval().select( std::declval>() ) ) > > {}; template constexpr bool is_content_negotiable_representation_v{ is_content_negotiable_representation::value }; // is_representation // template struct is_representation : std::bool_constant< is_basic_representation_v || is_content_negotiable_representation_v > {}; template constexpr bool is_representation_v{is_representation::value}; template struct is_optional_representation : std::false_type {}; template struct is_optional_representation> : std::bool_constant< is_basic_representation_v || is_content_negotiable_representation_v > {}; // is_optional_representation // template constexpr bool is_optional_representation_v{is_optional_representation::value}; // representation_traits // template struct representation_traits { using representation_type = common::traits::remove_optional_t; static constexpr bool is_optional{ // Using R here since optional<> is removed from representation_type. is_optional_representation_v }; static constexpr bool is_basic { is_basic_representation_v }; static constexpr bool is_content_negotiable { is_content_negotiable_representation_v }; static constexpr bool has_entity_tag{ has_entity_tag_v }; static constexpr bool has_last_modified{ has_last_modified_v }; }; } // namespace seafire::representation::traits #endif