WSF
WsfComponent.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 2003-2015 The Boeing 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 WSFCOMPONENT_HPP
13#define WSFCOMPONENT_HPP
14
15#include <cassert>
16#include <vector>
17
18#include "UtException.hpp"
19class UtInput;
20#include "wsf_export.h"
21
22#include "WsfComponentRoles.hpp"
23class WsfPlatform;
24#include "WsfStringId.hpp"
25
26// *************************************************************************************************
27// PROGRAMMING NOTE:
28//
29// Most of the methods within WsfComponent and WsfComponentList include the word 'Component' in the
30// name to avoid name conflicts if this class is derived from by another class (e.g.: WsfPlatform).
31// Also, some classes derive from both WsfComponent and WsfComponentList (i.e. they are a component,
32// but they also support sub-components). Thus, there may be no name conflicts between them.
33// *************************************************************************************************
34
39{
40public:
41 virtual ~WsfComponent() = default;
42
45
46
49 virtual WsfComponent* CloneComponent() const = 0;
50
55 virtual WsfStringId GetComponentName() const = 0;
56
66 virtual const int* GetComponentRoles() const = 0;
67
74 virtual void* QueryInterface(int aRole) = 0;
76
79 virtual int GetComponentInitializationOrder() const { return 0; }
80
91 template<typename T>
92 bool QueryInterfaceT(T*& aRolePtr)
93 {
94 aRolePtr = static_cast<T*>(QueryInterface(cCOMPONENT_ROLE<T>()));
95 return aRolePtr != nullptr;
96 }
97
99 bool ComponentHasRole(int aRole) { return QueryInterface(aRole) != nullptr; }
101
105
106 virtual bool PreInitialize(double aSimTime);
107 virtual bool Initialize(double aSimTime);
108 virtual bool Initialize2(double aSimTime);
109 virtual void PreInput();
110 virtual bool ProcessInput(UtInput& aInput);
112};
113
117template<typename PARENT_TYPE>
119{
120public:
122 typedef PARENT_TYPE ParentType;
123
125 : mParentPtr(nullptr)
126 {
127 }
128
129 WsfComponentT(const WsfComponentT& /* aSrc */) noexcept
130 : mParentPtr(nullptr)
131 {
132 }
133
134 WsfComponentT& operator=(const WsfComponentT& /* aSrc */) noexcept
135 {
136 mParentPtr = nullptr;
137 return *this;
138 }
139
140 ~WsfComponentT() override = default;
141
144
145
150 virtual void ComponentParentChanged(ParentType* aParentPtr) {}
151
154 ParentType* GetComponentParent() const { return mParentPtr; }
155
160 {
161 mParentPtr = aParentPtr;
162 ComponentParentChanged(aParentPtr); // Inform of change of parent
163 }
164
165
166private:
167 ParentType* mParentPtr;
168};
169
172
173#endif
WsfComponentT< WsfPlatform > WsfPlatformComponent
A convenient typedef for a platform component.
Definition WsfComponent.hpp:171
UtStringId WsfStringId
WsfStringId – the same thing as UtStringId.
Definition WsfStringId.hpp:23
#define WSF_EXPORT
Definition WsfXIO_Export.hpp:35
Definition WsfComponent.hpp:119
WsfComponentT & operator=(const WsfComponentT &) noexcept
Definition WsfComponent.hpp:134
~WsfComponentT() override=default
void SetComponentParent(ParentType *aParentPtr)
Definition WsfComponent.hpp:159
WsfComponentT(const WsfComponentT &) noexcept
Definition WsfComponent.hpp:129
PARENT_TYPE ParentType
This is needed to support the WsfComponentList template.
Definition WsfComponent.hpp:122
WsfComponentT()
Definition WsfComponent.hpp:124
virtual void ComponentParentChanged(ParentType *aParentPtr)
Definition WsfComponent.hpp:150
ParentType * GetComponentParent() const
Definition WsfComponent.hpp:154
Definition WsfComponent.hpp:39
virtual const int * GetComponentRoles() const =0
virtual WsfStringId GetComponentName() const =0
virtual ~WsfComponent()=default
virtual int GetComponentInitializationOrder() const
Definition WsfComponent.hpp:79
bool ComponentHasRole(int aRole)
Returns true if the component has the specified role.
Definition WsfComponent.hpp:99
virtual WsfComponent * CloneComponent() const =0
bool QueryInterfaceT(T *&aRolePtr)
Definition WsfComponent.hpp:92
virtual void * QueryInterface(int aRole)=0
Platforms represent a entity within the simulation.
Definition WsfPlatform.hpp:115
Definition WsfComponentRoles.hpp:60
Copyrights Multiple, All Rights Reserved