WSF
WsfPProxy.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 WSFPPROXY_HPP
16#define WSFPPROXY_HPP
17
18#include <functional>
19#include <memory>
20
21#include "UtMemoryDebug.hpp"
22#include "WsfPProxyIndex.hpp"
23#include "WsfPProxyRegistry.hpp"
24#include "WsfPProxyType.hpp"
25#include "WsfPProxyUndo.hpp"
26#include "WsfPProxyValue.hpp"
27
28class WsfPProxyNode;
29
30// Contains data pertaining to the proxy tree
31class WSF_PARSER_EXPORT WsfPProxy
32{
33public:
35 {
36 // An immediate child has been added
38 // An immediate child has been removed
40 // An immediate child has been renamed
42 // Value at path1 has been changed directly or one of its children has been changed
44 };
45 using ProxyModifiedFn = std::function<void(WsfPProxy*, ProxyModifiedReason, const WsfPProxyPath&, const std::string*)>;
46 using BeforeModifyFn = std::function<void(WsfPProxy*, ProxyModifiedReason, const WsfPProxyPath&, const std::string*)>;
47 WsfPProxy();
48 WsfPProxy(const WsfPProxy&) = delete;
49 WsfPProxy& operator=(const WsfPProxy&) = delete;
50 ~WsfPProxy();
51
52 void SetProxyModifiedCallback(ProxyModifiedFn aFunctionPtr) { mModifiedCallback = aFunctionPtr; }
54
55 void BuildPathMap();
56 bool GetChildrenPaths(const WsfPProxyPath& nodePath, WsfPProxyPathSet& childrenPaths, WsfPProxyPath& suffixPath) const;
57 const WsfPProxyPathSet* GetInheritedValuePaths(const WsfPProxyPath& nodePath) const;
58
59 void RecordObjectRename(const WsfPProxyPath& aOldPath, const WsfPProxyPath& aNewPath);
60
61 void NotifyProxyModified(ProxyModifiedReason aProxyModifiedReason, const WsfPProxyPath& aPath, const std::string* aRenameName)
62 {
64 {
65 return;
66 }
67 mModifiedCallback(this, aProxyModifiedReason, aPath, aRenameName);
68 }
69
71 const WsfPProxyPath& aPath,
72 const std::string* aRenameName)
73 {
75 {
76 return;
77 }
78 mBeforeModifiedCallback(this, aProxyModifiedReason, aPath, aRenameName);
79 }
80
81 void UndoPlatformRenames();
82 short SequenceNumber() const { return mProxySequenceNumber; }
83 void IncrementSequenceNumber() { ++mProxySequenceNumber; }
84 void SetSaveFile(const WsfPProxyPath& aPath, const std::string& aFilePath);
85 const std::map<WsfPProxyPath, std::string>& SaveFiles() const { return mSaveToFile; }
86 std::map<WsfPProxyPath, std::string> RenameMappingOldToNew();
87 size_t FindAttributeIndex(const std::string& aStructName, const std::string& aAttributeName);
88 WsfPProxyValue NewValue(const std::string& aTypeName);
89 void PropagateNodeChange(const WsfPProxyNode& aModifiedNode);
90 void PropagateNodeAddition(const WsfPProxyNode& aAddedNode);
91 void PropagateNodeDeletion(const WsfPProxyNode& aRemovedNode);
92 void Swap(WsfPProxy& aProxy);
93
94 const std::shared_ptr<WsfPProxyRegistry>& GetRegistry() const { return mRegistry; }
95 void Registry(const std::shared_ptr<WsfPProxyRegistry>& aRegistry) { mRegistry = aRegistry; }
96
97 using RenameMap = std::map<WsfPProxyPath, WsfPProxyPath>;
98
99 // Indicates the proxy has modifications made by the application after parsing
100 // the input files
102 // A mirror of 'root', but contains only basic types, like WSF_RADAR_SENSOR
104 // The root of the proxy tree containing data translated from the input file
106 // Optional. Indexes file location to proxy data paths
107 std::unique_ptr<WsfPProxyIndex> mIndex;
108
109 // maintains a mapping between base type path and derived type paths
110 // for quick lookup of derived types
111 std::unique_ptr<WsfPProxyPathMap> mPathMap;
112 // function pointer to be invoked when the proxy has been modified
114 // function pointer to be invoked before a change to the proxy is made
116 // key: path to newly named object
117 // value: path to old name
119
120private:
121 // If a new proxy root is loaded, this number is incremented to indicate the change
122 short mProxySequenceNumber;
123
124 // Proxy data types are registered here
125 std::shared_ptr<WsfPProxyRegistry> mRegistry;
126
127 // Given a proxy path, this indicates the file to save to
128 std::map<WsfPProxyPath, std::string> mSaveToFile;
129
130 UT_MEMORY_DEBUG_MARKER(cMDB_PROXY);
131};
132
133#endif
std::set< WsfPProxyPath > WsfPProxyPathSet
Definition WsfPProxyPath.hpp:179
@ cMDB_PROXY
Definition WsfParseDebugMarkers.hpp:25
Definition WsfPProxyNode.hpp:60
Represents a path or unique key to a value in the proxy.
Definition WsfPProxyPath.hpp:64
Definition WsfPProxyStructValue.hpp:23
Definition WsfPProxyValue.hpp:33
Definition WsfPProxy.hpp:32
std::map< WsfPProxyPath, WsfPProxyPath > RenameMap
Definition WsfPProxy.hpp:97
WsfPProxy()
Definition WsfPProxy.cpp:48
std::function< void(WsfPProxy *, ProxyModifiedReason, const WsfPProxyPath &, const std::string *)> ProxyModifiedFn
Definition WsfPProxy.hpp:45
BeforeModifyFn mBeforeModifiedCallback
Definition WsfPProxy.hpp:115
WsfPProxyStructValue mBasicRoot
Definition WsfPProxy.hpp:103
void SetBeforeProxyModifiedCallback(BeforeModifyFn aFunctionPtr)
Definition WsfPProxy.hpp:53
std::function< void(WsfPProxy *, ProxyModifiedReason, const WsfPProxyPath &, const std::string *)> BeforeModifyFn
Definition WsfPProxy.hpp:46
ProxyModifiedReason
Definition WsfPProxy.hpp:35
@ cPM_CHILD_ADDED
Definition WsfPProxy.hpp:37
@ cPM_CHILD_MOVED
Definition WsfPProxy.hpp:41
@ cPM_CHILD_REMOVED
Definition WsfPProxy.hpp:39
@ cPM_VALUE_CHANGED
Definition WsfPProxy.hpp:43
WsfPProxy(const WsfPProxy &)=delete
void IncrementSequenceNumber()
Definition WsfPProxy.hpp:83
std::unique_ptr< WsfPProxyPathMap > mPathMap
Definition WsfPProxy.hpp:111
short SequenceNumber() const
Definition WsfPProxy.hpp:82
void SetProxyModifiedCallback(ProxyModifiedFn aFunctionPtr)
Definition WsfPProxy.hpp:52
WsfPProxyValue mRoot
Definition WsfPProxy.hpp:105
ProxyModifiedFn mModifiedCallback
Definition WsfPProxy.hpp:113
RenameMap mRenamedObjects
Definition WsfPProxy.hpp:118
WsfPProxy & operator=(const WsfPProxy &)=delete
void NotifyBeforeProxyModified(ProxyModifiedReason aProxyModifiedReason, const WsfPProxyPath &aPath, const std::string *aRenameName)
Definition WsfPProxy.hpp:70
bool mHasModifications
Definition WsfPProxy.hpp:101
const std::shared_ptr< WsfPProxyRegistry > & GetRegistry() const
Definition WsfPProxy.hpp:94
std::unique_ptr< WsfPProxyIndex > mIndex
Definition WsfPProxy.hpp:107
void Registry(const std::shared_ptr< WsfPProxyRegistry > &aRegistry)
Definition WsfPProxy.hpp:95
const std::map< WsfPProxyPath, std::string > & SaveFiles() const
Definition WsfPProxy.hpp:85
void NotifyProxyModified(ProxyModifiedReason aProxyModifiedReason, const WsfPProxyPath &aPath, const std::string *aRenameName)
Definition WsfPProxy.hpp:61
Copyrights Multiple, All Rights Reserved