/// <summary> /// Parses Packet description /// </summary> /// <param name="in_element"></param> protected override void ParseElement(XPathNavigator in_element, TextReader in_xml_stream, object in_parent) { ParserDeviceSettingValue value = null; // parse only elements if (in_element.NodeType != XPathNodeType.Element) { return; } switch (in_element.Name) { case "Group": { ParserDeviceSettingsRoot parent = (ParserDeviceSettingsRoot)in_parent; ParserDeviceSettingsGroup group = new ParserDeviceSettingsGroup(); group.ParseXML(in_element); parent.AddGroup(in_element, group); ParseXMLChildNodes(in_element, in_xml_stream, group); } break; case "EnumDefs": { ParserDeviceSettingsRoot parent = (ParserDeviceSettingsRoot)in_parent; ParserDeviceSettingsEnumDefs enum_defs = new ParserDeviceSettingsEnumDefs(); enum_defs.ParseXML(in_element); parent.AddEnumDefs(in_element, enum_defs); ParseXMLChildNodes(in_element, in_xml_stream, enum_defs); } break; case "Title": { ParserDeviceSettingsEnumDefs parent = (ParserDeviceSettingsEnumDefs)in_parent; ParserDeviceSettingsEnumValue title = new ParserDeviceSettingsEnumValue(); title.ParseXML(in_element); parent.AddValue(in_element, title); } break; default: value = ParserDeviceSettingValue.ValueFactory(in_element, in_xml_stream, (ParserDeviceSettingsGroup)in_parent); break; } if (value != null) { value.SetValueIndex(m_value_index++); } }
/// <summary> /// Creates value class based on the XML content /// </summary> /// <param name="in_element"></param> /// <param name="in_xml_stream"></param> /// <param name="in_parent"></param> /// <returns></returns> public static ParserDeviceSettingValue ValueFactory(XPathNavigator in_element, TextReader in_xml_stream, ParserDeviceSettingsGroup in_parent) { ParserDeviceSettingValue value = null; // create value class switch (in_element.Name) { // UInt8 type case "UInt8": value = new ParserDeviceSettingValue(ParserDeviceSettingValue.ValueType.UInt8Value); break; // Int8 type case "Int8": value = new ParserDeviceSettingValue(ParserDeviceSettingValue.ValueType.Int8Value); break; // UInt16 type case "UInt16": value = new ParserDeviceSettingValue(ParserDeviceSettingValue.ValueType.UInt16Value); break; // UInt16 type case "Int16": value = new ParserDeviceSettingValue(ParserDeviceSettingValue.ValueType.Int16Value); break; case "Int32": case "Int": value = new ParserDeviceSettingValue(ParserDeviceSettingValue.ValueType.Int32Value); break; // Fixed UInt8 type case "FixedUInt8": value = new ParserDeviceSettingValue(ParserDeviceSettingValue.ValueType.UInt8FixedValue); break; // Fixed UInt8 type case "Int8Fixed": value = new ParserDeviceSettingValue(ParserDeviceSettingValue.ValueType.Int8FixedValue); break; // Fixed UInt16 type case "UInt16Fixed": value = new ParserDeviceSettingValue(ParserDeviceSettingValue.ValueType.UInt16FixedValue); break; // Fixed Int16 type case "Int16Fixed": value = new ParserDeviceSettingValue(ParserDeviceSettingValue.ValueType.Int16FixedValue); break; // enum type case "Enum": value = new ParserDeviceSettingValue(ParserDeviceSettingValue.ValueType.EnumValue); break; // float type case "Float": value = new ParserDeviceSettingValue(ParserDeviceSettingValue.ValueType.FloatValue); break; // string type case "String": value = new ParserDeviceSettingValue(ParserDeviceSettingValue.ValueType.StringValue); break; default: throw XMLParserBase.CreateXMLParseException(string.Format(ParserDeviceSettingsStringConstants.ErrorInvalidElementType, in_element.Name), in_element); } // parse and store value class if (value != null) { value.ParseXML(in_element); in_parent.AddValue(in_element, value); } return(value); }
/// <summary> /// Sets parent group of this value /// </summary> /// <param name="in_parent_group"></param> internal void SetParentGroup(ParserDeviceSettingsGroup in_parent_group) { m_parent_group = in_parent_group; }
/// <summary> /// Adds settings group to the root /// </summary> /// <param name="in_element"></param> /// <param name="in_group"></param> public void AddGroup(XPathNavigator in_element, ParserDeviceSettingsGroup in_group) { // store group m_groups.Add(in_group); in_group.SetRoot(this); }