QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
QxValidatorFct.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_VALIDATOR_FUNCTION_H_
33#define _QX_VALIDATOR_FUNCTION_H_
34
35#ifdef _MSC_VER
36#pragma once
37#endif
38
48
49#include <QxRegister/QxClass.h>
50
54
55namespace qx {
56template <class T>
57QxInvalidValueX validate(T & t, const QString & group);
58} // namespace qx
59
60namespace qx {
61namespace validator {
62namespace detail {
63
64template <class T>
66{
67
68 static inline qx::QxInvalidValueX validate(T & t, const QString & group)
69 {
70 static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
71
72 qx::QxInvalidValueX invalidValues;
74 if (! pClass) { qAssert(false); return invalidValues; }
75 qx::IxValidatorX * pAllValidator = pClass->getAllValidator();
76 if (! pAllValidator) { return invalidValues; }
77 invalidValues.setCurrentPath(pClass->getName());
78 invalidValues.insert(pAllValidator->validate((& t), group));
79 return invalidValues;
80 }
81
82};
83
84template <class T>
86{
87
88 static inline qx::QxInvalidValueX validate(T & t, const QString & group)
89 {
90 qx::QxInvalidValueX invalidValues; long lIndex = 0;
91 for (typename T::iterator it = t.begin(); it != t.end(); ++it)
92 {
93 invalidValues.setCurrentPath("[" + QString::number(lIndex) + "]");
94 invalidValues.insert(validateItem((* it), group));
95 lIndex++;
96 }
97 return invalidValues;
98 }
99
100private:
101
102 template <typename U>
103 static inline qx::QxInvalidValueX validateItem(U & item, const QString & group)
105
106 template <typename U, bool bIsPointer /* = true */>
108 {
109 static inline qx::QxInvalidValueX validate(U & item, const QString & group)
111 };
112
113 template <typename U1, typename U2>
114 struct validateItem_Helper<std::pair<U1, U2>, false>
115 {
116 static inline qx::QxInvalidValueX validate(std::pair<U1, U2> & item, const QString & group)
118 };
119
120 template <typename U1, typename U2>
121 struct validateItem_Helper<const std::pair<U1, U2>, false>
122 {
123 static inline qx::QxInvalidValueX validate(const std::pair<U1, U2> & item, const QString & group)
125 };
126
127#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
128 template <typename U1, typename U2>
129 struct validateItem_Helper<QPair<U1, U2>, false>
130 {
131 static inline qx::QxInvalidValueX validate(QPair<U1, U2> & item, const QString & group)
133 };
134
135 template <typename U1, typename U2>
136 struct validateItem_Helper<const QPair<U1, U2>, false>
137 {
138 static inline qx::QxInvalidValueX validate(const QPair<U1, U2> & item, const QString & group)
140 };
141#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
142
143 template <typename U>
144 struct validateItem_Helper<U, false>
145 { static qx::QxInvalidValueX validate(U & item, const QString & group) { return qx::validate(item, group); } };
146
147};
148
149template <class T>
151{
152
153 static inline qx::QxInvalidValueX validate(T & t, const QString & group)
154 { return (t ? qx::validate((* t), group) : qx::QxInvalidValueX()); }
155
156};
157
158template <class T>
160{
161
162 static inline qx::QxInvalidValueX validate(T & t, const QString & group)
163 {
164 typedef typename std::conditional< std::is_pointer<T>::value, qx::validator::detail::QxValidator_Helper_Ptr<T>, qx::validator::detail::QxValidator_Helper_Generic<T> >::type type_validator_1;
165 typedef typename std::conditional< qx::trait::is_smart_ptr<T>::value, qx::validator::detail::QxValidator_Helper_Ptr<T>, type_validator_1 >::type type_validator_2;
166 typedef typename std::conditional< qx::trait::is_container<T>::value, qx::validator::detail::QxValidator_Helper_Container<T>, type_validator_2 >::type type_validator_3;
167
168 return type_validator_3::validate(t, group);
169 }
170
171};
172
173} // namespace detail
174} // namespace validator
175} // namespace qx
176
177namespace qx {
178
179template <class T>
180QxInvalidValueX validate(T & t, const QString & group)
182
183template <class T>
186
187template <class T>
188QxInvalidValueX validate(T & t, const QStringList & groups)
189{
190 QxInvalidValueX invalidValues;
191 if (groups.count() <= 0) { return qx::validate(t); }
192 for (long l = 0; l < groups.count(); l++) { invalidValues.insert(qx::validate(t, groups.at(l))); }
193 return invalidValues;
194}
195
196} // namespace qx
197
198#endif // _QX_VALIDATOR_FUNCTION_H_
Common interface for a list of validators.
Concrete class registered into QxOrm context.
List of invalid values.
#define qAssert(x)
Definition QxMacro.h:52
qx::IxClass : common interface for all classes registered into QxOrm context
Definition IxClass.h:69
virtual IxValidatorX * getAllValidator()
QString getName() const
qx::IxValidatorX : common interface for a list of validators
QxInvalidValueX validate(void *pOwner, const QString &sGroup=QString()) const
qx::QxInvalidValueX : list of invalid values
void insert(const IxValidator *pValidator)
void setCurrentPath(const QString &s)
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...
Root namespace for all QxOrm library features.
QxInvalidValueX validate(T &t, const QString &group)
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...
static qx::QxInvalidValueX validate(std::pair< U1, U2 > &item, const QString &group)
static qx::QxInvalidValueX validate(U &item, const QString &group)
static qx::QxInvalidValueX validate(const std::pair< U1, U2 > &item, const QString &group)
static qx::QxInvalidValueX validate(U &item, const QString &group)
static qx::QxInvalidValueX validateItem(U &item, const QString &group)
static qx::QxInvalidValueX validate(T &t, const QString &group)
static qx::QxInvalidValueX validate(T &t, const QString &group)
static qx::QxInvalidValueX validate(T &t, const QString &group)
static qx::QxInvalidValueX validate(T &t, const QString &group)