Esempio n. 1
0
        static bool TryGetAttribute(XmlNode node, string attribute, out CapnpGen.CapOutputType value)
        {
            value = CapnpGen.CapOutputType.color;

            if (node.Attributes[attribute] == null)
            {
                return(false);
            }

            return(Enum.TryParse <CapnpGen.CapOutputType>(node.Attributes[attribute].Value, out value));
        }
Esempio n. 2
0
        static bool ParseOutput(XmlNode outputNode, List <CapnpGen.CapOutput> outputs, List <CapnpGen.CapBlender> blenders, out string error)
        {
            error = "";
            CapnpGen.CapOutput output = new CapnpGen.CapOutput();

            string name = "";

            if (!TryGetAttribute(outputNode, "name", out name))
            {
                error = "Output node does not have a name attribute";
                return(false);
            }
            output.Name = name;

            CapnpGen.CapOutputType outputType = CapnpGen.CapOutputType.color;
            if (!TryGetAttribute(outputNode, "type", out outputType))
            {
                error = "Output node \"" + output.Name + "\" does not have a valid type attribute, valid values: ";
                var values = Enum.GetValues(typeof(CapnpGen.CapOutputType));
                foreach (var value in values)
                {
                    error += value + " ";
                }
                return(false);
            }
            output.Type = outputType;

            output.Blender = null;
            // If output type was color we'll need a blender
            if (output.Type == CapnpGen.CapOutputType.color)
            {
                // Get the blender name
                string blenderName = "";
                if (!TryGetAttribute(outputNode, "blender", out blenderName))
                {
                    error = "Output node \"" + output.Name + "\" is of type Color but does not have a blender attribute. All color outputs need a blender attribute";
                    return(false);
                }

                // Find and reference the blender itself
                foreach (CapnpGen.CapBlender blender in blenders)
                {
                    if (blender.Name == blenderName)
                    {
                        output.Blender = blender;
                        break;
                    }
                }

                // If we didn't find one, let's report an error
                if (output.Blender == null)
                {
                    error = "Output node \"" + output.Name + "\" references unknown blender \"" + blenderName + "\"";
                    return(false);
                }

                CapnpGen.CapSubType subType = CapnpGen.CapSubType.@float;
                if (!TryGetAttribute(outputNode, "subtype", out subType))
                {
                    error = "Output node \"" + output.Name + "\" is of type Color but does not have a valid subtype attribute, valid values: ";
                    var values = Enum.GetValues(typeof(CapnpGen.CapSubType));
                    foreach (var value in values)
                    {
                        string valueString = value.ToString();
                        if (valueString[0] == '@') // Capnproto will prepend "@" on reserved keywords, let's filter that away
                        {
                            valueString = valueString.Substring(1);
                        }

                        error += value + " ";
                    }
                    return(false);
                }
                output.SubType = subType;
            }

            outputs.Add(output);
            return(true);
        }