WSF
WsfPProxyBasicTypes.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 VIPROXYBASICTYPES_HPP
16#define VIPROXYBASICTYPES_HPP
17
18#include "wsf_parser_export.h"
19
21#include "WsfParseNode.hpp"
22
23// clang-format off
24#include "WsfPProxyValue.hpp"
25#include "WsfPProxyType.hpp"
26// clang-format on
27
28//
29// This file contains many of the basic proxy types.
30// Important:
31// - Most basic types share the same format as normal c++ types, however, any value stored in the proxy
32// must have the capability to be stored as the 'unset' value.
33// - Placement New heavily used here to construct values in a preexisting memory location
34
35
36// Template class to handle most of the basic type routines.
37// T is the C++ data type stored as the proxy value.
38// T must support T(), T==T, T<T, T=T
39
40template<typename VALUE_TYPE>
42{
43public:
44 using DataType = VALUE_TYPE;
45 ProxyTypeAdapterBaseT(unsigned int aTypeFlags = WsfProxy::cPOD)
46 : WsfPProxyBasicType(VALUE_TYPE::cPROXY_TYPE_ID)
47 {
48 mTypeFlags |= aTypeFlags;
49 mDataSize = sizeof(VALUE_TYPE);
50 }
51
52protected:
53 static VALUE_TYPE& Get(void* p) { return *(VALUE_TYPE*)p; }
54
55public:
56 void Construct(void* p) const override { new (p) VALUE_TYPE(); }
57 void Destroy(void* p) const override { Get(p).~VALUE_TYPE(); }
58 void SetValue(void* p, const std::string& aText) const override { Get(p).SetFromString(aText); }
59 std::string ToString(void* p) const override { return Get(p).ToString(); }
60 void Copy(void* dest, void* src, int flags) const override { Get(dest).CopyValue(Get(src)); }
61 bool Equal(void* lhs, void* rhs) const override { return Get(lhs).Equal(Get(rhs)); }
62 bool Less(void* lhs, void* rhs) const override { return Get(lhs).Less(Get(rhs)); }
63};
64
65template<typename VALUE_TYPE>
66class ProxyTypeAdapterT : public ProxyTypeAdapterBaseT<VALUE_TYPE>
67{
68public:
69 using DataType = VALUE_TYPE;
70 ProxyTypeAdapterT(unsigned int aTypeFlags = WsfProxy::cPOD)
71 : ProxyTypeAdapterBaseT<VALUE_TYPE>(aTypeFlags)
72 {
73 }
74
75protected:
76 static VALUE_TYPE& Get(void* p) { return *(VALUE_TYPE*)p; }
77
78public:
79 void Read(void* p, WsfParseNode* aNodePtr) const override { Get(p).Read(aNodePtr); }
80 std::string Write(void* p, WsfParseRule* aRulePtr) const override { return Get(p).Write(aRulePtr); }
81};
82
83template<typename VALUE_TYPE>
85{
86public:
87 using UnitaryType = typename VALUE_TYPE::ContainedBasicType;
88 ProxyUnitaryTypeAdapterT(unsigned int aTypeFlags = WsfProxy::cPOD)
89 : ProxyTypeAdapterT<VALUE_TYPE>(aTypeFlags)
90 {
91 }
92
93
94 int GetUnitTypeId() const override { return UnitaryType::UnitType::cUNIT_TYPE_ID; }
95};
96
97class WsfPProxyPositionType : public ProxyTypeAdapterT<WsfProxy::Position>
98{
99};
100class WsfPProxyLength2Type : public ProxyTypeAdapterT<WsfProxy::Length2>
101{
102};
103class WsfPProxyLength3Type : public ProxyTypeAdapterT<WsfProxy::Length3>
104{
105};
106class WsfPProxyBoolType : public ProxyTypeAdapterT<WsfProxy::Bool>
107{
108};
109class WsfPProxyRealType : public ProxyTypeAdapterT<WsfProxy::Double>
110{
111};
112class WsfPProxyIntType : public ProxyTypeAdapterT<WsfProxy::Int>
113{
114};
115class WSF_PARSER_EXPORT WsfPProxyStringType : public ProxyTypeAdapterT<WsfProxy::String>
116{
117public:
119 void Construct(void* p) const override;
120 WsfPProxyHash Hash(void* aDataPtr) const override;
121 size_t MemoryUsage(void* aDataPtr) const override;
122 std::string Write(void* p, WsfParseRule* aRulePtr) const override;
123};
124class WSF_PARSER_EXPORT WsfPProxyQuotableStringType : public ProxyTypeAdapterT<WsfProxy::QuotableString>
125{
126public:
128 void Construct(void* p) const override;
129 WsfPProxyHash Hash(void* aDataPtr) const override;
130 size_t MemoryUsage(void* aDataPtr) const override;
131 std::string Write(void* p, WsfParseRule* aRulePtr) const override;
132};
133
134#define WSF_PPROXY_DEFINE_BASIC_TYPE(NAME, BASE) \
135 class WsfPProxy##NAME##Type : public BASE<WsfProxy::NAME> \
136 { \
137 }
138
139#define WSF_PPROXY_DEFINE_UNITARY_TYPE(NAME) WSF_PPROXY_DEFINE_BASIC_TYPE(NAME, ProxyUnitaryTypeAdapterT)
140
143
144
176
177using WsfPEnumStrMap = std::map<std::string, int>;
178using WsfPEnumIntMap = std::map<int, std::string>;
179
180// Enumerations are stored as integers.
181class WSF_PARSER_EXPORT WsfPProxyEnumType : public ProxyTypeAdapterT<WsfProxy::Int>
182{
183 static const int cNOT_SET_VALUE = -INT_MAX + 3;
184
185public:
187
188private:
189 static WsfProxy::Int& Get(void* p) { return *(WsfProxy::Int*)p; }
190
191public:
192 void Construct(void* p) const override;
193
194 void SetValue(void* p, const std::string& aText) const override;
195 void Read(void* p, WsfParseNode* aNodePtr) const override;
196 std::string Write(void* p, WsfParseRule* aRulePtr) const override;
197 std::string ToString(void* p) const override;
198
199 bool IsTypeOf(const WsfPProxyType* aOtherType) const override;
200
203};
204
205#endif
#define WSF_PPROXY_DEFINE_BASIC_TYPE(NAME, BASE)
Definition WsfPProxyBasicTypes.hpp:134
std::map< int, std::string > WsfPEnumIntMap
Definition WsfPProxyBasicTypes.hpp:178
std::map< std::string, int > WsfPEnumStrMap
Definition WsfPProxyBasicTypes.hpp:177
#define WSF_PPROXY_DEFINE_UNITARY_TYPE(NAME)
Definition WsfPProxyBasicTypes.hpp:139
std::string ToString(void *p) const override
Definition WsfPProxyBasicTypes.hpp:59
bool Less(void *lhs, void *rhs) const override
Definition WsfPProxyBasicTypes.hpp:62
VALUE_TYPE DataType
Definition WsfPProxyBasicTypes.hpp:44
void Destroy(void *p) const override
Definition WsfPProxyBasicTypes.hpp:57
void Copy(void *dest, void *src, int flags) const override
Definition WsfPProxyBasicTypes.hpp:60
void SetValue(void *p, const std::string &aText) const override
Definition WsfPProxyBasicTypes.hpp:58
bool Equal(void *lhs, void *rhs) const override
Definition WsfPProxyBasicTypes.hpp:61
static VALUE_TYPE & Get(void *p)
Definition WsfPProxyBasicTypes.hpp:53
ProxyTypeAdapterBaseT(unsigned int aTypeFlags=WsfProxy::cPOD)
Definition WsfPProxyBasicTypes.hpp:45
void Construct(void *p) const override
Definition WsfPProxyBasicTypes.hpp:56
Definition WsfPProxyBasicTypes.hpp:67
static VALUE_TYPE & Get(void *p)
Definition WsfPProxyBasicTypes.hpp:76
VALUE_TYPE DataType
Definition WsfPProxyBasicTypes.hpp:69
std::string Write(void *p, WsfParseRule *aRulePtr) const override
Definition WsfPProxyBasicTypes.hpp:80
ProxyTypeAdapterT(unsigned int aTypeFlags=WsfProxy::cPOD)
Definition WsfPProxyBasicTypes.hpp:70
void Read(void *p, WsfParseNode *aNodePtr) const override
Definition WsfPProxyBasicTypes.hpp:79
typename VALUE_TYPE::ContainedBasicType UnitaryType
Definition WsfPProxyBasicTypes.hpp:87
int GetUnitTypeId() const override
Definition WsfPProxyBasicTypes.hpp:94
ProxyUnitaryTypeAdapterT(unsigned int aTypeFlags=WsfProxy::cPOD)
Definition WsfPProxyBasicTypes.hpp:88
size_t MemoryUsage(void *aDataPtr) const override
Definition WsfPProxyType.hpp:168
WsfPProxyBasicType(WsfProxy::ValueKind aKind)
Definition WsfPProxyType.hpp:118
Definition WsfPProxyBasicTypes.hpp:107
WsfPEnumIntMap mIntToString
Definition WsfPProxyBasicTypes.hpp:202
WsfPProxyEnumType()
Definition WsfPProxyBasicTypes.cpp:85
WsfPEnumStrMap mStringToInt
Definition WsfPProxyBasicTypes.hpp:201
Definition WsfPProxyHash.hpp:26
Definition WsfPProxyBasicTypes.hpp:113
Definition WsfPProxyBasicTypes.hpp:101
Definition WsfPProxyBasicTypes.hpp:104
Definition WsfPProxyBasicTypes.hpp:98
WsfPProxyQuotableStringType()
Definition WsfPProxyBasicTypes.cpp:122
Definition WsfPProxyBasicTypes.hpp:110
WsfPProxyStringType()
Definition WsfPProxyBasicTypes.cpp:96
Definition WsfPProxyType.hpp:37
virtual bool IsTypeOf(const WsfPProxyType *aOtherType) const
Definition WsfPProxyType.hpp:103
int mTypeFlags
Definition WsfPProxyType.hpp:55
size_t mDataSize
Definition WsfPProxyType.hpp:58
virtual WsfPProxyHash Hash(void *aDataPtr) const
Definition WsfPProxyType.hpp:104
Definition WsfParseNode.hpp:61
Definition WsfParseRule.hpp:131
@ cPOD
Definition WsfPProxyCommon.hpp:27
NumericValueT< int, WsfProxy::cINT_VALUE > Int
Definition WsfPProxyBasicValues.hpp:407
Copyrights Multiple, All Rights Reserved