26 #include "../string_buffer.h"
34 template <
typename T >
37 template <
typename T >
42 T
const* val_ptr = std::get_if< T >( &var );
54 template <
typename T >
57 static_assert( std::is_enum_v< T > );
61 return static_cast< int64_t
>( m );
66 auto* val = std::get_if< int64_t >( &var );
70 return static_cast< T
>( *val );
84 template < std::
size_t N >
88 static std::optional< emlabcpp::string_buffer< N > > from_value(
value_type const& var )
90 auto const* val_ptr = std::get_if< string_buffer >( &var );
91 if ( val_ptr ==
nullptr )
106 template <
typename T >
107 requires( alternative_of< T, value_type > )
108 struct value_type_converter< T > : value_type_converter_getter< T >
112 template <
typename T >
113 requires( !std::same_as< T, int64_t > && std::is_integral_v< T > && !std::same_as< T, bool > )
116 static std::optional< T > from_value(
value_type const& var )
118 if ( std::holds_alternative< float >( var ) ) {
119 auto const v = *std::get_if< float >( &var );
123 std::optional< int64_t > opt_val =
127 return static_cast< T
>( *opt_val );
132 return {
static_cast< int64_t
>( item ) };
136 template < std::
size_t N >
139 static_assert(
N < 64 );
143 if (
auto* val = std::get_if< int64_t >( &var ) )
150 return static_cast< int64_t
>( item.to_ulong() );
177 return int64_t( item );
181 template <
typename Rep,
typename Ratio >
189 static std::optional< std::chrono::duration< Rep, Ratio > >
193 if ( !opt_raw.has_value() )
195 return std::chrono::duration< Rep, Ratio >{ *opt_raw };
199 template <
typename T >
204 } -> std::convertible_to< std::optional< T > >;
MIT License.
Definition: base.h:37
string_buffer< 128 > string_buffer
Definition: base.h:46
requires(N<=string_buffer::capacity) struct value_type_converter< emlabcpp requires(alternative_of< T, value_type >) struct value_type_converter< T > requires(!std::same_as< T, int64_t > &&std::is_integral_v< T > &&!std::same_as< T, bool >) struct value_type_converter< T >
Definition: convert.h:113
std::variant< int64_t, float, bool, string_buffer > value_type
Definition: base.h:51
concept value_type_convertible
Definition: convert.h:200
MIT License.
Definition: impl.h:31
N
Definition: static_storage.h:97
physical_quantity< 0, 0, 0, 0, 0, 0, 0, 0, 1 > byte
Definition: physical_quantity.h:118
physical_quantity represents all physical units defined using the International System of Units and m...
Definition: physical_quantity.h:56
Definition: string_buffer.h:38
static constexpr std::size_t capacity
Definition: string_buffer.h:39
static value_type to_value(char const *item)
Definition: convert.h:166
static value_type to_value(std::bitset< N > const &item)
Definition: convert.h:148
static std::optional< std::bitset< N > > from_value(value_type const &var)
Definition: convert.h:141
static value_type to_value(std::byte const item)
Definition: convert.h:175
static value_type to_value(std::chrono::duration< Rep, Ratio > const &val)
Definition: convert.h:184
static std::optional< std::chrono::duration< Rep, Ratio > > from_value(value_type const &var)
Definition: convert.h:190
static value_type to_value(std::string_view const &item)
Definition: convert.h:157
static value_type to_value(T m)
Definition: convert.h:59
static std::optional< T > from_value(value_type const &var)
Definition: convert.h:64
static std::optional< T > from_value(value_type const &var)
Definition: convert.h:40
static value_type to_value(T const &item)
Definition: convert.h:48