WSF
UtPackReflect.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// Updated by Infoscitex, a DCS Company
13//****************************************************************************
14
15#ifndef UTPACKREFLECT_HPP
16#define UTPACKREFLECT_HPP
17
18#include "UtCast.hpp"
19#include "UtPack.hpp"
20class UtPackType;
22class UtPackField;
24
25// See UtPack.hpp
26// This file contains the classes related to registering UtPack generated code
27// with a UtPackSerializer
28
30{
31public:
32 friend class UtPackSerializer;
34 ~UtPackReflector() = default;
35
36 template<typename T>
37 void BeginStruct(const char* aName, T& aInstance)
38 {
39 assert(mCurrentInstancePtr == nullptr);
40 mCurrentInstancePtr = (char*)&aInstance;
41 mCurrentLayoutPtr = new UtPackStructLayout;
42 mCurrentLayoutPtr->mStructName = aName;
43 mCurrentLayoutPtr->mStructSizeBytes = sizeof(T);
44 }
45
46 template<typename T>
48 {
49 static void Call(void* aUnionPtr, int aFieldType)
50 {
51 ((T*)aUnionPtr)->SetFieldType((typename T::FieldType)aFieldType);
52 }
53 };
54
55 template<typename T>
56 void BeginUnion(const char* aName, T& aInstance)
57 {
58 BeginStruct(aName, aInstance);
59 mCurrentLayoutPtr->mSetFieldTypeFuncPtr = &CallUnionSetFieldType<T>::Call;
60 }
61
62 void End();
63
64 template<typename T>
65 void OptionalFlags(T& aMember)
66 {
67 mCurrentLayoutPtr->mOptionalFlagsOffset = (int)((char*)&aMember - mCurrentInstancePtr);
68 mCurrentLayoutPtr->mOptionalFlagsBytes = sizeof(T);
69 }
70
71 template<typename T>
72 void OptionalMember(const char* aTypeName, const char* aMemberName, T& aMember, int aOptionIndex)
73 {
74 assert(mCurrentInstancePtr);
75 AddMember(aTypeName,
76 aMemberName,
77 reinterpret_cast<char*>(&aMember),
78 ut::safe_cast<unsigned short, size_t>(sizeof(T)),
79 aOptionIndex);
80 }
81
82 template<typename T>
83 void RequiredMember(const char* aTypeName, const char* aMemberName, T& aMember)
84 {
85 assert(mCurrentInstancePtr);
86 AddMember(aTypeName,
87 aMemberName,
88 reinterpret_cast<char*>(&aMember),
89 ut::safe_cast<unsigned short, size_t>(sizeof(T)),
90 -1);
91 }
92 template<typename T>
94 {
95 static UtPackMessage* Create() { return new T; }
96 };
97 template<typename T>
98 void RegisterMessage(T& aMessage)
99 {
100 mSerializerPtr->RegisterMessage(aMessage.GetMessageId(), MessageFactory<T>::Create);
101 }
102
103private:
104 void AddMember(const char* aTypeName, const char* aMemberName, char* aMemberPtr, unsigned short aMemberSize, int aOptionIndex);
105
106 UtPackStructLayout* mCurrentLayoutPtr;
107 char* mCurrentInstancePtr;
108 UtPackSerializer* mSerializerPtr;
109 int mNextOptionIndex;
110};
111
112#endif
#define WSF_UT_EXPORT
Definition WsfUtExport.hpp:32
A field in a struct or union.
Definition UtPackSchema.hpp:197
Definition UtPackMessage.hpp:119
~UtPackReflector()=default
void RequiredMember(const char *aTypeName, const char *aMemberName, T &aMember)
Definition UtPackReflect.hpp:83
void BeginUnion(const char *aName, T &aInstance)
Definition UtPackReflect.hpp:56
void OptionalFlags(T &aMember)
Definition UtPackReflect.hpp:65
friend class UtPackSerializer
Definition UtPackReflect.hpp:32
void BeginStruct(const char *aName, T &aInstance)
Definition UtPackReflect.hpp:37
void RegisterMessage(T &aMessage)
Definition UtPackReflect.hpp:98
UtPackReflector(UtPackSerializer &aSerializer)
Definition UtPackReflect.cpp:42
void OptionalMember(const char *aTypeName, const char *aMemberName, T &aMember, int aOptionIndex)
Definition UtPackReflect.hpp:72
Definition UtPackStream.hpp:26
Definition UtPack.hpp:137
Definition UtPack.hpp:64
const char * mStructName
Definition UtPack.hpp:112
Definition UtPackSchema.hpp:170
Definition UtPackSchema.hpp:118
Definition UtPackReflect.hpp:48
static void Call(void *aUnionPtr, int aFieldType)
Definition UtPackReflect.hpp:49
Definition UtPackReflect.hpp:94
static UtPackMessage * Create()
Definition UtPackReflect.hpp:95
Copyrights Multiple, All Rights Reserved