WSF
WsfPProxyPath.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 WSFPPROXYPATH_HPP
16#define WSFPPROXYPATH_HPP
17#include "wsf_parser_export.h"
18
19#include <algorithm>
20#include <map>
21#include <set>
22#include <string>
23#include <vector>
24
25#include "UtStringRef.hpp"
26#include "WsfPProxyKey.hpp"
27
28// clang-format off
29#include "WsfPProxyValue.hpp"
30#include "WsfPProxyType.hpp"
31// clang-format on
32
33using WsfParseTypePath = std::vector<UtStringRef>;
34
35class WsfPProxyValue;
36
38{
39 static const int bucket_size = 8;
40 static const int min_buckets = 4;
41 static size_t hashString(const std::string& aValue)
42 {
43 size_t value = 0;
44 for (size_t i = 0; i < aValue.size(); ++i)
45 {
46 value += value * 5 + aValue[i];
47 }
48 return value;
49 }
50
51 size_t operator()(const WsfPProxyKey& x) const
52 {
53 if (x.IsIndex())
54 {
55 return x.GetIndex();
56 }
57 return ~hashString(x.GetMapKey());
58 }
59 bool operator()(const WsfPProxyKey& _Left, const WsfPProxyKey& _Right) const { return (_Left < _Right); }
60};
61
63class WSF_PARSER_EXPORT WsfPProxyPath
64{
65public:
68 : mEntries(aRhs.mEntries)
69 {
70 }
71 WsfPProxyPath(const WsfPProxyPath& aRhs, size_t aSubPathSize)
72 : mEntries(aRhs.mEntries.begin(), aRhs.mEntries.begin() + aSubPathSize)
73 {
74 }
75 WsfPProxyPath(const WsfPProxyKey& aEntry) { *this += aEntry; }
76
77 WsfPProxyPath& operator+=(size_t aIndex)
78 {
79 mEntries.push_back(aIndex);
80 return *this;
81 }
82 WsfPProxyPath& operator+=(const std::string& aStr)
83 {
84 mEntries.push_back(aStr);
85 return *this;
86 }
88 {
89 mEntries.insert(mEntries.end(), aSuffixPath.mEntries.begin(), aSuffixPath.mEntries.end());
90 return *this;
91 }
93 {
94 mEntries.push_back(aEntry);
95 return *this;
96 }
98 {
99 WsfPProxyPath p(*this);
100 p += aEntry;
101 return p;
102 }
104 {
105 WsfPProxyPath p(*this);
106 for (size_t i = 0; i < aPath.size(); ++i)
107 {
108 p += aPath[i];
109 }
110 return p;
111 }
112 WsfPProxyPath operator+(const std::string& aEntry) const
113 {
114 WsfPProxyPath p(*this);
115 p += aEntry;
116 return p;
117 }
118 bool Push(const WsfPProxyValue& aBaseValue, const std::string& aAttrName);
119 bool operator==(const WsfPProxyPath& aRhs) const { return mEntries == aRhs.mEntries; }
120 bool operator!=(const WsfPProxyPath& aRhs) const { return !(*this == aRhs); }
121 bool operator<(const WsfPProxyPath& aRhs) const
122 {
123 return std::lexicographical_compare(mEntries.begin(), mEntries.end(), aRhs.mEntries.begin(), aRhs.mEntries.end());
124 }
125 bool operator>=(const WsfPProxyPath& aRhs) const { return !(*this < aRhs); }
126 WsfPProxyValue Lookup(WsfPProxyValue aRoot);
127
128 static WsfPProxyPath FromString(WsfPProxyValue aRoot, const std::string& aStr);
129 static WsfPProxyPath FromStringList(WsfPProxyValue aRoot, const std::vector<std::string>& aStrList);
130 static WsfPProxyPath FromTypePath(WsfPProxyValue aRoot, const WsfParseTypePath& aStrList);
131
132 // Return 'true' if this is a prefix of aPath
133 bool IsPrefixOf(const WsfPProxyPath& aPath) const
134 {
135 if (mEntries.size() <= aPath.mEntries.size())
136 {
137 return std::equal(mEntries.begin(), mEntries.end(), aPath.mEntries.begin());
138 }
139 return false;
140 }
141
142 size_t size() const { return mEntries.size(); }
143 const WsfPProxyKey& operator[](size_t i) const { return mEntries[i]; }
144 WsfPProxyKey& operator[](size_t i) { return mEntries[i]; }
145 void Clear() { mEntries.clear(); }
146 void Swap(WsfPProxyPath& aRhs) { std::swap(mEntries, aRhs.mEntries); }
147 std::string ToString(const WsfPProxyValue& aRootProxy) const;
148
149 std::string ToString(const WsfPProxyValue& aRootProxy, size_t aEntryIndex) const;
150 std::vector<std::string> ToStringList(const WsfPProxyValue& aRootProxy) const;
151 void Pop() { mEntries.pop_back(); }
152 bool Empty() const { return mEntries.empty(); }
153 WsfPProxyKey& Back() { return mEntries.back(); }
154 const WsfPProxyKey& Back() const { return mEntries.back(); }
155
156 size_t MemoryUsage() const;
157
158 void Trim(size_t aPathLength)
159 {
160 if (mEntries.size() > aPathLength)
161 {
162 mEntries.resize(aPathLength);
163 }
164 }
165
166private:
167 std::vector<WsfPProxyKey> mEntries;
168};
169
170namespace std
171{
172template<>
174{
175 a.Swap(b);
176}
177} // namespace std
178
179using WsfPProxyPathSet = std::set<WsfPProxyPath>;
180using WsfPProxyPathMap = std::map<WsfPProxyPath, WsfPProxyPathSet>;
181
182#endif
WsfComponentListT< T >::Iterator begin(const WsfComponentListT< T > &aList)
Definition WsfComponentList.hpp:540
std::set< WsfPProxyPath > WsfPProxyPathSet
Definition WsfPProxyPath.hpp:179
std::map< WsfPProxyPath, WsfPProxyPathSet > WsfPProxyPathMap
Definition WsfPProxyPath.hpp:180
std::vector< UtStringRef > WsfParseTypePath
Definition WsfParseTypePath.hpp:21
Definition WsfPProxyKey.hpp:24
bool IsIndex() const
Definition WsfPProxyKey.cpp:52
size_t GetIndex() const
Definition WsfPProxyKey.hpp:42
const std::string & GetMapKey() const
Definition WsfPProxyKey.hpp:43
Represents a path or unique key to a value in the proxy.
Definition WsfPProxyPath.hpp:64
const WsfPProxyKey & operator[](size_t i) const
Definition WsfPProxyPath.hpp:143
WsfPProxyKey & operator[](size_t i)
Definition WsfPProxyPath.hpp:144
bool operator!=(const WsfPProxyPath &aRhs) const
Definition WsfPProxyPath.hpp:120
WsfPProxyPath(const WsfPProxyKey &aEntry)
Definition WsfPProxyPath.hpp:75
WsfPProxyPath operator+(const WsfPProxyPath &aPath) const
Definition WsfPProxyPath.hpp:103
bool operator==(const WsfPProxyPath &aRhs) const
Definition WsfPProxyPath.hpp:119
WsfPProxyPath(const WsfPProxyPath &aRhs)
Definition WsfPProxyPath.hpp:67
WsfPProxyPath & operator+=(const std::string &aStr)
Definition WsfPProxyPath.hpp:82
WsfPProxyPath operator+(const std::string &aEntry) const
Definition WsfPProxyPath.hpp:112
bool operator>=(const WsfPProxyPath &aRhs) const
Definition WsfPProxyPath.hpp:125
void Clear()
Definition WsfPProxyPath.hpp:145
size_t size() const
Definition WsfPProxyPath.hpp:142
bool IsPrefixOf(const WsfPProxyPath &aPath) const
Definition WsfPProxyPath.hpp:133
void Trim(size_t aPathLength)
Definition WsfPProxyPath.hpp:158
WsfPProxyPath & operator+=(const WsfPProxyPath &aSuffixPath)
Definition WsfPProxyPath.hpp:87
WsfPProxyPath & operator+=(size_t aIndex)
Definition WsfPProxyPath.hpp:77
bool operator<(const WsfPProxyPath &aRhs) const
Definition WsfPProxyPath.hpp:121
WsfPProxyPath()
Definition WsfPProxyPath.hpp:66
void Pop()
Definition WsfPProxyPath.hpp:151
WsfPProxyKey & Back()
Definition WsfPProxyPath.hpp:153
bool Empty() const
Definition WsfPProxyPath.hpp:152
WsfPProxyPath operator+(const WsfPProxyKey &aEntry) const
Definition WsfPProxyPath.hpp:97
void Swap(WsfPProxyPath &aRhs)
Definition WsfPProxyPath.hpp:146
WsfPProxyPath & operator+=(const WsfPProxyKey &aEntry)
Definition WsfPProxyPath.hpp:92
const WsfPProxyKey & Back() const
Definition WsfPProxyPath.hpp:154
WsfPProxyPath(const WsfPProxyPath &aRhs, size_t aSubPathSize)
Definition WsfPProxyPath.hpp:71
Definition WsfPProxyValue.hpp:33
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
Definition WsfPProxyPath.hpp:38
static size_t hashString(const std::string &aValue)
Definition WsfPProxyPath.hpp:41
static const int bucket_size
Definition WsfPProxyPath.hpp:39
bool operator()(const WsfPProxyKey &_Left, const WsfPProxyKey &_Right) const
Definition WsfPProxyPath.hpp:59
static const int min_buckets
Definition WsfPProxyPath.hpp:40
size_t operator()(const WsfPProxyKey &x) const
Definition WsfPProxyPath.hpp:51
Copyrights Multiple, All Rights Reserved