Esempio n. 1
0
        [MethodImpl(MethodImplOptions.AggressiveInlining)]// Small function which is called frequently in loops, inline it
        public static bool TryEnum(Type enumType, AtomicString Keyword, out object outEnum)
        {
            if (enumType is null)
            {
                throw new ArgumentNullException(nameof(enumType));
            }
            Contract.EndContractBlock();

            int enumIndex = EnumMetaTable.Meta.Lookup(enumType.TypeHandle);

            if (enumIndex < 0)
            {
                /* Enum has no index */
                outEnum = null;
                return(false);
            }


            if (!EnumMetaTable.KEYWORD[enumIndex].TryGetValue(Keyword, out object outValue))
            {
                outEnum = default;
                return(false);
            }

            outEnum = outValue;
            return(true);
        }
Esempio n. 2
0
 [MethodImpl(MethodImplOptions.AggressiveInlining)]// Small function which is called frequently in loops, inline it
 public static bool Is_Declared <T>(AtomicString Keyword) where T : struct
 {
     if (!EnumMetaTable.Meta.Lookup <T>(out int outIndex))
     {
         return(false);/* Enum has no index */
     }
     return(EnumMetaTable.KEYWORD[outIndex]?.ContainsKey(Keyword) ?? false);
 }
Esempio n. 3
0
 public bool Equals(AtomicString other)
 {
     // Check if hashes match
     if (0 != ((other.Flags ^ Flags) & EAtomicStringFlags.CaseInsensitive))
     {/* Flag mismatch: the XOR of both flags still returned CaseInsensitive, meaning only one of these atomic-strings is trying to be case-insensitive */
         return(Hash_Lower == other.Hash_Lower);
     }
     else
     {
         return(other.GetHashCode() == GetHashCode());
     }
 }
Esempio n. 4
0
        [MethodImpl(MethodImplOptions.AggressiveInlining)]// Small function which is called frequently in loops, inline it
        public static T Enum <T>(AtomicString Keyword) where T : struct
        {
            int enumIndex = EnumMetaTable.Meta.Lookup <T>();

            if (enumIndex > -1)
            {
                if (EnumMetaTable.KEYWORD[enumIndex].TryGetValue(Keyword, out var outValue))
                {
                    return((T)outValue);
                }
            }

            throw new Exception($"Unable to find keyword for enum value {Keyword} in meta-enum table");
        }
Esempio n. 5
0
        [MethodImpl(MethodImplOptions.AggressiveInlining)]// Small function which is called frequently in loops, inline it
        public static bool Is_Declared(Type enumType, AtomicString Keyword)
        {
            if (enumType is null)
            {
                throw new ArgumentNullException(nameof(enumType));
            }
            Contract.EndContractBlock();

            int enumIndex = EnumMetaTable.Meta.Lookup(enumType.TypeHandle);

            if (enumIndex < 0)
            {
                return(false);/* Enum has no index */
            }
            return(EnumMetaTable.KEYWORD[enumIndex]?.ContainsKey(Keyword) ?? false);
        }
Esempio n. 6
0
        [MethodImpl(MethodImplOptions.AggressiveInlining)]// Small function which is called frequently in loops, inline it
        public static object Enum(Type enumType, AtomicString Keyword)
        {
            if (enumType is null)
            {
                throw new ArgumentNullException(nameof(enumType));
            }
            Contract.EndContractBlock();

            int enumIndex = EnumMetaTable.Meta.Lookup(enumType.TypeHandle);

            if (enumIndex > -1)
            {
                if (EnumMetaTable.KEYWORD[enumIndex].TryGetValue(Keyword, out var outValue))
                {
                    return(outValue);
                }
            }

            throw new Exception($"Unable to find keyword for enum value {Keyword} in meta-enum table");
        }
Esempio n. 7
0
        [MethodImpl(MethodImplOptions.AggressiveInlining)]// Small function which is called frequently in loops, inline it
        public static bool TryEnum <T>(AtomicString Keyword, out T outEnum) where T : struct
        {
            int enumIndex = EnumMetaTable.Meta.Lookup <T>();

            if (enumIndex < 0)
            {
                /* Enum has no index */
                outEnum = default;
                return(false);
            }

            if (!EnumMetaTable.KEYWORD[enumIndex].TryGetValue(Keyword, out object outValue))
            {
                outEnum = default;
                return(false);
            }

            outEnum = CastTo <T> .From(outValue);

            return(true);
        }
Esempio n. 8
0
        protected int Get_Or_Register_Name(AtomicString Name, out bool outIsCustom)
        {
            var nameValue = Name_To_Value(Name);

            if (nameValue.HasValue)
            {
                outIsCustom = false;
                return((int)nameValue.Value);
            }

            /* If we couldnt resolve this string name from our enum then it is a custom name */
            outIsCustom = true;

            if (!NameRegistry.TryGetValue(Name, out int Value))
            {/* Register new custom name */
                Value = CUSTOM_VALUE--;
                NameRegistry.TryAdd(Name, Value);
            }

            return(Value);
        }
Esempio n. 9
0
 public StyleFunction(AtomicString Name, params CssValue[] Args)
 {
     this.Name = Name;
     this.Args = Args.ToArray();
 }