WSF
WsfParseType.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 WSFPARSETYPE_HPP
16#define WSFPARSETYPE_HPP
17
18#include "wsf_parser_export.h"
19
20#include <algorithm>
21#include <cassert>
22#include <map>
23#include <string>
24#include <vector>
25
26#include "UtCast.hpp"
27#include "UtStringRef.hpp"
28#include "WsfParseTypePath.hpp"
29
30class WsfParseRule;
31// IMPORTANT:
32// WsfParseSymbolTable needs to be handled carefully.
33// In wsf core inputs, derived types are generally a copy of the base
34// type. Most of the time, the base type isn't going to change,
35// so to avoid the cost of copying entire nested type-trees,
36// we just maintain references to the base type's symbol table.
37
38
39class WSF_PARSER_EXPORT WsfParseType
40{
41 bool operator==(const WsfParseType& aRhs) const;
42
43public:
44 using SymbolTable = std::map<UtStringRef, WsfParseType*>;
45
46 const WsfParseType* FindNestedSymbol(const WsfParseTypePath& aKey) const;
48 {
49 const WsfParseType* thisPtr = this;
50 return const_cast<WsfParseType*>(thisPtr->FindNestedSymbol(aKey));
51 }
52
53 WsfParseType(const UtStringRef& aName, WsfParseType* aParentPtr = nullptr)
54 : mName(aName)
55 , mReaderPtr()
56 , mSourceTypePtr(nullptr)
57 , mContainer(aParentPtr)
58 {
59 }
60 WsfParseType(const UtStringRef& aName, const WsfParseType& aRhs, WsfParseType* aContainerPtr);
61
63 void Clear();
64
65 const UtStringRef& GetTypeName() const { return mName; }
66
67 WsfParseType* GetSourceType() const { return mSourceTypePtr; }
68 void SetSourceType(WsfParseType* aSourceTypePtr) { mSourceTypePtr = aSourceTypePtr; }
69 const WsfParseType* GetEffectiveSourceType() const;
70
71 WsfParseType* GetContainer() const { return mContainer; }
72 void SetContainer(WsfParseType* aContainerPtr) { mContainer = aContainerPtr; }
73 void Print(std::ostream& aStream, const std::string& aIndent);
74
75
76 const WsfParseType* FindType(const WsfParseTypePath& aKey) const;
78 {
79 const WsfParseType* thisPtr = this;
80 return const_cast<WsfParseType*>(thisPtr->FindType(aKey));
81 }
82 const WsfParseType* FindType(const UtStringRef& aKey) const;
83 WsfParseType* FindType(const UtStringRef& aKey)
84 {
85 const WsfParseType* thisPtr = this;
86 return const_cast<WsfParseType*>(thisPtr->FindType(aKey));
87 }
88 const WsfParseType* FindTypeLocal(const WsfParseTypePath& aKey) const;
90 {
91 return const_cast<WsfParseType*>(const_cast<const WsfParseType*>(this)->FindTypeLocal(aKey));
92 }
93 WsfParseType* FindTypeLocal(const UtStringRef& aKey) const;
94 // bool FindTypeLocal(const WsfParseTypePath& aKey,
95 // WsfParseType*& aTypePtr) const;
96
97 WsfParseType& AddType(const WsfParseTypePath& aPath, WsfParseType* aTypePtr);
98 WsfParseType& AddType(WsfParseType* aTypePtr);
99 // WsfParseType& SetType(WsfParseType& aTypePtr);
100 bool RemoveType(const UtStringRef& aKey);
101 bool RemoveType(const WsfParseTypePath& aKey);
102
103 void Merge(WsfParseType& aRhs);
104
105 void SetRule(WsfParseRule* aReaderPtr) { mReaderPtr = aReaderPtr; }
106 WsfParseRule* GetRule() const { return mReaderPtr; }
107
108 bool HasSymbols() const { return !mSymbols.empty(); }
109
110 const SymbolTable& GetSymbols() const { return mSymbols; }
111
112 SymbolTable::const_iterator begin() const { return mSymbols.begin(); }
113 SymbolTable::const_iterator end() const { return mSymbols.end(); }
114
115 int GetDepth() const
116 {
117 if (mContainer == nullptr)
118 {
119 return 0;
120 }
121 return mContainer->GetDepth();
122 }
123
124 void GetAncestry(std::vector<WsfParseType*>& aAncestry);
125 void GetAncestry(std::vector<const WsfParseType*>& aAncestry) const;
126 void GetPath(WsfParseTypePath& aPath) const;
127
128private:
129 UtStringRef mName;
130 WsfParseRule* mReaderPtr;
131
132 SymbolTable mSymbols;
133
134 WsfParseType* mSourceTypePtr;
135 WsfParseType* mContainer;
136};
137
138class WSF_PARSER_EXPORT WsfParseTypeName
139{
140public:
142 : mNestedLookup(false)
143 , mOrdinal(ut::npos)
144 {
145 }
148 // If not npos, identifies the token index from the sequence that is appended to the type path
149 // ; as in (type platformType $1)
150 size_t mOrdinal;
151};
152//
153// class WSF_PARSER_EXPORT WsfParseSymbolTable
154// {
155// public:
156// WsfParseSymbolTable(WsfParseSymbolTable* aParentPtr) : mParentPtr(aParentPtr) {}
157// WsfParseSymbolTable(const WsfParseSymbolTable& aRhs, WsfParseSymbolTable* aParentPtr)
158// : mSymbols(aRhs.mSymbols),
159// mParentPtr(aParentPtr)
160// {
161// for (SymbolTable::iterator i = mSymbols.begin(); i != mSymbols.end(); ++i)
162// {
163// i->second.SetContainer(this);
164// }
165// }
166// ~WsfParseSymbolTable();
167//
168//
169// private:
170// bool operator==(const WsfParseSymbolTable& aRhs) const;
171// };
172//
173
174
175#endif
std::vector< UtStringRef > WsfParseTypePath
Definition WsfParseTypePath.hpp:21
bool operator==(int aId, const WsfStringInt &aRhs)
Equal relational operator for the case of an integer on the LHS and a StringId on the RHS.
Definition WsfStringId.hpp:69
Definition WsfParseRule.hpp:131
bool mNestedLookup
Definition WsfParseType.hpp:146
WsfParseTypeName()
Definition WsfParseType.hpp:141
size_t mOrdinal
Definition WsfParseType.hpp:150
WsfParseTypePath mPath
Definition WsfParseType.hpp:147
Definition WsfParseType.hpp:40
WsfParseType * FindTypeLocal(const WsfParseTypePath &aKey)
Definition WsfParseType.hpp:89
WsfParseType * GetContainer() const
Definition WsfParseType.hpp:71
const UtStringRef & GetTypeName() const
Definition WsfParseType.hpp:65
int GetDepth() const
Definition WsfParseType.hpp:115
bool HasSymbols() const
Definition WsfParseType.hpp:108
SymbolTable::const_iterator begin() const
Definition WsfParseType.hpp:112
WsfParseType(const UtStringRef &aName, WsfParseType *aParentPtr=nullptr)
Definition WsfParseType.hpp:53
const SymbolTable & GetSymbols() const
Definition WsfParseType.hpp:110
WsfParseType * FindType(const WsfParseTypePath &aKey)
Definition WsfParseType.hpp:77
std::map< UtStringRef, WsfParseType * > SymbolTable
Definition WsfParseType.hpp:44
void SetSourceType(WsfParseType *aSourceTypePtr)
Definition WsfParseType.hpp:68
WsfParseRule * GetRule() const
Definition WsfParseType.hpp:106
void SetRule(WsfParseRule *aReaderPtr)
Definition WsfParseType.hpp:105
const WsfParseType * FindNestedSymbol(const WsfParseTypePath &aKey) const
Definition WsfParseType.cpp:136
void SetContainer(WsfParseType *aContainerPtr)
Definition WsfParseType.hpp:72
const WsfParseType * FindType(const WsfParseTypePath &aKey) const
Definition WsfParseType.cpp:261
WsfParseType * FindNestedSymbol(const WsfParseTypePath &aKey)
Definition WsfParseType.hpp:47
WsfParseType * GetSourceType() const
Definition WsfParseType.hpp:67
WsfParseType * FindType(const UtStringRef &aKey)
Definition WsfParseType.hpp:83
SymbolTable::const_iterator end() const
Definition WsfParseType.hpp:113
Definition WsfSensorErrorModel.hpp:21
Copyrights Multiple, All Rights Reserved