WSF
USMTF_Transformer.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 USMTF_TRANSFORMER_HPP
13#define USMTF_TRANSFORMER_HPP
14
15#include "usmtf_export.h"
16
17#include "Exportable.hpp"
18#include "InputBlock.hpp"
19#include "MacroEnabled.hpp"
20#include "Message.hpp"
21#include "USMTF_Exceptions.hpp"
22#include "USMTF_Factory.hpp"
23#include "USMTF_Transformer.hpp"
24#include "UtStringUtil.hpp"
25#include "Validatable.hpp"
26
27namespace usmtf
28{
31{
32public:
33 USMTF_Transformer() = default;
34 explicit USMTF_Transformer(const Segment& aSegment)
35 : mSegment(aSegment)
36 {
37 }
38 virtual ~USMTF_Transformer() = default;
39 template<typename SetType>
40 const SetType* ExtractSet(const std::string& aStf,
41 const std::string& aLogicalConceptName,
42 bool aSkipValidation = false,
43 bool aIsOptional = false)
44 {
45 static_assert(std::is_base_of<Set, SetType>::value, "Template argument must be subclass of Set");
46 try
47 {
48 Segment::SetLocation loc = mSegment.GetSet(aStf);
49 const SetType* set = SetFactory::GetFactory()->CastIfRegistered<SetType>(loc.first);
50
51 if (aSkipValidation)
52 {
53 return set;
54 }
55 if (!set)
56 {
57 AddError(aStf + " Set Type must be registered to create a " + aLogicalConceptName,
58 aStf + " Set",
59 "To create a " + aLogicalConceptName + " you must register a Set that handles " + aStf);
60 }
61 else if (!set->IsValid())
62 {
63 AddError(aStf + ": " + loc.first.GetReconstructedSet() + " is invalid. See below.",
64 aStf + " Set",
65 "To create a " + aLogicalConceptName + " " + aStf + " must be a valid set.");
66 AddErrors(set->GetErrors());
67 }
68 return set;
69 }
70 catch (const SetError& err)
71 {
72 if (!aIsOptional)
73 {
74 AddError(aLogicalConceptName + " requirements are not satisfied", aLogicalConceptName, std::string(err.what()));
75 }
76 return nullptr;
77 }
78 }
79
80 static const std::string ReplaceSpaces(const std::string& aTarget, char aDesiredChar) noexcept;
81
82protected:
84};
85} // namespace usmtf
86#endif
void AddError(const ValidationError &aError) noexcept
Definition ErrorManager.cpp:36
void AddErrors(const std::vector< ValidationError > &aErrors) noexcept
Definition ErrorManager.cpp:53
Definition Exportable.hpp:27
Definition MacroEnabled.hpp:27
Definition Segment.hpp:30
std::pair< const Set &, SetPosition > SetLocation
Definition Segment.hpp:34
Error in accessing a field that isn't present in the set.
Definition USMTF_Exceptions.hpp:52
static USMTF_Factory< Set, std::vector< Field > > * GetFactory()
const V * CastIfRegistered(const T &aEntity) noexcept
Definition USMTF_Factory.hpp:103
const Segment mSegment
Definition USMTF_Transformer.hpp:83
static const std::string ReplaceSpaces(const std::string &aTarget, char aDesiredChar) noexcept
This is in transformer because thats where this is needed in the lib. Script Blocks cant have spaces ...
Definition USMTF_Transformer.cpp:18
virtual ~USMTF_Transformer()=default
USMTF_Transformer(const Segment &aSegment)
Definition USMTF_Transformer.hpp:34
const SetType * ExtractSet(const std::string &aStf, const std::string &aLogicalConceptName, bool aSkipValidation=false, bool aIsOptional=false)
Definition USMTF_Transformer.hpp:40
Definition Validatable.hpp:24
Definition Acmid.cpp:17
Copyrights Multiple, All Rights Reserved