Ejemplo n.º 1
0
        public CppEnum(Spec spec, SpecReader.Enum e, List <string> suffixes, Dictionary <string, int> map)
        {
            OriginalName = FixName(e.Name);
            Name         = StripSuffix(OriginalName, suffixes, map).Substring(2);

            Values = new List <CppEnumValue>();

            if (Name.Contains("Flags"))
            {
                bool hasNone = false;
                foreach (var v in e.Values)
                {
                    if (v.Name.Contains("NONE"))
                    {
                        hasNone = true;
                        break;
                    }
                }

                if (!hasNone)
                {
                    Values.Add(new CppEnumValue("None", "0"));
                }
            }

            foreach (var v in e.Values)
            {
                Values.Add(new CppEnumValue(spec, e, v));
            }

            Bitmask = e.Bitmask;
        }
Ejemplo n.º 2
0
        string GetName(SpecReader.Enum e, EnumValue v)
        {
            var           enumNames = Split(e.Name);
            List <string> tokens    = new List <string>(v.Name.Split('_'));
            StringBuilder builder   = new StringBuilder();

            for (int i = tokens.Count - 1; i >= 0; i--)
            {
                if (tokens[i] == "VK" || tokens[i] == "BIT")
                {
                    tokens.RemoveAt(i);
                }
            }

            bool underscoreLast = false;
            int  emitted        = 0;

            for (int i = 0; i < tokens.Count; i++)
            {
                var token = tokens[i];
                if (enumNames.Contains(token.ToUpper()))      //strip name of enum from enum value (eg STRUCTURE_TYPE_INSTANCE_CREATE_INFO -> INSTANCE_CREATE_INFO)
                {
                    enumNames.Remove(token);
                    continue;
                }
                EmitValue(builder, token, emitted == 0, i, tokens.Count, ref underscoreLast);
                emitted++;
            }

            return(builder.ToString());
        }
Ejemplo n.º 3
0
        public CppEnumValue(Spec spec, SpecReader.Enum e, EnumValue v)
        {
            this.spec = spec;

            Name = GetName(e, v);
            string value;

            if (v.Bitpos)
            {
                value = ((int)Math.Pow(2, int.Parse(v.Value))).ToString();
            }
            else
            {
                value = v.Value;
            }
            Value = value;
        }
Ejemplo n.º 4
0
        public CSEnum(SpecReader.Enum e)
        {
            Name   = e.Name;
            Flags  = e.Bitmask;
            Values = new List <CSEnumValue>();

            foreach (var v in e.Values)
            {
                string vName = v.Name;
                string value;
                if (v.Bitpos)
                {
                    value = ((int)Math.Pow(2, int.Parse(v.Value))).ToString();
                }
                else
                {
                    value = v.Value;
                }
                Values.Add(new CSEnumValue(Name, vName, value));
            }
        }