Cutelyst  1.5.0
validator.h
1 /*
2  * Copyright (C) 2017 Matthias Fehring <kontakt@buschmann23.de>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 #ifndef CUTELYSTVALIDATOR_H
20 #define CUTELYSTVALIDATOR_H
21 
22 #include <Cutelyst/cutelyst_global.h>
23 #include <Cutelyst/ParamsMultiMap>
24 #include <QScopedPointer>
25 #include "validatorresult.h"
26 
27 namespace Cutelyst {
28 
29 class ValidatorPrivate;
30 class Context;
31 class ValidatorRule;
32 
196 class CUTELYST_PLUGIN_UTILS_VALIDATOR_EXPORT Validator
197 {
198 public:
203  NoSpecialBehavior = 0,
204  StopOnFirstError = 1,
205  FillStashOnError = 2,
206  NoTrimming = 4,
207  };
208  Q_DECLARE_FLAGS(ValidatorFlags, ValidatorFlag)
209 
210 
213  Validator();
214 
215 #ifdef Q_COMPILER_INITIALIZER_LISTS
216 
222  explicit Validator(std::initializer_list<ValidatorRule*> validators);
223 
231  Validator(std::initializer_list<ValidatorRule*> validators, std::initializer_list<std::pair<QString,QString> > labelDictionary);
232 #endif
233 
237  ~Validator();
238 
245  void clear();
246 
258  ValidatorResult validate(Context *c, ValidatorFlags flags = NoSpecialBehavior) const;
259 
269  ValidatorResult validate(const ParamsMultiMap &parameters, ValidatorFlags flags = NoSpecialBehavior) const;
270 
277  void addValidator(ValidatorRule *v);
278 
294  void setLabelDictionary(const QHash<QString,QString> &labelDict);
295 
304  void addLabelDictionary(const QHash<QString,QString> &labelDict);
305 
313  void addLabel(const QString &field, const QString &label);
314 
315 protected:
316  const QScopedPointer<ValidatorPrivate> d_ptr;
317 
318 private:
319  Q_DECLARE_PRIVATE(Validator)
320  Q_DISABLE_COPY(Validator)
321 };
322 
323 }
324 
325 Q_DECLARE_OPERATORS_FOR_FLAGS(Cutelyst::Validator::ValidatorFlags)
326 
327 #endif //CUTELYSTVALIDATOR_H
QMap< QString, QString > ParamsMultiMap
The Cutelyst Context.
Definition: context.h:52
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7
ValidatorFlag
Flags that change the behavior of the Validator.
Definition: validator.h:202
Base class for all validators.
Validation processor for input data.
Definition: validator.h:196
Contains the result of Validator.