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
<
20
boost
::
multiprecision
::
cpp_dec_float
<
Precision
>>;
21
22
namespace
io
{
23
24
template
<
unsigned
Precision
>
25
struct
BufferFormatter
<
MultiPrecision
<
Precision
>> {
26
using
Value
=
MultiPrecision
<
Precision
>;
27
const
Value
&
value
;
28
29
BufferFormatter
(
const
Value
&
val
) :
value
{
val
} {}
30
31
template
<
typename
Buffer
>
32
void
operator
()(
const
UserTypes
&,
Buffer
&
buf
)
const
{
33
auto
str_rep
=
value
.
str
(
std
::
numeric_limits
<
Value
>::
max_digits10
,
34
std
::
ios_base
::
fixed
);
35
auto
bin_str
=
detail
::
StringToNumericBuffer
(
str_rep
);
36
buf
.
reserve
(
buf
.
size
() +
bin_str
.
size
());
37
std
::
copy
(
bin_str
.
begin
(),
bin_str
.
end
(),
std
::
back_inserter
(
buf
));
38
}
39
};
40
41
template
<
unsigned
Precision
>
42
struct
BufferParser
<
MultiPrecision
<
Precision
>>
43
:
detail
::
BufferParserBase
<
MultiPrecision
<
Precision
>> {
44
using
BaseType
=
detail
::
BufferParserBase
<
MultiPrecision
<
Precision
>>;
45
using
BaseType
::
BaseType
;
46
using
NumberType
=
boost
::
multiprecision
::
cpp_dec_float
<
Precision
>;
47
48
void
operator
()(
const
FieldBuffer
&
buffer
) {
49
auto
str
=
detail
::
NumericBufferToString
(
buffer
);
50
// cpp_dec_float provides const char* constructor, where it parses the
51
// contents to internal buffers. no std::string constructor is provided.
52
this
->
value
=
NumberType
{
str
.
c_str
()};
53
}
54
};
55
56
template
<
unsigned
Precision
>
57
struct
CppToSystemPg
<
MultiPrecision
<
Precision
>>
58
:
PredefinedOid
<
PredefinedOids
::
kNumeric
> {};
59
60
}
// namespace io
61
}
// namespace storages::postgres
62
63
USERVER_NAMESPACE_END
userver
storages
postgres
io
boost_multiprecision.hpp
Generated on Wed May 15 2024 22:28:55 for userver by
Doxygen
1.10.0