aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--odb/sqlite/traits.hxx150
1 files changed, 131 insertions, 19 deletions
diff --git a/odb/sqlite/traits.hxx b/odb/sqlite/traits.hxx
index 0de67f9..b812361 100644
--- a/odb/sqlite/traits.hxx
+++ b/odb/sqlite/traits.hxx
@@ -7,12 +7,18 @@
#include <odb/pre.hxx>
+#include <odb/details/config.hxx> // ODB_CXX11
+
#include <string>
#include <vector>
#include <limits> // std::numeric_limits
#include <cstddef> // std::size_t
#include <cstring> // std::memcpy, std::memset, std::strlen
+#ifdef ODB_CXX11
+# include <array>
+#endif
+
#include <odb/traits.hxx>
#include <odb/wrapper-traits.hxx>
@@ -303,13 +309,13 @@ namespace odb
{
};
- template <std::size_t n>
- struct default_value_traits<char[n], id_text>: c_string_value_traits
+ template <std::size_t N>
+ struct default_value_traits<char[N], id_text>: c_string_value_traits
{
};
- template <std::size_t n>
- struct default_value_traits<const char[n], id_text>: c_string_value_traits
+ template <std::size_t N>
+ struct default_value_traits<const char[N], id_text>: c_string_value_traits
{
};
@@ -380,20 +386,20 @@ namespace odb
{
};
- template <std::size_t n>
- struct image_traits<wchar_t[n], id_text>: c_wstring_image_traits {};
+ template <std::size_t N>
+ struct image_traits<wchar_t[N], id_text>: c_wstring_image_traits {};
- template <std::size_t n>
- struct default_value_traits<wchar_t[n], id_text>:
+ template <std::size_t N>
+ struct default_value_traits<wchar_t[N], id_text>:
c_wstring_value_traits
{
};
- template <std::size_t n>
- struct image_traits<const wchar_t[n], id_text>: c_wstring_image_traits {};
+ template <std::size_t N>
+ struct image_traits<const wchar_t[N], id_text>: c_wstring_image_traits {};
- template <std::size_t n>
- struct default_value_traits<const wchar_t[n], id_text>:
+ template <std::size_t N>
+ struct default_value_traits<const wchar_t[N], id_text>:
c_wstring_value_traits
{
};
@@ -463,7 +469,7 @@ namespace odb
const value_type&);
};
- // char[n] (buffer) specialization.
+ // char[N] (buffer) specialization.
//
template <std::size_t N>
struct default_value_traits<char[N], id_blob>
@@ -501,7 +507,7 @@ namespace odb
}
};
- // unsigned char[n] (buffer) specialization.
+ // unsigned char[N] (buffer) specialization.
//
template <std::size_t N>
struct default_value_traits<unsigned char[N], id_blob>
@@ -539,6 +545,84 @@ namespace odb
}
};
+#ifdef ODB_CXX11
+ // std::array<char, N> (buffer) specialization.
+ //
+ template <std::size_t N>
+ struct default_value_traits<std::array<char, N>, id_blob>
+ {
+ public:
+ typedef std::array<char, N> value_type;
+ typedef value_type 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)
+ std::memcpy (v.data (), b.data (), (n < N ? n : N));
+ else
+ std::memset (v.data (), 0, N);
+ }
+
+ static void
+ set_image (details::buffer& b,
+ std::size_t& n,
+ bool& is_null,
+ const value_type& v)
+ {
+ is_null = false;
+ n = N;
+
+ if (n > b.capacity ())
+ b.capacity (n);
+
+ std::memcpy (b.data (), v.data (), n);
+ }
+ };
+
+ // std::array<unsigned char, N> (buffer) specialization.
+ //
+ template <std::size_t N>
+ struct default_value_traits<std::array<unsigned char, N>, id_blob>
+ {
+ public:
+ typedef std::array<unsigned char, N> value_type;
+ typedef value_type 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)
+ std::memcpy (v.data (), b.data (), (n < N ? n : N));
+ else
+ std::memset (v.data (), 0, N);
+ }
+
+ static void
+ set_image (details::buffer& b,
+ std::size_t& n,
+ bool& is_null,
+ const value_type& v)
+ {
+ is_null = false;
+ n = N;
+
+ if (n > b.capacity ())
+ b.capacity (n);
+
+ std::memcpy (b.data (), v.data (), n);
+ }
+ };
+#endif
+
//
// type_traits
//
@@ -633,7 +717,7 @@ namespace odb
static const database_type_id db_type_id = id_real;
};
- // String type.
+ // String types.
//
template <>
struct default_type_traits<std::string>
@@ -647,17 +731,45 @@ namespace odb
static const database_type_id db_type_id = id_text;
};
- template <std::size_t n>
- struct default_type_traits<char[n]>
+ template <std::size_t N>
+ struct default_type_traits<char[N]>
{
static const database_type_id db_type_id = id_text;
};
- template <std::size_t n>
- struct default_type_traits<const char[n]>
+ template <std::size_t N>
+ struct default_type_traits<const char[N]>
{
static const database_type_id db_type_id = id_text;
};
+
+ // Binary types.
+ //
+ template <>
+ struct default_type_traits<std::vector<char> >
+ {
+ static const database_type_id db_type_id = id_blob;
+ };
+
+ template <>
+ struct default_type_traits<std::vector<unsigned char> >
+ {
+ static const database_type_id db_type_id = id_blob;
+ };
+
+#ifdef ODB_CXX11
+ template <std::size_t N>
+ struct default_type_traits<std::array<char, N> >
+ {
+ static const database_type_id db_type_id = id_blob;
+ };
+
+ template <std::size_t N>
+ struct default_type_traits<std::array<unsigned char, N> >
+ {
+ static const database_type_id db_type_id = id_blob;
+ };
+#endif
}
}