Caffa  1.1.0
C++ Application Framework for Embedded Systems with introspection
cafFieldValidator.h
1 // ##################################################################################################
2 //
3 // Custom Visualization Core library
4 // Copyright (C) 2021- 3D-Radar AS
5 //
6 // This library may be used under the terms of the GNU Lesser General Public License as follows:
7 //
8 // GNU Lesser General Public License Usage
9 // This library is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU Lesser General Public License as published by
11 // the Free Software Foundation; either version 2.1 of the License, or
12 // (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful, but WITHOUT ANY
15 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 // FITNESS FOR A PARTICULAR PURPOSE.
17 //
18 // See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
19 // for more details.
20 //
21 // ##################################################################################################
22 #pragma once
23 
24 #include <string>
25 #include <utility>
26 
27 namespace caffa
28 {
29 
35 {
36 public:
44  enum class FailureSeverity
45  {
46  VALIDATOR_WARNING,
47  VALIDATOR_ERROR,
48  VALIDATOR_CRITICAL
49  };
50 
57  : m_failureSeverity( failureSeverity )
58  {
59  }
60 
61  virtual ~FieldValidatorInterface() = default;
67  virtual void readFromString( const std::string& string ) = 0;
68 
74  virtual std::string writeToString() const = 0;
75 
81  FailureSeverity failureSeverity() const { return m_failureSeverity; }
82 
83 private:
84  FailureSeverity m_failureSeverity;
85 };
86 
93 template <typename DataType>
95 {
96 public:
98 
99  FieldValidator( FailureSeverity failureSeverity = FailureSeverity::VALIDATOR_ERROR )
101  {
102  }
103 
111  virtual std::pair<bool, std::string> validate( const DataType& value ) const = 0;
112 };
113 
114 } // namespace caffa
virtual void readFromString(const std::string &string)=0
Read the validator from string.
Used to validate the value of data fields Implementations need the the validate method as well as rea...
Definition: cafFieldValidator.h:94
An abstract field validator interface for validating field values.
Definition: cafFieldValidator.h:34
FailureSeverity failureSeverity() const
Get the severity of a failure of the validator.
Definition: cafFieldValidator.h:81
FailureSeverity
The severity of failure. Essentially tells the application how to treat a validator failure: VALIDATO...
Definition: cafFieldValidator.h:44
FieldValidatorInterface(FailureSeverity failureSeverity)
Construct a new Field Validator Interface object.
Definition: cafFieldValidator.h:56
virtual std::string writeToString() const =0
Write the validator tostring.
Main Caffa namespace.
Definition: cafApplication.h:30