18#include "UtInputBlock.hpp"
20#include "UtMemory.hpp"
33struct ObjectTypeTraits
35 static_assert(std::is_base_of<WsfObject, T>::value,
36 "ObjectTypeTraits may only be instantiated with types deriving from WsfObject.");
38 static constexpr bool cIS_NAMED = wsf::multiresolution::ComponentName<T>::cREQUIRES_USER_INPUT_NAME;
39 static constexpr bool cIS_UNNAMED = !wsf::multiresolution::ComponentName<T>::cREQUIRES_USER_INPUT_NAME;
41 static constexpr bool cIS_PLATFORM_COMPONENT = std::is_base_of<WsfPlatformComponent, T>::value;
42 static constexpr bool cIS_MOVER = std::is_base_of<WsfMover, T>::value;
43 static constexpr bool cIS_NON_MOVER_COMPONENT = cIS_PLATFORM_COMPONENT && !cIS_MOVER;
44 static constexpr bool cIS_NAMED_NON_MOVER_COMPONENT = cIS_NON_MOVER_COMPONENT && cIS_NAMED;
45 static constexpr bool cIS_UNNAMED_NON_MOVER_COMPONENT = cIS_NON_MOVER_COMPONENT && cIS_UNNAMED;
46 static constexpr bool cIS_SIGNATURE = std::is_base_of<WsfSignature, T>::value;
49template<
typename DerivedComponent>
50typename std::enable_if<ObjectTypeTraits<DerivedComponent>::cIS_PLATFORM_COMPONENT, std::string>::type
51NameForWarning(
const DerivedComponent& derivedComponent)
53 return "component " + derivedComponent.GetComponentName();
56template<
typename DerivedComponent>
57typename std::enable_if<ObjectTypeTraits<DerivedComponent>::cIS_SIGNATURE, std::string>::type
58NameForWarning(
const DerivedComponent& derivedComponent)
60 return "signature " + derivedComponent.GetName();
65template<
typename DerivedComponent>
66typename std::enable_if<ObjectTypeTraits<DerivedComponent>::cIS_MOVER,
bool>::type
67SetComponentOnPlatform(
WsfPlatform& aPlatform, DerivedComponent* aComponent,
const std::string& )
75template<
typename DerivedComponent>
76typename std::enable_if<ObjectTypeTraits<DerivedComponent>::cIS_NAMED_NON_MOVER_COMPONENT,
bool>::type
77SetComponentOnPlatform(
WsfPlatform& aPlatform, DerivedComponent* aComponent,
const std::string& aComponentName)
79 aComponent->SetName(aComponentName);
85template<
typename DerivedComponent>
86typename std::enable_if<ObjectTypeTraits<DerivedComponent>::cIS_UNNAMED_NON_MOVER_COMPONENT,
bool>::type
87SetComponentOnPlatform(
WsfPlatform& aPlatform, DerivedComponent* aComponent,
const std::string& )
94template<
typename DerivedComponent>
95typename std::enable_if<ObjectTypeTraits<DerivedComponent>::cIS_SIGNATURE,
bool>::type
96SetComponentOnPlatform(
WsfPlatform& aPlatform, DerivedComponent* aComponent,
const std::string& )
103 return interfacePtr !=
nullptr;
108template<
typename DerivedComponent>
109typename std::enable_if<ObjectTypeTraits<DerivedComponent>::cIS_PLATFORM_COMPONENT,
bool>::type
110PreInitializeComponent(
WsfPlatform*
const , DerivedComponent*
const aComponent,
const double aSimTime)
112 return aComponent->PreInitialize(aSimTime);
115template<
typename DerivedComponent>
116typename std::enable_if<ObjectTypeTraits<DerivedComponent>::cIS_SIGNATURE,
bool>::type
117PreInitializeComponent(
WsfPlatform*
const aPlatform, DerivedComponent*
const aComponent,
const double aSimTime)
119 return aComponent->
Initialize(aSimTime, aPlatform);
124template<
typename DerivedComponent>
132template<
typename DerivedComponent>
139template<
typename DerivedComponent>
142 if (aRole == cMULTIRESOLUTION_COMPONENT_ROLE)
149template<
typename DerivedComponent>
158template<
typename DerivedComponent>
161 const std::string command(aInput.GetCommand());
162 if (command ==
"fidelity")
164 aInput.ReadValue(mFidelity);
165 aInput.ValueInClosedRange(mFidelity, 0.0, 1.0);
178 throw UtInput::BadValue(aInput,
179 "Unexpected command " + command +
" encountered in " +
184template<
typename DerivedComponent>
196 std::move(componentName)})
197 .value_or(mFidelity);
200template<
typename DerivedComponent>
205 ok &= parentPlatform !=
nullptr;
208 std::unique_ptr<DerivedComponent> componentModel =
GetModel();
209 ok &= componentModel !=
nullptr;
212 ok &= SetComponentOnPlatform(*parentPlatform, componentModel.get(),
GetName());
216 ok &= PreInitializeComponent(parentPlatform, componentModel.release(), aSimTime);
221 << NameForWarning(*componentModel) <<
" to platform with name " << parentPlatform->
GetName();
@ cWSF_COMPONENT_NULL
A special entry to indicate the end of the list of roles assumed by a component.
Definition WsfComponentRoles.hpp:92
WsfComponentT< WsfPlatform > WsfPlatformComponent
A convenient typedef for a platform component.
Definition WsfComponent.hpp:171
bool ok
Definition WsfScriptWeaponClass.cpp:211
bool AddComponent(ComponentType *aComponentPtr)
Definition WsfComponentList.hpp:464
bool FindByRole(T *&aPtr) const
Definition WsfComponentList.hpp:170
ParentType * GetComponentParent() const
Definition WsfComponent.hpp:154
virtual bool PreInitialize(double aSimTime)
Definition WsfComponent.cpp:24
virtual bool ProcessInput(UtInput &aInput)
Definition WsfComponent.cpp:100
Definition WsfMultiresolutionMultirunTable.hpp:39
static WsfMultiresolutionMultirunTable * Find(const WsfScenario &aScenario)
Definition WsfMultiresolutionMultirunTable.cpp:193
ut::optional< double > GetFidelity(const wsf::multiresolution::PlatformComponentName &aPlatformComponentName) const
Definition WsfMultiresolutionMultirunTable.cpp:178
const std::string & GetName() const
Definition WsfObject.cpp:235
WsfObject()
This is the constructor for the WsfObject class.
Definition WsfObject.cpp:88
void SetName(WsfStringId aName)
Definition WsfObject.hpp:70
virtual bool ProcessInput(UtInput &aInput)
Definition WsfObject.cpp:140
Definition WsfSignatureInterface.hpp:32
virtual bool Initialize(double aSimTime, WsfPlatform *aPlatformPtr)
Definition WsfSignatureInterface.cpp:47
void SetSignature(WsfSignature *aSignaturePtr)
Definition WsfSignatureInterface.cpp:89
Interface * GetInterface(size_t aIndex)
Return the pointer to the interface with the specified index.
Definition WsfSignatureList.hpp:48
std::string CommandName()
This name, associated with DerivedComponent, is for use in the multiresolution framework....
Definition ComponentNameHelper.hpp:74
constexpr bool RequiresUserInputName()
Definition ComponentNameHelper.hpp:97
Helper struct for assigning names to platform components.
Definition ComponentNameHelper.hpp:54