WSF
usmtf::FFIRN_Validator Class Referenceabstract

#include <FFIRN_Validator.hpp>

Inheritance diagram for usmtf::FFIRN_Validator:
Collaboration diagram for usmtf::FFIRN_Validator:

Public Types

using FFIRN_Func = std::function<bool(void)>
using FFIRN_DescriptorMap = std::unordered_map<std::string, FFIRN_Func>

Public Member Functions

 FFIRN_Validator ()=default
virtual bool ParseAndValidate (const usmtf::Field &aField)=0
const std::string & GetRawContent () const noexcept
 Return the content of the field as it was in the USMTF set.
std::vector< std::string > SplitOnDelimeter (const std::string &value, const std::string &delimeter)
 Values separated by delimeter.
const std::string & GetFieldContent () const noexcept
Public Member Functions inherited from usmtf::Validatable
bool IsValid () const noexcept
Public Member Functions inherited from usmtf::ErrorManager
virtual ~ErrorManager ()=default
bool HasErrors () const noexcept
void LogErrors (std::ostream &aOut) const noexcept
const std::vector< ValidationError > & GetErrors () const

Static Public Member Functions

static bool IsInSelection (const std::string &aValue, const std::vector< std::string > &choices) noexcept
static bool IsStringLength (const std::string &aValue, size_t aLength) noexcept
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.
static size_t CheckForAnyDelimeter (const std::string &aValue, const std::vector< std::string > &aDelimeters, std::string &aFoundDelimeter) noexcept
template<class T>
static bool IsInRange (T aValue, T aLowerBound, T aUpperBound) noexcept

Protected Member Functions

bool ValidateByDescriptor (const FFIRN_DescriptorMap &aDescriptorMap)
 Speed up validation if descriptor is present. Runs all functions if it isn't.
void ClearErrorsIfValid (bool aHasAtLeastOnePassed) noexcept
void SetField (const Field &aField) noexcept
 Field Setter for internal use only.
Protected Member Functions inherited from usmtf::ErrorManager
void AddError (const ValidationError &aError) noexcept
void AddError (const std::string &aFailureReason, const std::string &aValueValidatied, const std::string &aOptionalSuggestion="") noexcept
void AddError (const std::string &aErrorMessage) noexcept
void AddErrors (const std::vector< ValidationError > &aErrors) noexcept
void ClearErrors () noexcept

Protected Attributes

Field mField

Detailed Description

The idea behind FFIRNValidators is simple. In the USMTF Spec there lives FFIRN/FUDN numbers that are identifiers to a set of rules that validate field content. Programmatically were representing this as classes that the content of the field will be ran through. Interested parties will extract the data they are interested in.

Member Typedef Documentation

◆ FFIRN_DescriptorMap

using usmtf::FFIRN_Validator::FFIRN_DescriptorMap = std::unordered_map<std::string, FFIRN_Func>

The Descriptor Map is an optimization technique so that if Descriptors are present only that set of validations needs to be ran.

◆ FFIRN_Func

using usmtf::FFIRN_Validator::FFIRN_Func = std::function<bool(void)>

Constructor & Destructor Documentation

◆ FFIRN_Validator()

usmtf::FFIRN_Validator::FFIRN_Validator ( )
default

Member Function Documentation

◆ CheckForAnyDelimeter() [1/2]

◆ CheckForAnyDelimeter() [2/2]

size_t usmtf::FFIRN_Validator::CheckForAnyDelimeter ( const std::string & aValue,
const std::vector< std::string > & aDelimeters,
std::string & aFoundDelimeter )
staticnoexcept

References CheckForAnyDelimeter(), and pos.

◆ ClearErrorsIfValid()

void usmtf::FFIRN_Validator::ClearErrorsIfValid ( bool aHasAtLeastOnePassed)
protectednoexcept

Clear Errors If the validator is Valid. Confusingly this IS a possible state. Given Validation can pass one of many rules, the errors added by prior validations that passed will need to be cleared to make IsValid() accurate, as it just returns whether or not the error container has errors. So instead of forcing users to clear it in each of their validation function an potentially forgetting, we slim that potential to a single call in their ParseAndValidate override.

References usmtf::ErrorManager::ClearErrors(), and ClearErrorsIfValid().

