cutelyst  4.5.1
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
validator.h
1 /*
2  * SPDX-FileCopyrightText: (C) 2017-2023 Matthias Fehring <mf@huessenbergnetz.de>
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 #ifndef CUTELYSTVALIDATOR_H
6 #define CUTELYSTVALIDATOR_H
7 
8 #include "validatorresult.h"
9 
10 #include <Cutelyst/ParamsMultiMap>
11 #include <Cutelyst/Plugins/Utils/validator_export.h>
12 
13 namespace Cutelyst {
14 
45 class ValidatorPrivate;
46 class Context;
47 class Application;
48 class ValidatorRule;
49 
273 class CUTELYST_PLUGIN_UTILS_VALIDATOR_EXPORT Validator
274 {
275 public:
280  NoSpecialBehavior = 0,
281  StopOnFirstError =
282  1,
283  FillStashOnError = 2,
284  NoTrimming = 4,
286  BodyParamsOnly =
287  8,
289  QueryParamsOnly =
290  16
292  };
293  Q_DECLARE_FLAGS(ValidatorFlags, ValidatorFlag)
294 
295 
301  explicit Validator(const char *translationContext = nullptr);
302 
312  explicit Validator(std::initializer_list<ValidatorRule *> validators,
313  const char *translationContext = nullptr);
314 
319 
324  void clear();
325 
337  ValidatorResult validate(Context *c, ValidatorFlags flags = NoSpecialBehavior) const;
338 
349  ValidatorResult validate(Context *c,
350  const ParamsMultiMap &parameters,
351  ValidatorFlags flags = NoSpecialBehavior) const;
352 
357  void addValidator(ValidatorRule *v);
358 
365  static void loadTranslations(Application *app);
366 
367 private:
368  const std::unique_ptr<ValidatorPrivate> d_ptr;
369 
370  Q_DECLARE_PRIVATE(Validator) // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
371  Q_DISABLE_COPY(Validator)
372 };
373 
374 } // namespace Cutelyst
375 
376 Q_DECLARE_OPERATORS_FOR_FLAGS(Cutelyst::Validator::ValidatorFlags)
377 
378 #endif // CUTELYSTVALIDATOR_H
The Cutelyst application.
Definition: application.h:66
The Cutelyst Context.
Definition: context.h:42
Provides information about performed validations.
Base class for all validator rules.
Validation processor for input data.
Definition: validator.h:274
The Cutelyst namespace holds all public Cutelyst API.