WSF
WsfPProxyVisitor.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 WSFPPROXYVISITOR_HPP
16#define WSFPPROXYVISITOR_HPP
17
18#include <vector>
19
20#include "WsfPProxyList.hpp"
21#include "WsfPProxyNode.hpp"
24#include "WsfPProxyValue.hpp"
25
27{
28public:
33 template<typename FUNC>
34 static void Visit(FUNC& aFunc, WsfPProxyValue aValue, WsfPProxyValue aParent = WsfPProxyValue())
35 {
36 std::vector<std::pair<WsfPProxyValue, WsfPProxyValue>> stack;
37 stack.push_back(std::make_pair(aParent, aValue));
38 while (!stack.empty())
39 {
40 auto top = stack.back();
41 stack.pop_back();
42 WsfPProxyValue& val = top.second;
43 if (aFunc(val, top.first))
44 {
45 const WsfPProxyType* typePtr = top.second.GetType();
46 switch (typePtr->mTypeKind)
47 {
48 case WsfProxy::cLIST:
49 {
50 WsfPProxyList* listPtr = top.second.GetList();
51 if (listPtr)
52 {
53 for (size_t i = 0; i < listPtr->Size(); ++i)
54 {
55 stack.push_back(std::make_pair(val, listPtr->Get(i)));
56 }
57 }
58 }
59 break;
61 {
62 if (!val.IsUnset())
63 {
64 const WsfPProxyStructType* structPtr = (const WsfPProxyStructType*)typePtr;
65 size_t memberCount = structPtr->GetMemberCount();
66 for (size_t i = 0; i < memberCount; ++i)
67 {
68 stack.push_back(std::make_pair(val, structPtr->GetAtIndex(val.GetDataPtr(), i)));
69 }
70 }
71 }
72 break;
74 {
75 WsfPProxyObjectMap* mapPtr = val.GetObjectMap();
76 if (mapPtr)
77 {
78 auto& vals = mapPtr->GetValues();
79 for (auto i = vals.begin(); i != vals.end(); ++i)
80 {
81 stack.push_back(std::make_pair(val, i->second));
82 }
83 }
84 }
85 break;
86 }
87 }
88 }
89 }
90
95 template<typename FUNC>
96 static void VisitNodes(FUNC& aFunc, WsfPProxyNode aNode)
97 {
98 if (aFunc(aNode))
99 {
100 const WsfPProxyValue nodeValue = aNode.GetValue();
101 const WsfPProxyType* typePtr = nodeValue.GetType();
102
103 switch (typePtr->mTypeKind)
104 {
105 case WsfProxy::cLIST:
106 {
107 WsfPProxyList* listPtr = nodeValue.GetList();
108
109 if (listPtr)
110 {
111 for (size_t i = 0; i < listPtr->Size(); ++i)
112 {
113 aNode += i;
114 VisitNodes(aFunc, aNode);
115 aNode.ToParent();
116 }
117 }
118
119 break;
120 }
121
123 {
124 if (!nodeValue.IsUnset())
125 {
126 const WsfPProxyStructType* structPtr = (const WsfPProxyStructType*)typePtr;
127 size_t memberCount = structPtr->GetMemberCount();
128
129 for (size_t i = 0; i < memberCount; ++i)
130 {
131 aNode += i;
132 VisitNodes(aFunc, aNode);
133 aNode.ToParent();
134 }
135 }
136
137 break;
138 }
139
141 {
142 WsfPProxyObjectMap* mapPtr = nodeValue.GetObjectMap();
143
144 if (mapPtr)
145 {
146 auto& vals = mapPtr->GetValues();
147
148 for (auto i = vals.begin(); i != vals.end(); ++i)
149 {
150 const std::string& valName = i->first;
151 aNode += valName;
152 VisitNodes(aFunc, aNode);
153 aNode.ToParent();
154 }
155 }
156
157 break;
158 }
159 }
160 }
161 }
162};
163
164#endif
Definition WsfPProxyList.hpp:34
size_t Size()
Definition WsfPProxyList.cpp:25
WsfPProxyValue Get(size_t aIndex)
Definition WsfPProxyList.cpp:67
Definition WsfPProxyNode.hpp:60
WsfPProxyValue GetValue() const
Definition WsfPProxyNode.cpp:79
WsfPProxyNode & ToParent()
Definition WsfPProxyNode.hpp:228
Definition WsfPProxyObjectMap.hpp:36
std::map< std::string, WsfPProxyValue > & GetValues()
Definition WsfPProxyObjectMap.hpp:74
Definition WsfPProxyStructType.hpp:33
WsfPProxyValue GetAtIndex(void *aDataPtr, size_t aIndex) const override
Definition WsfPProxyStructType.hpp:97
size_t GetMemberCount() const
Definition WsfPProxyStructType.hpp:147
Definition WsfPProxyType.hpp:37
int mTypeKind
Definition WsfPProxyType.hpp:56
Definition WsfPProxyValue.hpp:33
WsfPProxyList * GetList() const
Definition WsfPProxyValue.cpp:67
WsfPProxyObjectMap * GetObjectMap() const
Definition WsfPProxyValue.cpp:76
bool IsUnset() const
Definition WsfPProxyValue.cpp:151
const WsfPProxyType * GetType() const
Definition WsfPProxyValue.hpp:61
void * GetDataPtr() const
Definition WsfPProxyValue.hpp:60
Definition WsfPProxyVisitor.hpp:27
static void VisitNodes(FUNC &aFunc, WsfPProxyNode aNode)
Definition WsfPProxyVisitor.hpp:96
static void Visit(FUNC &aFunc, WsfPProxyValue aValue, WsfPProxyValue aParent=WsfPProxyValue())
Definition WsfPProxyVisitor.hpp:34
@ cOBJECT_MAP
Definition WsfPProxyCommon.hpp:42
@ cLIST
Definition WsfPProxyCommon.hpp:41
@ cSTRUCT
Definition WsfPProxyCommon.hpp:40
Copyrights Multiple, All Rights Reserved