diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2018-05-21 21:10:09 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2018-05-24 17:39:13 +0300 |
commit | 3a6c4ab1b6fc79a6a543088553cdd6bc8cb0a1dd (patch) | |
tree | 1ca0c3b9ef763276ff45c20a62d2504833e5f67d /bpkg/value-traits.hxx | |
parent | 1cab4fbd051ee5a71f073446ad5ad1b3d79f1031 (diff) |
Adapt to inventing package_name type
Diffstat (limited to 'bpkg/value-traits.hxx')
-rw-r--r-- | bpkg/value-traits.hxx | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/bpkg/value-traits.hxx b/bpkg/value-traits.hxx new file mode 100644 index 0000000..b55cfb5 --- /dev/null +++ b/bpkg/value-traits.hxx @@ -0,0 +1,54 @@ +// file : bpkg/value-traits.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_VALUE_TRAITS_HXX +#define BPKG_VALUE_TRAITS_HXX + +#include <string> +#include <cstddef> // size_t +#include <utility> // move() + +#include <odb/sqlite/traits.hxx> + +#include <libbpkg/package-name.hxx> + +namespace odb +{ + namespace sqlite + { + template <> + class value_traits<bpkg::package_name, id_text>: + value_traits<std::string, id_text> + { + public: + using value_type = bpkg::package_name; + using query_type = bpkg::package_name; + using image_type = details::buffer; + + using base_type = value_traits<std::string, id_text>; + + static void + set_value (value_type& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + std::string s; + base_type::set_value (s, b, n, is_null); + v = !s.empty () ? value_type (std::move (s)) : value_type (); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + const value_type& v) + { + base_type::set_image (b, n, is_null, v.string ()); + } + }; + }; +} + +#endif // BPKG_WRAPPER_TRAITS_HXX |