/// <summary>
        /// Parses value member of the realtimeobject
        /// </summary>
        /// <param name="in_element"></param>
        /// <param name="in_xml_stream"></param>
        /// <param name="in_parent"></param>
        internal void ParseValueMember(XPathNavigator in_element, TextReader in_xml_stream, object in_parent)
        {
            // get name
            m_name = XMLAttributeParser.ConvertAttributeToString(in_element, "Name", XMLAttributeParser.atObligatory);

            // get type
            m_member_type = TypeStringToMemberType(in_element.Name);

            // check type
            if (m_member_type == RealtimeObjectMember.MemberType.Unknown)
            {
                throw XMLParserBase.CreateXMLParseException(string.Format(ParserRealtimeObjectStringConstants.ErrorInvalidElementType, in_element.Name), in_element);
            }

            // get multiplier for fixed types
            if (RealtimeObjectMember.IsFixedMember(m_member_type))
            {
                m_fixed_multiplier = XMLAttributeParser.ConvertAttributeToInt(in_element, "Multiplier", XMLAttributeParser.atObligatory);
            }

            // store attributes for further processing
            XPathNavigator element = in_element.Clone();

            if (element.MoveToFirstAttribute())
            {
                m_attributes.Add(element.Name, element.Value);
            }

            while (element.MoveToNextAttribute())
            {
                m_attributes.Add(element.Name, element.Value);
            }
        }
        /// <summary>
        /// Parses real time object description file elements
        /// </summary>
        /// <param name="in_element"></param>
        protected override void ParseElement(XPathNavigator in_element, TextReader in_xml_stream, object in_parent)
        {
            string name;
            string cdecl;

            RealtimeObjectMember.MemberType type;

            switch (in_element.Name)
            {
            case "Type":
            {
                name  = XMLAttributeParser.ConvertAttributeToString(in_element, "Name", XMLAttributeParser.atObligatory);
                cdecl = XMLAttributeParser.ConvertAttributeToString(in_element, "CDecl", XMLAttributeParser.atObligatory);

                if (name == "PacketHeader")
                {
                    m_packet_header_declaration = cdecl;
                }
                else
                {
                    type = ParserRealtimeObjectMember.TypeStringToMemberType(name);

                    if (type == RealtimeObjectMember.MemberType.Unknown)
                    {
                        throw XMLParserBase.CreateXMLParseException(string.Format(ParserRealtimeObjectStringConstants.ErrorInvalidElementType, in_element.Name), in_element);
                    }

                    m_type_lookup.Add(type, cdecl);
                }
            }
            break;

            default:
                throw XMLParserBase.CreateXMLParseException(string.Format(ParserRealtimeObjectStringConstants.ErrorInvalidElementType, in_element.Name), in_element);
            }
        }
Пример #3
0
        /// <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);
        }