WSF
WsfPProxyType.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 VIPROXYTYPE_HPP
16#define VIPROXYTYPE_HPP
17
18#include "wsf_parser_export.h"
19
20#include <cassert>
21#include <string>
22
23#include "UtMemoryDebug.hpp"
24#include "WsfPProxyCommon.hpp"
25#include "WsfPProxyHash.hpp"
26#include "WsfPProxyValue.hpp"
27
28// For every value stored in the proxy, it must have a type class. The type class defines how
29// to do basic operations on values of that type.
30// Type values must have a fixed size, and be able to be constructed in a preexisting memory buffer.
31// There are 4 main kinds of types.
32// struct - stores a static set of members
33// list - stores a dynamic list of members that all share a single type
34// object map - stores a dynamic set of members sharing a single type, each with a string name
35// basic types - Stores a single value (integer, string, Latitude, etc...)
36class WSF_PARSER_EXPORT WsfPProxyType
37{
38public:
40 : mTypeFlags(0)
41 , mTypeKind(aKind)
42 , mTypeStoredKind(aKind)
43 {
44 // Handle the general case here
47 {
49 }
50 }
51 virtual ~WsfPProxyType() {}
52
53 const std::string& GetTypeName() const { return mTypeName; }
54 size_t GetDataSize() const { return mDataSize; }
58 size_t mDataSize;
59 std::string mTypeName;
60
61 // Construct a value at the given address
62 virtual void Construct(void* aValuePtr) const = 0;
63
64 // Destroy the value
65 virtual void Destroy(void* aValuePtr) const = 0;
66
67 // Copy aSrc to a Dest
68 virtual void Copy(void* aDest, void* aSrc, int copyFlags) const = 0;
69
70 // If this value is an object map, return the value mapped to the given name.
71 // If this value is a struct, return the member with the given name
72 virtual WsfPProxyValue GetAttr(void* aPtr, const std::string& aName) const = 0;
73
74 virtual bool SwapAttr(void* aPtr, const WsfPProxyKey& aKey, WsfPProxyValue& aValue) const { return false; }
75
76 // If the value contains other values which may be indexed, returns the contained value
77 // at the given index. Valid for lists and structs.
78 virtual WsfPProxyValue GetAtIndex(void* aPtr, size_t aIndex) const { return WsfPProxyValue(); }
79 virtual std::string GetNameAtIndex(size_t aIndex) const { return std::string(); }
80 virtual size_t GetAttrCount(void* aPtr) const { return 0; }
81 virtual size_t GetMemberIndex(const std::string& aAttrName) const { return ut::npos; }
82
83 // Returns 'true' if the value is in the unset state
84 virtual bool IsUnset(void* aValuePtr) const = 0;
85 // Sets the value to the 'unset' state
86 virtual void SetUnset(void* aValuePtr) const = 0;
87 virtual void ClearUnset(void* aValuePtr) const {}
88
89 virtual bool IsInherited(void* aValuePtr) const = 0;
90 virtual void SetInherited(void* aValuePtr, bool aIsInherited) const = 0;
91
92 virtual bool IsOfBasicType(const std::string& aTypeName) const { return aTypeName == mTypeName; }
93
94 // If this type can contain other types, this returns the type contained at the given index.
95 // The index is only necessary for structs, maps and lists have only one contained type.
96 virtual WsfPProxyType* GetContainedType(size_t aIndex) const { return nullptr; }
97
98 bool IsBasicType() const { return 0 != (mTypeFlags & WsfProxy::cVALUE_FLAG); }
99 bool IsStruct() const { return mTypeKind == WsfProxy::cSTRUCT; }
100 bool IsList() const { return mTypeKind == WsfProxy::cLIST; }
101 bool IsObjectMap() const { return mTypeKind == WsfProxy::cOBJECT_MAP; }
102 // bool IsPointer() const { return mTypeKind == cPOINTER; }
103 virtual bool IsTypeOf(const WsfPProxyType* aOtherType) const { return this == aOtherType; }
104 virtual WsfPProxyHash Hash(void* aDataPtr) const { return WsfPProxyHash(aDataPtr, mDataSize); }
105 virtual size_t MemoryUsage(void* aDataPtr) const = 0;
106};
107
108
109class WsfParseNode;
110
111// Basic types are the most atomic type in the proxy.
112// They must support this interface.
113class WSF_PARSER_EXPORT WsfPProxyBasicType : public WsfPProxyType
114{
115public:
116 // Store an extra byte at the end for flags
117 static const int cBASIC_TYPE_HEADER_SIZE = 1;
119 : WsfPProxyType(aKind)
120 {
121 }
122
123 // Sets the value given a string representation
124 virtual void SetValue(void* p, const std::string& aText) const = 0;
125 // Reads the value from a node containing the result of the parse
126 virtual void Read(void* aValuePtr, WsfParseNode* aNodePtr) const = 0;
127
128 // Writes the value when serializing wsf core files
129 // using aRulePtr allows for multiple formats
130 virtual std::string Write(void* aValuePtr, WsfParseRule* aRulePtr) const = 0;
131
132 // Writes the proxy value to a string for user presentation --
133 // may or may not be wsf core formatting
134 virtual std::string ToString(void* aDataPtr) const { return std::string(); }
135 // Returns true if the two values pointed to are equal
136 virtual bool Equal(void* dest, void* src) const = 0;
137 // Returns true if dest points to a value which is less than src
138 virtual bool Less(void* dest, void* src) const = 0;
139 // Attempts to negate the value pointed to by p, returns true if successful
140 virtual bool Negate(void* p) const { return false; }
141
142 WsfPProxyValue GetAttr(void*, const std::string&) const override { return WsfPProxyValue(); }
143
144 // Returns 'true' if the value is in the unset state
145 bool IsUnset(void* aValuePtr) const override { return 0 != (BasicValueFlags(aValuePtr) & WsfProxy::cVALUE_UNSET); }
146 // Sets the value to the 'unset' state
147 void SetUnset(void* aValuePtr) const override { BasicValueFlags(aValuePtr) |= WsfProxy::cVALUE_UNSET; }
148 void ClearUnset(void* aValuePtr) const override { BasicValueFlags(aValuePtr) &= ~WsfProxy::cVALUE_UNSET; }
149
150 bool IsInherited(void* aValuePtr) const override
151 {
152 return 0 != (BasicValueFlags(aValuePtr) & WsfProxy::cVALUE_INHERITED);
153 }
154 void SetInherited(void* aValuePtr, bool aIsInherited) const override
155 {
156 if (aIsInherited)
157 {
159 }
160 else
161 {
162 BasicValueFlags(aValuePtr) &= ~WsfProxy::cVALUE_INHERITED;
163 }
164 }
165
166 virtual int GetUnitTypeId() const { return -1; }
167
168 size_t MemoryUsage(void* aDataPtr) const override { return mDataSize; }
169
170protected:
171 static unsigned char& BasicValueFlags(void* aValuePtr) { return *((unsigned char*)aValuePtr); }
172};
173
174#endif
static const int cBASIC_TYPE_HEADER_SIZE
Definition WsfPProxyType.hpp:117
bool IsUnset(void *aValuePtr) const override
Definition WsfPProxyType.hpp:145
virtual bool Equal(void *dest, void *src) const =0
virtual void SetValue(void *p, const std::string &aText) const =0
size_t MemoryUsage(void *aDataPtr) const override
Definition WsfPProxyType.hpp:168
virtual std::string Write(void *aValuePtr, WsfParseRule *aRulePtr) const =0
bool IsInherited(void *aValuePtr) const override
Definition WsfPProxyType.hpp:150
void SetUnset(void *aValuePtr) const override
Definition WsfPProxyType.hpp:147
virtual std::string ToString(void *aDataPtr) const
Definition WsfPProxyType.hpp:134
virtual bool Less(void *dest, void *src) const =0
WsfPProxyBasicType(WsfProxy::ValueKind aKind)
Definition WsfPProxyType.hpp:118
void SetInherited(void *aValuePtr, bool aIsInherited) const override
Definition WsfPProxyType.hpp:154
virtual void Read(void *aValuePtr, WsfParseNode *aNodePtr) const =0
virtual bool Negate(void *p) const
Definition WsfPProxyType.hpp:140
void ClearUnset(void *aValuePtr) const override
Definition WsfPProxyType.hpp:148
WsfPProxyValue GetAttr(void *, const std::string &) const override
Definition WsfPProxyType.hpp:142
static unsigned char & BasicValueFlags(void *aValuePtr)
Definition WsfPProxyType.hpp:171
virtual int GetUnitTypeId() const
Definition WsfPProxyType.hpp:166
Definition WsfPProxyHash.hpp:26
Definition WsfPProxyKey.hpp:24
virtual std::string GetNameAtIndex(size_t aIndex) const
Definition WsfPProxyType.hpp:79
virtual WsfPProxyValue GetAtIndex(void *aPtr, size_t aIndex) const
Definition WsfPProxyType.hpp:78
int mTypeKind
Definition WsfPProxyType.hpp:56
virtual void Copy(void *aDest, void *aSrc, int copyFlags) const =0
size_t GetDataSize() const
Definition WsfPProxyType.hpp:54
const std::string & GetTypeName() const
Definition WsfPProxyType.hpp:53
virtual void SetUnset(void *aValuePtr) const =0
virtual void SetInherited(void *aValuePtr, bool aIsInherited) const =0
virtual void ClearUnset(void *aValuePtr) const
Definition WsfPProxyType.hpp:87
virtual bool SwapAttr(void *aPtr, const WsfPProxyKey &aKey, WsfPProxyValue &aValue) const
Definition WsfPProxyType.hpp:74
virtual WsfPProxyValue GetAttr(void *aPtr, const std::string &aName) const =0
virtual size_t GetMemberIndex(const std::string &aAttrName) const
Definition WsfPProxyType.hpp:81
WsfPProxyType(WsfProxy::ValueKind aKind)
Definition WsfPProxyType.hpp:39
virtual void Destroy(void *aValuePtr) const =0
virtual void Construct(void *aValuePtr) const =0
bool IsObjectMap() const
Definition WsfPProxyType.hpp:101
bool IsBasicType() const
Definition WsfPProxyType.hpp:98
int mTypeStoredKind
Definition WsfPProxyType.hpp:57
bool IsStruct() const
Definition WsfPProxyType.hpp:99
virtual bool IsUnset(void *aValuePtr) const =0
virtual bool IsInherited(void *aValuePtr) const =0
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 bool IsOfBasicType(const std::string &aTypeName) const
Definition WsfPProxyType.hpp:92
virtual WsfPProxyType * GetContainedType(size_t aIndex) const
Definition WsfPProxyType.hpp:96
virtual size_t GetAttrCount(void *aPtr) const
Definition WsfPProxyType.hpp:80
virtual WsfPProxyHash Hash(void *aDataPtr) const
Definition WsfPProxyType.hpp:104
bool IsList() const
Definition WsfPProxyType.hpp:100
std::string mTypeName
Definition WsfPProxyType.hpp:59
virtual size_t MemoryUsage(void *aDataPtr) const =0
virtual ~WsfPProxyType()
Definition WsfPProxyType.hpp:51
Definition WsfPProxyValue.hpp:33
Definition WsfParseNode.hpp:61
Definition WsfParseRule.hpp:131
Definition WsfPProxyBasicValues.hpp:41
@ cVALUE_FLAG
Definition WsfPProxyCommon.hpp:29
ValueKind
Definition WsfPProxyCommon.hpp:39
@ cOBJECT_MAP
Definition WsfPProxyCommon.hpp:42
@ cENUMERATION_VALUE
Definition WsfPProxyCommon.hpp:44
@ cLIST
Definition WsfPProxyCommon.hpp:41
@ cSTRUCT
Definition WsfPProxyCommon.hpp:40
@ cVALUE_INHERITED
Definition WsfPProxyCommon.hpp:34
@ cVALUE_UNSET
Definition WsfPProxyCommon.hpp:35
static std::string ValueKindToString(WsfProxy::ValueKind aKind) noexcept
Definition WsfPProxyCommon.hpp:117
Copyrights Multiple, All Rights Reserved