Cutelyst  2.1.0
validator.h
1 /*
2  * Copyright (C) 2017-2018 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 Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 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  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 #ifndef CUTELYSTVALIDATOR_H
19 #define CUTELYSTVALIDATOR_H
20 
21 #include <Cutelyst/cutelyst_global.h>
22 #include <Cutelyst/ParamsMultiMap>
23 #include <QScopedPointer>
24 #include "validatorresult.h"
25 
26 namespace Cutelyst {
27 
55 class ValidatorPrivate;
56 class Context;
57 class Application;
58 class ValidatorRule;
59 
239 class CUTELYST_PLUGIN_UTILS_VALIDATOR_EXPORT Validator
240 {
241 public:
246  NoSpecialBehavior = 0,
247  StopOnFirstError = 1,
248  FillStashOnError = 2,
249  NoTrimming = 4,
250  BodyParamsOnly = 8,
251  QueryParamsOnly = 16
252  };
253  Q_DECLARE_FLAGS(ValidatorFlags, ValidatorFlag)
254 
255 
258  explicit Validator(QLatin1String translationContext = QLatin1String());
259 
260 #ifdef Q_COMPILER_INITIALIZER_LISTS
261 
268  explicit Validator(std::initializer_list<ValidatorRule*> validators, QLatin1String translationContext = QLatin1String());
269 #endif
270 
274  ~Validator();
275 
282  void clear();
283 
295  ValidatorResult validate(Context *c, ValidatorFlags flags = NoSpecialBehavior) const;
296 
307  ValidatorResult validate(Context *c, const ParamsMultiMap &parameters, ValidatorFlags flags = NoSpecialBehavior) const;
308 
315  void addValidator(ValidatorRule *v);
316 
320  static void loadTranslations(Application *app);
321 
322 protected:
323  const QScopedPointer<ValidatorPrivate> d_ptr;
324 
325 private:
326  Q_DECLARE_PRIVATE(Validator)
327  Q_DISABLE_COPY(Validator)
328 };
329 
330 }
331 
332 Q_DECLARE_OPERATORS_FOR_FLAGS(Cutelyst::Validator::ValidatorFlags)
333 
334 #endif //CUTELYSTVALIDATOR_H
QMap< QString, QString > ParamsMultiMap
The Cutelyst Context.
Definition: context.h:50
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7
ValidatorFlag
Flags that change the behavior of the Validator.
Definition: validator.h:245
Base class for all validator rules.
Validation processor for input data.
Definition: validator.h:239
The Cutelyst Application.
Definition: application.h:55
Provides information about performed validations.