/// <summary> /// Initializes a new instance of the EnumDefinition class /// Populates this object with information extracted from the XML /// </summary> /// <param name="theNode">XML node describing the Enum object</param> /// <param name="manager">The data dictionary manager constructing this type.</param> public EnumDefinition(XElement theNode, DictionaryManager manager) : base(theNode, TypeId.EnumType) { // ByteSize may be set either directly as an integer or by inference from the Type field. // If no Type field is present then the type is assumed to be 'int' if (theNode.Element("ByteSize") != null) { SetByteSize(theNode.Element("ByteSize").Value); } else { string baseTypeName = theNode.Element("Type") != null ? theNode.Element("Type").Value : "int"; BaseType = manager.GetElementType(baseTypeName); BaseType = DictionaryManager.DereferenceTypeDef(BaseType); FixedSizeBytes = BaseType.FixedSizeBytes.Value; } // Common properties are parsed by the base class. // Remaining properties are the Name/Value Literal elements List<LiteralDefinition> theLiterals = new List<LiteralDefinition>(); foreach (var literalNode in theNode.Elements("Literal")) { theLiterals.Add(new LiteralDefinition(literalNode)); } m_Literals = new ReadOnlyCollection<LiteralDefinition>(theLiterals); // Check the name. If it's null then make one up if (theNode.Element("Name") == null) { Name = String.Format("Enum_{0}", Ref); } }
/// <summary> /// Overrides the initial type. /// </summary> /// <param name="theInitialType">The initial type.</param> public void OverrideInitialType (TypeDefinition theInitialType) { InitialType = theInitialType; }
/// <summary> /// Follow typedefs until a concrete type is found /// </summary> /// <param name="theType"></param> /// <returns>Type definition aliased by theType</returns> public static TypeDefinition DereferenceTypeDef(TypeDefinition theType) { TypedefDefinition theTypeDef = theType as TypedefDefinition; while (theTypeDef != null) { theType = theTypeDef.AliasedType; theTypeDef = theType as TypedefDefinition; } return theType; }
/// <summary> /// Initializes a new instance of the <see cref="Value"/> class. /// </summary> /// <param name="theTypeDefinition">The type definition.</param> /// <param name="parent">The parent.</param> public Value(TypeDefinition theTypeDefinition, Value parent) { FundamentalType = InitialType = theTypeDefinition; Parent = parent; }
/// <summary> /// Initializes a new instance of the AttributeDefinition class /// Constructor. Create a new object by reading contents from the XML node. /// </summary> /// <param name="attributeNode">The attribute node.</param> /// <param name="theManager">The manager.</param> /// <param name="parentType">The parent structure.</param> public AttributeDefinition(XElement attributeNode, DictionaryManager theManager, TypeDefinition parentType) { Name = attributeNode.Element("Name").Value; if (attributeNode.Element("Discriminator") == null) { Discriminator = string.Empty; HasDiscriminator = false; } else { Discriminator = attributeNode.Element("Discriminator").Value; HasDiscriminator = true; } if (attributeNode.Element("ByteOffset") != null) { int byteOffset; if (!int.TryParse(attributeNode.Element("ByteOffset").Value, out byteOffset)) { throw new DataDictionaryException("{0} : failed to parse ByteOffset as an integer", attributeNode.ToString()); } ByteOffset = byteOffset; } HasLengthIndicator = false; if (attributeNode.Element("ByteSize") != null) { LengthIndicator = attributeNode.Element("ByteSize").Value; HasLengthIndicator = true; } // Type of the attribute may identified by a number that is the Ref field of a type somewhere // or by the name of the type // or by the XML element nested within the attribute definition if (attributeNode.Element("Type") != null) { Type = theManager.GetElementType(attributeNode.Element("Type").Value); } else { // Nested type Type = theManager.GetNestedTypeDefinition(attributeNode); } // Follow aliases of typedefs so that the underlying type is stored TypeDefinition theType = Type; while (theType is TypedefDefinition) { theType = ((TypedefDefinition)theType).AliasedType; } // Finally, if we've just created a Switch type set the discriminator if (theType != null && theType.TypeId == TypeId.SwitchType) { SwitchDefinition theSwitchDefinition = Type as SwitchDefinition; if (string.IsNullOrEmpty(Discriminator)) { throw new DataDictionaryException("Attribute {0}: no discriminator supplied for Switch {1}", Name, Type.Name); } StructureDefinition structureDefinition = (StructureDefinition)parentType; theSwitchDefinition.Discriminator = structureDefinition.AttributeDefinitions[Discriminator]; theSwitchDefinition.Discriminator.DiscriminatorFor = this; } }