QxOrm  1.4.5
C++ Object Relational Mapping library

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>

List of all members.

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);

Definition at line 138 of file QxDaoPointer.h.


Constructor & Destructor Documentation

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

Definition at line 151 of file QxDaoPointer.h.

template<typename T>
qx::dao::ptr< T >::ptr ( T *  ptr) [inline, explicit]

Definition at line 152 of file QxDaoPointer.h.

template<typename T>
qx::dao::ptr< T >::ptr ( T *  ptr,
T *  original 
) [inline, explicit]

Definition at line 153 of file QxDaoPointer.h.

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

Definition at line 154 of file QxDaoPointer.h.

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

Definition at line 155 of file QxDaoPointer.h.

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.

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

Definition at line 157 of file QxDaoPointer.h.

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.

template<typename T>
virtual qx::dao::ptr< T >::~ptr ( ) [inline, virtual]

Definition at line 159 of file QxDaoPointer.h.

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

Definition at line 161 of file QxDaoPointer.h.

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.

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.

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

Definition at line 165 of file QxDaoPointer.h.

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.

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

Definition at line 167 of file QxDaoPointer.h.

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

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

Definition at line 187 of file QxDaoPointer.h.

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.

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

Definition at line 180 of file QxDaoPointer.h.

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

Definition at line 181 of file QxDaoPointer.h.

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.

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

Definition at line 178 of file QxDaoPointer.h.

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

Definition at line 179 of file QxDaoPointer.h.

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

Definition at line 191 of file QxDaoPointer.h.

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

Definition at line 200 of file QxDaoPointer.h.

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

Definition at line 182 of file QxDaoPointer.h.

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

Definition at line 183 of file QxDaoPointer.h.

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

Definition at line 184 of file QxDaoPointer.h.

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

Definition at line 185 of file QxDaoPointer.h.

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

Definition at line 186 of file QxDaoPointer.h.

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.

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.

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.

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.

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.

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.

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

Definition at line 188 of file QxDaoPointer.h.

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

Definition at line 189 of file QxDaoPointer.h.

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

Definition at line 190 of file QxDaoPointer.h.

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

Definition at line 194 of file QxDaoPointer.h.

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

Definition at line 193 of file QxDaoPointer.h.

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.

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

Definition at line 192 of file QxDaoPointer.h.


Friends And Related Function Documentation

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

Member Data Documentation

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.

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: