QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
QxValidator.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_H_
33#define _QX_VALIDATOR_H_
34
35#ifdef _MSC_VER
36#pragma once
37#endif
38
48
50
51namespace qx {
52
53template <class T>
54QxInvalidValueX validate(T & t, const QString & group);
55
63template <class Owner>
65{
66
67public:
68
69 typedef std::function<void (Owner *, QxInvalidValueX &)> type_fct_custom_validator_member;
70 typedef std::function<void (const QVariant &, QxInvalidValueX &)> type_fct_custom_validator_variant;
71 typedef std::function<void (const QVariant &, const IxValidator *, QxInvalidValueX &)> type_fct_custom_validator_variant_validator;
72
73protected:
74
78
79public:
80
82 virtual ~QxValidator() { ; }
83
87
88 virtual void validate(void * pOwner, QxInvalidValueX & lstInvalidValues) const
89 {
91 { m_fctCustomValidator_Member(static_cast<Owner *>(pOwner), lstInvalidValues); }
93 { m_fctCustomValidator_Variant(m_pDataMember->toVariant(pOwner), lstInvalidValues); }
95 { m_fctCustomValidator_VariantValidator(m_pDataMember->toVariant(pOwner), this, lstInvalidValues); }
96 }
97
98};
99
107template <typename DataType, class Owner>
109{
110
111public:
112
113 typedef std::function<void (const DataType &, QxInvalidValueX &)> type_fct_custom_validator_data_type;
114 typedef std::function<void (const DataType &, const IxValidator *, QxInvalidValueX &)> type_fct_custom_validator_data_type_validator;
115
116protected:
117
120
121public:
122
125
128
129 virtual void validate(void * pOwner, QxInvalidValueX & lstInvalidValues) const
130 {
131 if (! m_pDataMember) { return; }
132 IxDataMember * pDataMember = const_cast<IxDataMember *>(m_pDataMember);
133 DataType * val = pDataMember->getValuePtr<DataType>(pOwner);
135 { m_fctCustomValidator_DataType((* val), lstInvalidValues); }
137 { m_fctCustomValidator_DataTypeValidator((* val), this, lstInvalidValues); }
138 }
139
140};
141
149template <typename DataType, class Owner>
151{
152
153public:
154
157
158 virtual void validate(void * pOwner, QxInvalidValueX & lstInvalidValues) const
159 {
160 if (! m_pDataMember) { qAssert(false); return; }
161 IxDataMember * pDataMember = const_cast<IxDataMember *>(m_pDataMember);
162 DataType * val = pDataMember->getValuePtr<DataType>(pOwner);
163 if (! val) { qAssert(false); return; }
164 QxInvalidValueX invalidValues;
165 invalidValues.setCurrentPath(m_pDataMember->getName());
166 invalidValues.insert(qx::validate((* val), m_group));
167 lstInvalidValues.insert(invalidValues);
168 }
169
170};
171
172} // namespace qx
173
174#endif // _QX_VALIDATOR_H_
Common interface for all class properties registered into QxOrm context.
Common interface for validator engine.
List of invalid values.
#define qAssert(x)
Definition QxMacro.h:52
qx::IxDataMember : common interface for all class properties registered into QxOrm context
QString getName() const
T * getValuePtr(void *pOwner, bool *bOk=NULL)
virtual QVariant toVariant(const void *pOwner, const QString &sFormat, int iIndexName=-1, qx::cvt::context::ctx_type ctx=qx::cvt::context::e_no_context) const =0
qx::IxValidator : common interface for validator engine
Definition IxValidator.h:61
IxDataMember * m_pDataMember
Registered property associated to validator.
Definition IxValidator.h:79
QString m_group
Validator group.
Definition IxValidator.h:77
qx::QxInvalidValueX : list of invalid values
void insert(const IxValidator *pValidator)
void setCurrentPath(const QString &s)
qx::QxValidator_Recursive<DataType, Owner> : concrete class for a recursive validator
virtual void validate(void *pOwner, QxInvalidValueX &lstInvalidValues) const
qx::QxValidator_WithDataType<DataType, Owner> : concrete class for a custom validator with data type
std::function< void(const DataType &, QxInvalidValueX &)> type_fct_custom_validator_data_type
void setFunction(type_fct_custom_validator_data_type fct)
type_fct_custom_validator_data_type_validator m_fctCustomValidator_DataTypeValidator
Custom validator function : global function with value and a IxValidator pointer containing all param...
virtual void validate(void *pOwner, QxInvalidValueX &lstInvalidValues) const
type_fct_custom_validator_data_type m_fctCustomValidator_DataType
Custom validator function : global function with value.
void setFunction(type_fct_custom_validator_data_type_validator fct)
std::function< void(const DataType &, const IxValidator *, QxInvalidValueX &)> type_fct_custom_validator_data_type_validator
qx::QxValidator<Owner> : concrete class for a custom validator
Definition QxValidator.h:65
std::function< void(Owner *, QxInvalidValueX &)> type_fct_custom_validator_member
Definition QxValidator.h:69
std::function< void(const QVariant &, const IxValidator *, QxInvalidValueX &)> type_fct_custom_validator_variant_validator
Definition QxValidator.h:71
void setFunction(type_fct_custom_validator_variant fct)
Definition QxValidator.h:85
type_fct_custom_validator_variant m_fctCustomValidator_Variant
Custom validator function : global function with value converted to QVariant type.
Definition QxValidator.h:76
type_fct_custom_validator_variant_validator m_fctCustomValidator_VariantValidator
Custom validator function : global function with value converted to QVariant type and a IxValidator p...
Definition QxValidator.h:77
void setFunction(type_fct_custom_validator_member fct)
Definition QxValidator.h:84
virtual void validate(void *pOwner, QxInvalidValueX &lstInvalidValues) const
Definition QxValidator.h:88
type_fct_custom_validator_member m_fctCustomValidator_Member
Custom validator function : class method.
Definition QxValidator.h:75
virtual ~QxValidator()
Definition QxValidator.h:82
std::function< void(const QVariant &, QxInvalidValueX &)> type_fct_custom_validator_variant
Definition QxValidator.h:70
void setFunction(type_fct_custom_validator_variant_validator fct)
Definition QxValidator.h:86
Root namespace for all QxOrm library features.
QxInvalidValueX validate(T &t, const QString &group)