| QxOrm 1.1.8 C++ Object Relational Mapping library

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

QxDaoPointer.h
Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** http://www.qxorm.com/
    00004 ** http://sourceforge.net/projects/qxorm/
    00005 ** Original file by Lionel Marty
    00006 **
    00007 ** This file is part of the QxOrm library
    00008 **
    00009 ** This software is provided 'as-is', without any express or implied
    00010 ** warranty. In no event will the authors be held liable for any
    00011 ** damages arising from the use of this software.
    00012 **
    00013 ** GNU Lesser General Public License Usage
    00014 ** This file must be used under the terms of the GNU Lesser
    00015 ** General Public License version 2.1 as published by the Free Software
    00016 ** Foundation and appearing in the file 'license.lgpl.txt' included in the
    00017 ** packaging of this file.  Please review the following information to
    00018 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00019 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00020 **
    00021 ** If you have questions regarding the use of this file, please contact :
    00022 ** contact@qxorm.com
    00023 **
    00024 ****************************************************************************/
    00025
    00026 #ifndef _QX_DAO_POINTER_H_
    00027 #define _QX_DAO_POINTER_H_
    00028
    00029 #ifdef _MSC_VER
    00030 #pragma once
    00031 #endif
    00032
    00040 #include <QtCore/qsharedpointer.h>
    00041 #include <QtCore/qstringlist.h>
    00042
    00043 namespace qx {
    00044 namespace dao {
    00045
    00046 namespace detail {
    00047 template <class T> struct QxDao_IsDirty;
    00048 } // namespace detail
    00049
    00115 template <typename T>
    00116 class ptr
    00117 {
    00118
    00119 private:
    00120
    00121    QSharedPointer<T> m_pWork;
    00122    QSharedPointer<T> m_pOriginal;
    00123
    00124 public:
    00125
    00126    ptr()                                                                                                             { ; }
    00127    explicit ptr(T * ptr) : m_pWork(ptr)                                                                              { ; }
    00128    explicit ptr(T * ptr, T * original) : m_pWork(ptr), m_pOriginal(original)                                         { ; }
    00129    ptr(const qx::dao::ptr<T> & other) : m_pWork(other.m_pWork), m_pOriginal(other.m_pOriginal)                       { ; }
    00130    ptr(const QSharedPointer<T> & other) : m_pWork(other)                                                             { ; }
    00131    ptr(const QSharedPointer<T> & other, const QSharedPointer<T> & original) : m_pWork(other), m_pOriginal(original)  { ; }
    00132    ptr(const QWeakPointer<T> & other) : m_pWork(other)                                                               { ; }
    00133    ptr(const QWeakPointer<T> & other, const QWeakPointer<T> & original) : m_pWork(other), m_pOriginal(original)      { ; }
    00134    virtual ~ptr()                                                                                                    { ; }
    00135
    00136    template <typename Deleter> ptr(T * ptr, Deleter deleter) : m_pWork(ptr, deleter)                                       { ; }
    00137    template <typename Deleter> ptr(T * ptr, T * original, Deleter deleter) : m_pWork(ptr, deleter), m_pOriginal(original)  { ; }
    00138
    00139    template <class X> ptr(const qx::dao::ptr<X> & other) : m_pWork(qSharedPointerCast<T>(other.m_pWork)), m_pOriginal(qSharedPointerCast<T>(other.m_pOriginal))                                                { ; }
    00140    template <class X> ptr(const QSharedPointer<X> & other) : m_pWork(qSharedPointerCast<T>(other))                                                                                                             { ; }
    00141    template <class X> ptr(const QSharedPointer<X> & other, const QSharedPointer<T> & original) : m_pWork(qSharedPointerCast<T>(other)), m_pOriginal(qSharedPointerCast<T>(original))                           { ; }
    00142    template <class X> ptr(const QWeakPointer<X> & other) : m_pWork(qSharedPointerCast<T>(other.toStrongRef()))                                                                                                 { ; }
    00143    template <class X> ptr(const QWeakPointer<X> & other, const QWeakPointer<X> & original) : m_pWork(qSharedPointerCast<T>(other.toStrongRef())), m_pOriginal(qSharedPointerCast<T>(original.toStrongRef()))   { ; }
    00144
    00145    qx::dao::ptr<T> & operator=(const qx::dao::ptr<T> & other)     { m_pWork = other.m_pWork; m_pOriginal = other.m_pOriginal; return (* this); }
    00146    qx::dao::ptr<T> & operator=(const QSharedPointer<T> & other)   { m_pWork = other; m_pOriginal.clear(); return (* this); }
    00147    qx::dao::ptr<T> & operator=(const QWeakPointer<T> & other)     { m_pWork = other; m_pOriginal.clear(); return (* this); }
    00148
    00149    template <class X> qx::dao::ptr<T> & operator=(const qx::dao::ptr<X> & other)    { m_pWork = qSharedPointerCast<T>(other.m_pWork); m_pOriginal = qSharedPointerCast<T>(other.m_pOriginal); return (* this); }
    00150    template <class X> qx::dao::ptr<T> & operator=(const QSharedPointer<X> & other)  { m_pWork = qSharedPointerCast<T>(other); m_pOriginal.clear(); return (* this); }
    00151    template <class X> qx::dao::ptr<T> & operator=(const QWeakPointer<X> & other)    { m_pWork = qSharedPointerCast<T>(other.toStrongRef()); m_pOriginal.clear(); return (* this); }
    00152
    00153    inline T * get() const                                      { return m_pWork.data(); }
    00154    inline T * getOriginal() const                              { return m_pOriginal.data(); }
    00155    inline T * data() const                                     { return m_pWork.data(); }
    00156    inline T * dataOriginal() const                             { return m_pOriginal.data(); }
    00157    inline bool isNull() const                                  { return m_pWork.isNull(); }
    00158    inline operator bool() const                                { return (! m_pWork.isNull()); }
    00159    inline bool operator!() const                               { return m_pWork.isNull(); }
    00160    inline T & operator*() const                                { return (* m_pWork.data()); }
    00161    inline T * operator->() const                               { return m_pWork.data(); }
    00162    inline void clear()                                         { m_pWork.clear(); m_pOriginal.clear(); }
    00163    inline void reset()                                         { m_pWork.clear(); m_pOriginal.clear(); }
    00164    inline void reset(const QSharedPointer<T> & ptr)            { m_pWork = ptr; m_pOriginal.clear(); }
    00165    inline void resetOriginal(const QSharedPointer<T> & ptr)    { m_pOriginal = ptr; }
    00166    inline bool isDirty() const                                 { QStringList lstDiff; return isDirty(lstDiff); }
    00167    inline QSharedPointer<T> toQtSharedPointer() const          { return m_pWork; }
    00168
    00169    template <class X> qx::dao::ptr<X> staticCast() const       { return qx::dao::ptr<X>(m_pWork.staticCast<X>(), m_pOriginal.staticCast<X>()); }
    00170    template <class X> qx::dao::ptr<X> dynamicCast() const      { return qx::dao::ptr<X>(m_pWork.dynamicCast<X>(), m_pOriginal.dynamicCast<X>()); }
    00171    template <class X> qx::dao::ptr<X> constCast() const        { return qx::dao::ptr<X>(m_pWork.constCast<X>(), m_pOriginal.constCast<X>()); }
    00172
    00173    bool isDirty(QStringList & lstDiff) const
    00174    {
    00175       lstDiff.clear();
    00176       if (m_pWork.isNull() || m_pOriginal.isNull()) { lstDiff.append("*"); return true; }
    00177       if (m_pWork == m_pOriginal) { return false; }
    00178       qx::dao::detail::QxDao_IsDirty<T>::compare((* m_pWork), (* m_pOriginal), lstDiff);
    00179       return (! lstDiff.isEmpty());
    00180    }
    00181
    00182 };
    00183
    00184 } // namespace dao
    00185 } // namespace qx
    00186
    00187 template<class T, class X> bool operator==(const qx::dao::ptr<T> & ptr1, const qx::dao::ptr<X> & ptr2)   { return (ptr1.toQtSharedPointer() == ptr2.toQtSharedPointer()); }
    00188 template<class T, class X> bool operator!=(const qx::dao::ptr<T> & ptr1, const qx::dao::ptr<X> & ptr2)   { return (ptr1.toQtSharedPointer() != ptr2.toQtSharedPointer()); }
    00189 template<class T, class X> bool operator==(const qx::dao::ptr<T> & ptr1, const X * ptr2)                 { return (ptr1.toQtSharedPointer() == ptr2); }
    00190 template<class T, class X> bool operator!=(const qx::dao::ptr<T> & ptr1, const X * ptr2)                 { return (ptr1.toQtSharedPointer() != ptr2); }
    00191 template<class T, class X> bool operator==(const T * ptr1, const qx::dao::ptr<X> & ptr2)                 { return (ptr1 == ptr2.toQtSharedPointer()); }
    00192 template<class T, class X> bool operator!=(const T * ptr1, const qx::dao::ptr<X> & ptr2)                 { return (ptr1 != ptr2.toQtSharedPointer()); }
    00193
    00194 #endif // _QX_DAO_POINTER_H_

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines