-
Notifications
You must be signed in to change notification settings - Fork 0
/
AsrPathInfo.cs
291 lines (273 loc) · 8.65 KB
/
AsrPathInfo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
namespace AutosarClass
{
/// <summary>
/// Autosar path and reference information class.
/// </summary>
public class AsrPathInfo
{
public event PropertyChangedEventHandler? PropertyChanged;
public void RaisePropertyChanged(string name, object oldValue, object newVaule)
{
PropertyChanged?.Invoke(this, name, oldValue, newVaule);
}
private string asrPathLiteral;
/// <summary>
/// Initialize Autosar path information class.
/// </summary>
/// <param name="pathLiteral">Path literal of Autosar model.</param>
public AsrPathInfo(string pathLiteral)
{
var parts = pathLiteral.Split('@');
if (parts.Length != 2)
{
throw new Exception("Invalid path literal to initialize AsrPathInfo");
}
else
{
asrPathLiteral = pathLiteral;
}
}
/// <summary>
/// Initialize Autosar path information class.
/// </summary>
/// <param name="path">Path of Autosar model.</param>
/// <param name="tag">Tag of Autosar model.</param>
public AsrPathInfo(string path, string tag)
{
tag = tag.Replace("Autosar.", "");
asrPathLiteral = $"{path}@{tag}";
}
/// <summary>
/// Autosar path literal information.
/// AsrPathLiteral is composed by AsrPath and AsrPathTag.
/// The literal form is AsrPath@AsrPathTag.
/// </summary>
public string AsrPathLiteral
{
get
{
return asrPathLiteral;
}
set
{
if (value != null)
{
var oldPathLiteral = asrPathLiteral;
var parts = value.Split('@');
if (parts.Length != 2)
{
throw new Exception("Invalid Autosar path information");
}
asrPathLiteral = value;
RaisePropertyChanged("AsrPathLiteral", oldPathLiteral, value);
}
}
}
public string AsrPathLiteralShort
{
get
{
return $"{AsrPath}@{AsrPathTagShort}";
}
}
/// <summary>
/// Autosar path.
/// </summary>
public string AsrPath
{
get
{
var parts = AsrPathLiteral.Split('@');
if (parts == null)
{
throw new Exception("Invalid Autosar path information");
}
if (parts.Length != 2)
{
throw new Exception("Invalid Autosar path information");
}
return parts[0];
}
set
{
if (value != AsrPath)
{
var oldPathLiteral = AsrPathLiteral;
var parts = AsrPathLiteral.Split('@');
if (parts.Length != 2)
{
throw new Exception("Invalid Autosar path information");
}
parts[0] = value;
var newPathLiteral = string.Join('@', parts);
AsrPathLiteral = newPathLiteral;
RaisePropertyChanged("AsrPath", oldPathLiteral, newPathLiteral);
}
}
}
/// <summary>
/// Short form of Autosar path.
/// </summary>
public string AsrPathShort
{
get
{
var parts = AsrPath.Split('/');
if (parts.Length <= 1)
{
throw new Exception("Invalid Autosar path information");
}
else
{
return parts[^1];
}
}
set
{
if (value != AsrPathShort)
{
var parts = AsrPath.Split("/");
if (parts.Length <= 1)
{
throw new Exception("Invalid Autosar path information");
}
parts[^1] = value;
AsrPath = string.Join('/', parts);
}
}
}
/// <summary>
/// Tag of model.
/// </summary>
public string AsrPathTag
{
get
{
var parts = AsrPathLiteral.Split('@');
if (parts.Length != 2)
{
throw new Exception("Invalid Autosar path information");
}
return parts[1];
}
set
{
if (value != AsrPathTag)
{
var oldPathLiteral = AsrPathLiteral;
var parts = AsrPathLiteral.Split('@');
if (parts.Length != 2)
{
throw new Exception("Invalid Autosar path information");
}
parts[1] = value;
var newPathLiteral = string.Join('@', parts);
asrPathLiteral = newPathLiteral;
RaisePropertyChanged("AsrPathTag", oldPathLiteral, newPathLiteral);
}
}
}
/// <summary>
/// Short form of Autosar path.
/// </summary>
public string AsrPathTagShort
{
get
{
var parts = AsrPathTag.Split('/');
if (parts.Length <= 1)
{
throw new Exception("Invalid Autosar path information");
}
else
{
return parts[^1];
}
}
set
{
if (value != AsrPathTagShort)
{
var parts = AsrPathTag.Split("/");
if (parts.Length <= 1)
{
throw new Exception("Invalid Autosar path information");
}
parts[^1] = value;
AsrPathTag = string.Join('/', parts);
}
}
}
/// <summary>
/// Create Autosar path information of child node.
/// </summary>
/// <param name="path">ShortName of child node.</param>
/// <param name="tag">Tag of child node.</param>
/// <returns>Created Autosar path information</returns>
public AsrPathInfo CreateChildPathInfo(string path, string tag)
{
return new AsrPathInfo($"{AsrPathLiteral}/{path}", $"{tag}");
}
/// <summary>
/// Equal determination function.
/// </summary>
/// <param name="obj">Other object to check.</param>
/// <returns>
/// true: equal
/// false: not equal
/// </returns>
public override bool Equals(object? obj)
{
if (obj is AsrPathInfo pathInfo)
{
if (pathInfo.AsrPathLiteral == AsrPathLiteral)
{
return true;
}
}
return false;
}
/// <summary>
/// Hash code generator.
/// </summary>
/// <returns>Hash code generated.</returns>
public override int GetHashCode()
{
return base.GetHashCode();
}
/// <summary>
/// Operator == function.
/// </summary>
/// <param name="a">One Autosar path information.</param>
/// <param name="b">Another Autosar path information.</param>
/// <returns>
/// true: equal
/// false: not equal
/// </returns>
public static bool operator ==(AsrPathInfo a, AsrPathInfo b)
{
return Equals(a, b);
}
/// <summary>
/// Operator != function.
/// </summary>
/// <param name="a">One Autosar path information.</param>
/// <param name="b">Another Autosar path information.</param>
/// <returns>
/// true: not equal
/// false: equal
/// </returns>
public static bool operator !=(AsrPathInfo a, AsrPathInfo b)
{
return !Equals(a, b);
}
/// <summary>
/// Covert to string.
/// </summary>
/// <returns>String converted.</returns>
public override string ToString()
{
return $"{AsrPathShort}@{AsrPathTagShort}";
}
}
}