QxOrm  1.2.3
C++ Object Relational Mapping library
IxValidator.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** http://www.qxorm.com/
00004 ** http://sourceforge.net/projects/qxorm/
00005 ** Original file by Lionel Marty
00006 **
00007 ** This file is part of the QxOrm library
00008 **
00009 ** This software is provided 'as-is', without any express or implied
00010 ** warranty. In no event will the authors be held liable for any
00011 ** damages arising from the use of this software.
00012 **
00013 ** GNU Lesser General Public License Usage
00014 ** This file must be used under the terms of the GNU Lesser
00015 ** General Public License version 2.1 as published by the Free Software
00016 ** Foundation and appearing in the file 'license.lgpl.txt' included in the
00017 ** packaging of this file.  Please review the following information to
00018 ** ensure the GNU Lesser General Public License version 2.1 requirements
00019 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00020 **
00021 ** If you have questions regarding the use of this file, please contact :
00022 ** contact@qxorm.com
00023 **
00024 ****************************************************************************/
00025 
00026 #ifndef _IX_VALIDATOR_H_
00027 #define _IX_VALIDATOR_H_
00028 
00029 #ifdef _MSC_VER
00030 #pragma once
00031 #endif
00032 
00040 #include <QxCommon/QxPropertyBag.h>
00041 
00042 namespace qx {
00043 
00044 class IxDataMember;
00045 class QxInvalidValueX;
00046 
00054 class QX_DLL_EXPORT IxValidator : public QxPropertyBag
00055 {
00056 
00057 public:
00058 
00059    enum validator_type
00060    {
00061       not_null, not_empty, min_value, max_value, 
00062       min_length, max_length, date_past, date_future, 
00063       min_decimal, max_decimal, regular_expression, e_mail, 
00064       recursive_validator, custom_validator
00065    };
00066 
00067 protected:
00068 
00069    validator_type    m_type;           
00070    QString           m_message;        
00071    QString           m_group;          
00072    QVariantList      m_Constraints;    
00073    IxDataMember *    m_pDataMember;    
00074 
00075 public:
00076 
00077    IxValidator(validator_type type);
00078    virtual ~IxValidator();
00079 
00080    validator_type getType() const;
00081    QString getMessage() const;
00082    QString getGroup() const;
00083    QVariant getConstraint() const;
00084    QVariantList getConstraints() const;
00085    IxDataMember * getDataMember() const;
00086 
00087    void setMessage(const QString & s);
00088    void setGroup(const QString & s);
00089    void setConstraint(const QVariant & v);
00090    void setConstraints(const QVariantList & lst);
00091    void setDataMember(IxDataMember * p);
00092 
00093    virtual void validate(void * pOwner, QxInvalidValueX & lstInvalidValues) const;
00094 
00095 protected:
00096 
00097    void initDefaultMessage();
00098 
00099    void validateNotNull(const QVariant & v, QxInvalidValueX & lstInvalidValues) const;
00100    void validateNotEmpty(const QVariant & v, QxInvalidValueX & lstInvalidValues) const;
00101    void validateMinValue(const QVariant & v, QxInvalidValueX & lstInvalidValues) const;
00102    void validateMaxValue(const QVariant & v, QxInvalidValueX & lstInvalidValues) const;
00103    void validateMinDecimal(const QVariant & v, QxInvalidValueX & lstInvalidValues) const;
00104    void validateMaxDecimal(const QVariant & v, QxInvalidValueX & lstInvalidValues) const;
00105    void validateMinLength(const QVariant & v, QxInvalidValueX & lstInvalidValues) const;
00106    void validateMaxLength(const QVariant & v, QxInvalidValueX & lstInvalidValues) const;
00107    void validateDatePast(const QVariant & v, QxInvalidValueX & lstInvalidValues) const;
00108    void validateDateFuture(const QVariant & v, QxInvalidValueX & lstInvalidValues) const;
00109    void validateRegularExpression(const QVariant & v, QxInvalidValueX & lstInvalidValues) const;
00110    void validateEMail(const QVariant & v, QxInvalidValueX & lstInvalidValues) const;
00111 
00112 };
00113 
00114 typedef boost::shared_ptr<IxValidator> IxValidator_ptr;
00115 
00116 } // namespace qx
00117 
00118 #endif // _IX_VALIDATOR_H_