WSF
WsfPM_ObjectMap.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 WSFPM_OBJECTMAP_HPP
16#define WSFPM_OBJECTMAP_HPP
17
18#include "wsf_parser_export.h"
19
20#include "WsfPProxyNode.hpp"
22
23// This file contains classes which wrap the proxy values providing a more simplified interface
24// to a reduced set of information.
25//
26// Users should be wary that these classes are just references to the proxy tree.
27// If the proxy tree is changed, these references may become invalid. Invalidate() may be used
28// to attempt to recreate the reference. In general, no instances of these classes should be
29// retained for longer than necessary.
30
31class WSF_PARSER_EXPORT WsfPM_ObjectMap : public WsfPProxyNode
32{
33public:
35 WsfPM_ObjectMap(const WsfPProxyNode& aNode);
36
38 std::vector<std::string> GetObjectNames() const;
39 std::vector<std::string> GetAllObjectNames();
40
41 using iterator = std::map<std::string, WsfPProxyValue>::iterator;
42 using const_iterator = std::map<std::string, WsfPProxyValue>::const_iterator;
43 iterator begin() const;
44 iterator end() const;
45
46 WsfPProxyNode Find(const std::string& aName) const;
47 WsfPProxyNode At(const iterator& i) const;
48 bool Exists(const std::string& aName) const;
49 bool Remove(const std::string& aName, bool removedByUser = false);
50
51 WsfPProxyNode Add(const std::string& aName, WsfPProxyValue aEntry);
52 WsfPProxyNode AssignEntry(const std::string& aName, WsfPProxyValue aEntry);
53
54 bool Move(const std::string& aOldName, const std::string& aNewName);
55 bool CanMove(const std::string& aOldName, const std::string& aNewName);
56 void GetValues(std::vector<WsfPProxyNode>& aAll) const;
57 void GetAllValues(std::vector<WsfPProxyNode>& aAll);
58
59protected:
60 template<typename TYPE>
61 void GetValuesT(std::vector<TYPE>& aAll) const
62 {
64 if (val.GetObjectMap())
65 {
66 WsfPProxyObjectMap* mapPtr = val.GetObjectMap();
67 for (auto i = mapPtr->GetValues().begin(); i != mapPtr->GetValues().end(); ++i)
68 {
69 aAll.push_back(TYPE(*this + i->first));
70 }
71 }
72 }
73
74 template<typename TYPE>
75 void GetAllValuesT(std::vector<TYPE>& aAll)
76 {
77 GetValuesT<TYPE>(aAll);
79 {
80 GetValuesT<TYPE>(aAll);
81 Invalidate();
82 }
83 }
84};
85
86template<typename TYPE>
88{
89public:
92 : WsfPM_ObjectMap(aNode)
93 {
94 }
95
98 TYPE FindT(const std::string& aName) const { return TYPE(WsfPM_ObjectMap::Find(aName)); }
99
100 TYPE AtT(const iterator& i) const { return TYPE(WsfPM_ObjectMap::At(i)); }
101
102 void GetValuesT(std::vector<TYPE>& aAll) const { WsfPM_ObjectMap::GetValuesT<TYPE>(aAll); }
103
104 void GetAllValuesT(std::vector<TYPE>& aAll) { WsfPM_ObjectMap::GetAllValuesT<TYPE>(aAll); }
105};
106
107#endif
WsfComponentListT< T >::Iterator end(const WsfComponentListT< T > &aList)
Definition WsfComponentList.hpp:546
WsfComponentListT< T >::Iterator begin(const WsfComponentListT< T > &aList)
Definition WsfComponentList.hpp:540
TYPE FindT(const std::string &aName) const
Definition WsfPM_ObjectMap.hpp:98
void GetAllValuesT(std::vector< TYPE > &aAll)
Definition WsfPM_ObjectMap.hpp:104
WsfPM_ObjectMapT()
Definition WsfPM_ObjectMap.hpp:90
void GetValuesT(std::vector< TYPE > &aAll) const
Definition WsfPM_ObjectMap.hpp:102
TYPE AtT(const iterator &i) const
Definition WsfPM_ObjectMap.hpp:100
WsfPM_ObjectMapT(const WsfPProxyNode &aNode)
Definition WsfPM_ObjectMap.hpp:91
bool Move(const std::string &aOldName, const std::string &aNewName)
Definition WsfPM_ObjectMap.cpp:169
WsfPProxyNode Find(const std::string &aName) const
Definition WsfPM_ObjectMap.cpp:60
std::vector< std::string > GetAllObjectNames()
Definition WsfPM_ObjectMap.cpp:35
WsfPM_ObjectMap()
Definition WsfPM_ObjectMap.cpp:17
std::map< std::string, WsfPProxyValue >::iterator iterator
Definition WsfPM_ObjectMap.hpp:41
WsfPProxyNode AssignEntry(const std::string &aName, WsfPProxyValue aEntry)
Definition WsfPM_ObjectMap.cpp:134
bool Remove(const std::string &aName, bool removedByUser=false)
Definition WsfPM_ObjectMap.cpp:87
WsfPProxyNode At(const iterator &i) const
Definition WsfPM_ObjectMap.cpp:77
bool Exists(const std::string &aName) const
Definition WsfPM_ObjectMap.cpp:82
std::map< std::string, WsfPProxyValue >::const_iterator const_iterator
Definition WsfPM_ObjectMap.hpp:42
void GetAllValues(std::vector< WsfPProxyNode > &aAll)
Definition WsfPM_ObjectMap.cpp:114
bool CanMove(const std::string &aOldName, const std::string &aNewName)
Definition WsfPM_ObjectMap.cpp:198
WsfPProxyObjectMap * GetObjectMap() const
Definition WsfPM_ObjectMap.cpp:24
void GetValuesT(std::vector< TYPE > &aAll) const
Definition WsfPM_ObjectMap.hpp:61
void GetValues(std::vector< WsfPProxyNode > &aAll) const
Definition WsfPM_ObjectMap.cpp:109
std::vector< std::string > GetObjectNames() const
Definition WsfPM_ObjectMap.cpp:29
WsfPProxyNode Add(const std::string &aName, WsfPProxyValue aEntry)
Definition WsfPM_ObjectMap.cpp:119
void GetAllValuesT(std::vector< TYPE > &aAll)
Definition WsfPM_ObjectMap.hpp:75
Definition WsfPProxyNode.hpp:60
void Invalidate()
Definition WsfPProxyNode.cpp:361
WsfPProxyValue GetValue() const
Definition WsfPProxyNode.cpp:79
WsfPProxyNode()
Definition WsfPProxyNode.cpp:24
bool SwitchToBasicTypes()
Definition WsfPProxyNode.cpp:367
Definition WsfPProxyObjectMap.hpp:36
std::map< std::string, WsfPProxyValue > & GetValues()
Definition WsfPProxyObjectMap.hpp:74
Definition WsfPProxyValue.hpp:33
WsfPProxyObjectMap * GetObjectMap() const
Definition WsfPProxyValue.cpp:76
Copyrights Multiple, All Rights Reserved