WSF
WsfMultiresolutionTypes.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 (C) 2021 Stellar Science; U.S. Government has Unlimited Rights.
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 WSF_MULTIRESOLUTION_TYPES_HPP
13#define WSF_MULTIRESOLUTION_TYPES_HPP
14
15#include <unordered_map>
16
22#include "WsfObjectTypeList.hpp"
23#include "WsfPlatform.hpp"
24
25class WsfScenario;
26
27template<typename DerivedComponent>
28class WsfMultiresolutionTypes : public WsfObjectTypeList<WsfMultiresolutionPlatformComponent<DerivedComponent>>
29{
30public:
32
34 static const WsfMultiresolutionTypes<DerivedComponent>& Get(const WsfScenario& aScenario);
36
37 explicit WsfMultiresolutionTypes(WsfScenario& aScenario);
38};
39
41{
42public:
43 void AddedToScenario() override;
44
47 template<typename DerivedComponent>
49 {
50 const size_t index = mRoleIndexMap.at(cCOMPONENT_ROLE<WsfMultiresolutionPlatformComponent<DerivedComponent>>());
51 auto& types = dynamic_cast<WsfMultiresolutionTypes<DerivedComponent>&>(*GetScenario().GetTypeLists().at(index));
52 return types;
53 }
54
55private:
56 template<typename DerivedComponent>
57 void AddMultiresolutionType()
58 {
60 GetScenario().GetTypeLists().size();
62 }
63
64 std::unordered_map<int, size_t> mRoleIndexMap;
65};
66
67namespace impl
68{
69template<typename DerivedComponent>
71{
72public:
73 static constexpr int cMULTIRESOLUTION_COMPONENT_ROLE =
75
76 bool ProcessAddOrEditCommand(UtInput& aInput, WsfPlatform& aPlatform, bool aIsAdding) override
77 {
78 return ProcessAddOrEditCommandImpl(aInput, aPlatform, aIsAdding);
79 }
80 bool ProcessDeleteCommand(UtInput& aInput, WsfPlatform& aPlatform) override
81 {
82 return ProcessDeleteCommandImpl(aInput, aPlatform);
83 }
84
85private:
86 // The following functions can be replaced with `if constexpr` in C++17
87 template<typename U = DerivedComponent>
88 typename std::enable_if<wsf::multiresolution::ComponentName<U>::cREQUIRES_USER_INPUT_NAME, bool>::type
89 ProcessAddOrEditCommandImpl(UtInput& aInput, WsfPlatform& aPlatform, bool aIsAdding)
90 {
92 return types.LoadNamedComponent(aInput, aPlatform, aIsAdding, cMULTIRESOLUTION_COMPONENT_ROLE);
93 }
94 template<typename U = DerivedComponent>
95 typename std::enable_if<!wsf::multiresolution::ComponentName<U>::cREQUIRES_USER_INPUT_NAME, bool>::type
96 ProcessAddOrEditCommandImpl(UtInput& aInput, WsfPlatform& aPlatform, bool aIsAdding)
97 {
99 return types.LoadUnnamedComponent(aInput, aPlatform, aIsAdding, cMULTIRESOLUTION_COMPONENT_ROLE);
100 }
101 template<typename U = DerivedComponent>
102 typename std::enable_if<wsf::multiresolution::ComponentName<U>::cREQUIRES_USER_INPUT_NAME, bool>::type
103 ProcessDeleteCommandImpl(UtInput& aInput, WsfPlatform& aPlatform)
104 {
106 return types.DeleteNamedComponent(aInput, aPlatform, cMULTIRESOLUTION_COMPONENT_ROLE);
107 }
108 template<typename U = DerivedComponent>
109 typename std::enable_if<!wsf::multiresolution::ComponentName<U>::cREQUIRES_USER_INPUT_NAME, bool>::type
110 ProcessDeleteCommandImpl(UtInput& aInput, WsfPlatform& aPlatform)
111 {
113 return types.DeleteUnnamedComponent(aInput, aPlatform, cMULTIRESOLUTION_COMPONENT_ROLE);
114 }
115};
116} // namespace impl
117
118template<typename DerivedComponent>
125
126template<typename DerivedComponent>
128{
129 const auto& registration = dynamic_cast<const WsfMultiresolutionTypesRegistration&>(
131 return registration.GetMultiresolutionTypes<DerivedComponent>();
132}
133
134template<typename DerivedComponent>
145
146#endif
WsfScenario & GetScenario() const
Returns a reference to the scenario to which this factory is registered.
Definition WsfComponentFactory.hpp:37
WsfComponentFactory()
Definition WsfComponentFactory.hpp:56
A base class template for defining multiresolution WsfPlatformComponent types.
Definition WsfMultiresolutionPlatformComponent.hpp:40
Definition WsfMultiresolutionTypes.hpp:41
void AddedToScenario() override
Definition WsfMultiresolutionTypes.cpp:14
WsfMultiresolutionTypes< DerivedComponent > & GetMultiresolutionTypes() const
Definition WsfMultiresolutionTypes.hpp:48
Definition WsfMultiresolutionTypes.hpp:29
static WsfMultiresolutionTypes< DerivedComponent > & Get(WsfScenario &aScenario)
Definition WsfMultiresolutionTypes.hpp:119
WsfMultiresolutionTypes(WsfScenario &aScenario)
Definition WsfMultiresolutionTypes.hpp:135
A class template for defining multiresolution containers for WsfPlatformComponent types.
Definition WsfMultiresolutionWrapperMetaModel.hpp:47
@ cREDEFINITION_ALLOWED
Definition WsfObjectTypeListBase.hpp:99
WsfObjectTypeListBase(const WsfObjectTypeListBase &)=delete
bool Add(WsfStringId aId, std::unique_ptr< WsfMultiresolutionPlatformComponent< DerivedComponent > > aDefinitionPtr)
Definition WsfObjectTypeList.hpp:91
WsfObjectTypeList(WsfScenario &aScenario, unsigned int aFlags, const std::string &aBlockName)
Definition WsfObjectTypeList.hpp:76
Platforms represent a entity within the simulation.
Definition WsfPlatform.hpp:115
WsfScenarioExtension()
Definition WsfScenarioExtension.cpp:21
WsfScenario & GetScenario() const
Definition WsfScenarioExtension.hpp:46
Contains the data required to create a simulation, and acts as the entry point for input file process...
Definition WsfScenario.hpp:111
WsfScenarioExtension & GetExtension(const std::string &aName) const
Definition WsfScenario.cpp:814
void RegisterComponentFactory(std::unique_ptr< WsfComponentFactoryBase > aFactoryPtr)
Definition WsfScenario.cpp:850
void AddTypeList(std::unique_ptr< WsfObjectTypeListBaseI > aTypeListPtr)
Definition WsfScenario.cpp:1326
std::vector< WsfObjectTypeListBaseI * > GetTypeLists() const
Definition WsfScenario.hpp:232
Definition WsfMultiresolutionTypes.hpp:71
bool ProcessDeleteCommand(UtInput &aInput, WsfPlatform &aPlatform) override
Definition WsfMultiresolutionTypes.hpp:80
static constexpr int cMULTIRESOLUTION_COMPONENT_ROLE
Definition WsfMultiresolutionTypes.hpp:73
bool ProcessAddOrEditCommand(UtInput &aInput, WsfPlatform &aPlatform, bool aIsAdding) override
Definition WsfMultiresolutionTypes.hpp:76
str types
Definition MessageDefines_Generate.py:19
Definition WsfMultiresolutionTypes.hpp:68
constexpr auto cEXTENSION_NAME
Definition ComponentNameHelper.hpp:46
std::string BaseTypeName()
This name, associated with DerivedComponent, is used as the base input type for scenario input.
Definition ComponentNameHelper.hpp:81
Function definitions for those who need run-time access to the version.
Definition WsfComm.cpp:32
Definition WsfComponentRoles.hpp:60
Copyrights Multiple, All Rights Reserved