Referenced by ClearErrorsIfValid(), usmtf::IntervalDuration::ParseAndValidate(), usmtf::TimePoint::ParseAndValidate(), usmtf::VariantValidator< UTM_Location, NamedLocation, FreeText >::ParseAndValidate(), and usmtf::VerifiedTimePoint::ParseAndValidate().

◆ GetFieldContent()

const std::string & usmtf::FFIRN_Validator::GetFieldContent ( ) const
noexcept

References GetFieldContent(), and mField.

Referenced by GetFieldContent().

◆ GetRawContent()

const std::string & usmtf::FFIRN_Validator::GetRawContent ( ) const
noexcept

Return the content of the field as it was in the USMTF set.

References GetRawContent(), and mField.

Referenced by usmtf::AerialRefuelingInfo::AerialRefuelingInfo(), and GetRawContent().

◆ IsInRange()

◆ IsInSelection()

◆ IsStringLength()

◆ ParseAndValidate()

virtual bool usmtf::FFIRN_Validator::ParseAndValidate ( const usmtf::Field & aField)
pure virtual

I am not a huge fan of violating command query separation. But, in this case it makes sense. The functions that come into ParseAndValidate have to parse to get value of the component, sometimes there are many components in a single field. Unfortunately parsing is an intertwined attribute of validation. You cant parse according to some rule set if the field is invalid, making it impossible to separate the two notions easily. I have opted to instead name the functions for what they are actually doing. Parsing components and validating them as well. Optionally members can be set within the function as well.

Implemented in usmtf::AerialRefuelingSystem, usmtf::AircraftControlAgency, usmtf::AirspaceShape, usmtf::AirspaceTimeMode, usmtf::Altitude, usmtf::Beacon, usmtf::EllipticalArea, usmtf::FreeText, usmtf::Frequency, usmtf::FuelLoad, usmtf::FuelType, usmtf::InnerOuterRange, usmtf::IntervalDuration, usmtf::IntervalFrequency, usmtf::LatLon, usmtf::NamedLocation, usmtf::OrbitAlignment, usmtf::RadialBearing, usmtf::Radius, usmtf::RangeValidator< T >, usmtf::RangeValidator< double >, usmtf::RangeValidator< float >, usmtf::RangeValidator< int >, usmtf::RegexValidator, usmtf::RelativeBearingRange, usmtf::SectorGeometry, usmtf::TacanChannel, usmtf::TimePoint, usmtf::TrackWidth, usmtf::UTM_Location, usmtf::VariantValidator< Types >, usmtf::VariantValidator< LatLon, VerifiedLatLonS, RelativeBearingRange, FreeText >, usmtf::VariantValidator< Radius, EllipticalArea, SectorGeometry >, usmtf::VariantValidator< usmtf::Frequency, usmtf::FreeText >, usmtf::VariantValidator< usmtf::LatLon, usmtf::RelativeBearingRange, usmtf::FreeText >, usmtf::VariantValidator< usmtf::LatLon, usmtf::UTM_Location, usmtf::VerifiedLatLonTM, usmtf::VerifiedLatLonDS, usmtf::FreeText >, usmtf::VariantValidator< usmtf::RangeValidator< int >, usmtf::FreeText >, usmtf::VariantValidator< UTM_Location, NamedLocation, FreeText >, usmtf::VerifiedLatLonDS, usmtf::VerifiedLatLonS, usmtf::VerifiedLatLonTM, usmtf::VerifiedTimePoint, and usmtf::VerticalDimension.

References CheckForAnyDelimeter(), IsInSelection(), and IsStringLength().

◆ SetField()

◆ SplitOnDelimeter()

std::vector< std::string > usmtf::FFIRN_Validator::SplitOnDelimeter ( const std::string & value,
const std::string & delimeter )

◆ ValidateByDescriptor()

bool usmtf::FFIRN_Validator::ValidateByDescriptor ( const FFIRN_DescriptorMap & aDescriptorMap)
protected

Speed up validation if descriptor is present. Runs all functions if it isn't.

References mField.

Referenced by usmtf::LatLon::ParseAndValidate(), and usmtf::VerticalDimension::ParseAndValidate().

Member Data Documentation

◆ mField


The documentation for this class was generated from the following files:
Copyrights Multiple, All Rights Reserved