8#include <userver/storages/postgres/exceptions.hpp>
9#include <userver/storages/postgres/io/buffer_io_base.hpp>
10#include <userver/storages/postgres/io/field_buffer.hpp>
11#include <userver/storages/postgres/io/floating_point_types.hpp>
12#include <userver/storages/postgres/io/traits.hpp>
13#include <userver/storages/postgres/io/type_mapping.hpp>
14#include <userver/storages/postgres/io/type_traits.hpp>
15#include <userver/storages/postgres/io/user_types.hpp>
17USERVER_NAMESPACE_BEGIN
28 constexpr bool operator==(
const Point& rhs)
const {
return x == rhs.x && y == rhs.y; }
29 constexpr bool operator!=(
const Point& rhs)
const {
return !(*
this == rhs); }
36 constexpr bool operator==(
const LineSegment& rhs)
const {
return ends[0] == rhs.ends[0] && ends[1] == rhs.ends[1]; }
37 constexpr bool operator!=(
const LineSegment& rhs)
const {
return !(*
this == rhs); }
39 std::array<Point, 2> ends{};
44 constexpr bool operator==(
const Line& rhs)
const {
return a == rhs.a && b == rhs.b && c == rhs.c; }
45 constexpr bool operator!=(
const Line& rhs)
const {
return !(*
this == rhs); }
53 constexpr bool operator==(
const Box& rhs)
const {
54 return corners[0] == rhs.corners[0] && corners[1] == rhs.corners[1];
56 constexpr bool operator!=(
const Box& rhs)
const {
return !(*
this == rhs); }
58 std::array<Point, 2> corners{};
62 bool operator==(
const Path& rhs)
const {
return is_closed == rhs.is_closed && points == rhs.points; }
63 bool operator!=(
const Path& rhs)
const {
return !(*
this == rhs); }
65 bool is_closed{
false};
66 std::vector<Point> points;
70 bool operator==(
const Polygon& rhs)
const {
return points == rhs.points; }
71 bool operator!=(
const Polygon& rhs)
const {
return !(*
this == rhs); }
73 std::vector<Point> points;
77 constexpr bool operator==(
const Circle& rhs)
const {
return center == rhs.center && radius == rhs.radius; }
78 constexpr bool operator!=(
const Circle& rhs)
const {
return !(*
this == rhs); }
85struct PointParser : BufferParserBase<Point> {
86 using BaseType = BufferParserBase<Point>;
87 using BaseType::BaseType;
95struct PointFormatter : BufferFormatterBase<Point> {
96 using BaseType = BufferFormatterBase<Point>;
97 using BaseType::BaseType;
99 template <
typename Buffer>
100 void operator()(
const UserTypes& types, Buffer& buffer)
const {
101 io::WriteBuffer(types, buffer, value.x);
102 io::WriteBuffer(types, buffer, value.y);
106struct LineSegmentParser : BufferParserBase<LineSegment> {
107 using BaseType = BufferParserBase<LineSegment>;
108 using BaseType::BaseType;
111 buffer.Read(value.ends[0]);
112 buffer.Read(value.ends[1]);
116struct LineSegmentFormatter : BufferFormatterBase<LineSegment> {
117 using BaseType = BufferFormatterBase<LineSegment>;
118 using BaseType::BaseType;
120 template <
typename Buffer>
121 void operator()(
const UserTypes& types, Buffer& buffer)
const {
122 io::WriteBuffer(types, buffer, value.ends[0]);
123 io::WriteBuffer(types, buffer, value.ends[1]);
127struct LineParser : BufferParserBase<Line> {
128 using BaseType = BufferParserBase<Line>;
129 using BaseType::BaseType;
132 buffer.Read(value.a);
133 buffer.Read(value.b);
134 buffer.Read(value.c);
138struct LineFormatter : BufferFormatterBase<Line> {
139 using BaseType = BufferFormatterBase<Line>;
140 using BaseType::BaseType;
142 template <
typename Buffer>
143 void operator()(
const UserTypes& types, Buffer& buffer)
const {
144 io::WriteBuffer(types, buffer, value.a);
145 io::WriteBuffer(types, buffer, value.b);
146 io::WriteBuffer(types, buffer, value.c);
150struct BoxParser : BufferParserBase<Box> {
151 using BaseType = BufferParserBase<Box>;
152 using BaseType::BaseType;
155 buffer.Read(value.corners[0]);
156 buffer.Read(value.corners[1]);
160struct BoxFormatter : BufferFormatterBase<Box> {
161 using BaseType = BufferFormatterBase<Box>;
162 using BaseType::BaseType;
164 template <
typename Buffer>
165 void operator()(
const UserTypes& types, Buffer& buffer)
const {
166 io::WriteBuffer(types, buffer, value.corners[0]);
167 io::WriteBuffer(types, buffer, value.corners[1]);
171struct PathParser : BufferParserBase<Path> {
172 using BaseType = BufferParserBase<Path>;
173 using BaseType::BaseType;
176 buffer.Read(value.is_closed);
178 buffer.Read(point_no);
179 value.points.resize(point_no);
180 for (
auto i = 0; i < point_no; ++i) {
181 buffer.Read(value.points[i]);
186struct PathFormatter : BufferFormatterBase<Path> {
187 using BaseType = BufferFormatterBase<Path>;
188 using BaseType::BaseType;
190 template <
typename Buffer>
191 void operator()(
const UserTypes& types, Buffer& buffer)
const {
192 io::WriteBuffer(types, buffer, value.is_closed);
193 Integer points_no = value.points.size();
194 io::WriteBuffer(types, buffer, points_no);
195 for (
const auto& p : value.points) {
196 io::WriteBuffer(types, buffer, p);
201struct PolygonParser : BufferParserBase<Polygon> {
202 using BaseType = BufferParserBase<Polygon>;
203 using BaseType::BaseType;
207 buffer.Read(point_no);
208 value.points.resize(point_no);
209 for (
auto i = 0; i < point_no; ++i) {
210 buffer.Read(value.points[i]);
215struct PolygonFormatter : BufferFormatterBase<Polygon> {
216 using BaseType = BufferFormatterBase<Polygon>;
217 using BaseType::BaseType;
219 template <
typename Buffer>
220 void operator()(
const UserTypes& types, Buffer& buffer)
const {
221 Integer points_no = value.points.size();
222 io::WriteBuffer(types, buffer, points_no);
223 for (
const auto& p : value.points) {
224 io::WriteBuffer(types, buffer, p);
229struct CircleParser : BufferParserBase<Circle> {
230 using BaseType = BufferParserBase<Circle>;
231 using BaseType::BaseType;
234 buffer.Read(value.center);
235 buffer.Read(value.radius);
239struct CircleFormatter : BufferFormatterBase<Circle> {
240 using BaseType = BufferFormatterBase<Circle>;
241 using BaseType::BaseType;
243 template <
typename Buffer>
244 void operator()(
const UserTypes& types, Buffer& buffer)
const {
245 io::WriteBuffer(types, buffer, value.center);
246 io::WriteBuffer(types, buffer, value.radius);
355struct CppToSystemPg<detail::Point> : PredefinedOid<PredefinedOids::kPoint> {};
357struct CppToSystemPg<detail::LineSegment> : PredefinedOid<PredefinedOids::kLseg> {};
359struct CppToSystemPg<detail::Line> : PredefinedOid<PredefinedOids::kLine> {};
361struct CppToSystemPg<detail::Box> : PredefinedOid<PredefinedOids::kBox> {};
363struct CppToSystemPg<detail::Path> : PredefinedOid<PredefinedOids::kPath> {};
365struct CppToSystemPg<detail::Polygon> : PredefinedOid<PredefinedOids::kPolygon> {};
367struct CppToSystemPg<detail::Circle> : PredefinedOid<PredefinedOids::kCircle> {};