userver
C++ Async Framework
Loading...
Searching...
No Matches
boost_multiprecision.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/storages/postgres/io/boost_multiprecision.hpp
4
/// @brief boost::multiprecision I/O support
5
/// @ingroup userver_postgres_parse_and_format
6
7
#
include
<
userver
/
storages
/
postgres
/
io
/
buffer_io
.
hpp
>
8
#
include
<
userver
/
storages
/
postgres
/
io
/
buffer_io_base
.
hpp
>
9
#
include
<
userver
/
storages
/
postgres
/
io
/
numeric_data
.
hpp
>
10
#
include
<
userver
/
storages
/
postgres
/
io
/
type_mapping
.
hpp
>
11
12
#
include
<
boost
/
multiprecision
/
cpp_dec_float
.
hpp
>
13
14
USERVER_NAMESPACE_BEGIN
15
16
namespace
storages::
postgres
{
17
18
template
<
unsigned
Precision
= 50>
19
using
MultiPrecision
=
boost
::
multiprecision
::
number
<
boost
::
multiprecision
::
cpp_dec_float
<
Precision
>>;
20
21
namespace
io
{
22
23
template
<
unsigned
Precision
>
24
struct
BufferFormatter
<
MultiPrecision
<
Precision
>> {
25
using
Value
=
MultiPrecision
<
Precision
>;
26
const
Value
&
value
;
27
28
BufferFormatter
(
const
Value
&
val
) :
value
{
val
} {}
29
30
template
<
typename
Buffer
>
31
void
operator
()(
const
UserTypes
&,
Buffer
&
buf
)
const
{
32
auto
str_rep
=
value
.
str
(
std
::
numeric_limits
<
Value
>::
max_digits10
,
std
::
ios_base
::
fixed
);
33
auto
bin_str
=
detail
::
StringToNumericBuffer
(
str_rep
);
34
buf
.
reserve
(
buf
.
size
() +
bin_str
.
size
());
35
std
::
copy
(
bin_str
.
begin
(),
bin_str
.
end
(),
std
::
back_inserter
(
buf
));
36
}
37
};
38
39
template
<
unsigned
Precision
>
40
struct
BufferParser
<
MultiPrecision
<
Precision
>> :
detail
::
BufferParserBase
<
MultiPrecision
<
Precision
>> {
41
using
BaseType
=
detail
::
BufferParserBase
<
MultiPrecision
<
Precision
>>;
42
using
BaseType
::
BaseType
;
43
using
NumberType
=
boost
::
multiprecision
::
cpp_dec_float
<
Precision
>;
44
45
void
operator
()(
const
FieldBuffer
&
buffer
) {
46
auto
str
=
detail
::
NumericBufferToString
(
buffer
);
47
// cpp_dec_float provides const char* constructor, where it parses the
48
// contents to internal buffers. no std::string constructor is provided.
49
this
->
value
=
NumberType
{
str
.
c_str
()};
50
}
51
};
52
53
template
<
unsigned
Precision
>
54
struct
CppToSystemPg
<
MultiPrecision
<
Precision
>> :
PredefinedOid
<
PredefinedOids
::
kNumeric
> {};
55
56
}
// namespace io
57
}
// namespace storages::postgres
58
59
USERVER_NAMESPACE_END
userver
storages
postgres
io
boost_multiprecision.hpp
Generated on Tue Nov 19 2024 11:31:51 for userver by
Doxygen
1.10.0