WSF
MessageDefines.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI//REL TO USA ONLY
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#ifndef LINK16_MESSAGEDEFINES_HPP
12#define LINK16_MESSAGEDEFINES_HPP
13
15#include "FieldTypes.hpp"
17#include "Messages.hpp"
18#include "UtMemory.hpp"
19
21namespace WsfL16
22{
23namespace Messages
24{
25class MessageReader;
26class MessageWriter;
27} // namespace Messages
28} // namespace WsfL16
29
31#define DEFINE_VIRTUAL_TRANSERS__() \
32 virtual void TransferI(MessageBitInput& aMR) { Transfer(aMR); } \
33 virtual void TransferO(MessageBitOutput& aMW) { Transfer(aMW); } \
34 virtual void CreateAccessor(MessageAccessorFiller& aMP) { Transfer(aMP); }
35
37#define DEFINE_INITIAL(_LABEL_, _SUB_LABEL_) \
38public: \
39 virtual InitialBase* Clone() const { return new Initial(*this); } \
40 \
41protected: \
42 static const unsigned int ___RequiredMessageSize = 57; \
43 \
44public: \
45 virtual void GetLabel(int& aLabel, int& aSubLabel) const \
46 { \
47 aLabel = _LABEL_; \
48 aSubLabel = _SUB_LABEL_; \
49 } \
50 virtual int GetUID() const { return (_LABEL_ * 100 + _SUB_LABEL_) * 1000; } \
51 static const int cWORD_LABEL = _LABEL_; \
52 static const int cWORD_SUB_LABEL = _SUB_LABEL_; \
53 DEFINE_VIRTUAL_TRANSERS__()
54
56#define DEFINE_EXTENSION(_LABEL_, _SUB_LABEL_, _EXT_NUM_) \
57public: \
58 virtual ExtensionBase* Clone() const { return new Extension##_EXT_NUM_(*this); } \
59 \
60protected: \
61 static const unsigned int ___RequiredMessageSize = 68; \
62 \
63public: \
64 static const unsigned int cEXTENSION_NUMBER = _EXT_NUM_; \
65 virtual int GetExtensionNumber() const { return cEXTENSION_NUMBER; } \
66 virtual int GetUID() const { return (_LABEL_ * 100 + _SUB_LABEL_) * 1000 + _EXT_NUM_ + 1; } \
67 static const int cWORD_LABEL = _LABEL_; \
68 static const int cWORD_SUB_LABEL = _SUB_LABEL_; \
69 DEFINE_VIRTUAL_TRANSERS__()
70
72#define DEFINE_CONTINUATION(_LABEL_, _SUB_LABEL_, _CONT_NUM_) \
73public: \
74 virtual ContinuationBase* Clone() const { return new Continuation##_CONT_NUM_(*this); } \
75 \
76protected: \
77 static const unsigned int ___RequiredMessageSize = 63; \
78 \
79public: \
80 static const unsigned int cCONTINUATION_NUMBER = _CONT_NUM_; \
81 virtual int GetLabel() const { return _CONT_NUM_; } \
82 virtual int GetUID() const { return (_LABEL_ * 100 + _SUB_LABEL_) * 1000 + _CONT_NUM_ * 10; } \
83 static const int cWORD_LABEL = _LABEL_; \
84 static const int cWORD_SUB_LABEL = _SUB_LABEL_; \
85 DEFINE_VIRTUAL_TRANSERS__()
86
87//
93//
96
97//
100//
101
102// Helper definition...
103#define DEFINE_CONT_CASE__(NUM) \
104 case NUM: \
105 return ut::make_unique<Continuation##NUM>();
106#define DEFINE_CONT_CASE2__(N1, N2) DEFINE_CONT_CASE__(N1) DEFINE_CONT_CASE__(N2)
107#define DEFINE_CONT_CASE4__(N1, N2, N3, N4) DEFINE_CONT_CASE2__(N1, N2) DEFINE_CONT_CASE2__(N3, N4)
108#define DEFINE_CONT_CASE8__(N1, N2, N3, N4, N5, N6, N7, N8) \
109 DEFINE_CONT_CASE4__(N1, N2, N3, N4) DEFINE_CONT_CASE4__(N5, N6, N7, N8)
110
111#define DEFINE_CONT_DEFS(NUM) using Continuation##NUM##Type = Continuation##NUM;
112#define DEFINE_CONT_DEFS2(N1, N2) DEFINE_CONT_DEFS(N1) DEFINE_CONT_DEFS(N2)
113#define DEFINE_CONT_DEFS3(N1, N2, N3) DEFINE_CONT_DEFS2(N1, N2) DEFINE_CONT_DEFS(N3)
114#define DEFINE_CONT_DEFS4(N1, N2, N3, N4) DEFINE_CONT_DEFS2(N1, N2) DEFINE_CONT_DEFS2(N3, N4)
115#define DEFINE_CONT_DEFS8(N1, N2, N3, N4, N5, N6, N7, N8) \
116 DEFINE_CONT_DEFS4(N1, N2, N3, N4) DEFINE_CONT_DEFS4(N5, N6, N7, N8)
117
118// One of these should be in each Initial word definitions
119#define DEFINE_CONTINUATIONS12(N1, N2, N3, N4, N5, N6, N7, N8, N9, N10, N11, N12) \
120 DEFINE_CONT_DEFS8(N1, N2, N3, N4, N5, N6, N7, N8) \
121 DEFINE_CONT_DEFS4(N9, N10, N11, N12) std::unique_ptr<ContinuationBase> CreateContinuationWord(int lbl) override \
122 { \
123 switch (lbl) \
124 { \
125 DEFINE_CONT_CASE8__(N1, N2, N3, N4, N5, N6, N7, N8) DEFINE_CONT_CASE4__(N9, N10, N11, N12) \
126 } \
127 return nullptr; \
128 }
129#define DEFINE_CONTINUATIONS11(N1, N2, N3, N4, N5, N6, N7, N8, N9, N10, N11) \
130 DEFINE_CONT_DEFS8(N1, N2, N3, N4, N5, N6, N7, N8) \
131 DEFINE_CONT_DEFS3(N9, N10, N11) std::unique_ptr<ContinuationBase> CreateContinuationWord(int lbl) override \
132 { \
133 switch (lbl) \
134 { \
135 DEFINE_CONT_CASE8__(N1, N2, N3, N4, N5, N6, N7, N8) DEFINE_CONT_CASE2__(N9, N10) DEFINE_CONT_CASE__(N11) \
136 } \
137 return nullptr; \
138 }
139#define DEFINE_CONTINUATIONS10(N1, N2, N3, N4, N5, N6, N7, N8, N9, N10) \
140 DEFINE_CONT_DEFS8(N1, N2, N3, N4, N5, N6, N7, N8) \
141 DEFINE_CONT_DEFS2(N9, N10) std::unique_ptr<ContinuationBase> CreateContinuationWord(int lbl) override \
142 { \
143 switch (lbl) \
144 { \
145 DEFINE_CONT_CASE8__(N1, N2, N3, N4, N5, N6, N7, N8) DEFINE_CONT_CASE2__(N9, N10) \
146 } \
147 return nullptr; \
148 }
149#define DEFINE_CONTINUATIONS9(N1, N2, N3, N4, N5, N6, N7, N8, N9) \
150 DEFINE_CONT_DEFS8(N1, N2, N3, N4, N5, N6, N7, N8) \
151 DEFINE_CONT_DEFS(N9) std::unique_ptr<ContinuationBase> CreateContinuationWord(int lbl) override \
152 { \
153 switch (lbl) \
154 { \
155 DEFINE_CONT_CASE8__(N1, N2, N3, N4, N5, N6, N7, N8) DEFINE_CONT_CASE__(N9) \
156 } \
157 return nullptr; \
158 }
159#define DEFINE_CONTINUATIONS8(N1, N2, N3, N4, N5, N6, N7, N8) \
160 DEFINE_CONT_DEFS8(N1, N2, N3, N4, N5, N6, N7, N8) \
161 std::unique_ptr<ContinuationBase> CreateContinuationWord(int lbl) override \
162 { \
163 switch (lbl) \
164 { \
165 DEFINE_CONT_CASE8__(N1, N2, N3, N4, N5, N6, N7, N8) \
166 } \
167 return nullptr; \
168 }
169#define DEFINE_CONTINUATIONS7(N1, N2, N3, N4, N5, N6, N7) \
170 DEFINE_CONT_DEFS4(N1, N2, N3, N4) \
171 DEFINE_CONT_DEFS3(N5, N6, N7) std::unique_ptr<ContinuationBase> CreateContinuationWord(int lbl) override \
172 { \
173 switch (lbl) \
174 { \
175 DEFINE_CONT_CASE4__(N1, N2, N3, N4) DEFINE_CONT_CASE2__(N5, N6) DEFINE_CONT_CASE__(N7) \
176 } \
177 return nullptr; \
178 }
179#define DEFINE_CONTINUATIONS6(N1, N2, N3, N4, N5, N6) \
180 DEFINE_CONT_DEFS4(N1, N2, N3, N4) \
181 DEFINE_CONT_DEFS2(N5, N6) std::unique_ptr<ContinuationBase> CreateContinuationWord(int lbl) override \
182 { \
183 switch (lbl) \
184 { \
185 DEFINE_CONT_CASE4__(N1, N2, N3, N4) DEFINE_CONT_CASE2__(N5, N6) \
186 } \
187 return nullptr; \
188 }
189#define DEFINE_CONTINUATIONS5(N1, N2, N3, N4, N5) \
190 DEFINE_CONT_DEFS4(N1, N2, N3, N4) \
191 DEFINE_CONT_DEFS(N5) std::unique_ptr<ContinuationBase> CreateContinuationWord(int lbl) override \
192 { \
193 switch (lbl) \
194 { \
195 DEFINE_CONT_CASE4__(N1, N2, N3, N4) DEFINE_CONT_CASE__(N5) \
196 } \
197 return nullptr; \
198 }
199#define DEFINE_CONTINUATIONS4(N1, N2, N3, N4) \
200 DEFINE_CONT_DEFS4(N1, N2, N3, N4) std::unique_ptr<ContinuationBase> CreateContinuationWord(int lbl) override \
201 { \
202 switch (lbl) \
203 { \
204 DEFINE_CONT_CASE4__(N1, N2, N3, N4) \
205 } \
206 return nullptr; \
207 }
208#define DEFINE_CONTINUATIONS3(N1, N2, N3) \
209 DEFINE_CONT_DEFS2(N1, N2) \
210 DEFINE_CONT_DEFS(N3) std::unique_ptr<ContinuationBase> CreateContinuationWord(int lbl) override \
211 { \
212 switch (lbl) \
213 { \
214 DEFINE_CONT_CASE2__(N1, N2) DEFINE_CONT_CASE__(N3) \
215 } \
216 return nullptr; \
217 }
218#define DEFINE_CONTINUATIONS2(N1, N2) \
219 DEFINE_CONT_DEFS2(N1, N2) std::unique_ptr<ContinuationBase> CreateContinuationWord(int lbl) override \
220 { \
221 switch (lbl) \
222 { \
223 DEFINE_CONT_CASE2__(N1, N2) \
224 } \
225 return nullptr; \
226 }
227#define DEFINE_CONTINUATIONS1(N1) \
228 DEFINE_CONT_DEFS(N1) std::unique_ptr<ContinuationBase> CreateContinuationWord(int lbl) override \
229 { \
230 switch (lbl) \
231 { \
232 DEFINE_CONT_CASE__(N1) \
233 } \
234 return nullptr; \
235 }
236#define DEFINE_CONTINUATIONS0() \
237 std::unique_ptr<ContinuationBase> CreateContinuationWord(int lbl) override { return nullptr; }
238
239// One of these should be inside each Initial word definition
240#define DEFINE_EXTENSIONS0() \
241 std::unique_ptr<ExtensionBase> CreateExtensionWord(int /*aEn*/) override { return nullptr; }
242#define DEFINE_EXTENSIONS1() \
243 typedef Extension0 Extension0Type; \
244 std::unique_ptr<ExtensionBase> CreateExtensionWord(int aEn) override \
245 { \
246 switch (aEn) \
247 { \
248 case 0: \
249 return ut::make_unique<Extension0>(); \
250 default: \
251 return nullptr; \
252 } \
253 }
254#define DEFINE_EXTENSIONS2() \
255 typedef Extension0 Extension0Type; \
256 typedef Extension1 Extension1Type; \
257 std::unique_ptr<ExtensionBase> CreateExtensionWord(int aEn) override \
258 { \
259 switch (aEn) \
260 { \
261 case 0: \
262 return ut::make_unique<Extension0>(); \
263 case 1: \
264 return ut::make_unique<Extension1>(); \
265 default: \
266 return nullptr; \
267 } \
268 }
269#define DEFINE_EXTENSIONS3() \
270 typedef Extension0 Extension0Type; \
271 typedef Extension1 Extension1Type; \
272 typedef Extension2 Extension2Type; \
273 std::unique_ptr<ExtensionBase> CreateExtensionWord(int aEn) override \
274 { \
275 switch (aEn) \
276 { \
277 case 0: \
278 return ut::make_unique<Extension0>(); \
279 case 1: \
280 return ut::make_unique<Extension1>(); \
281 case 2: \
282 return ut::make_unique<Extension2>(); \
283 default: \
284 return nullptr; \
285 } \
286 }
287
288namespace WsfL16
289{
290namespace Messages
291{
292
293template<typename INIT_TYPE, typename SUB_WORD, typename WORD_TYPE_TAG, unsigned CORRECT_SUB_TYPE>
295{
296};
297
298template<typename INIT_TYPE, typename SUB_WORD>
299struct WordFinder<INIT_TYPE, SUB_WORD, ContinuationBase, 1>
300{
301 static bool FindWord(INIT_TYPE& aInitial, SUB_WORD*& aContinuation)
302 {
303 aContinuation = static_cast<SUB_WORD*>(aInitial.FindContinuation(SUB_WORD::cCONTINUATION_NUMBER));
304 return aContinuation != nullptr;
305 }
306};
307
308template<typename INIT_TYPE, typename SUB_WORD>
309struct WordFinder<INIT_TYPE, SUB_WORD, ExtensionBase, 1>
310{
311 static bool FindWord(INIT_TYPE& aInitial, SUB_WORD*& aExtension)
312 {
313 if (aInitial.GetExtensionCount() > SUB_WORD::cEXTENSION_NUMBER)
314 {
315 aExtension = static_cast<SUB_WORD*>(aInitial.GetExtension(SUB_WORD::cEXTENSION_NUMBER));
316 }
317 else
318 {
319 aExtension = nullptr;
320 }
321 return aExtension != nullptr;
322 }
323};
324
325template<typename INIT_TYPE, typename SUB_WORD>
326inline bool FindWordT(INIT_TYPE& aInitialWord, SUB_WORD*& aSubWord)
327{
328 const bool correctSubType =
329 (INIT_TYPE::cWORD_LABEL == SUB_WORD::cWORD_LABEL) && (INIT_TYPE::cWORD_SUB_LABEL == SUB_WORD::cWORD_SUB_LABEL);
331 return Finder::FindWord(aInitialWord, aSubWord);
332}
333
334} // namespace Messages
335} // namespace WsfL16
336
337#endif
std::vector< ScenarioAnalyzerMessage > Messages
Definition ScenarioAnalyzerUtilities.hpp:67
The base class for J-Message ContinuationBase words.
Definition Messages.hpp:168
Definition Messages.hpp:183
Definition ComputerPart.hpp:45
bool FindWordT(INIT_TYPE &aInitialWord, SUB_WORD *&aSubWord)
Definition MessageDefines.hpp:326
This file should be included prior to defining a message. Currently there is a limit of 32 fields per...
Definition AllMessages.hpp:55
static bool FindWord(INIT_TYPE &aInitial, SUB_WORD *&aContinuation)
Definition MessageDefines.hpp:301
static bool FindWord(INIT_TYPE &aInitial, SUB_WORD *&aExtension)
Definition MessageDefines.hpp:311
Definition MessageDefines.hpp:295
Copyrights Multiple, All Rights Reserved