WSF
FFIRN_Validator.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2019 Infoscitex, a DCS Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef FFIRNVALIDATOR_HPP
13#define FFIRNVALIDATOR_HPP
14
15#include "usmtf_export.h"
16
17#include <algorithm>
18#include <functional>
19#include <unordered_map>
20
21#include "Field.hpp"
22#include "Validatable.hpp"
23
24namespace usmtf
25{
26const static std::string NULL_FIELD = "-";
27
35{
36const std::string cLATM = "LATM";
37const std::string cLATS = "LATS";
38const std::string cRARA = "RARA";
39const std::string cFLFL = "FLFL";
40const std::string cRAFL = "RAFL";
41const std::string cBRFL = "BRFL";
42const std::string cBRRA = "BRRA";
43const std::string cSNWP = "SNWP";
44} // namespace ffirn_descriptors
45
50class USMTF_EXPORT FFIRN_Validator : public Validatable
51{
52public:
53 using FFIRN_Func = std::function<bool(void)>;
56 using FFIRN_DescriptorMap = std::unordered_map<std::string, FFIRN_Func>;
57 FFIRN_Validator() = default;
58
65 virtual bool ParseAndValidate(const usmtf::Field& aField) = 0;
66
69 static bool IsInSelection(const std::string& aValue, const std::vector<std::string>& choices) noexcept;
70 static bool IsStringLength(const std::string& aValue, size_t aLength) noexcept;
72 static size_t CheckForAnyDelimeter(const std::string& aValue, const std::vector<std::string>& aDelimeters) noexcept;
73 static size_t CheckForAnyDelimeter(const std::string& aValue,
74 const std::vector<std::string>& aDelimeters,
75 std::string& aFoundDelimeter) noexcept;
76
77 template<class T>
78 static bool IsInRange(T aValue, T aLowerBound, T aUpperBound) noexcept
79 {
80 return aValue >= aLowerBound && aValue <= aUpperBound;
81 }
82
84 const std::string& GetRawContent() const noexcept;
85
87 std::vector<std::string> SplitOnDelimeter(const std::string& value, const std::string& delimeter);
88 const std::string& GetFieldContent() const noexcept;
89
90protected:
92 bool ValidateByDescriptor(const FFIRN_DescriptorMap& aDescriptorMap);
93
100 void ClearErrorsIfValid(bool aHasAtLeastOnePassed) noexcept;
102 void SetField(const Field& aField) noexcept;
104};
105} // namespace usmtf
106#endif // !
static bool IsInRange(T aValue, T aLowerBound, T aUpperBound) noexcept
Definition FFIRN_Validator.hpp:78
static bool IsStringLength(const std::string &aValue, size_t aLength) noexcept
Definition FFIRN_Validator.cpp:67
Field mField
Definition FFIRN_Validator.hpp:103
virtual bool ParseAndValidate(const usmtf::Field &aField)=0
std::unordered_map< std::string, FFIRN_Func > FFIRN_DescriptorMap
Definition FFIRN_Validator.hpp:56
std::function< bool(void)> FFIRN_Func
Definition FFIRN_Validator.hpp:53
static size_t CheckForAnyDelimeter(const std::string &aValue, const std::vector< std::string > &aDelimeters) noexcept
Returns the positions of a specified delimiter if present, npos if not.
Definition FFIRN_Validator.cpp:72
static bool IsInSelection(const std::string &aValue, const std::vector< std::string > &choices) noexcept
Definition FFIRN_Validator.cpp:62
Definition Field.hpp:48
Definition Validatable.hpp:24
Template specialization for wsf::comm::Address. Allows usage of Address in std::unordered_map/set.
Definition WsfCommAddress.hpp:185
Definition FFIRN_Validator.hpp:35
const std::string cLATM
Definition FFIRN_Validator.hpp:36
const std::string cBRRA
Definition FFIRN_Validator.hpp:42
const std::string cBRFL
Definition FFIRN_Validator.hpp:41
const std::string cRARA
Definition FFIRN_Validator.hpp:38
const std::string cSNWP
Definition FFIRN_Validator.hpp:43
const std::string cRAFL
Definition FFIRN_Validator.hpp:40
const std::string cFLFL
Definition FFIRN_Validator.hpp:39
const std::string cLATS
Definition FFIRN_Validator.hpp:37
Definition Acmid.cpp:17
static const std::string NULL_FIELD
Definition FFIRN_Validator.hpp:26
Copyrights Multiple, All Rights Reserved