11#include "syscache.hpp"
17 bool is(
const type &t) {
return t.oid == INTERNALOID; }
18 constexpr type type_for() {
return type{.oid = INTERNALOID}; }
22 bool is(
const type &t) {
return t.oid == VOIDOID; }
23 constexpr type type_for() {
return type{.oid = VOIDOID}; }
27 static bool is(
const type &t) {
return t.oid == OIDOID; }
28 static constexpr type type_for() {
return type{.oid = OIDOID}; }
32 static bool is(
const type &t) {
return true; }
33 static constexpr type type_for() {
return type{.oid = ANYOID}; }
37 static bool is(
const type &t) {
return true; }
38 static constexpr type type_for() {
return type{.oid = ANYOID}; }
41template <
typename S>
struct type_traits<S, std::enable_if_t<utils::is_std_tuple<S>::value>> {
42 bool is(
const type &t) {
43 if (t.oid == RECORDOID) {
45 }
else if constexpr (std::tuple_size_v<S> == 1) {
51 constexpr type type_for() {
return type{.oid = RECORDOID}; }
57 bool is(
const type &t) {
return t.oid == BOOLOID; }
58 constexpr type type_for() {
return type{.oid = BOOLOID}; }
64 bool is(
const type &t) {
return t.oid == INT8OID || t.oid == INT4OID || t.oid == INT2OID; }
65 constexpr type type_for() {
return type{.oid = INT8OID}; }
71 bool is(
const type &t) {
return t.oid == INT4OID || t.oid == INT2OID; }
72 constexpr type type_for() {
return type{.oid = INT4OID}; }
78 bool is(
const type &t) {
return t.oid == INT2OID; }
79 constexpr type type_for() {
return type{.oid = INT2OID}; }
85 bool is(
const type &t) {
return t.oid == INT2OID; }
86 constexpr type type_for() {
return type{.oid = INT2OID}; }
92 bool is(
const type &t) {
return t.oid == FLOAT8OID || t.oid == FLOAT4OID; }
93 constexpr type type_for() {
return type{.oid = FLOAT8OID}; }
99 bool is(
const type &t) {
return t.oid == FLOAT4OID; }
100 constexpr type type_for() {
return type{.oid = FLOAT4OID}; }
106 bool is(
const type &t) {
return t.oid == TEXTOID; }
107 constexpr type type_for() {
return type{.oid = TEXTOID}; }
113 bool is(
const type &t) {
return t.oid == TEXTOID; }
114 constexpr type type_for() {
return type{.oid = TEXTOID}; }
120 bool is(
const type &t) {
return t.oid == TEXTOID; }
121 constexpr type type_for() {
return type{.oid = TEXTOID}; }
127 bool is(
const type &t) {
return t.oid == BYTEAOID; }
128 constexpr type type_for() {
return type{.oid = BYTEAOID}; }
134 bool is(
const type &t) {
return t.oid == BYTEAOID; }
135 constexpr type type_for() {
return type{.oid = BYTEAOID}; }
141 bool is(
const type &t) {
return t.oid == CSTRINGOID; }
142 constexpr type type_for() {
return type{.oid = CSTRINGOID}; }
148 bool is(
const type &t) {
return t.oid == CSTRINGOID; }
149 constexpr type type_for() {
return type{.oid = CSTRINGOID}; }
155 bool is(
const type &t) {
return t.oid == CSTRINGOID; }
156 constexpr type type_for() {
return type{.oid = CSTRINGOID}; }
162 bool is(
const type &t) {
return t.oid == F::type().oid; }
163 constexpr type type_for() {
return F::type(); }
181 static void *from_datum(
const datum &d,
oid, std::optional<memory_context>) {
182 return reinterpret_cast<void *
>(d.operator const ::Datum &());
185 static datum into_datum(
const void *
const &t) {
return datum(
reinterpret_cast<::Datum
>(t)); }
190 return static_cast<oid>(d.operator const ::Datum &());
198 return static_cast<size_t>(d.operator const ::Datum &());
206 return static_cast<int64_t
>(d.operator const ::Datum &());
214 return static_cast<int32_t
>(d.operator const ::Datum &());
221 return static_cast<int16_t
>(d.operator const ::Datum &());
228 return static_cast<bool>(d.operator const ::Datum &());
235 return DatumGetFloat8(d.operator const ::Datum &());
243 return DatumGetFloat4(d.operator const ::Datum &());
260 return bytea{d, ctx};
267 static byte_array
from_datum(
const datum &d,
oid, std::optional<memory_context> ctx) {
268 return bytea{d, ctx};
287 size_t sz = t.size();
288 void *result =
ffi_guard{::palloc}(sz + VARHDRSZ);
289 SET_VARSIZE(result, t.size() + VARHDRSZ);
290 memcpy(VARDATA(result), t.data(), sz);
291 return datum(
reinterpret_cast<::Datum
>(result));
307 static const char *from_datum(
const datum &d,
oid, std::optional<memory_context> ctx) {
308 return DatumGetPointer(d);
311 static datum into_datum(
const char *
const &t) {
return datum(PointerGetDatum(t)); }
314template <std::
size_t N>
316 static const char *
from_datum(
const datum &d,
oid, std::optional<memory_context> ctx) {
317 return DatumGetPointer(d);
326 static T
from_datum(
const datum &d,
oid, std::optional<memory_context> ctx) {
return {d, ctx}; }
334 std::optional<memory_context> context = std::nullopt) {
368 :
type({.oid = ([&]() {
371 if (OidIsValid(nsoid)) {
373 TYPENAMENSP, std::string(
name).c_str(), nsoid))
A trait to convert from and into a cppgres::datum.
Definition: datum.hpp:110
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.
Definition: datum.hpp:137
Definition: memory.hpp:61
Type identified by its name.
Definition: types.hpp:354
named_type(const std::string_view schema, const std::string_view name)
Type identified by a qualified name.
Definition: types.hpp:367
named_type(const std::string_view name)
Type identified by an unqualified name.
Definition: types.hpp:360
Definition: syscache.hpp:27
Postgres type.
Definition: type.hpp:20