WSF
WsfPProxyDeserializeContext.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 WSFPPROXYDESERIALIZECONTEXT_HPP
16#define WSFPPROXYDESERIALIZECONTEXT_HPP
17
20#include "WsfPProxyPath.hpp"
21#include "WsfPProxyUndo.hpp"
22#include "WsfPProxyValue.hpp"
23#include "WsfParseAction.hpp"
24#include "WsfParseType.hpp"
25
26class WsfParseNode;
27
28// Stores the evaluation context.
30{
31public:
39
41 {
43 ReturnValue(const std::string& aText)
44 : mTextValue(aText)
45 {
46 }
48 : mProxyValue(val)
49 {
50 }
52 {
53 mProxyValue = aLhs;
54 mTextValue.clear();
55 return *this;
56 }
57 ReturnValue& operator=(const std::string& aText)
58 {
59 mTextValue = aText;
60 return *this;
61 }
63 {
65 if (mTextValue.empty())
66 {
68 }
69 return *this;
70 }
71 std::string ToString()
72 {
73 if (mProxyValue && mProxyValue.IsBasicType())
74 {
76 }
77 return mTextValue;
78 }
79 std::string mTextValue;
81 };
82
84
87 {
88 for (size_t i = 0; i < mNodesReturnValues.size(); ++i)
89 {
90 if (mNodesReturnValues[i])
91 {
92 mDeserializer->AddValue(mNodesReturnValues[i]);
93 }
94 }
95 }
96 void BeginNode(WsfParseNode* aNodePtr);
97 void EndNode(WsfParseNode* aNodePtr);
98 // Return true if the deserialize process should be aborted.
99 bool IsAborting() { return *mDeserializer->mAbortSwitch; }
100
101
102 ReturnValue GetOrdValue(size_t aOrd);
103 std::string GetOrdString(size_t aOrd);
104
105 std::string NodeValue(const WsfParseNode* aValue) const;
106
107 WsfPProxyRegistry* GetRegistry() const { return mDeserializer->GetRegistry(); }
108
109 // Nodes are processed in sequences - aka sibling nodes. This is the first sibling / first node in the current sequence.
111 // Because some nodes return values, we need a place to store the returns.
112 // This is filled with the return value of each node in a sequence.
113 // i.e. mNodesReturnValues[0] will store the return value of mCurrentNodePtr
114 // Actions may reference one of these returned values using the "$1" notation.
115 std::vector<WsfPProxyValue> mNodesReturnValues;
116
117 const WsfPProxyUndoValue& Container() const { return mContainer; }
118 const WsfPProxyPath& CurrentPath() const { return mContainer.GetPath(); }
119 WsfPProxyDeserialize& Deserializer() { return *mDeserializer; }
120 WsfPProxyDeserializeObserver* Observer() { return mDeserializer->mObserver; }
121
122 void SetContainer(const WsfPProxyUndoValue& aContainer) { mContainer = aContainer; }
123 WsfPProxyUndoValue& BasicRoot() { return mDeserializer->GetBasicRoot(); }
124 // WsfPProxyUndoValue& Root() { return mDeserializer->mProxyRoot; }
125 void SetContainer(const WsfPProxyValue& aContainer) { mContainer = WsfPProxyUndoValue(aContainer); }
126 void SetSkip(bool aSkip) { mSkip = aSkip; }
127 bool IsSkip() { return mSkip; }
128 void AddToIndex(const WsfPProxyPath& aPath, WsfParseNode* aNodePtr, WsfPProxyIndex::EntryType aEntryType);
129
130
131 // Execute actions on this node and all children.
132 bool ApplyActions();
133
134 // Execute a sequence of action parts
135 bool DoActions(WsfParseAction* aActions, WsfParseNode* aNodePtr);
136
137private:
138 WsfPProxyDeserializeTracerI::DeserializeAction CanContinue(WsfParseNode* aParentNodePtr, WsfParseNode* aChildNodePtr)
139 {
140 WsfPProxyDeserializeTracerI* tracer = GetTracer();
141 if (!tracer)
142 {
144 }
145 return tracer->CanContinue(aParentNodePtr, aChildNodePtr);
146 }
147
148 void RollbackComplete(WsfParseNode* aParentNodePtr)
149 {
150 WsfPProxyDeserializeTracerI* tracer = GetTracer();
151 if (tracer)
152 {
153 tracer->RollbackComplete(aParentNodePtr);
154 }
155 }
156
157 WsfPProxyDeserializeTracerI* GetTracer() { return mDeserializer->mTraceBuilder; }
158
159 WsfPProxyUndoValue Lookup(const WsfParseActionAddress& aAddr, const WsfPProxyUndoValue& aBaseContainer);
160
161 // Lookup a value in either basic types or proxy root.
162 WsfPProxyUndoValue LookupRoot(const WsfParseTypePath& aLookupPath);
163
164
165 // Evaluate an action. The action may have side-effects upon the context.
166 ReturnValue Eval(WsfParseValueType* aLHS_TypePtr, WsfParseActionPart& aExpr);
167
168
169 // Some nodes output values, like (value ...) nodes.
170 // Prior to executing actions on these nodes, we create the value
171 // to be stored as the current value
172 WsfPProxyValue CreateNodeOutput(WsfParseNode* aNodePtr);
173
174
175 WsfPProxyUndoValue LookupP(const WsfParseActionAddress& aAddr, const WsfPProxyUndoValue& aAddressBase);
176
178 WsfPProxyDeserialize* mDeserializer;
179
180
181 // The current container. This may be any proxy value and is the current value
182 // that actions are operating on. If the container is a struct instance,
183 // we might process an action like side="blue". If the container is a basic type,
184 // we might process an action like this="blue".
185 WsfPProxyUndoValue mContainer;
186
187 bool mSkip;
188};
189
190
191#endif
WsfPProxyDeserializeContext::ReturnValue ReturnValue
Definition WsfPProxyDeserializeContext.cpp:28
std::vector< UtStringRef > WsfParseTypePath
Definition WsfParseTypePath.hpp:21
Definition WsfPProxyBasicValue.hpp:29
std::string ToString() const
Definition WsfPProxyBasicValue.cpp:30
std::string NodeValue(const WsfParseNode *aValue) const
Definition WsfPProxyDeserializeContext.cpp:128
WsfPProxyDeserialize & Deserializer()
Definition WsfPProxyDeserializeContext.hpp:119
void SetContainer(const WsfPProxyUndoValue &aContainer)
Definition WsfPProxyDeserializeContext.hpp:122
void SetSkip(bool aSkip)
Definition WsfPProxyDeserializeContext.hpp:126
ApplyResult
Definition WsfPProxyDeserializeContext.hpp:33
@ cAPPLY_DELAY
Definition WsfPProxyDeserializeContext.hpp:36
@ cAPPLY_SKIP
Definition WsfPProxyDeserializeContext.hpp:35
@ cAPPLY_SUCCESS
Definition WsfPProxyDeserializeContext.hpp:34
@ cAPPLY_PRUNE
Definition WsfPProxyDeserializeContext.hpp:37
WsfPProxyRegistry * GetRegistry() const
Definition WsfPProxyDeserializeContext.hpp:107
const WsfPProxyUndoValue & Container() const
Definition WsfPProxyDeserializeContext.hpp:117
WsfPProxyDeserializeContext(WsfPProxyDeserializeContext &aBase)
Definition WsfPProxyDeserializeContext.cpp:30
ReturnValue GetOrdValue(size_t aOrd)
Definition WsfPProxyDeserializeContext.cpp:110
void EndNode(WsfParseNode *aNodePtr)
Definition WsfPProxyDeserializeContext.cpp:60
bool ApplyActions()
Definition WsfPProxyDeserializeContext.cpp:786
std::vector< WsfPProxyValue > mNodesReturnValues
Definition WsfPProxyDeserializeContext.hpp:115
void SetContainer(const WsfPProxyValue &aContainer)
Definition WsfPProxyDeserializeContext.hpp:125
bool DoActions(WsfParseAction *aActions, WsfParseNode *aNodePtr)
Definition WsfPProxyDeserializeContext.cpp:704
WsfPProxyUndoValue & BasicRoot()
Definition WsfPProxyDeserializeContext.hpp:123
bool IsSkip()
Definition WsfPProxyDeserializeContext.hpp:127
const WsfPProxyPath & CurrentPath() const
Definition WsfPProxyDeserializeContext.hpp:118
std::string GetOrdString(size_t aOrd)
Definition WsfPProxyDeserializeContext.cpp:121
void BeginNode(WsfParseNode *aNodePtr)
Definition WsfPProxyDeserializeContext.cpp:47
~WsfPProxyDeserializeContext()
Definition WsfPProxyDeserializeContext.hpp:86
WsfParseNode * mCurrentNodePtr
Definition WsfPProxyDeserializeContext.hpp:110
WsfPProxyDeserializeObserver * Observer()
Definition WsfPProxyDeserializeContext.hpp:120
bool IsAborting()
Definition WsfPProxyDeserializeContext.hpp:99
void AddToIndex(const WsfPProxyPath &aPath, WsfParseNode *aNodePtr, WsfPProxyIndex::EntryType aEntryType)
Definition WsfPProxyDeserializeContext.cpp:149
Definition WsfPProxyUndo.hpp:30
Definition WsfPProxyI.hpp:22
virtual DeserializeAction CanContinue(WsfParseNode *aParentNodePtr, WsfParseNode *aChildNodePtr)=0
DeserializeAction
Definition WsfPProxyI.hpp:32
@ cDA_CONTINUE
Definition WsfPProxyI.hpp:33
virtual void RollbackComplete(WsfParseNode *aNodePtr)=0
Definition WsfPProxyDeserialize.hpp:26
EntryType
Definition WsfPProxyIndex.hpp:99
Represents a path or unique key to a value in the proxy.
Definition WsfPProxyPath.hpp:64
Definition WsfPProxyRegistry.hpp:37
Definition WsfPProxyUndo.hpp:102
Definition WsfPProxyValue.hpp:33
Definition WsfParseAction.hpp:329
Definition WsfParseNode.hpp:61
Definition WsfPProxyDeserializeContext.hpp:41
ReturnValue(WsfPProxyValue &val)
Definition WsfPProxyDeserializeContext.hpp:47
WsfPProxyValue mProxyValue
Definition WsfPProxyDeserializeContext.hpp:80
std::string ToString()
Definition WsfPProxyDeserializeContext.hpp:71
std::string mTextValue
Definition WsfPProxyDeserializeContext.hpp:79
ReturnValue()
Definition WsfPProxyDeserializeContext.hpp:42
ReturnValue(const std::string &aText)
Definition WsfPProxyDeserializeContext.hpp:43
ReturnValue & operator=(const WsfPProxyValue &aLhs)
Definition WsfPProxyDeserializeContext.hpp:51
ReturnValue & operator=(const std::string &aText)
Definition WsfPProxyDeserializeContext.hpp:57
ReturnValue & operator=(const ReturnValue &aRhs)
Definition WsfPProxyDeserializeContext.hpp:62
Copyrights Multiple, All Rights Reserved