QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
QxDao_IsDirty.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** https://www.qxorm.com/
4** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
5**
6** This file is part of the QxOrm library
7**
8** This software is provided 'as-is', without any express or implied
9** warranty. In no event will the authors be held liable for any
10** damages arising from the use of this software
11**
12** Commercial Usage
13** Licensees holding valid commercial QxOrm licenses may use this file in
14** accordance with the commercial license agreement provided with the
15** Software or, alternatively, in accordance with the terms contained in
16** a written agreement between you and Lionel Marty
17**
18** GNU General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU
20** General Public License version 3.0 as published by the Free Software
21** Foundation and appearing in the file 'license.gpl3.txt' included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU General Public License version 3.0 requirements will be
24** met : http://www.gnu.org/copyleft/gpl.html
25**
26** If you are unsure which license is appropriate for your use, or
27** if you have questions regarding the use of this file, please contact :
28** contact@qxorm.com
29**
30****************************************************************************/
31
32#ifndef _QX_DAO_IS_DIRTY_H_
33#define _QX_DAO_IS_DIRTY_H_
34
35#ifdef _MSC_VER
36#pragma once
37#endif
38
39#include <QtCore/qstringlist.h>
40
42#include <QxDao/IxSqlRelation.h>
43
48
49namespace qx {
50namespace dao {
51namespace detail {
52
53template <class T>
54inline void is_dirty(const T & obj1, const T & obj2, QStringList & lstDiff);
55
56template <class T>
58{
59
60 static void compare(const T & obj1, const T & obj2, QStringList & lstDiff)
61 {
62 static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
63
64 qx::QxSqlQueryBuilder_Count<T> builder; builder.init();
65 qx::IxDataMember * pId = builder.getDataId();
66 if (pId && (! pId->isEqual((& obj1), (& obj2)))) { lstDiff.append(pId->getKey()); }
67
68 long l = 0;
69 qx::IxDataMember * p = NULL;
70 while ((p = builder.nextData(l)))
71 { if (p && (! p->isEqual((& obj1), (& obj2)))) { lstDiff.append(p->getKey()); } }
72 }
73
74};
75
76template <class T>
78{
79
80 static void compare(const T & obj1, const T & obj2, QStringList & lstDiff)
81 {
82 if (qx::trait::generic_container<T>::size(obj1) <= 0) { return; }
83 if (qx::trait::generic_container<T>::size(obj1) != qx::trait::generic_container<T>::size(obj2)) { lstDiff.append("*"); return; }
84
85 long lCurrIndex = 0;
86 typename T::const_iterator it2 = obj2.begin();
87
88 for (typename T::const_iterator it1 = obj1.begin(); it1 != obj1.end(); ++it1)
89 {
90 QStringList lstDiffItem;
91 qx::dao::detail::is_dirty((* it1), (* it2), lstDiffItem);
92 if (lstDiffItem.count() > 0) { lstDiff.append(QString::number(lCurrIndex) + "|" + lstDiffItem.join("|")); }
93 ++lCurrIndex; ++it2;
94 }
95 }
96
97};
98
99template <class T>
101{
102
103 static void compare(const T & obj1, const T & obj2, QStringList & lstDiff)
104 { qx::dao::detail::is_dirty((* obj1), (* obj2), lstDiff); }
105
106};
107
108template <class T>
109struct QxDao_IsDirty
110{
111
112 static void compare(const T & obj1, const T & obj2, QStringList & lstDiff)
113 {
114 typedef typename std::conditional< std::is_pointer<T>::value, qx::dao::detail::QxDao_IsDirty_Ptr<T>, qx::dao::detail::QxDao_IsDirty_Generic<T> >::type type_dao_1;
115 typedef typename std::conditional< qx::trait::is_smart_ptr<T>::value, qx::dao::detail::QxDao_IsDirty_Ptr<T>, type_dao_1 >::type type_dao_2;
116 typedef typename std::conditional< qx::trait::is_container<T>::value, qx::dao::detail::QxDao_IsDirty_Container<T>, type_dao_2 >::type type_dao_3;
117 type_dao_3::compare(obj1, obj2, lstDiff);
118 }
119
120};
121
122template <class T>
123inline void is_dirty(const T & obj1, const T & obj2, QStringList & lstDiff)
124{ return qx::dao::detail::QxDao_IsDirty<T>::compare(obj1, obj2, lstDiff); }
125
126} // namespace detail
127} // namespace dao
128} // namespace qx
129
130#endif // _QX_DAO_IS_DIRTY_H_
Common interface for all relationships defined between 2 classes (or between 2 tables in database)
Concrete SQL query builder by class with a cache mechanism to backup and restore queries already buil...
qx::IxDataMember : common interface for all class properties registered into QxOrm context
QString getKey() const
virtual bool isEqual(const void *pOwner1, const void *pOwner2) const =0
IxDataMember * nextData(long &l) const
IxDataMember * getDataId() const
qx::QxSqlQueryBuilder_Count<T> : concrete SQL query builder for class T to build a COUNT SQL query
qx::trait::generic_container<T> : provide some tools to manage all containers without knowing its typ...
qx::trait::is_container<T>::value : return true if T is a container from stl, boost,...
qx::trait::is_qx_registered<T>::value : return true if T is registered into QxOrm context to provide ...
qx::trait::is_smart_ptr<T>::value : return true if T is a smart-pointer of boost, Qt or QxOrm librari...
void is_dirty(const T &obj1, const T &obj2, QStringList &lstDiff)
Root namespace for all QxOrm library features.
static void compare(const T &obj1, const T &obj2, QStringList &lstDiff)
static void compare(const T &obj1, const T &obj2, QStringList &lstDiff)
static void compare(const T &obj1, const T &obj2, QStringList &lstDiff)
static void compare(const T &obj1, const T &obj2, QStringList &lstDiff)
qx::trait::generic_container<T> : provide some tools to manage all containers without knowing its typ...
qx::trait::is_qx_registered<T>::value : return true if T is registered into QxOrm context to provide ...