From fc0acda2f0a9f27b490df84de2580306942e42ea Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 4 Aug 2011 13:33:21 +0200 Subject: Add support for Qt QSharedPointer as value wrapper --- odb/qt/smart-ptr.options | 5 ++++ odb/qt/smart-ptr/wrapper-traits.hxx | 60 +++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 odb/qt/smart-ptr/wrapper-traits.hxx diff --git a/odb/qt/smart-ptr.options b/odb/qt/smart-ptr.options index 636b130..f3dfbc6 100644 --- a/odb/qt/smart-ptr.options +++ b/odb/qt/smart-ptr.options @@ -14,3 +14,8 @@ # --odb-epilogue '#include ' --hxx-prologue '#include ' + +# Include wrapper traits. +# +--odb-epilogue '#include ' +--hxx-prologue '#include ' diff --git a/odb/qt/smart-ptr/wrapper-traits.hxx b/odb/qt/smart-ptr/wrapper-traits.hxx new file mode 100644 index 0000000..1f61b5e --- /dev/null +++ b/odb/qt/smart-ptr/wrapper-traits.hxx @@ -0,0 +1,60 @@ +// file : odb/qt/smart-ptr/wrapper-traits.hxx +// author : Constantin Michael +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_QT_SMART_PTR_WRAPPER_TRAITS_HXX +#define ODB_QT_SMART_PTR_WRAPPER_TRAITS_HXX + +#include + +#include + +#include + +namespace odb +{ + // Specialization for QSharedPointer. + // + template + class wrapper_traits< QSharedPointer > + { + public: + typedef T wrapped_type; + typedef QSharedPointer wrapper_type; + + static const bool null_handler = true; + static const bool null_default = false; + + static bool + get_null (const wrapper_type& p) + { + return p.isNull (); + } + + static void + set_null (wrapper_type& p) + { + p.clear (); + } + + static const wrapped_type& + get_ref (const wrapper_type& p) + { + return *p; + } + + static wrapped_type& + set_ref (wrapper_type& p) + { + if (p.isNull ()) + p = wrapper_type (new wrapped_type); + + return *p; + } + }; +} + +#include + +#endif // ODB_QT_SMART_PTR_WRAPPER_TRAITS_HXX -- cgit v1.1