QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches

qx::dao::ptr<T> : provide a classic smart-pointer (like boost::shared_ptr<T> or QSharedPointer<T>) with some features associated with QxDao module of QxOrm library More...

#include <QxDaoPointer.h>

Public Member Functions

 ptr ()
 
 ptr (T *ptr)
 
 ptr (T *ptr, T *original)
 
 ptr (const qx::dao::ptr< T > &other)
 
 ptr (const QSharedPointer< T > &other)
 
 ptr (const QSharedPointer< T > &other, const QSharedPointer< T > &original)
 
 ptr (const QWeakPointer< T > &other)
 
 ptr (const QWeakPointer< T > &other, const QWeakPointer< T > &original)
 
virtual ~ptr ()
 
template<typename Deleter >
 ptr (T *ptr, Deleter deleter)
 
template<typename Deleter >
 ptr (T *ptr, T *original, Deleter deleter)
 
template<class X >
 ptr (const qx::dao::ptr< X > &other)
 
template<class X >
 ptr (const QSharedPointer< X > &other)
 
template<class X >
 ptr (const QSharedPointer< X > &other, const QSharedPointer< T > &original)
 
template<class X >
 ptr (const QWeakPointer< X > &other)
 
template<class X >
 ptr (const QWeakPointer< X > &other, const QWeakPointer< X > &original)
 
qx::dao::ptr< T > & operator= (const qx::dao::ptr< T > &other)
 
qx::dao::ptr< T > & operator= (const QSharedPointer< T > &other)
 
qx::dao::ptr< T > & operator= (const QWeakPointer< T > &other)
 
template<class X >
qx::dao::ptr< T > & operator= (const qx::dao::ptr< X > &other)
 
template<class X >
qx::dao::ptr< T > & operator= (const QSharedPointer< X > &other)
 
template<class X >
qx::dao::ptr< T > & operator= (const QWeakPointer< X > &other)
 
T * get () const
 
T * getOriginal () const
 
T * data () const
 
T * dataOriginal () const
 
bool isNull () const
 
 operator bool () const
 
bool operator! () const
 
T & operator* () const
 
T * operator-> () const
 
void clear ()
 
void reset ()
 
void reset (const QSharedPointer< T > &ptr)
 
void resetOriginal (const QSharedPointer< T > &ptr)
 
bool isDirty () const
 
QSharedPointer< T > toQtSharedPointer () const
 
void saveToOriginal ()
 
void restoreFromOriginal ()
 
template<class X >
qx::dao::ptr< X > staticCast () const
 
template<class X >
qx::dao::ptr< X > dynamicCast () const
 
template<class X >
qx::dao::ptr< X > constCast () const
 
bool isDirty (QStringList &lstDiff) const
 

Private Attributes

QSharedPointer< T > m_pWork
 Default pointer => user works with this pointer.
 
QSharedPointer< T > m_pOriginal
 Keep original pointer containing all values from database.
 

Friends

template<class U >
QDataStream & operator<< (QDataStream &stream, const qx::dao::ptr< U > &t)
 
template<class U >
QDataStream & operator>> (QDataStream &stream, qx::dao::ptr< U > &t)
 

Detailed Description

template<typename T>
class qx::dao::ptr< T >

qx::dao::ptr<T> : provide a classic smart-pointer (like boost::shared_ptr<T> or QSharedPointer<T>) with some features associated with QxDao module of QxOrm library

QxOrm can be used with smart-pointers of boost and Qt libraries. QxOrm smart-pointer is based on QSharedPointer and provides new features with qx::dao::xxx functions of QxDao module. qx::dao::ptr<T> keeps automatically values from database. So it's possible to detect if an instance has been modified using the method isDirty() : this method can return list of properties changed. qx::dao::ptr<T> can also be used with the function qx::dao::update_optimized() to update in database only properties changed. qx::dao::ptr<T> can be used with a simple object and with many containers : stl, boost, Qt and qx::QxCollection<Key, Value>.

Quick sample using qx::dao::ptr<T> smart-pointer :

