source: OniSplit/Metadata/MetaStruct.cs@ 1161

Last change on this file since 1161 was 1114, checked in by iritscen, 5 years ago

Adding OniSplit source code (v0.9.99.0). Many thanks to Neo for all his work over the years.

File size: 1.5 KB
Line 
1using System;
2using System.Collections.Generic;
3
4namespace Oni.Metadata
5{
6 internal class MetaStruct : MetaType
7 {
8 private readonly List<Field> fields = new List<Field>();
9 private readonly MetaStruct baseStruct;
10
11 public MetaStruct(params Field[] declaredFields)
12 : this(null, null, declaredFields)
13 {
14 }
15
16 public MetaStruct(MetaStruct baseStruct, params Field[] declaredFields)
17 : this(null, null, declaredFields)
18 {
19 }
20
21 public MetaStruct(string name, params Field[] declaredFields)
22 : this(name, null, declaredFields)
23 {
24 }
25
26 public MetaStruct(string name, MetaStruct baseStruct, params Field[] declaredFields)
27 {
28 this.baseStruct = baseStruct;
29
30 if (baseStruct != null)
31 fields.AddRange(baseStruct.fields);
32
33 fields.AddRange(declaredFields);
34
35 int size = 0;
36
37 foreach (var field in fields)
38 size += field.Type.Size;
39
40 Name = name;
41 Size = size;
42 }
43
44 public IEnumerable<Field> Fields => fields;
45
46 protected override bool IsLeafImpl()
47 {
48 foreach (var field in fields)
49 {
50 if (!field.Type.IsLeaf)
51 return false;
52 }
53
54 return true;
55 }
56
57 public override void Accept(IMetaTypeVisitor visitor)
58 {
59 visitor.VisitStruct(this);
60 }
61 }
62}
Note: See TracBrowser for help on using the repository browser.