aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConstantin Michael <constantin@codesynthesis.com>2011-04-12 17:52:37 +0200
committerConstantin Michael <constantin@codesynthesis.com>2011-04-22 14:39:42 +0200
commit7db38e8c622c2cd23d7a38e3cf70cb1b00dbc838 (patch)
tree38150a1912a234ec28c84395858ad2a82019cfaf
parent621bc135b9825fc9f18ada204f67d3800c5f6fda (diff)
Add qt/smart-ptr implementation
-rw-r--r--odb/qt.options1
-rw-r--r--odb/qt/lazy-ptr.hxx11
-rw-r--r--odb/qt/smart-ptr.options16
-rw-r--r--odb/qt/smart-ptr/lazy-pointer-traits.hxx63
-rw-r--r--odb/qt/smart-ptr/lazy-ptr.hxx415
-rw-r--r--odb/qt/smart-ptr/lazy-ptr.ixx603
-rw-r--r--odb/qt/smart-ptr/lazy-ptr.txx99
-rw-r--r--odb/qt/smart-ptr/pointer-traits.hxx87
-rw-r--r--odb/qt/version.hxx6
-rw-r--r--odb/qt/version.options2
-rw-r--r--version2
11 files changed, 1300 insertions, 5 deletions
diff --git a/odb/qt.options b/odb/qt.options
index 76c25ec..a1360f2 100644
--- a/odb/qt.options
+++ b/odb/qt.options
@@ -5,3 +5,4 @@
--profile qt/basic
--profile qt/date-time
+--profile qt/smart-ptr
diff --git a/odb/qt/lazy-ptr.hxx b/odb/qt/lazy-ptr.hxx
new file mode 100644
index 0000000..4587132
--- /dev/null
+++ b/odb/qt/lazy-ptr.hxx
@@ -0,0 +1,11 @@
+// file : odb/qt/lazy-ptr.hxx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_LAZY_PTR_HXX
+#define ODB_QT_LAZY_PTR_HXX
+
+#include <odb/qt/smart-ptr/lazy-ptr.hxx>
+
+#endif // ODB_QT_LAZY_PTR_HXX
diff --git a/odb/qt/smart-ptr.options b/odb/qt/smart-ptr.options
new file mode 100644
index 0000000..f9de219
--- /dev/null
+++ b/odb/qt/smart-ptr.options
@@ -0,0 +1,16 @@
+# file : odb/qt/smart-ptr.options
+# author : Constantin Michael <constantin@codesynthesis.com>
+# copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+# license : GNU GPL v2; see accompanying LICENSE file
+
+--profile qt/version
+
+# Make QSharedPointer the default object pointer.
+#
+--hxx-prologue '#include <QSharedPointer>'
+--default-pointer QSharedPointer
+
+# Include pointer traits.
+#
+--odb-epilogue '#include <odb/qt/smart-ptr/pointer-traits.hxx>'
+--hxx-prologue '#include <odb/qt/smart-ptr/pointer-traits.hxx>'
diff --git a/odb/qt/smart-ptr/lazy-pointer-traits.hxx b/odb/qt/smart-ptr/lazy-pointer-traits.hxx
new file mode 100644
index 0000000..89c1222
--- /dev/null
+++ b/odb/qt/smart-ptr/lazy-pointer-traits.hxx
@@ -0,0 +1,63 @@
+// file : odb/qt/smart-ptr/lazy-pointer-traits.hxx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_SMART_PTR_LAZY_POINTER_TRAITS_HXX
+#define ODB_QT_SMART_PTR_LAZY_POINTER_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <odb/pointer-traits.hxx>
+#include <odb/qt/smart-ptr/lazy-ptr.hxx>
+
+namespace odb
+{
+ template <typename T>
+ class pointer_traits<QLazySharedPointer<T> >
+ {
+ public:
+ static const pointer_kind kind = pk_shared;
+ static const bool lazy = true;
+
+ typedef T element_type;
+ typedef QLazySharedPointer<element_type> pointer_type;
+ typedef QSharedPointer<element_type> eager_pointer_type;
+
+ static bool
+ null_ptr (const pointer_type& p)
+ {
+ return !p;
+ }
+
+ template <class O /* = T */>
+ static typename object_traits<O>::id_type
+ object_id (const pointer_type& p)
+ {
+ return p.template objectId<O> ();
+ }
+ };
+
+ template <typename T>
+ class pointer_traits<QLazyWeakPointer<T> >
+ {
+ public:
+ static const pointer_kind kind = pk_weak;
+ static const bool lazy = true;
+
+ typedef T element_type;
+ typedef QLazyWeakPointer<element_type> pointer_type;
+ typedef QLazySharedPointer<element_type> strong_pointer_type;
+ typedef QWeakPointer<element_type> eager_pointer_type;
+
+ static strong_pointer_type
+ lock (const pointer_type& p)
+ {
+ return p.toStrongRef ();
+ }
+ };
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_QT_SMART_PTR_LAZY_POINTER_TRAITS_HXX
diff --git a/odb/qt/smart-ptr/lazy-ptr.hxx b/odb/qt/smart-ptr/lazy-ptr.hxx
new file mode 100644
index 0000000..0d0e60a
--- /dev/null
+++ b/odb/qt/smart-ptr/lazy-ptr.hxx
@@ -0,0 +1,415 @@
+// file : odb/qt/smart-ptr/lazy-ptr.hxx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_SMART_PTR_LAZY_PTR_HXX
+#define ODB_QT_SMART_PTR_LAZY_PTR_HXX
+
+#include <odb/pre.hxx>
+
+#include <QSharedPointer>
+#include <QWeakPointer>
+#include <QGlobalStatic>
+
+#include <odb/forward.hxx> // odb::database
+#include <odb/traits.hxx>
+#include <odb/lazy-ptr-impl.hxx>
+
+template <class T>
+class QLazyWeakPointer;
+
+//
+// QLazySharedPointer declaration.
+//
+
+template <class T>
+class QLazySharedPointer
+{
+ // The standard QSharedPointer interface.
+ //
+public:
+ // These typedefs are inherited by QSharedPointer indirectly from
+ // QtSharedPointer::Basic<T>
+ //
+ typedef T Type;
+ typedef T element_type;
+ typedef T value_type;
+ typedef value_type* pointer;
+ typedef const value_type* const_pointer;
+ typedef value_type& reference;
+ typedef const value_type& const_reference;
+ typedef qptrdiff difference_type;
+
+ QLazySharedPointer ();
+
+ explicit
+ QLazySharedPointer (T*);
+
+ template <class Deleter>
+ QLazySharedPointer (T*, Deleter);
+
+ QLazySharedPointer (const QLazySharedPointer&);
+
+ template <class X>
+ QLazySharedPointer (const QLazySharedPointer<X>&);
+
+ template <class X>
+ QLazySharedPointer (const QLazyWeakPointer<X>&);
+
+ ~QLazySharedPointer ();
+
+ QLazySharedPointer&
+ operator= (const QLazySharedPointer&);
+
+ template <class X>
+ QLazySharedPointer&
+ operator= (const QLazySharedPointer<X>&);
+
+ template <class X>
+ QLazySharedPointer&
+ operator= (const QLazyWeakPointer<X>&);
+
+ typedef QSharedPointer<T> QLazySharedPointer<T>::*unspecified_bool_type;
+ operator unspecified_bool_type () const
+ {
+ return isNull () ? 0 : &QLazySharedPointer::p_;
+ }
+
+ bool
+ operator! () const;
+
+ T&
+ operator* () const;
+
+ T*
+ operator-> () const;
+
+ void
+ swap (QLazySharedPointer&);
+
+ bool
+ isNull () const;
+
+ T*
+ data () const;
+
+ QLazyWeakPointer<T>
+ toWeakRef () const;
+
+ void
+ clear ();
+
+ template <class X>
+ QLazySharedPointer<X>
+ staticCast () const;
+
+ template <class X>
+ QLazySharedPointer<X>
+ dynamicCast () const;
+
+ template <class X>
+ QLazySharedPointer<X>
+ constCast () const;
+
+ // Initialization and assignment from QSharedPointer and QWeakPointer.
+ //
+public:
+ template <class X>
+ QLazySharedPointer (const QSharedPointer<X>&);
+
+ template <class X>
+ explicit
+ QLazySharedPointer (const QWeakPointer<X>&);
+
+ template <class X>
+ QLazySharedPointer&
+ operator= (const QSharedPointer<X>&);
+
+ template <class X>
+ QLazySharedPointer&
+ operator= (const QWeakPointer<X>&);
+
+ // Lazy loading interface.
+ //
+public:
+ typedef odb::database database_type;
+
+ // isNull() loaded()
+ //
+ // true true NULL pointer to transient object
+ // false true valid pointer to persistent object
+ // true false unloaded pointer to persistent object
+ // false false valid pointer to transient object
+ //
+ bool
+ loaded () const;
+
+ QSharedPointer<T>
+ load () const;
+
+ // Unload the pointer. For transient objects this function is
+ // equivalent to clear().
+ //
+ void unload () const;
+
+ template <class ID>
+ QLazySharedPointer (database_type&, const ID&);
+
+ QLazySharedPointer (database_type&, T*);
+
+ template <class Deleter>
+ QLazySharedPointer (database_type&, T*, Deleter);
+
+ template <class X>
+ QLazySharedPointer (database_type&, const QSharedPointer<X>&);
+
+ template <class X>
+ QLazySharedPointer (database_type&, const QWeakPointer<X>&);
+
+ template <class O /* = T */>
+ typename odb::object_traits<O>::id_type
+ objectId () const;
+
+ database_type&
+ database () const;
+
+ // Helpers.
+ //
+public:
+ template <class X>
+ bool
+ equal (const QLazySharedPointer<X>&) const;
+
+private:
+ template <class X> friend class QLazySharedPointer;
+ template <class X> friend class QLazyWeakPointer;
+
+ mutable QSharedPointer<T> p_;
+ mutable odb::lazy_ptr_impl<T> i_;
+};
+
+//
+// QLazySharedPointer related non-members.
+//
+
+template <class T, class X>
+QLazySharedPointer<X>
+qSharedPointerCast (const QLazySharedPointer<T>&);
+
+template <class T, class X>
+QLazySharedPointer<X>
+qSharedPointerConstCast (const QLazySharedPointer<T>&);
+
+template <class T, class X>
+QLazySharedPointer<X>
+qSharedPointerDynamicCast (const QLazySharedPointer<T>&);
+
+template <class T, class X>
+bool
+operator== (const QLazySharedPointer<T>&, const QLazySharedPointer<X>&);
+
+template <class T, class X>
+bool
+operator!= (const QLazySharedPointer<T>&, const QLazySharedPointer<T>&);
+
+//
+// QLazyWeakPointer declaration
+//
+
+template <class T>
+class QLazyWeakPointer
+{
+ // The standard QWeakPointer interface
+ //
+public:
+ typedef T element_type;
+ typedef T value_type;
+ typedef value_type* pointer;
+ typedef const value_type* const_pointer;
+ typedef value_type& reference;
+ typedef const value_type& const_reference;
+ typedef qptrdiff difference_type;
+
+ QLazyWeakPointer ();
+
+ QLazyWeakPointer (const QLazyWeakPointer&);
+
+ template <class X>
+ QLazyWeakPointer (const QLazyWeakPointer<X>&);
+
+ template <class X>
+ QLazyWeakPointer (const QLazySharedPointer<X>&);
+
+ ~QLazyWeakPointer ();
+
+ QLazyWeakPointer&
+ operator= (const QLazyWeakPointer&);
+
+ template <class X>
+ QLazyWeakPointer&
+ operator= (const QLazyWeakPointer<X>&);
+
+ template <class X>
+ QLazyWeakPointer&
+ operator= (const QLazySharedPointer<X>&);
+
+ typedef QWeakPointer<T> QLazyWeakPointer<T>::*unspecified_bool_type;
+ operator unspecified_bool_type () const
+ {
+ return isNull () ? 0 : &QLazyWeakPointer<T>::p_;
+ }
+
+ bool
+ operator! () const;
+
+#ifdef QWEAKPOINTER_ENABLE_ARROW
+ T*
+ operator-> () const;
+#endif
+
+ void
+ clear ();
+
+ T*
+ data () const;
+
+ bool
+ isNull () const;
+
+ QLazySharedPointer<T>
+ toStrongRef () const;
+
+ // Initialization/assignment from QSharedPointer and QWeakPointer.
+ //
+public:
+ template <class X>
+ QLazyWeakPointer (const QWeakPointer<X>&);
+
+ template <class X>
+ QLazyWeakPointer (const QSharedPointer<X>&);
+
+ template <class X>
+ QLazyWeakPointer&
+ operator= (const QWeakPointer<X>&);
+
+ template <class X>
+ QLazyWeakPointer&
+ operator= (const QSharedPointer<X>&);
+
+ // Lazy loading interface.
+ //
+public:
+ typedef odb::database database_type;
+
+ // toStrongRef().isNull() loaded()
+ //
+ // true true expired pointer to transient object
+ // false true valid pointer to persistent object
+ // true false expired pointer to persistent object
+ // false false valid pointer to transient object
+ //
+ bool
+ loaded () const;
+
+ // Create a strong reference using toStrongRef() and load.
+ //
+ QSharedPointer<T>
+ load () const;
+
+ // Unload the pointer. For transient objects this function is equivalent
+ // to clear().
+ //
+ void
+ unload () const;
+
+ template <class ID>
+ QLazyWeakPointer (database_type&, const ID&);
+
+ template <class X>
+ QLazyWeakPointer (database_type&, const QSharedPointer<X>&);
+
+ template <class X>
+ QLazyWeakPointer (database_type&, const QWeakPointer<X>&);
+
+ // The objectId() function can only be called when the object is persistent,
+ // or: toStrongRef().isNull() XOR loaded() (can use != for XOR).
+ //
+ template <class O /* = T */>
+ typename odb::object_traits<O>::id_type
+ objectId () const;
+
+ database_type&
+ database () const;
+
+ // Helpers.
+ //
+public:
+ template <class X>
+ bool
+ equal (const QLazyWeakPointer<X>&) const;
+
+ template <class X>
+ bool
+ equal (const QLazySharedPointer<X>&) const;
+
+private:
+ template <class X> friend class QLazySharedPointer;
+ template <class X> friend class QLazyWeakPointer;
+
+ mutable QWeakPointer<T> p_;
+ mutable odb::lazy_ptr_impl<T> i_;
+};
+
+//
+// QLazyWeakPointer related non-members.
+//
+
+template <class T, class X>
+QLazySharedPointer<X>
+qSharedPointerCast (const QLazyWeakPointer<T>&);
+
+template <class T, class X>
+QLazySharedPointer<X>
+qSharedPointerConstCast (const QLazyWeakPointer<T>&);
+
+template <class T, class X>
+QLazySharedPointer<X>
+qSharedPointerDynamicCast (const QLazyWeakPointer<T>&);
+
+template <class T, class X>
+QLazyWeakPointer<X>
+qWeakPointerCast (const QLazyWeakPointer<T>&);
+
+template <class T, class X>
+bool
+operator== (const QLazyWeakPointer<T>&, const QLazyWeakPointer<X>&);
+
+template <class T, class X>
+bool
+operator== (const QLazyWeakPointer<T>&, const QLazySharedPointer<X>&);
+
+template <class T, class X>
+bool
+operator== (const QLazySharedPointer<T>&, const QLazyWeakPointer<X>&);
+
+template <class T, class X>
+bool
+operator!= (const QLazyWeakPointer<T>&, const QLazyWeakPointer<X>&);
+
+template <class T, class X>
+bool
+operator!= (const QLazyWeakPointer<T>&, const QLazySharedPointer<X>&);
+
+template <class T, class X>
+bool
+operator!= (const QLazySharedPointer<T>&, const QLazyWeakPointer<X>&);
+
+#include <odb/qt/smart-ptr/lazy-ptr.ixx>
+#include <odb/qt/smart-ptr/lazy-ptr.txx>
+
+#include <odb/qt/smart-ptr/lazy-pointer-traits.hxx>
+
+#include <odb/post.hxx>
+
+#endif // ODB_QT_SMART_PTR_LAZY_PTR_HXX
diff --git a/odb/qt/smart-ptr/lazy-ptr.ixx b/odb/qt/smart-ptr/lazy-ptr.ixx
new file mode 100644
index 0000000..331f20a
--- /dev/null
+++ b/odb/qt/smart-ptr/lazy-ptr.ixx
@@ -0,0 +1,603 @@
+// file : odb/qt/smart-ptr/lazy-ptr.ixx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+//
+// QLazySharedPointer definition.
+//
+
+template <class T>
+inline QLazySharedPointer<T>::
+QLazySharedPointer () {}
+
+template <class T>
+inline QLazySharedPointer<T>::
+QLazySharedPointer (T* p): p_ (p) {}
+
+template <class T>
+template <class Deleter>
+inline QLazySharedPointer<T>::
+QLazySharedPointer (T* p, Deleter d): p_ (p, d) {}
+
+template <class T>
+inline QLazySharedPointer<T>::
+QLazySharedPointer (const QLazySharedPointer& r): p_ (r.p_), i_ (r.i_) {}
+
+template <class T>
+template <class X>
+inline QLazySharedPointer<T>::
+QLazySharedPointer (const QLazySharedPointer<X>& r): p_ (r.p_), i_ (r.i_) {}
+
+template <class T>
+template <class X>
+inline QLazySharedPointer<T>::
+QLazySharedPointer (const QLazyWeakPointer<X>& r): p_ (r.p_), i_ (r.i_) {}
+
+template <class T>
+inline QLazySharedPointer<T>::
+~QLazySharedPointer () {}
+
+template <class T>
+inline QLazySharedPointer<T>& QLazySharedPointer<T>::
+operator= (const QLazySharedPointer& r)
+{
+ p_ = r.p_;
+ i_ = r.i_;
+ return *this;
+}
+
+template <class T>
+template <class X>
+inline QLazySharedPointer<T>& QLazySharedPointer<T>::
+operator= (const QLazySharedPointer<X>& r)
+{
+ p_ = r.p_;
+ i_ = r.i_;
+ return *this;
+}
+
+template <class T>
+template <class X>
+inline QLazySharedPointer<T>& QLazySharedPointer<T>::
+operator= (const QLazyWeakPointer<X>& r)
+{
+ p_ = r.p_;
+ i_ = r.i_;
+ return *this;
+}
+
+template <class T>
+inline bool QLazySharedPointer<T>::
+operator! () const
+{
+ return isNull ();
+}
+
+template <class T>
+inline T& QLazySharedPointer<T>::
+operator* () const
+{
+ return *p_;
+}
+
+template <class T>
+inline T* QLazySharedPointer<T>::
+operator-> () const
+{
+ return p_.operator-> ();
+}
+
+template <class T>
+inline void QLazySharedPointer<T>::
+swap (QLazySharedPointer& x)
+{
+ p_.swap (x.p_);
+ i_.swap (x.i_);
+}
+
+template <class T>
+inline bool QLazySharedPointer<T>::
+isNull () const
+{
+ return !(p_ || i_);
+}
+
+template <class T>
+inline T* QLazySharedPointer<T>::
+data () const
+{
+ return p_.data ();
+}
+
+template <class T>
+inline QLazyWeakPointer<T> QLazySharedPointer<T>::
+toWeakRef () const
+{
+ return QLazyWeakPointer<T> (*this);
+}
+
+template <class T>
+inline void QLazySharedPointer<T>::
+clear ()
+{
+ p_.clear ();
+ i_.reset ();
+}
+
+template <class T>
+template <class X>
+inline QLazySharedPointer<X> QLazySharedPointer<T>::
+staticCast () const
+{
+ QLazySharedPointer c (p_.staticCast<X> ());
+ c.i_ = i_;
+ return c;
+}
+
+template <class T>
+template <class X>
+inline QLazySharedPointer<X> QLazySharedPointer<T>::
+dynamicCast () const
+{
+ QLazySharedPointer<X> c (p_.dynamicCast<X> ());
+
+ if (c)
+ c.i_ = i_;
+
+ return c;
+}
+
+template <class T>
+template <class X>
+inline QLazySharedPointer<X> QLazySharedPointer<T>::
+constCast () const
+{
+ QLazySharedPointer<X> c (p_.constCast<X> ());
+ c.i_ = i_;
+ return c;
+}
+
+template <class T>
+template <class Y>
+inline QLazySharedPointer<T>::
+QLazySharedPointer (const QSharedPointer<Y>& r): p_ (r) {}
+
+template <class T>
+template <class Y>
+inline QLazySharedPointer<T>::
+QLazySharedPointer (const QWeakPointer<Y>& r): p_ (r) {}
+
+template <class T>
+template <class X>
+inline QLazySharedPointer<T>& QLazySharedPointer<T>::
+operator= (const QSharedPointer<X>& r)
+{
+ p_ = r;
+ i_.reset ();
+ return *this;
+}
+
+template <class T>
+template <class X>
+inline QLazySharedPointer<T>& QLazySharedPointer<T>::
+operator= (const QWeakPointer<X>& r)
+{
+ p_ = r;
+ i_.reset ();
+ return *this;
+}
+
+template <class T>
+inline bool QLazySharedPointer<T>::
+loaded () const
+{
+ bool i (i_);
+ return !p_ != i; // !p_ XOR i_
+}
+
+template <class T>
+inline QSharedPointer<T> QLazySharedPointer<T>::
+load () const
+{
+ if (!loaded ())
+ p_ = i_.template load<T> (true); // Reset id.
+
+ return p_;
+}
+
+template <class T>
+inline void QLazySharedPointer<T>::
+unload () const
+{
+ typedef typename odb::object_traits<T>::object_type object_type;
+
+ if (p_)
+ {
+ if (i_.database () != 0)
+ i_.reset_id (odb::object_traits<object_type>::id (*p_));
+
+ p_.clear ();
+ }
+}
+
+template <class T>
+template <class ID>
+inline QLazySharedPointer<T>::
+QLazySharedPointer (database_type& db, const ID& id): i_ (db, id) {}
+
+template <class T>
+inline QLazySharedPointer<T>::
+QLazySharedPointer (database_type& db, T* p)
+ : p_ (p)
+{
+ if (p_)
+ i_.reset (db);
+}
+
+template <class T>
+template <class Deleter>
+inline QLazySharedPointer<T>::
+QLazySharedPointer (database_type& db, T* p, Deleter d)
+ : p_ (p, d)
+{
+ if (p_)
+ i_.reset (db);
+}
+
+template <class T>
+template <class Y>
+inline QLazySharedPointer<T>::
+QLazySharedPointer (database_type& db, const QSharedPointer<Y>& r)
+ : p_ (r)
+{
+ if (p_)
+ i_.reset (db);
+}
+
+template <class T>
+template <class Y>
+inline QLazySharedPointer<T>::
+QLazySharedPointer (database_type& db, const QWeakPointer<Y>& r)
+ : p_ (r)
+{
+ if (p_)
+ i_.reset (db);
+}
+
+template <class T>
+inline typename QLazySharedPointer<T>::database_type& QLazySharedPointer<T>::
+database () const
+{
+ return *i_.database ();
+}
+
+template <class T>
+template <class O>
+inline typename odb::object_traits<O>::id_type QLazySharedPointer<T>::
+objectId () const
+{
+ typedef typename odb::object_traits<T>::object_type object_type;
+
+ return p_ ?
+ odb::object_traits<object_type>::id (*p_) : i_.template object_id<O> ();
+}
+
+//
+// QLazySharedPointer related non-member function definitions.
+//
+
+template <class T, class X>
+inline QLazySharedPointer<X>
+qSharedPointerCast (const QLazySharedPointer<T>& r)
+{
+ return r.template staticCast<X> ();
+}
+
+template <class T, class X>
+inline QLazySharedPointer<X>
+qSharedPointerConstCast (const QLazySharedPointer<T>& r)
+{
+ return r.template constCast<X> ();
+}
+
+template <class T, class X>
+inline QLazySharedPointer<X>
+qSharedPointerDynamicCast (const QLazySharedPointer<T>& r)
+{
+ return r.template dynamicCast<X> ();
+}
+
+template <class T, class X>
+inline bool
+operator== (const QLazySharedPointer<T>& a, const QLazySharedPointer<X>& b)
+{
+ return a.equal (b);
+}
+
+template <class T, class X>
+inline bool
+operator!= (const QLazySharedPointer<T>& a, const QLazySharedPointer<X>& b)
+{
+ return !a.equal (b);
+}
+
+//
+// QLazyWeakPointer definition.
+//
+
+template <class T>
+inline QLazyWeakPointer<T>::
+QLazyWeakPointer () {}
+
+
+template <class T>
+inline QLazyWeakPointer<T>::
+QLazyWeakPointer (const QLazyWeakPointer& r): p_ (r.p_), i_ (r.i_) {}
+
+template <class T>
+template <class X>
+inline QLazyWeakPointer<T>::
+QLazyWeakPointer (const QLazyWeakPointer<X>& r): p_ (r.p_), i_ (r.i_) {}
+
+template <class T>
+template <class X>
+inline QLazyWeakPointer<T>::
+QLazyWeakPointer (const QLazySharedPointer<X>& r): p_ (r.p_), i_ (r.i_) {}
+
+template <class T>
+inline QLazyWeakPointer<T>::
+~QLazyWeakPointer () {}
+
+template <class T>
+inline QLazyWeakPointer<T>& QLazyWeakPointer<T>::
+operator= (const QLazyWeakPointer& r)
+{
+ p_ = r.p_;
+ i_ = r.i_;
+ return *this;
+}
+
+template <class T>
+template <class X>
+inline QLazyWeakPointer<T>& QLazyWeakPointer<T>::
+operator= (const QLazyWeakPointer<X>& r)
+{
+ p_ = r.p_;
+ i_ = r.i_;
+ return *this;
+}
+
+template <class T>
+template <class X>
+inline QLazyWeakPointer<T>& QLazyWeakPointer<T>::
+operator= (const QLazySharedPointer<X>& r)
+{
+ p_ = r.p_;
+ i_ = r.i_;
+ return *this;
+}
+
+template <class T>
+inline bool QLazyWeakPointer<T>::
+operator! () const
+{
+ return isNull ();
+}
+
+#ifdef QWEAKPOINTER_ENABLE_ARROW
+template <class T>
+inline T* QLazyWeakPointer<T>::
+operator-> () const
+{
+ return p_.operator-> ();
+}
+#endif
+
+template <class T>
+inline void QLazyWeakPointer<T>::
+clear ()
+{
+ p_.clear ();
+ i_.reset ();
+}
+
+template <class T>
+inline T* QLazyWeakPointer<T>::
+data () const
+{
+ return p_.data ();
+}
+
+template <class T>
+inline bool QLazyWeakPointer<T>::
+isNull () const
+{
+ return !(p_ || i_);
+}
+
+template <class T>
+template <class X>
+inline QLazyWeakPointer<T>::
+QLazyWeakPointer (const QWeakPointer<X>& r): p_ (r) {}
+
+template <class T>
+template <class X>
+inline QLazyWeakPointer<T>::
+QLazyWeakPointer (const QSharedPointer<X>& r): p_ (r) {}
+
+template <class T>
+template <class X>
+inline QLazyWeakPointer<T>& QLazyWeakPointer<T>::
+operator= (const QWeakPointer<X>& r)
+{
+ p_ = r;
+ i_.reset ();
+ return *this;
+}
+
+template <class T>
+template <class X>
+inline QLazyWeakPointer<T>& QLazyWeakPointer<T>::
+operator= (const QSharedPointer<X>& r)
+{
+ p_ = r;
+ i_.reset ();
+ return *this;
+}
+
+template <class T>
+inline bool QLazyWeakPointer<T>::
+loaded () const
+{
+ bool i (i_);
+ return p_.toStrongRef ().isNull () != i; // expired () XOR i_
+}
+
+template <class T>
+inline QSharedPointer<T> QLazyWeakPointer<T>::
+load () const
+{
+ QSharedPointer<T> r (p_.toStrongRef ());
+
+ if (r || !i_)
+ return r;
+
+ r = i_.template load<T> (false); // Keep id.
+ p_ = r;
+ return r;
+}
+
+template <class T>
+inline void QLazyWeakPointer<T>::
+unload () const
+{
+ // With weak pointer we always keep i_ up to date.
+ //
+ p_.clear ();
+}
+
+template <class T>
+template <class ID>
+inline QLazyWeakPointer<T>::
+QLazyWeakPointer (database_type& db, const ID& id): i_ (db, id) {}
+
+template <class T>
+template <class X>
+inline QLazyWeakPointer<T>::
+QLazyWeakPointer (database_type& db, const QSharedPointer<X>& r)
+ : p_ (r)
+{
+ typedef typename odb::object_traits<T>::object_type object_type;
+
+ if (r)
+ i_.reset (db, odb::object_traits<object_type>::id (*r));
+}
+
+template <class T>
+template <class X>
+inline QLazyWeakPointer<T>::
+QLazyWeakPointer (database_type& db, const QWeakPointer<X>& r)
+ : p_ (r)
+{
+ typedef typename odb::object_traits<T>::object_type object_type;
+
+ QSharedPointer<T> sp (p_.toStrongRef ());
+
+ if (sp)
+ i_.reset (db, odb::object_traits<object_type>::id (*sp));
+}
+
+template <class T>
+template <class O /* = T */>
+inline typename odb::object_traits<O>::id_type QLazyWeakPointer<T>::
+objectId () const
+{
+ typedef typename odb::object_traits<T>::object_type object_type;
+
+ QSharedPointer<T> sp (p_.toStrongRef ());
+
+ return sp ?
+ odb::object_traits<object_type>::id (*sp) :i_.template object_id<O> ();
+}
+
+template <class T>
+inline typename QLazyWeakPointer<T>::database_type& QLazyWeakPointer<T>::
+database () const
+{
+ return *i_.database ();
+}
+
+//
+// QLazyWeakPointer related non-member functions.
+//
+
+template <class T, class X>
+inline QLazySharedPointer<X>
+qSharedPointerCast (const QLazyWeakPointer<T>& r)
+{
+ return QLazySharedPointer<T> (r).template staticCast<X> ();
+}
+
+template <class T, class X>
+inline QLazySharedPointer<X>
+qSharedPointerConstCast (const QLazyWeakPointer<T>& r)
+{
+ return QLazySharedPointer<T> (r).template constCast<X> ();
+}
+
+template <class T, class X>
+inline QLazySharedPointer<X>
+qSharedPointerDynamicCast (const QLazyWeakPointer<T>& r)
+{
+ return QLazySharedPointer<T> (r).template dynamicCast<X> ();
+}
+
+template <class T, class X>
+inline QLazyWeakPointer<X>
+qWeakPointerCast (const QLazyWeakPointer<T>& r)
+{
+ return QLazySharedPointer<T> (r).template staticCast<X> ().toWeakRef ();
+}
+
+template <class T, class X>
+inline bool
+operator== (const QLazyWeakPointer<T>& t, const QLazyWeakPointer<X>& x)
+{
+ return t.equal (x);
+}
+
+template <class T, class X>
+inline bool
+operator== (const QLazyWeakPointer<T>& t, const QLazySharedPointer<X>& x)
+{
+ return t.equal (x);
+}
+
+template <class T, class X>
+inline bool
+operator== (const QLazySharedPointer<T>& t, const QLazyWeakPointer<X>& x)
+{
+ return x.equal (t);
+}
+
+template <class T, class X>
+inline bool
+operator!= (const QLazyWeakPointer<T>& t, const QLazyWeakPointer<X>& x)
+{
+ return !t.equal (x);
+}
+
+template <class T, class X>
+inline bool
+operator!= (const QLazyWeakPointer<T>& t, const QLazySharedPointer<X>& x)
+{
+ return !t.equal (x);
+}
+
+template <class T, class X>
+inline bool
+operator!= (const QLazySharedPointer<T>& t, const QLazyWeakPointer<X>& x)
+{
+ return !x.equal (t);
+}
diff --git a/odb/qt/smart-ptr/lazy-ptr.txx b/odb/qt/smart-ptr/lazy-ptr.txx
new file mode 100644
index 0000000..2323536
--- /dev/null
+++ b/odb/qt/smart-ptr/lazy-ptr.txx
@@ -0,0 +1,99 @@
+// file : odb/qt/smart-ptr/lazy-ptr.txx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+template <class T>
+template <class X>
+bool QLazySharedPointer<T>::
+equal (const QLazySharedPointer<X>& r) const
+{
+ bool t1 (!p_ == loaded ());
+ bool t2 (!r.p_ == r.loaded ());
+
+ // If both are transient, then compare the underlying pointers.
+ //
+ if (t1 && t2)
+ return p_ == r.p_;
+
+ // If one is transient and the other is persistent, then compare
+ // the underlying pointers but only if they are non NULL. Note
+ // that an unloaded persistent object is always unequal to a
+ // transient object.
+ //
+ if (t1 || t2)
+ return p_ == r.p_ && p_;
+
+ // If both objects are persistent, then we compare databases and
+ // object ids.
+ //
+ typedef typename odb::object_traits<T>::object_type object_type1;
+ typedef typename odb::object_traits<X>::object_type object_type2;
+
+ return i_.database () == r.i_.database () &&
+ objectId<object_type1> () == r.objectId<object_type2> ();
+}
+
+//
+// QLazyWeakPointer
+//
+
+template <class T>
+template <class X>
+bool QLazyWeakPointer<T>::
+equal (const QLazyWeakPointer<X>& r) const
+{
+ if (isNull () && r.isNull ())
+ return true;
+
+ QLazySharedPointer<T> sp1 (toStrongRef ());
+ QLazySharedPointer<T> sp2 (r.toStrongRef ());
+
+ // If either one has expired, they are not equal.
+ //
+ if (!sp1 || !sp2)
+ return false;
+
+ return sp1.equal (sp2);
+}
+
+template <class T>
+template <class X>
+bool QLazyWeakPointer<T>::
+equal (const QLazySharedPointer<X>& r) const
+{
+ if (isNull () && r.isNull ())
+ return true;
+
+ QLazySharedPointer<T> sp (toStrongRef ());
+
+ // If the weak pointer has expired, they are not equal.
+ //
+ if (!sp)
+ return false;
+
+ return r.equal (sp);
+}
+
+template <class T>
+QLazySharedPointer<T> QLazyWeakPointer<T>::
+toStrongRef () const
+{
+ QSharedPointer<T> sp (p_.toStrongRef ());
+
+ if (sp)
+ {
+ if (database_type* db = i_.database ())
+ return QLazySharedPointer<T> (*db, sp);
+ else
+ return QLazySharedPointer<T> (sp);
+ }
+ else
+ {
+ if (i_)
+ return QLazySharedPointer<T> (*i_.database (),
+ i_.template object_id<T> ());
+ else
+ return QLazySharedPointer<T> ();
+ }
+}
diff --git a/odb/qt/smart-ptr/pointer-traits.hxx b/odb/qt/smart-ptr/pointer-traits.hxx
new file mode 100644
index 0000000..488e1db
--- /dev/null
+++ b/odb/qt/smart-ptr/pointer-traits.hxx
@@ -0,0 +1,87 @@
+// file : odb/qt/smart-ptr/pointer-traits.hxx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_SMART_PTR_POINTER_TRAITS_HXX
+#define ODB_QT_SMART_PTR_POINTER_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <QSharedPointer>
+#include <QWeakPointer>
+
+#include <odb/pointer-traits.hxx>
+
+namespace odb
+{
+ // Specialization for QSharedPointer.
+ //
+ template <typename T>
+ class pointer_traits<QSharedPointer<T> >
+ {
+ public:
+ static const pointer_kind kind = pk_shared;
+ static const bool lazy = false;
+
+ typedef T element_type;
+ typedef QSharedPointer<element_type> pointer_type;
+ typedef QSharedPointer<const element_type> const_pointer_type;
+ typedef smart_ptr_guard<pointer_type> guard;
+
+ static element_type*
+ get_ptr (const pointer_type& p)
+ {
+ return p.data ();
+ }
+
+ static element_type&
+ get_ref (const pointer_type& p)
+ {
+ return *p;
+ }
+
+ static bool
+ null_ptr (const pointer_type& p)
+ {
+ return !p;
+ }
+
+ public:
+ static void*
+ allocate (std::size_t n)
+ {
+ return operator new (n);
+ }
+
+ static void
+ free (void* p)
+ {
+ operator delete (p);
+ }
+ };
+
+ // Specialization for QWeakPointer.
+ //
+ template <typename T>
+ class pointer_traits<QWeakPointer<T> >
+ {
+ public:
+ static const pointer_kind kind = pk_weak;
+ static const bool lazy = false;
+
+ typedef T element_type;
+ typedef QWeakPointer<element_type> pointer_type;
+ typedef QSharedPointer<element_type> strong_pointer_type;
+
+ static strong_pointer_type
+ lock (const pointer_type& p)
+ {
+ return p.toStrongRef ();
+ }
+ };
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_QT_SMART_PTR_POINTER_TRAITS_HXX
diff --git a/odb/qt/version.hxx b/odb/qt/version.hxx
index 9f97768..a186f40 100644
--- a/odb/qt/version.hxx
+++ b/odb/qt/version.hxx
@@ -29,15 +29,15 @@
// Check that we have compatible ODB version.
//
-#if ODB_VERSION != 10251
+#if ODB_VERSION != 10300
# error incompatible odb interface version detected
#endif
// libodb-qt version: odb interface version plus the bugfix
// version.
//
-#define LIBODB_QT_VERSION 1029951
-#define LIBODB_QT_VERSION_STR "1.3.0.b1"
+#define LIBODB_QT_VERSION 1030000
+#define LIBODB_QT_VERSION_STR "1.3.0"
#include <odb/post.hxx>
diff --git a/odb/qt/version.options b/odb/qt/version.options
index 13285bc..cbec4c6 100644
--- a/odb/qt/version.options
+++ b/odb/qt/version.options
@@ -8,6 +8,6 @@
#
--hxx-prologue '#include <odb/qt/version.hxx>'
---hxx-prologue '#if LIBODB_QT_VERSION != 1029951 // 1.3.0.b1'
+--hxx-prologue '#if LIBODB_QT_VERSION != 1030000 // 1.3.0'
--hxx-prologue '# error ODB and C++ compilers see different libodb-qt versions'
--hxx-prologue '#endif'
diff --git a/version b/version
index c92d778..f0bb29e 100644
--- a/version
+++ b/version
@@ -1 +1 @@
-1.3.0.b1
+1.3.0