aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-07-28 09:45:36 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-07-28 09:45:36 +0200
commit9abf73c8180e3664a71bac73629f67851c6c12da (patch)
tree16f0ac542674af8516020d955b663c661e1eded5
parent9f28115b3733971779a357b42f2c7fa0941d926c (diff)
Add value_traits specializations for std::vector<char>
This allows using it as a buffer for BLOB mapping.
-rw-r--r--odb/pgsql/traits.cxx22
-rw-r--r--odb/pgsql/traits.hxx30
2 files changed, 52 insertions, 0 deletions
diff --git a/odb/pgsql/traits.cxx b/odb/pgsql/traits.cxx
index bdffa45..1c167b8 100644
--- a/odb/pgsql/traits.cxx
+++ b/odb/pgsql/traits.cxx
@@ -54,5 +54,27 @@ namespace odb
if (n != 0)
memcpy (b.data (), v, n);
}
+
+ //
+ // default_value_traits<vector<char>, id_bytea>
+ //
+
+ void default_value_traits<vector<char>, id_bytea>::
+ set_image (details::buffer& b,
+ size_t& n,
+ bool& is_null,
+ const value_type& v)
+ {
+ is_null = false;
+ n = v.size ();
+
+ if (n > b.capacity ())
+ b.capacity (n);
+
+ // std::vector::data() may not be available in older compilers.
+ //
+ if (n != 0)
+ memcpy (b.data (), &v[0], n);
+ }
}
}
diff --git a/odb/pgsql/traits.hxx b/odb/pgsql/traits.hxx
index 7b4f746..f34a1ca 100644
--- a/odb/pgsql/traits.hxx
+++ b/odb/pgsql/traits.hxx
@@ -9,6 +9,7 @@
#include <odb/pre.hxx>
#include <string>
+#include <vector>
#include <cstddef> // std::size_t
#include <odb/traits.hxx>
@@ -211,6 +212,35 @@ namespace odb
{
};
+ // std::vector<char> (buffer) specialization.
+ //
+ template <>
+ struct LIBODB_PGSQL_EXPORT default_value_traits<std::vector<char>, id_bytea>
+ {
+ public:
+ typedef std::vector<char> value_type;
+ typedef std::vector<char> query_type;
+ typedef details::buffer image_type;
+
+ static void
+ set_value (value_type& v,
+ const details::buffer& b,
+ std::size_t n,
+ bool is_null)
+ {
+ if (!is_null)
+ v.assign (b.data (), b.data () + n);
+ else
+ v.clear ();
+ }
+
+ static void
+ set_image (details::buffer&,
+ std::size_t& n,
+ bool& is_null,
+ const value_type&);
+ };
+
//
// type_traits
//