Exemplo n.º 1
0
        VkStruct CreateBasetypeStruct(string name, string type)
        {
            var vkStruct = new VkStruct();

            vkStruct.Name = vkStruct.SpecName = name;

            var vkMember = new VkMember();

            vkMember.Name = vkMember.SpecName = "value";
            vkMember.Type = GetOrAddType(type);

            vkStruct.Members = new[] { vkMember };

            return(vkStruct);
        }
Exemplo n.º 2
0
        VkMember ReadMember(XElement xmember)
        {
            // note: pretty much identical to <param>

            if (xmember.Name != "member")
            {
                throw new ArgumentException("Not a member", nameof(xmember));
            }

            var xelements = xmember.Elements();

            if (!xelements.Any())
            {
                throw new ArgumentException("Contains no elements", nameof(xmember));
            }

            var vkMember = new VkMember();

            foreach (var elm in xelements)
            {
                switch (elm.Name.ToString())
                {
                case "type":
                    vkMember.Type = GetOrAddType(elm.Value);
                    break;

                case "name":
                    vkMember.Name = vkMember.SpecName = elm.Value;
                    break;

                case "enum":     // todo
                    break;

                default: throw new NotImplementedException(elm.Name.ToString());
                }
            }

            const string fixedSizePattern = @"\[(<enum>)?([^<\]]+)(</enum>)?\]";
            var          fixedSizeMatch   = Regex.Match(xmember.Value, fixedSizePattern);

            if (fixedSizeMatch.Success)
            {
                vkMember.IsFixedSize = true;
                vkMember.FixedSize   = fixedSizeMatch.Groups[2].Value;
            }

            if (string.IsNullOrEmpty(vkMember.Name) || vkMember.Type == null)
            {
                throw new InvalidOperationException("Member does not have proper `<name>` or `<type>` element");
            }

            // Gah! Why are these not encoded properly!
            var paramStr = xmember.Value;

            vkMember.PointerRank = paramStr.Count(x => x == '*');
            vkMember.IsConst     = paramStr.Contains("const");

            // read member attributes
            var xattributes = xmember.Attributes();

            if (xattributes.Any())
            {
                foreach (var xattrib in xattributes)
                {
                    switch (xattrib.Name.ToString())
                    {
                    case "optional":
                        var value = xattrib.Value;
                        if (value != "true")
                        {
                            throw new NotImplementedException(value);
                        }
                        vkMember.Optional = value;
                        break;

                    case "len":
                        vkMember.Len = xattrib.Value.Split(',');
                        break;

                    /*case "externsync":
                     * param.ExternSync = attrib.Value == "true";
                     * break;*/
                    case "noautovalidity":
                        vkMember.NoAutoValidity = xattrib.Value == "true";
                        break;

                    case "validextensionstructs":
                        vkMember.ValidExtensionStructs = xattrib.Value.Split(',');
                        break;

                    default: throw new NotImplementedException(xattrib.Name.ToString());
                    }
                }
            }

            return(vkMember);
        }
Exemplo n.º 3
0
 public VkStruct()
 {
     Members  = new VkMember[0];
     Validity = new string[0];
 }