// Test 'isDirty()' method
qx::dao::ptr<blog> blog_isdirty = qx::dao::ptr<blog>(new blog());
blog_isdirty->m_id = blog_1->m_id;
daoError = qx::dao::fetch_by_id(blog_isdirty);
qAssert(! daoError.isValid() && ! blog_isdirty.isDirty());
blog_isdirty->m_text = "blog property 'text' modified => blog is dirty !!!";
QStringList lstDiff; bool bDirty = blog_isdirty.isDirty(lstDiff);
qAssert(bDirty && (lstDiff.count() == 1) && (lstDiff.at(0) == "blog_text"));
if (bDirty) { qDebug("[QxOrm] test dirty 1 : blog is dirty => '%s'", qPrintable(lstDiff.join("|"))); }
// Update only property 'm_text' of 'blog_isdirty'
daoError = qx::dao::update_optimized(blog_isdirty);
qAssert(! daoError.isValid() && ! blog_isdirty.isDirty());
qx::dump(blog_isdirty);
// Test 'isDirty()' method with a container
typedef qx::dao::ptr< QList<author_ptr> > type_lst_author_test_is_dirty;
type_lst_author_test_is_dirty container_isdirty = type_lst_author_test_is_dirty(new QList<author_ptr>());
daoError = qx::dao::fetch_all(container_isdirty);
qAssert(! daoError.isValid() && ! container_isdirty.isDirty() && (container_isdirty->count() == 3));
author_ptr author_ptr_dirty = container_isdirty->at(1);
author_ptr_dirty->m_name = "author name modified at index 1 => container is dirty !!!";
bDirty = container_isdirty.isDirty(lstDiff);
qAssert(bDirty && (lstDiff.count() == 1));
if (bDirty) { qDebug("[QxOrm] test dirty 2 : container is dirty => '%s'", qPrintable(lstDiff.join("|"))); }
author_ptr_dirty = container_isdirty->at(2);
author_ptr_dirty->m_birthdate = QDate(1998, 03, 06);
bDirty = container_isdirty.isDirty(lstDiff);
qAssert(bDirty && (lstDiff.count() == 2));
if (bDirty) { qDebug("[QxOrm] test dirty 3 : container is dirty => '%s'", qPrintable(lstDiff.join("|"))); }
// Update only property 'm_name' at position 1, only property 'm_birthdate' at position 2 and nothing at position 0
daoError = qx::dao::update_optimized(container_isdirty);
qAssert(! daoError.isValid() && ! container_isdirty.isDirty());
qx::dump(container_isdirty);
// Fetch only property 'm_dt_creation' of blog
QStringList lstColumns = QStringList() << "date_creation";
list_blog lst_blog_with_only_date_creation;
daoError = qx::dao::fetch_all(lst_blog_with_only_date_creation, NULL, lstColumns);
qAssert(! daoError.isValid() && (lst_blog_with_only_date_creation.size() > 0));
if ((lst_blog_with_only_date_creation.size() > 0) && (lst_blog_with_only_date_creation[0] != NULL))
{ qAssert(lst_blog_with_only_date_creation[0]->m_text.isEmpty()); }
qx::dump(lst_blog_with_only_date_creation);
#define qAssert(x)
Definition QxMacro.h:52
qx::dao::ptr<T> : provide a classic smart-pointer (like boost::shared_ptr<T> or QSharedPointer<T>) wi...
bool isDirty() const
QSqlError fetch_by_id(T &t, QSqlDatabase *pDatabase=NULL, const QStringList &columns=QStringList())
Fetch an object t (retrieve all its properties) of type T (registered into QxOrm context) mapped to a...
Definition QxDao.h:636
QSqlError fetch_all(T &t, QSqlDatabase *pDatabase=NULL, const QStringList &columns=QStringList())
Fetch a list of objects (retrieve all elements and properties associated) of type T (container regist...
Definition QxDao.h:651
QSqlError update_optimized(qx::dao::ptr< T > &ptr, QSqlDatabase *pDatabase=NULL, bool bUseExecBatch=false)
Update only modified fields/properties of an element or a list of elements into database (using is di...
Definition QxDao.h:715
void dump(const T &t, bool bJsonFormat=false)
qx::dump(const T & t, bool bJsonFormat) : dump class of type T registered into QxOrm context using XM...
Definition QxDump.h:63

Definition at line 138 of file QxDaoPointer.h.

Constructor & Destructor Documentation

◆ ptr() [1/15]

template<typename T >
qx::dao::ptr< T >::ptr ( )
inline

Definition at line 151 of file QxDaoPointer.h.

◆ ptr() [2/15]

template<typename T >
qx::dao::ptr< T >::ptr ( T * ptr)
inlineexplicit

Definition at line 152 of file QxDaoPointer.h.

◆ ptr() [3/15]

template<typename T >
qx::dao::ptr< T >::ptr ( T * ptr,
T * original )
inlineexplicit

Definition at line 153 of file QxDaoPointer.h.

◆ ptr() [4/15]

template<typename T >
qx::dao::ptr< T >::ptr ( const qx::dao::ptr< T > & other)
inline

Definition at line 154 of file QxDaoPointer.h.

◆ ptr() [5/15]

template<typename T >
qx::dao::ptr< T >::ptr ( const QSharedPointer< T > & other)
inline

Definition at line 155 of file QxDaoPointer.h.

◆ ptr() [6/15]

template<typename T >
qx::dao::ptr< T >::ptr ( const QSharedPointer< T > & other,
const QSharedPointer< T > & original )
inline

Definition at line 156 of file QxDaoPointer.h.

◆ ptr() [7/15]

template<typename T >
qx::dao::ptr< T >::ptr ( const QWeakPointer< T > & other)
inline

Definition at line 157 of file QxDaoPointer.h.

◆ ptr() [8/15]

template<typename T >
qx::dao::ptr< T >::ptr ( const QWeakPointer< T > & other,
const QWeakPointer< T > & original )
inline

Definition at line 158 of file QxDaoPointer.h.

◆ ~ptr()

template<typename T >
virtual qx::dao::ptr< T >::~ptr ( )
inlinevirtual

Definition at line 159 of file QxDaoPointer.h.

◆ ptr() [9/15]

template<typename T >
template<typename Deleter >
qx::dao::ptr< T >::ptr ( T * ptr,
Deleter deleter )
inline

Definition at line 161 of file QxDaoPointer.h.

◆ ptr() [10/15]

template<typename T >
template<typename Deleter >
qx::dao::ptr< T >::ptr ( T * ptr,
T * original,
Deleter deleter )
inline

Definition at line 162 of file QxDaoPointer.h.

◆ ptr() [11/15]

template<typename T >
template<class X >
qx::dao::ptr< T >::ptr ( const qx::dao::ptr< X > & other)
inline

Definition at line 164 of file QxDaoPointer.h.

◆ ptr() [12/15]

template<typename T >
template<class X >
qx::dao::ptr< T >::ptr ( const QSharedPointer< X > & other)
inline

Definition at line 165 of file QxDaoPointer.h.

◆ ptr() [13/15]

template<typename T >
template<class X >
qx::dao::ptr< T >::ptr ( const QSharedPointer< X > & other,
const QSharedPointer< T > & original )
inline

Definition at line 166 of file QxDaoPointer.h.

◆ ptr() [14/15]

template<typename T >
template<class X >
qx::dao::ptr< T >::ptr ( const QWeakPointer< X > & other)
inline

Definition at line 167 of file QxDaoPointer.h.

◆ ptr() [15/15]

template<typename T >
template<class X >
qx::dao::ptr< T >::ptr ( const QWeakPointer< X > & other,
const QWeakPointer< X > & original )
inline

Definition at line 168 of file QxDaoPointer.h.

Member Function Documentation

◆ clear()

template<typename T >
void qx::dao::ptr< T >::clear ( )
inline

Definition at line 187 of file QxDaoPointer.h.

◆ constCast()

template<typename T >
template<class X >
qx::dao::ptr< X > qx::dao::ptr< T >::constCast ( ) const
inline

Definition at line 198 of file QxDaoPointer.h.

◆ data()

template<typename T >
T * qx::dao::ptr< T >::data ( ) const
inline

Definition at line 180 of file QxDaoPointer.h.

◆ dataOriginal()

template<typename T >
T * qx::dao::ptr< T >::dataOriginal ( ) const
inline

Definition at line 181 of file QxDaoPointer.h.

◆ dynamicCast()

template<typename T >
template<class X >
qx::dao::ptr< X > qx::dao::ptr< T >::dynamicCast ( ) const
inline

Definition at line 197 of file QxDaoPointer.h.

◆ get()

template<typename T >
T * qx::dao::ptr< T >::get ( ) const
inline

Definition at line 178 of file QxDaoPointer.h.

◆ getOriginal()

template<typename T >
T * qx::dao::ptr< T >::getOriginal ( ) const
inline

Definition at line 179 of file QxDaoPointer.h.

◆ isDirty() [1/2]

template<typename T >
bool qx::dao::ptr< T >::isDirty ( ) const
inline

Definition at line 191 of file QxDaoPointer.h.

◆ isDirty() [2/2]

template<typename T >
bool qx::dao::ptr< T >::isDirty ( QStringList & lstDiff) const
inline

Definition at line 200 of file QxDaoPointer.h.

◆ isNull()

template<typename T >
bool qx::dao::ptr< T >::isNull ( ) const
inline

Definition at line 182 of file QxDaoPointer.h.

◆ operator bool()

template<typename T >
qx::dao::ptr< T >::operator bool ( ) const
inline

Definition at line 183 of file QxDaoPointer.h.

◆ operator!()

template<typename T >
bool qx::dao::ptr< T >::operator! ( ) const
inline

Definition at line 184 of file QxDaoPointer.h.

◆ operator*()

template<typename T >
T & qx::dao::ptr< T >::operator* ( ) const
inline

Definition at line 185 of file QxDaoPointer.h.

◆ operator->()

template<typename T >
T * qx::dao::ptr< T >::operator-> ( ) const
inline

Definition at line 186 of file QxDaoPointer.h.

◆ operator=() [1/6]

template<typename T >
qx::dao::ptr< T > & qx::dao::ptr< T >::operator= ( const QSharedPointer< T > & other)
inline

Definition at line 171 of file QxDaoPointer.h.

◆ operator=() [2/6]

template<typename T >
template<class X >
qx::dao::ptr< T > & qx::dao::ptr< T >::operator= ( const QSharedPointer< X > & other)
inline

Definition at line 175 of file QxDaoPointer.h.

◆ operator=() [3/6]

template<typename T >
qx::dao::ptr< T > & qx::dao::ptr< T >::operator= ( const QWeakPointer< T > & other)
inline

Definition at line 172 of file QxDaoPointer.h.

◆ operator=() [4/6]

template<typename T >
template<class X >
qx::dao::ptr< T > & qx::dao::ptr< T >::operator= ( const QWeakPointer< X > & other)
inline

Definition at line 176 of file QxDaoPointer.h.

◆ operator=() [5/6]

template<typename T >
qx::dao::ptr< T > & qx::dao::ptr< T >::operator= ( const qx::dao::ptr< T > & other)
inline

Definition at line 170 of file QxDaoPointer.h.

◆ operator=() [6/6]

template<typename T >
template<class X >
qx::dao::ptr< T > & qx::dao::ptr< T >::operator= ( const qx::dao::ptr< X > & other)
inline

Definition at line 174 of file QxDaoPointer.h.

◆ reset() [1/2]

template<typename T >
void qx::dao::ptr< T >::reset ( )
inline

Definition at line 188 of file QxDaoPointer.h.

◆ reset() [2/2]

template<typename T >
void qx::dao::ptr< T >::reset ( const QSharedPointer< T > & ptr)
inline

Definition at line 189 of file QxDaoPointer.h.

◆ resetOriginal()

template<typename T >
void qx::dao::ptr< T >::resetOriginal ( const QSharedPointer< T > & ptr)
inline

Definition at line 190 of file QxDaoPointer.h.

◆ restoreFromOriginal()

template<typename T >
void qx::dao::ptr< T >::restoreFromOriginal ( )
inline

Definition at line 194 of file QxDaoPointer.h.

◆ saveToOriginal()

template<typename T >
void qx::dao::ptr< T >::saveToOriginal ( )
inline

Definition at line 193 of file QxDaoPointer.h.

◆ staticCast()

template<typename T >
template<class X >
qx::dao::ptr< X > qx::dao::ptr< T >::staticCast ( ) const
inline

Definition at line 196 of file QxDaoPointer.h.

◆ toQtSharedPointer()

template<typename T >
QSharedPointer< T > qx::dao::ptr< T >::toQtSharedPointer ( ) const
inline

Definition at line 192 of file QxDaoPointer.h.

Friends And Related Symbol Documentation

◆ operator<<

template<typename T >
template<class U >
QDataStream & operator<< ( QDataStream & stream,
const qx::dao::ptr< U > & t )
friend

◆ operator>>

template<typename T >
template<class U >
QDataStream & operator>> ( QDataStream & stream,
qx::dao::ptr< U > & t )
friend

Member Data Documentation

◆ m_pOriginal

template<typename T >
QSharedPointer<T> qx::dao::ptr< T >::m_pOriginal
private

Keep original pointer containing all values from database.

Definition at line 147 of file QxDaoPointer.h.

◆ m_pWork

template<typename T >
QSharedPointer<T> qx::dao::ptr< T >::m_pWork
private

Default pointer => user works with this pointer.

Definition at line 146 of file QxDaoPointer.h.


The documentation for this class was generated from the following file: