From 26f53799c911e44da5d229e8f6bf2c40f79c31b1 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 3 Nov 2011 10:11:24 +0200 Subject: Add support for mapping char[N] and unsigned char[N] types to BLOB New test: common/blob. --- odb/pgsql/traits.cxx | 2 -- odb/pgsql/traits.hxx | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/odb/pgsql/traits.cxx b/odb/pgsql/traits.cxx index 9e31c9f..b19b7f9 100644 --- a/odb/pgsql/traits.cxx +++ b/odb/pgsql/traits.cxx @@ -3,8 +3,6 @@ // copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file -#include // std::memcpy, std::strlen - #include using namespace std; diff --git a/odb/pgsql/traits.hxx b/odb/pgsql/traits.hxx index 85a6af4..026e1d3 100644 --- a/odb/pgsql/traits.hxx +++ b/odb/pgsql/traits.hxx @@ -11,6 +11,7 @@ #include #include #include // std::size_t +#include // std::memcpy, std::memset, std::strlen #include #include @@ -527,6 +528,82 @@ namespace odb const value_type&); }; + // char[n] (buffer) specialization. + // + template + struct default_value_traits + { + public: + typedef char* value_type; + typedef const char* query_type; + typedef details::buffer image_type; + + static void + set_value (char* const& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + if (!is_null) + std::memcpy (v, b.data (), (n < N ? n : N)); + else + std::memset (v, 0, N); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + const char* v) + { + is_null = false; + n = N; + + if (n > b.capacity ()) + b.capacity (n); + + std::memcpy (b.data (), v, n); + } + }; + + // unsigned char[n] (buffer) specialization. + // + template + struct default_value_traits + { + public: + typedef unsigned char* value_type; + typedef const unsigned char* query_type; + typedef details::buffer image_type; + + static void + set_value (unsigned char* const& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + if (!is_null) + std::memcpy (v, b.data (), (n < N ? n : N)); + else + std::memset (v, 0, N); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + const unsigned char* v) + { + is_null = false; + n = N; + + if (n > b.capacity ()) + b.capacity (n); + + std::memcpy (b.data (), v, n); + } + }; + // // type_traits // -- cgit v1.1