diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2018-03-08 18:06:26 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2018-03-08 18:06:26 +0200 |
commit | df5e58e6e5eb2727a185bf9a98a462c18fa3a83d (patch) | |
tree | fb0cc76643865390ac3e45462d51ea02575a3175 /bdep/wrapper-traits.hxx | |
parent | f9ebe2d1e920df001be2dd543a63677f8728f53d (diff) | |
download | bdep-df5e58e6e5eb2727a185bf9a98a462c18fa3a83d.tar.gz bdep-df5e58e6e5eb2727a185bf9a98a462c18fa3a83d.tar.xz bdep-df5e58e6e5eb2727a185bf9a98a462c18fa3a83d.zip |
Setup project database infrastructure
Diffstat (limited to 'bdep/wrapper-traits.hxx')
-rw-r--r-- | bdep/wrapper-traits.hxx | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/bdep/wrapper-traits.hxx b/bdep/wrapper-traits.hxx new file mode 100644 index 0000000..80b0cff --- /dev/null +++ b/bdep/wrapper-traits.hxx @@ -0,0 +1,59 @@ +// file : bdep/wrapper-traits.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BDEP_WRAPPER_TRAITS_HXX +#define BDEP_WRAPPER_TRAITS_HXX + +#include <libbutl/optional.mxx> + +#include <odb/wrapper-traits.hxx> + +namespace odb +{ + template <typename T> + class wrapper_traits<butl::optional<T>> + { + public: + typedef T wrapped_type; + typedef butl::optional<T> wrapper_type; + + // T can be const. + // + typedef + typename odb::details::meta::remove_const<T>::result + unrestricted_wrapped_type; + + static const bool null_handler = true; + static const bool null_default = true; + + static bool + get_null (const wrapper_type& o) + { + return !o; + } + + static void + set_null (wrapper_type& o) + { + o = wrapper_type (); + } + + static const wrapped_type& + get_ref (const wrapper_type& o) + { + return *o; + } + + static unrestricted_wrapped_type& + set_ref (wrapper_type& o) + { + if (!o) + o = unrestricted_wrapped_type (); + + return const_cast<unrestricted_wrapped_type&> (*o); + } + }; +} + +#endif // BDEP_WRAPPER_TRAITS_HXX |