diff options
Diffstat (limited to 'odb/mysql/traits.hxx')
-rw-r--r-- | odb/mysql/traits.hxx | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/odb/mysql/traits.hxx b/odb/mysql/traits.hxx new file mode 100644 index 0000000..18aeac5 --- /dev/null +++ b/odb/mysql/traits.hxx @@ -0,0 +1,74 @@ +// file : odb/mysql/traits.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_MYSQL_TRAITS_HXX +#define ODB_MYSQL_TRAITS_HXX + +#include <string> +#include <cstddef> // std::size_t +#include <cstring> // std::memcpy + +#include <odb/traits.hxx> + +namespace odb +{ + namespace mysql + { + template <typename T> + struct value_traits: odb::value_traits<T> + { + }; + + template <> + struct value_traits<std::string> + { + typedef std::string value_type; + + static void + set_value (value_type& v, const char* s, std::size_t n, bool is_null) + { + if (!is_null) + v.assign (s, n); + else + v.erase (); + } + + static void + set_image (char* s, + std::size_t c, + std::size_t& n, + bool& is_null, + const value_type& v) + { + is_null = false; + n = v.size (); + + if (n > c) + n = c; + + if (n != 0) + std::memcpy (s, v.c_str (), n); + } + + static void + set_image (buffer& b, + std::size_t& n, + bool& is_null, + const value_type& v) + { + is_null = false; + n = v.size (); + + if (n > b.capacity ()) + b.capacity (n); + + if (n != 0) + std::memcpy (b.data (), v.c_str (), n); + } + }; + } +} + +#endif // ODB_MYSQL_TRAITS_HXX |