12#include "syscache.hpp"
18 bool is(
const type &t) {
return t.oid == INTERNALOID; }
19 constexpr type type_for() {
return type{.oid = INTERNALOID}; }
23 bool is(
const type &t) {
return t.oid == VOIDOID; }
24 constexpr type type_for() {
return type{.oid = VOIDOID}; }
28 static bool is(
const type &t) {
return t.oid == OIDOID; }
29 static constexpr type type_for() {
return type{.oid = OIDOID}; }
33 static bool is(
const type &t) {
return true; }
34 static constexpr type type_for() {
return type{.oid = ANYOID}; }
38 static bool is(
const type &t) {
return true; }
39 static constexpr type type_for() {
return type{.oid = ANYOID}; }
42template <
typename S>
struct type_traits<S, std::enable_if_t<utils::is_std_tuple<S>::value>> {
43 bool is(
const type &t) {
44 if (t.oid == RECORDOID) {
46 }
else if constexpr (std::tuple_size_v<S> == 1) {
52 constexpr type type_for() {
return type{.oid = RECORDOID}; }
58 bool is(
const type &t) {
return t.oid == BOOLOID; }
59 constexpr type type_for() {
return type{.oid = BOOLOID}; }
65 bool is(
const type &t) {
return t.oid == INT8OID || t.oid == INT4OID || t.oid == INT2OID; }
66 constexpr type type_for() {
return type{.oid = INT8OID}; }
72 bool is(
const type &t) {
return t.oid == INT4OID || t.oid == INT2OID; }
73 constexpr type type_for() {
return type{.oid = INT4OID}; }
79 bool is(
const type &t) {
return t.oid == INT2OID; }
80 constexpr type type_for() {
return type{.oid = INT2OID}; }
86 bool is(
const type &t) {
return t.oid == INT2OID; }
87 constexpr type type_for() {
return type{.oid = INT2OID}; }
93 bool is(
const type &t) {
return t.oid == FLOAT8OID || t.oid == FLOAT4OID; }
94 constexpr type type_for() {
return type{.oid = FLOAT8OID}; }
100 bool is(
const type &t) {
return t.oid == FLOAT4OID; }
101 constexpr type type_for() {
return type{.oid = FLOAT4OID}; }
107 bool is(
const type &t) {
return t.oid == TEXTOID; }
108 constexpr type type_for() {
return type{.oid = TEXTOID}; }
114 bool is(
const type &t) {
return t.oid == TEXTOID; }
115 constexpr type type_for() {
return type{.oid = TEXTOID}; }
121 bool is(
const type &t) {
return t.oid == TEXTOID; }
122 constexpr type type_for() {
return type{.oid = TEXTOID}; }
128 bool is(
const type &t) {
return t.oid == BYTEAOID; }
129 constexpr type type_for() {
return type{.oid = BYTEAOID}; }
135 bool is(
const type &t) {
return t.oid == BYTEAOID; }
136 constexpr type type_for() {
return type{.oid = BYTEAOID}; }
142 bool is(
const type &t) {
return t.oid == CSTRINGOID; }
143 constexpr type type_for() {
return type{.oid = CSTRINGOID}; }
149 bool is(
const type &t) {
return t.oid == CSTRINGOID; }
150 constexpr type type_for() {
return type{.oid = CSTRINGOID}; }
156 bool is(
const type &t) {
return t.oid == CSTRINGOID; }
157 constexpr type type_for() {
return type{.oid = CSTRINGOID}; }
163 bool is(
const type &t) {
return t.oid == F::type().oid; }
164 constexpr type type_for() {
return F::type(); }
182 static void *from_datum(
const datum &d,
oid, std::optional<memory_context>) {
183 return reinterpret_cast<void *
>(d.operator const ::Datum &());
186 static datum into_datum(
const void *
const &t) {
return datum(
reinterpret_cast<::Datum
>(t)); }
191 return static_cast<oid>(d.operator const ::Datum &());
199 return static_cast<size_t>(d.operator const ::Datum &());
207 return static_cast<int64_t
>(d.operator const ::Datum &());
215 return static_cast<int32_t
>(d.operator const ::Datum &());
222 return static_cast<int16_t
>(d.operator const ::Datum &());
229 return static_cast<bool>(d.operator const ::Datum &());
236 return DatumGetFloat8(d.operator const ::Datum &());
244 return DatumGetFloat4(d.operator const ::Datum &());
261 return bytea{d, ctx};
268 static byte_array
from_datum(
const datum &d,
oid, std::optional<memory_context> ctx) {
269 return bytea{d, ctx};
288 size_t sz = t.size();
289 void *result =
ffi_guard{::palloc}(sz + VARHDRSZ);
290 SET_VARSIZE(result, t.size() + VARHDRSZ);
291 memcpy(VARDATA(result), t.data(), sz);
292 return datum(
reinterpret_cast<::Datum
>(result));
308 static const char *from_datum(
const datum &d,
oid, std::optional<memory_context> ctx) {
309 return DatumGetPointer(d);
312 static datum into_datum(
const char *
const &t) {
return datum(PointerGetDatum(t)); }
315template <std::
size_t N>
317 static const char *
from_datum(
const datum &d,
oid, std::optional<memory_context> ctx) {
318 return DatumGetPointer(d);
327 static T
from_datum(
const datum &d,
oid, std::optional<memory_context> ctx) {
return {d, ctx}; }
335 std::optional<memory_context> context = std::nullopt) {
379 :
type({.oid = ([&]() {
382 if (OidIsValid(nsoid)) {
384 TYPENAMENSP, std::string(
name).c_str(), nsoid))
A trait to convert from and into a cppgres::datum.
Definition: datum.hpp:114
static T from_datum(const datum &, const oid, std::optional< memory_context > context=std::nullopt)=delete
Convert from a datum.
static T from_nullable_datum(const nullable_datum &d, const oid oid, std::optional< memory_context > context=std::nullopt)=delete
Convert from a nullable datum.
static datum into_datum(const T &d)=delete
Convert datum into a type.
static nullable_datum into_nullable_datum(const T &d)=delete
Convert into a nullable datum.
Definition: datum.hpp:146
Definition: memory.hpp:85
Type identified by its name.
Definition: types.hpp:365
named_type(const std::string_view schema, const std::string_view name)
Type identified by a qualified name.
Definition: types.hpp:378
named_type(const std::string_view name)
Type identified by an unqualified name.
Definition: types.hpp:371
Definition: syscache.hpp:27
Postgres type.
Definition: type.hpp:20