WSF
WsfPProxyValue.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 WSFPPROXYVALUE_HPP
16#define WSFPPROXYVALUE_HPP
17
18#include <string>
19
21#include "WsfPProxyHash.hpp"
22#include "WsfPProxyKey.hpp"
23#include "WsfParseType.hpp"
24class WsfPProxyType;
25
27class WsfPProxyList;
28class WsfPProxyPath;
29
30// This is a helper class for holding and operating on proxy values
31// Notice: Instances of WsfPProxyValue act as pointers to proxy values when using the copy constructor or assignment operator
32class WSF_PARSER_EXPORT WsfPProxyValue
33{
34public:
36 : mTypePtr(nullptr)
37 , mDataPtr(nullptr)
38 {
39 }
40
41 WsfPProxyValue(void* aDataPtr, WsfPProxyType const* aTypePtr)
42 : mTypePtr(aTypePtr)
43 , mDataPtr(aDataPtr)
44 {
45 }
46
47 WsfPProxyValue(const WsfPProxyValue&) = default;
51 virtual ~WsfPProxyValue() = default;
52
53 static WsfPProxyValue ConstructNew(const WsfPProxyType* aType);
54
55 bool IsBasicType() const;
56
57 bool IsStruct() const;
58
59 bool IsValid() const { return mTypePtr != nullptr; }
60 void* GetDataPtr() const { return mDataPtr; }
61 const WsfPProxyType* GetType() const { return mTypePtr; }
62 WsfPProxyValue GetAttr(const WsfPProxyKey& aEntry) const
63 {
64 if (aEntry.IsString())
65 {
66 return GetAttr(aEntry.GetMapKey());
67 }
68 return GetAttr(aEntry.GetIndex());
69 }
70 WsfPProxyValue GetAttr(const std::string& aName) const;
71 WsfPProxyValue GetAttr(size_t aIndex) const;
72
74 bool SwapAttr(const WsfPProxyKey& aEntry, WsfPProxyValue& aValue) const;
75
76 WsfPProxyValue GetAtIndex(size_t aIndex) const;
77 size_t GetAttrCount() const;
78 std::string NameAtIndex(size_t aIndex) const;
79 virtual size_t GetMemberIndex(const std::string& aName) const;
80 virtual WsfPProxyType* GetMemberType(const std::string& aName) const;
81 virtual WsfPProxyType* GetMemberType(size_t aMemberIndex) const;
82
83 WsfPProxyList* GetList() const;
84 WsfPProxyObjectMap* GetObjectMap() const;
85 bool Copy(WsfPProxyValue aSrc, int flags = WsfProxy::cCOPY_ALL) const;
86 void SetValue(const std::string& aText);
87 void SetBoolValue(bool value);
88 std::string ValueToString() const;
89 // Returns a new copy of this value. Warning: These values are NOT reference counted, and extra care must be
90 // taken to ensure the value is deleted to avoid a memory leak;
91 WsfPProxyValue Copy(int flags = WsfProxy::cCOPY_ALL) const;
92 void SetUnset();
93 void ClearUnset();
94 bool IsUnset() const;
95 bool IsInherited() const;
96 void SetInherited(bool aIsInherited);
97
100 WsfPProxyPath* GetBasePath() const;
101
102
103 operator bool() const { return IsValid(); }
104 operator bool() { return IsValid(); }
105 // Returns true if both proxy values point to the same underlying value. Does not test for equality of value.
106 bool operator==(const WsfPProxyValue& aRhs) const { return mDataPtr == aRhs.mDataPtr; }
107 bool operator<(const WsfPProxyValue& aRhs) const { return mDataPtr < aRhs.mDataPtr; }
108 void Delete();
109 void Swap(WsfPProxyValue& aRhs) noexcept
110 {
111 std::swap(mTypePtr, aRhs.mTypePtr);
112 std::swap(mDataPtr, aRhs.mDataPtr);
113 }
114 WsfPProxyValue operator[](const char* aAttrName) { return GetAttr(aAttrName); }
115 WsfPProxyValue operator[](const std::string& aAttrName) { return GetAttr(aAttrName); }
116 WsfPProxyValue operator[](size_t aIndex) { return GetAtIndex(aIndex); }
117 WsfPProxyHash Hash();
118
119 WsfPProxyValue Lookup(const WsfPProxyPath& aPath, size_t aElements = 0x7fffffff) const;
120 WsfPProxyValue Lookup(const WsfParseTypePath& aPath) const;
121
122 WsfPProxyValue& operator=(const std::string& aStringValue);
123 WsfPProxyValue& operator=(const char* aStringPtr);
124 WsfPProxyValue& operator=(bool aBoolValue);
125#define ADD_TYPE_OPERATOR(VALUE_TYPE) \
126 operator VALUE_TYPE*() const; \
127 WsfPProxyValue& operator=(const VALUE_TYPE& aVal);
167#undef ADD_TYPE_OPERATOR
168
169 bool GetIntegerValue(int& aValue);
170
171 void SetIntegerValue(int aValue);
172
173
174 bool IsBoolValue();
175 bool GetBoolValue();
176
177 void DebugOut(std::ostream& aStream, unsigned int aDepth = 0) const;
178
179 // template <typename VALUE_TYPE>
180 // inline VALUE_TYPE* proxy_cast(const WsfPProxyValue& aValue)
181 // {
182 // WsfPProxyType* typePtr = aValue.GetType();
183 // if (typePtr && typePtr->mTypeStoredKind == VALUE_TYPE::cPROXY_TYPE_ID)
184 // {
185 // return (VALUE_TYPE*)aValue.GetDataPtr();
186 // }
187 // return 0;
188 // }
189
190 bool IsAttributeUsable(const std::string& aAttribute) const noexcept;
191
192protected:
193 template<typename T>
194 T* CastToValue() const;
195 // Pointer to the value's type
197 // Raw pointer to the data
198 void* mDataPtr;
199};
200
201namespace std
202{
203template<>
204inline void swap(WsfPProxyValue& a, WsfPProxyValue& b) noexcept
205{
206 a.Swap(b);
207}
208} // namespace std
209
211
212#endif
#define ADD_TYPE_OPERATOR(VALUE_TYPE)
Definition WsfPProxyValue.hpp:125
std::vector< UtStringRef > WsfParseTypePath
Definition WsfParseTypePath.hpp:21
Definition WsfPProxyHash.hpp:26
Definition WsfPProxyKey.hpp:24
size_t GetIndex() const
Definition WsfPProxyKey.hpp:42
const std::string & GetMapKey() const
Definition WsfPProxyKey.hpp:43
bool IsString() const
Definition WsfPProxyKey.cpp:47
Definition WsfPProxyList.hpp:34
Definition WsfPProxyObjectMap.hpp:36
Represents a path or unique key to a value in the proxy.
Definition WsfPProxyPath.hpp:64
Definition WsfPProxyType.hpp:37
Definition WsfPProxyValue.hpp:33
bool operator==(const WsfPProxyValue &aRhs) const
Definition WsfPProxyValue.hpp:106
void Swap(WsfPProxyValue &aRhs) noexcept
Definition WsfPProxyValue.hpp:109
void * mDataPtr
Definition WsfPProxyValue.hpp:198
bool operator<(const WsfPProxyValue &aRhs) const
Definition WsfPProxyValue.hpp:107
WsfPProxyValue & operator=(const WsfPProxyValue &)=default
WsfPProxyValue(const WsfPProxyValue &)=default
bool IsBasicType() const
Definition WsfPProxyValue.cpp:48
static WsfPProxyValue ConstructNew(const WsfPProxyType *aType)
Definition WsfPProxyValue.cpp:23
bool IsValid() const
Definition WsfPProxyValue.hpp:59
WsfPProxyValue()
Definition WsfPProxyValue.hpp:35
virtual ~WsfPProxyValue()=default
WsfPProxyValue operator[](const std::string &aAttrName)
Definition WsfPProxyValue.hpp:115
WsfPProxyValue(WsfPProxyValue &&)=default
const WsfPProxyType * GetType() const
Definition WsfPProxyValue.hpp:61
WsfPProxyValue GetAtIndex(size_t aIndex) const
Definition WsfPProxyValue.cpp:34
WsfPProxyValue operator[](size_t aIndex)
Definition WsfPProxyValue.hpp:116
WsfPProxyValue(void *aDataPtr, WsfPProxyType const *aTypePtr)
Definition WsfPProxyValue.hpp:41
WsfPProxyValue GetAttr(const WsfPProxyKey &aEntry) const
Definition WsfPProxyValue.hpp:62
WsfPProxyValue & operator=(WsfPProxyValue &&)=default
WsfPProxyValue operator[](const char *aAttrName)
Definition WsfPProxyValue.hpp:114
bool IsStruct() const
Definition WsfPProxyValue.cpp:53
const WsfPProxyType * mTypePtr
Definition WsfPProxyValue.hpp:196
void * GetDataPtr() const
Definition WsfPProxyValue.hpp:60
Definition WsfPProxyBasicValues.hpp:211
Definition WsfPProxyBasicValues.hpp:167
Definition WsfPProxyBasicValues.hpp:89
Definition WsfPProxyBasicValues.hpp:478
NumericUnitaryValueT< UtTimeValue, WsfProxy::cTIME_VALUE > Time
Definition WsfPProxyBasicValues.hpp:415
NumericUnitaryValueT< UtTime2Value, WsfProxy::cTIME2_VALUE > Time2
Definition WsfPProxyBasicValues.hpp:439
NumericUnitaryValueT< UtTorqueValue, WsfProxy::cTORQUE_VALUE > Torque
Definition WsfPProxyBasicValues.hpp:431
NumericUnitaryValueT< UtRatioValue, WsfProxy::cRATIO_VALUE > Ratio
Definition WsfPProxyBasicValues.hpp:463
NumericValueT< UtLonPos, WsfProxy::cLONGITUDE_VALUE > Longitude
Definition WsfPProxyBasicValues.hpp:411
NumericUnitaryValueT< UtLengthValue, WsfProxy::cLENGTH_VALUE > Length
Definition WsfPProxyBasicValues.hpp:413
NumericUnitaryValueT< UtAngularInertiaValue, WsfProxy::cANGULARINERTIA_VALUE > AngularInertia
Definition WsfPProxyBasicValues.hpp:473
NumericUnitaryValueT< UtDataRateValue, WsfProxy::cDATARATE_VALUE > DataRate
Definition WsfPProxyBasicValues.hpp:451
NumericUnitaryValueT< UtAreaDBValue, WsfProxy::cAREADB_VALUE > AreaDB
Definition WsfPProxyBasicValues.hpp:435
NumericUnitaryValueT< UtSpecificRangeValue, WsfProxy::cSPECIFICRANGE_VALUE > SpecificRange
Definition WsfPProxyBasicValues.hpp:471
NumericUnitaryValueT< UtFrequencyValue, WsfProxy::cFREQUENCY_VALUE > Frequency
Definition WsfPProxyBasicValues.hpp:443
NumericUnitaryValueT< UtAreaValue, WsfProxy::cAREA_VALUE > Area
Definition WsfPProxyBasicValues.hpp:433
NumericUnitaryValueT< UtVolumeValue, WsfProxy::cVOLUME_VALUE > Volume
Definition WsfPProxyBasicValues.hpp:437
NumericUnitaryValueT< UtFluenceValue, WsfProxy::cFLUENCE_VALUE > Fluence
Definition WsfPProxyBasicValues.hpp:459
NumericUnitaryValueT< UtSpeedValue, WsfProxy::cSPEED_VALUE > Speed
Definition WsfPProxyBasicValues.hpp:417
NumericValueT< UtLatPos, WsfProxy::cLATITUDE_VALUE > Latitude
Definition WsfPProxyBasicValues.hpp:409
NumericUnitaryValueT< UtPowerDBValue, WsfProxy::cPOWERDB_VALUE > PowerDB
Definition WsfPProxyBasicValues.hpp:423
NumericValueT< int, WsfProxy::cINT_VALUE > Int
Definition WsfPProxyBasicValues.hpp:407
NumericUnitaryValueT< UtAngularAccelerationValue, WsfProxy::cANGULARACCELERATION_VALUE > AngularAcceleration
Definition WsfPProxyBasicValues.hpp:449
NumericUnitaryValueT< UtIrradianceValue, WsfProxy::cIRRADIANCE_VALUE > Irradiance
Definition WsfPProxyBasicValues.hpp:461
@ cCOPY_ALL
Definition WsfPProxyCommon.hpp:104
NumericUnitaryValueT< UtPowerValue, WsfProxy::cPOWER_VALUE > Power
Definition WsfPProxyBasicValues.hpp:421
NumericUnitaryValueT< UtDataSizeValue, WsfProxy::cDATASIZE_VALUE > DataSize
Definition WsfPProxyBasicValues.hpp:419
NumericUnitaryValueT< UtMassTransferValue, WsfProxy::cMASSTRANSFER_VALUE > MassTransfer
Definition WsfPProxyBasicValues.hpp:455
NumericUnitaryValueT< UtMassDensityValue, WsfProxy::cMASSDENSITY_VALUE > MassDensity
Definition WsfPProxyBasicValues.hpp:453
NumericUnitaryValueT< UtSolidAngleValue, WsfProxy::cSOLIDANGLE_VALUE > SolidAngle
Definition WsfPProxyBasicValues.hpp:425
NumericUnitaryValueT< UtAngleValue, WsfProxy::cANGLE_VALUE > Angle
Definition WsfPProxyBasicValues.hpp:445
NumericUnitaryValueT< UtForceValue, WsfProxy::cFORCE_VALUE > Force
Definition WsfPProxyBasicValues.hpp:429
NumericUnitaryValueT< UtAccelerationValue, WsfProxy::cACCELERATION_VALUE > Acceleration
Definition WsfPProxyBasicValues.hpp:441
NumericUnitaryValueT< UtEnergyValue, WsfProxy::cENERGY_VALUE > Energy
Definition WsfPProxyBasicValues.hpp:457
NumericUnitaryValueT< UtAngularRateValue, WsfProxy::cANGULARRATE_VALUE > AngularRate
Definition WsfPProxyBasicValues.hpp:447
NumericUnitaryValueT< UtTemperatureValue, WsfProxy::cTEMPERATURE_VALUE > Temperature
Definition WsfPProxyBasicValues.hpp:469
NumericUnitaryValueT< UtMassValue, WsfProxy::cMASS_VALUE > Mass
Definition WsfPProxyBasicValues.hpp:427
NumericUnitaryValueT< UtNoisePressureValue, WsfProxy::cNOISEPRESSURE_VALUE > NoisePressure
Definition WsfPProxyBasicValues.hpp:465
NumericUnitaryValueT< UtPressureValue, WsfProxy::cPRESSURE_VALUE > Pressure
Definition WsfPProxyBasicValues.hpp:467
NumericValueT< double, WsfProxy::cDOUBLE_VALUE > Double
Definition WsfPProxyBasicValues.hpp:405
Template specialization for wsf::comm::Address. Allows usage of Address in std::unordered_map/set.
Definition WsfCommAddress.hpp:185
void swap(WsfRoute &aLhs, WsfRoute &aRhs)
Definition WsfRoute.hpp:294
Copyrights Multiple, All Rights Reserved