From 5f1cd97b9727fe10df79e1eb316ff493d9dfc2a9 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 1 Feb 2024 20:50:43 +0300 Subject: Turn libodb-qt repository into package for muti-package repository --- libodb-qt/odb/qt/smart-ptr/lazy-ptr.hxx | 442 ++++++++++++++++++++++++++++++++ 1 file changed, 442 insertions(+) create mode 100644 libodb-qt/odb/qt/smart-ptr/lazy-ptr.hxx (limited to 'libodb-qt/odb/qt/smart-ptr/lazy-ptr.hxx') diff --git a/libodb-qt/odb/qt/smart-ptr/lazy-ptr.hxx b/libodb-qt/odb/qt/smart-ptr/lazy-ptr.hxx new file mode 100644 index 0000000..865e355 --- /dev/null +++ b/libodb-qt/odb/qt/smart-ptr/lazy-ptr.hxx @@ -0,0 +1,442 @@ +// file : odb/qt/smart-ptr/lazy-ptr.hxx +// 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 + +#include +#include +#include + +#include // odb::database +#include +#include +#include // ODB_CXX11 + +template +class QLazyWeakPointer; + +// +// QLazySharedPointer declaration. +// + +template +class QLazySharedPointer +{ + // The standard QSharedPointer interface. + // +public: + // These typedefs are inherited by QSharedPointer indirectly from + // QtSharedPointer::Basic + // + 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 + QLazySharedPointer (T*, Deleter); + + QLazySharedPointer (const QLazySharedPointer&); + + template + QLazySharedPointer (const QLazySharedPointer&); + + template + QLazySharedPointer (const QLazyWeakPointer&); + + ~QLazySharedPointer (); + + QLazySharedPointer& + operator= (const QLazySharedPointer&); + + template + QLazySharedPointer& + operator= (const QLazySharedPointer&); + + template + QLazySharedPointer& + operator= (const QLazyWeakPointer&); + + typedef QSharedPointer QLazySharedPointer::*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 + toWeakRef () const; + + void + clear (); + + template + QLazySharedPointer + staticCast () const; + + template + QLazySharedPointer + dynamicCast () const; + + template + QLazySharedPointer + constCast () const; + + // Initialization and assignment from QSharedPointer and QWeakPointer. + // +public: + template + QLazySharedPointer (const QSharedPointer&); + + template + explicit + QLazySharedPointer (const QWeakPointer&); + + template + QLazySharedPointer& + operator= (const QSharedPointer&); + + template + QLazySharedPointer& + operator= (const QWeakPointer&); + + // 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 + load () const; + + // Unload the pointer. For transient objects this function is + // equivalent to clear(). + // + void unload () const; + + // Get the underlying eager pointer. If this is an unloaded pointer + // to a persistent object, then the returned pointer will be NULL. + // + QSharedPointer + getEager () const; + + template + QLazySharedPointer (DB&, const ID&); + + template + QLazySharedPointer (DB&, T*); + + template + QLazySharedPointer (DB&, T*, Deleter); + + template + QLazySharedPointer (DB&, const QSharedPointer&); + + template + QLazySharedPointer (DB&, const QWeakPointer&); + +#ifdef ODB_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGUMENT + template +#else + template +#endif + typename odb::object_traits::id_type + objectId () const; + + database_type& + database () const; + + // Helpers. + // +public: + template + bool + equal (const QLazySharedPointer&) const; + +private: + template friend class QLazySharedPointer; + template friend class QLazyWeakPointer; + + // For QLazyWeakPointer::toStrongRef(). + // + QLazySharedPointer (const QSharedPointer& p, + const odb::lazy_ptr_impl& i) + : p_ (p), i_ (i) {} + +private: + mutable QSharedPointer p_; + mutable odb::lazy_ptr_impl i_; +}; + +// +// QLazySharedPointer related non-members. +// + +template +QLazySharedPointer +qSharedPointerCast (const QLazySharedPointer&); + +template +QLazySharedPointer +qSharedPointerConstCast (const QLazySharedPointer&); + +template +QLazySharedPointer +qSharedPointerDynamicCast (const QLazySharedPointer&); + +template +bool +operator== (const QLazySharedPointer&, const QLazySharedPointer&); + +template +bool +operator!= (const QLazySharedPointer&, const QLazySharedPointer&); + +// +// QLazyWeakPointer declaration +// + +template +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 + QLazyWeakPointer (const QLazyWeakPointer&); + + template + QLazyWeakPointer (const QLazySharedPointer&); + + ~QLazyWeakPointer (); + + QLazyWeakPointer& + operator= (const QLazyWeakPointer&); + + template + QLazyWeakPointer& + operator= (const QLazyWeakPointer&); + + template + QLazyWeakPointer& + operator= (const QLazySharedPointer&); + + typedef QWeakPointer QLazyWeakPointer::*unspecified_bool_type; + operator unspecified_bool_type () const + { + return isNull () ? 0 : &QLazyWeakPointer::p_; + } + + bool + operator! () const; + +#ifdef QWEAKPOINTER_ENABLE_ARROW + T* + operator-> () const; +#endif + + void + clear (); + + T* + data () const; + + bool + isNull () const; + + QLazySharedPointer + toStrongRef () const; + + // Initialization/assignment from QSharedPointer and QWeakPointer. + // +public: + template + QLazyWeakPointer (const QWeakPointer&); + + template + QLazyWeakPointer (const QSharedPointer&); + + template + QLazyWeakPointer& + operator= (const QWeakPointer&); + + template + QLazyWeakPointer& + operator= (const QSharedPointer&); + + // 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 + load () const; + + // Unload the pointer. For transient objects this function is equivalent + // to clear(). + // + void + unload () const; + + // Get the underlying eager pointer. If this is an unloaded pointer + // to a persistent object, then the returned pointer will be NULL. + // + QWeakPointer + getEager () const; + + template + QLazyWeakPointer (DB&, const ID&); + + template + QLazyWeakPointer (DB&, const QSharedPointer&); + + template + QLazyWeakPointer (DB&, const QWeakPointer&); + + // The objectId() function can only be called when the object is persistent, + // or: toStrongRef().isNull() XOR loaded() (can use != for XOR). + // +#ifdef ODB_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGUMENT + template +#else + template +#endif + typename odb::object_traits::id_type + objectId () const; + + database_type& + database () const; + + // Helpers. + // +public: + template + bool + equal (const QLazyWeakPointer&) const; + + template + bool + equal (const QLazySharedPointer&) const; + +private: + template friend class QLazySharedPointer; + template friend class QLazyWeakPointer; + + mutable QWeakPointer p_; + mutable odb::lazy_ptr_impl i_; +}; + +// +// QLazyWeakPointer related non-members. +// + +template +QLazySharedPointer +qSharedPointerCast (const QLazyWeakPointer&); + +template +QLazySharedPointer +qSharedPointerConstCast (const QLazyWeakPointer&); + +template +QLazySharedPointer +qSharedPointerDynamicCast (const QLazyWeakPointer&); + +template +QLazyWeakPointer +qWeakPointerCast (const QLazyWeakPointer&); + +template +bool +operator== (const QLazyWeakPointer&, const QLazyWeakPointer&); + +template +bool +operator== (const QLazyWeakPointer&, const QLazySharedPointer&); + +template +bool +operator== (const QLazySharedPointer&, const QLazyWeakPointer&); + +template +bool +operator!= (const QLazyWeakPointer&, const QLazyWeakPointer&); + +template +bool +operator!= (const QLazyWeakPointer&, const QLazySharedPointer&); + +template +bool +operator!= (const QLazySharedPointer&, const QLazyWeakPointer&); + +#include +#include + +#include + +#include + +#endif // ODB_QT_SMART_PTR_LAZY_PTR_HXX -- cgit v1.1