WSF
WsfSimpleComponent.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 WSFSIMPLECOMPONENT_HPP
13#define WSFSIMPLECOMPONENT_HPP
14
15#include "wsf_export.h"
16
17#include "WsfComponent.hpp"
18#include "WsfNamed.hpp"
19
31template<typename COMPONENT_TYPE>
32class WsfSimpleComponentT : public COMPONENT_TYPE, public WsfNamed
33{
34 static_assert(std::is_base_of<WsfComponent, COMPONENT_TYPE>::value,
35 "Template argument to WsfSimpleComponentT must be a subclass of WsfComponent");
36
37 using ComponentType = COMPONENT_TYPE;
38
39public:
42
47 : ComponentType()
48 , WsfNamed(aName)
49 {
50 mRoles[0] = aRole;
51 mRoles[1] = 0;
52 }
53
57 // Using 'explicit' prevents casting a WsfStringId to a role.
58 explicit WsfSimpleComponentT(int aRole)
59 : ComponentType()
60 , WsfNamed()
61 {
62 mRoles[0] = aRole;
63 mRoles[1] = 0;
64 }
65
69 : ComponentType()
70 , WsfNamed(aName)
71 {
72 mRoles[0] = 0;
73 mRoles[1] = 0;
74 }
75
77 : ComponentType(aSrc)
78 , WsfNamed(aSrc)
79 {
80 mRoles[0] = aSrc.mRoles[0];
81 mRoles[1] = aSrc.mRoles[1];
82 }
83
85 {
86 if (this != &aRhs)
87 {
90 mRoles[0] = aRhs.mRoles[0];
91 mRoles[1] = aRhs.mRoles[1];
92 }
93 return *this;
94 }
95
96 ~WsfSimpleComponentT() override = default;
97
98 // *******************************************************************************************
99 // PROGRAMMING NOTE: QueryInterface cannot be provided by this class as this will return the
100 // wrong pointer if derived class utilizes multiple inheritance and this class is not derived
101 // first! For example: The following would NOT work if this class provided QueryInterface:
102 //
103 // class MyComponent : public OtherBase, public WsfSimpleComponent<Z>
104 //
105 // The problem is that QueryInterface would return the pointer to the WsfSimpleComponentT<Z>
106 // and NOT MyComponent. The addresses are separated by the size of OtherBase!
107 // *******************************************************************************************
108
110
111 WsfStringId GetComponentName() const override { return GetNameId(); }
112 const int* GetComponentRoles() const override { return mRoles; }
114
115protected:
116 int mRoles[2];
117};
118
121template<class PARENT_TYPE>
123
127
128#endif
WsfSimpleComponentT< WsfComponentT< PARENT_TYPE > > WsfSimpleComponentParentT
Definition WsfSimpleComponent.hpp:122
WsfSimpleComponentT< WsfPlatformComponent > WsfSimplePlatformComponent
Definition WsfSimpleComponent.hpp:126
UtStringId WsfStringId
WsfStringId – the same thing as UtStringId.
Definition WsfStringId.hpp:23
#define WSF_EXPORT
Definition WsfXIO_Export.hpp:35
WsfComponentT & operator=(const WsfComponentT &) noexcept
Definition WsfComponent.hpp:134
WsfStringId GetNameId() const
Definition WsfNamed.hpp:36
WsfNamed()
Definition WsfNamed.cpp:17
WsfNamed & operator=(const WsfNamed &)=default
Definition WsfSimpleComponent.hpp:33
const int * GetComponentRoles() const override
Definition WsfSimpleComponent.hpp:112
WsfSimpleComponentT(int aRole, WsfStringId aName)
Definition WsfSimpleComponent.hpp:46
WsfSimpleComponentT(int aRole)
Definition WsfSimpleComponent.hpp:58
WsfSimpleComponentT(const WsfSimpleComponentT &aSrc)
Definition WsfSimpleComponent.hpp:76
WsfSimpleComponentT()=default
Empty constructor for serialization.
WsfSimpleComponentT & operator=(const WsfSimpleComponentT &aRhs)
Definition WsfSimpleComponent.hpp:84
WsfSimpleComponentT(WsfStringId aName)
Definition WsfSimpleComponent.hpp:68
WsfStringId GetComponentName() const override
Definition WsfSimpleComponent.hpp:111
~WsfSimpleComponentT() override=default
int mRoles[2]
Definition WsfSimpleComponent.hpp:116
Copyrights Multiple, All Rights Reserved