Esempio n. 1
0
        /// <summary>
        /// Loads the sprites of the given sprite palette from the given XML-node.
        /// </summary>
        /// <typeparam name="TVariant">The type of the enumeration that determines the variants of a sprite.</typeparam>
        /// <param name="spritePaletteElem">The XML-node to load from.</param>
        /// <param name="palette">The target sprite palette.</param>
        /// <param name="defaultVariant">The default variant that should be used when no variant was found for a sprite definition.</param>
        private static void LoadSprites <TVariant>(XElement spritePaletteElem, SpritePalette <TVariant> palette, TVariant defaultVariant) where TVariant : struct
        {
            foreach (XElement spriteElem in spritePaletteElem.Elements(SPRITE_ELEM))
            {
                XAttribute spriteNameAttr    = spriteElem.Attribute(SPRITE_NAME_ATTR);
                XAttribute spriteVariantAttr = spriteElem.Attribute(SPRITE_VARIANT_ATTR);
                XAttribute sourceRegionAttr  = spriteElem.Attribute(SPRITE_SOURCEREGION_ATTR);
                XAttribute offsetAttr        = spriteElem.Attribute(SPRITE_OFFSET_ATTR);
                if (spriteNameAttr == null)
                {
                    throw new InvalidOperationException("Sprite name not defined for a sprite in sprite palette!");
                }
                if (sourceRegionAttr == null)
                {
                    throw new InvalidOperationException("Source region not defined in sprite palette!");
                }

                TVariant variant = defaultVariant;
                if (spriteVariantAttr != null)
                {
                    if (!EnumMap <TVariant, string> .TryDemap(spriteVariantAttr.Value, out variant))
                    {
                        throw new InvalidOperationException(string.Format("Unexpected sprite variant '{0}'!", spriteVariantAttr.Value));
                    }
                }
                palette.AddSprite(spriteNameAttr.Value,
                                  variant,
                                  XmlHelper.LoadIntRectangle(sourceRegionAttr.Value),
                                  offsetAttr != null ? XmlHelper.LoadIntVector(offsetAttr.Value) : new RCIntVector(0, 0));
            }
        }
Esempio n. 2
0
        /*--------------------------------------------------------------------------------------------*/
        private static string ConvertToken(string pToken)
        {
            Match  m      = Regex.Match(pToken, @"('s)?" + DelimSet);
            string key    = (m.Length == 0 ? pToken : pToken.Replace(m.Value, ""));
            string result = key;

            if (VertMap.ContainsKey(key))
            {
                result = "[[" + key + "|Object|" + VertMap[key] + "]]";
                //Log.Debug("VERT "+pToken+" // "+key+" // "+(result+m.Value));
            }
            else if (ObjMap.ContainsKey(key))
            {
                result = "[[" + key + "|Object|" + ObjMap[key] + "]]";
                //Log.Debug("OBJT "+pToken+" // "+key+" // "+(result+m.Value));
            }
            else if (EdgeMap.ContainsKey(key))
            {
                result = "[[" + key + "|Edge|" + EdgeMap[key] + "]]";
                //Log.Debug("EDGE "+pToken+" // "+key+" // "+(result+m.Value));
            }
            else if (EnumMap.ContainsKey(key))
            {
                result = "[[" + key + "|Enum|" + EnumMap[key] + "]]";
                //Log.Debug("ENUM "+pToken+" // "+key+" // "+(result+m.Value));
            }
            else if (key.IndexOf('!') == 0)
            {
                result = key.Substring(1);
                //Log.Debug("EXCL "+pToken+" // "+key+" // "+(result+m.Value));
            }

            return(result + m.Value);
        }
Esempio n. 3
0
        public void ExplicitlyTypedArrayType()
        {
            var parameter = new BigqueryParameter(BigqueryParameterType.Array, new[] { new DateTimeOffset(new DateTime(2016, 10, 31), new TimeSpan(8, 30, 0)) });

            parameter.ArrayType = BigqueryParameterType.DateTime;
            string actualJson = JsonConvert.SerializeObject(parameter.ToQueryParameter(BigqueryParameterMode.Positional));

            var expectedResult = new QueryParameter
            {
                ParameterType = new QueryParameterType
                {
                    Type      = EnumMap.ToApiValue(BigqueryParameterType.Array),
                    ArrayType = new QueryParameterType {
                        Type = EnumMap.ToApiValue(BigqueryParameterType.DateTime)
                    }
                },
                ParameterValue = new QueryParameterValue
                {
                    ArrayValues = new[] { new QueryParameterValue {
                                              Value = "2016-10-31 00:00:00"
                                          } }
                }
            };
            string expectedJson = JsonConvert.SerializeObject(expectedResult);

            Assert.Equal(actualJson, expectedJson);
        }
 public void InvalidConversion()
 {
     Assert.Throws <ArgumentException>(() => EnumMap <WriteDisposition> .ToValue("WRITEIFEMPTY"));
     Assert.Throws <ArgumentException>(() => EnumMap <WriteDisposition> .ToValue("Bogus"));
     Assert.Throws <ArgumentException>(() => EnumMap <WriteDisposition> .ToValue("Write_Empty"));
     Assert.Throws <ArgumentException>(() => EnumMap <WriteDisposition> .ToApiValue((WriteDisposition)100));
 }
Esempio n. 5
0
        public virtual void TestReadURL()
        {
            HttpURLConnection conn = Org.Mockito.Mockito.Mock <HttpURLConnection>();

            Org.Mockito.Mockito.DoReturn(new ByteArrayInputStream(FakeLogData)).When(conn).GetInputStream
                ();
            Org.Mockito.Mockito.DoReturn(HttpURLConnection.HttpOk).When(conn).GetResponseCode
                ();
            Org.Mockito.Mockito.DoReturn(Sharpen.Extensions.ToString(FakeLogData.Length)).When
                (conn).GetHeaderField("Content-Length");
            URLConnectionFactory factory = Org.Mockito.Mockito.Mock <URLConnectionFactory>();

            Org.Mockito.Mockito.DoReturn(conn).When(factory).OpenConnection(Org.Mockito.Mockito
                                                                            .Any <Uri>(), Matchers.AnyBoolean());
            Uri url = new Uri("http://localhost/fakeLog");
            EditLogInputStream elis = EditLogFileInputStream.FromUrl(factory, url, HdfsConstants
                                                                     .InvalidTxid, HdfsConstants.InvalidTxid, false);
            // Read the edit log and verify that we got all of the data.
            EnumMap <FSEditLogOpCodes, Holder <int> > counts = FSImageTestUtil.CountEditLogOpTypes
                                                                   (elis);

            Assert.AssertThat(counts[FSEditLogOpCodes.OpAdd].held, CoreMatchers.Is(1));
            Assert.AssertThat(counts[FSEditLogOpCodes.OpSetGenstampV1].held, CoreMatchers.Is(
                                  1));
            Assert.AssertThat(counts[FSEditLogOpCodes.OpClose].held, CoreMatchers.Is(1));
            // Check that length header was picked up.
            NUnit.Framework.Assert.AreEqual(FakeLogData.Length, elis.Length());
            elis.Close();
        }
Esempio n. 6
0
        /// <summary>
        /// Loads a mixed tile type from the XML element into the given tileset.
        /// </summary>
        /// <param name="fromElem">The XML element to load from.</param>
        /// <param name="tileset">The TileSet to load to.</param>
        private static void LoadMixedTile(XElement fromElem, TileSet tileset)
        {
            XAttribute terrainAAttr    = fromElem.Attribute(XmlTileSetConstants.MIXEDTILE_TERRAINA_ATTR);
            XAttribute terrainBAttr    = fromElem.Attribute(XmlTileSetConstants.MIXEDTILE_TERRAINB_ATTR);
            XAttribute combinationAttr = fromElem.Attribute(XmlTileSetConstants.MIXEDTILE_COMBINATION_ATTR);

            if (terrainAAttr == null)
            {
                throw new TileSetException("Terrain type A not defined for mixed tile!");
            }
            if (terrainBAttr == null)
            {
                throw new TileSetException("Terrain type B not defined for mixed tile!");
            }
            if (combinationAttr == null)
            {
                throw new TileSetException("Terrain combination not defined for mixed tile!");
            }

            TerrainCombination combination;

            if (!EnumMap <TerrainCombination, string> .TryDemap(combinationAttr.Value, out combination))
            {
                throw new TileSetException(string.Format("Unexpected terrain combination '{0}' defined for mixed tile.", combinationAttr.Value));
            }

            tileset.CreateMixedTileType(terrainAAttr.Value, terrainBAttr.Value, combination);
            IsoTileType tile = tileset.GetIsoTileTypeImpl(terrainAAttr.Value, terrainBAttr.Value, combination);

            LoadVariants(fromElem, tile, tileset);
        }
Esempio n. 7
0
        /// <summary>
        /// Ctor
        /// </summary>
        public MainForm()
        {
            InitializeComponent();

            //Init Scintilla Component
            m_scintillaCtrl = new Scintilla();

            m_scintillaCtrl.Parent           = panelTextEditor;
            m_scintillaCtrl.Dock             = DockStyle.Fill;
            m_scintillaCtrl.Margins[0].Width = 16;
            m_scintillaCtrl.TabWidth         = 2;

            // Configuring the default style with properties
            // we have common to every lexer style saves time.
            m_scintillaCtrl.StyleResetDefault();
            m_scintillaCtrl.Styles[Style.Default].Font      = "Consolas";
            m_scintillaCtrl.Styles[Style.Default].Size      = 10;
            m_scintillaCtrl.Styles[Style.Default].BackColor = Color.FromArgb(219, 227, 227);
            m_scintillaCtrl.StyleClearAll();

            // Configure the lexer styles
            m_scintillaCtrl.Styles[Style.Cpp.Default].ForeColor        = Color.Silver;
            m_scintillaCtrl.Styles[Style.Cpp.Comment].ForeColor        = Color.FromArgb(0, 128, 0);     // Green
            m_scintillaCtrl.Styles[Style.Cpp.CommentLine].ForeColor    = Color.FromArgb(0, 128, 0);     // Green
            m_scintillaCtrl.Styles[Style.Cpp.CommentLineDoc].ForeColor = Color.FromArgb(128, 128, 128); // Gray
            m_scintillaCtrl.Styles[Style.Cpp.Number].ForeColor         = Color.Olive;
            m_scintillaCtrl.Styles[Style.Cpp.Word].ForeColor           = Color.Blue;
            m_scintillaCtrl.Styles[Style.Cpp.Word2].ForeColor          = Color.Blue;
            m_scintillaCtrl.Styles[Style.Cpp.String].ForeColor         = Color.FromArgb(163, 21, 21); // Red
            m_scintillaCtrl.Styles[Style.Cpp.Character].ForeColor      = Color.FromArgb(163, 21, 21); // Red
            m_scintillaCtrl.Styles[Style.Cpp.Verbatim].ForeColor       = Color.FromArgb(163, 21, 21); // Red
            m_scintillaCtrl.Styles[Style.Cpp.StringEol].BackColor      = Color.Pink;
            m_scintillaCtrl.Styles[Style.Cpp.Operator].ForeColor       = Color.Purple;
            m_scintillaCtrl.Styles[Style.Cpp.Preprocessor].ForeColor   = Color.Maroon;

            m_scintillaCtrl.Lexer = Lexer.Cpp;


            //Create keywords for HLSL
            StringBuilder sb  = new StringBuilder();
            var           map = new EnumMap <ShaderToken>();

            map.Load("HLSLKeywords.map");
            foreach (var kw in map)
            {
                var str = kw.Key + " ";

                if (str[0] == ':')
                {
                    str = str.Substring(1);
                }

                sb.Append(str);
            }
            m_scintillaCtrl.SetKeywords(0, sb.ToString());

            //MRU
            mruMenu = new MruStripMenuInline(fileToolStripMenuItem, recentFilesToolStripMenuItem, new MruStripMenu.ClickedHandler(OnMruFile), mruRegKey + "\\MRU", 16);
            mruMenu.LoadFromRegistry();
        }
Esempio n. 8
0
        public void clear()
        {
            EnumMap <Size, Int32> enumSizeMap = new EnumMap <Size, Int32>(typeof(Size));

            enumSizeMap.Put(Size.Small, 1);
            enumSizeMap.Clear();
            Assertion.AssertEquals("Failed to clear all elements", enumSizeMap.Get(Size.Small), default(Int32)); //$NON-NLS-1$
        }
Esempio n. 9
0
        /// <summary>
        /// Ctor
        /// </summary>
        public MainForm()
        {
            InitializeComponent();

            //Init Scintilla Component
            m_scintillaCtrl = new Scintilla();

            m_scintillaCtrl.Parent = panelTextEditor;
            m_scintillaCtrl.Dock = DockStyle.Fill;
            m_scintillaCtrl.Margins[0].Width = 16;
            m_scintillaCtrl.TabWidth = 2;

            // Configuring the default style with properties
            // we have common to every lexer style saves time.
            m_scintillaCtrl.StyleResetDefault();
            m_scintillaCtrl.Styles[Style.Default].Font = "Consolas";
            m_scintillaCtrl.Styles[Style.Default].Size = 10;
            m_scintillaCtrl.Styles[Style.Default].BackColor = Color.FromArgb(219, 227, 227);
            m_scintillaCtrl.StyleClearAll();

            // Configure the lexer styles
            m_scintillaCtrl.Styles[Style.Cpp.Default].ForeColor = Color.Silver;
            m_scintillaCtrl.Styles[Style.Cpp.Comment].ForeColor = Color.FromArgb(0, 128, 0); // Green
            m_scintillaCtrl.Styles[Style.Cpp.CommentLine].ForeColor = Color.FromArgb(0, 128, 0); // Green
            m_scintillaCtrl.Styles[Style.Cpp.CommentLineDoc].ForeColor = Color.FromArgb(128, 128, 128); // Gray
            m_scintillaCtrl.Styles[Style.Cpp.Number].ForeColor = Color.Olive;
            m_scintillaCtrl.Styles[Style.Cpp.Word].ForeColor = Color.Blue;
            m_scintillaCtrl.Styles[Style.Cpp.Word2].ForeColor = Color.Blue;
            m_scintillaCtrl.Styles[Style.Cpp.String].ForeColor = Color.FromArgb(163, 21, 21); // Red
            m_scintillaCtrl.Styles[Style.Cpp.Character].ForeColor = Color.FromArgb(163, 21, 21); // Red
            m_scintillaCtrl.Styles[Style.Cpp.Verbatim].ForeColor = Color.FromArgb(163, 21, 21); // Red
            m_scintillaCtrl.Styles[Style.Cpp.StringEol].BackColor = Color.Pink;
            m_scintillaCtrl.Styles[Style.Cpp.Operator].ForeColor = Color.Purple;
            m_scintillaCtrl.Styles[Style.Cpp.Preprocessor].ForeColor = Color.Maroon;

            m_scintillaCtrl.Lexer = Lexer.Cpp;


            //Create keywords for HLSL
            StringBuilder sb = new StringBuilder();
            var map = new EnumMap<ShaderToken>();
            map.Load("HLSLKeywords.map");
            foreach (var kw in map)
            {
                var str = kw.Key + " ";

                if (str[0] == ':')
                    str = str.Substring(1);

                sb.Append(str);
            }
            m_scintillaCtrl.SetKeywords(0, sb.ToString());

            //MRU
            mruMenu = new MruStripMenuInline(fileToolStripMenuItem, recentFilesToolStripMenuItem, new MruStripMenu.ClickedHandler(OnMruFile), mruRegKey + "\\MRU", 16);
            mruMenu.LoadFromRegistry();
        }
Esempio n. 10
0
        /// <summary>
        /// Load a tile-constraint for a terrain object from the given XML element.
        /// </summary>
        /// <param name="fromElem">The XML element to load from.</param>
        /// <param name="terrainObj">The terrain object.</param>
        /// <param name="tileset">The tileset being loaded.</param>
        /// <returns>The loaded tile-constraint.</returns>
        private static ITerrainObjectConstraint LoadTileConstraint(XElement fromElem, TerrainObjectType terrainObj, TileSet tileset)
        {
            /// Load the attributes of the constraint.
            XAttribute quadCoordsAttr   = fromElem.Attribute(XmlTileSetConstants.TERRAINOBJ_TILECONSTRAINT_QUADCOORDS_ATTR);
            XAttribute terrainAttr      = fromElem.Attribute(XmlTileSetConstants.TERRAINOBJ_TILECONSTRAINT_TERRAIN_ATTR);
            XAttribute terrainAAttr     = fromElem.Attribute(XmlTileSetConstants.TERRAINOBJ_TILECONSTRAINT_TERRAINA_ATTR);
            XAttribute terrainBAttr     = fromElem.Attribute(XmlTileSetConstants.TERRAINOBJ_TILECONSTRAINT_TERRAINB_ATTR);
            XAttribute combinationsAttr = fromElem.Attribute(XmlTileSetConstants.TERRAINOBJ_TILECONSTRAINT_COMBINATIONS_ATTR);

            if (quadCoordsAttr == null)
            {
                throw new TileSetException("Quadratic coordinates not defined for tile constraint element!");
            }
            if (terrainAttr != null && (terrainAAttr != null || terrainBAttr != null || combinationsAttr != null))
            {
                throw new TileSetException("Invalid attributes defined for tile constraint on a simple tile!");
            }
            if (terrainAttr == null && (terrainAAttr == null || terrainBAttr == null || combinationsAttr == null))
            {
                throw new TileSetException("Invalid attributes defined for tile constraint on a mixed tile!");
            }

            RCIntVector quadCoords = XmlHelper.LoadIntVector(quadCoordsAttr.Value);

            if (terrainObj.IsExcluded(quadCoords))
            {
                throw new TileSetException(string.Format("TileConstraint at excluded coordinates {0} cannot be defined!", quadCoords));
            }
            if (terrainAttr != null)
            {
                TerrainType terrain = tileset.GetTerrainTypeImpl(terrainAttr.Value);
                return(new IsoTileConstraint(quadCoords, terrain, tileset));
            }
            else
            {
                TerrainType terrainA = tileset.GetTerrainTypeImpl(terrainAAttr.Value);
                TerrainType terrainB = tileset.GetTerrainTypeImpl(terrainBAttr.Value);
                List <TerrainCombination> combinations = new List <TerrainCombination>();
                string[] combinationStrings            = combinationsAttr.Value.Split(';');
                if (combinationStrings.Length == 0)
                {
                    throw new TileSetException("Terrain combination not defined for tile constraint on a mixed tile!");
                }
                foreach (string combStr in combinationStrings)
                {
                    TerrainCombination combination;
                    if (!EnumMap <TerrainCombination, string> .TryDemap(combStr, out combination) || combination == TerrainCombination.Simple)
                    {
                        throw new TileSetException(string.Format("Unexpected terrain combination '{0}' defined for tile constraint!", combStr));
                    }
                    combinations.Add(combination);
                }

                return(new IsoTileConstraint(quadCoords, terrainA, terrainB, combinations, tileset));
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Constructs a built-in HeapType.
        /// </summary>
        /// <param name="builtInType">The built-in type to be constructed.</param>
        public HeapType(BuiltInTypeEnum builtInType)
        {
            /// Members filled at initialization.
            switch (builtInType)
            {
            case BuiltInTypeEnum.Byte:
                this.allocationSize = 1;
                break;

            case BuiltInTypeEnum.Short:
                this.allocationSize = 2;
                break;

            case BuiltInTypeEnum.Integer:
            case BuiltInTypeEnum.Number:
                this.allocationSize = 4;
                break;

            case BuiltInTypeEnum.Long:
                this.allocationSize = 8;
                break;

            case BuiltInTypeEnum.IntVector:
            case BuiltInTypeEnum.NumVector:
                this.allocationSize = 9;
                break;

            case BuiltInTypeEnum.IntRectangle:
            case BuiltInTypeEnum.NumRectangle:
                this.allocationSize = 17;
                break;

            default:
                throw new ArgumentException("Unexpected value of 'builtInType'!", "builtInType");
            }
            string name;

            if (!EnumMap <BuiltInTypeEnum, string> .TryMap(builtInType, out name) || name == null)
            {
                throw new ArgumentException("No name defined for the built-in type!", "builtInType");
            }
            if (!IDENTIFIER_SYNTAX.IsMatch(name) || name.EndsWith("*"))
            {
                throw new HeapException(string.Format("Invalid built-in type name '{0}'!", name));
            }
            this.name              = name;
            this.builtInType       = builtInType;
            this.pointedTypeID     = -1;
            this.fieldTypeIDs      = null;
            this.fieldOffsets      = null;
            this.tmpFieldTypeNames = null;
            this.fieldIndices      = null;

            /// Members that will be filled during validation.
            this.id = -1;
        }
Esempio n. 12
0
 private static QueryParameter ScalarParameter(BigqueryParameterType type, string value) =>
 new QueryParameter
 {
     ParameterType = new QueryParameterType {
         Type = EnumMap.ToApiValue(type)
     },
     ParameterValue = new QueryParameterValue {
         Value = value
     }
 };
        public void TypeInference(string name, object value, BigQueryDbType expectedType)
        {
            var parameter = new BigQueryParameter();

            parameter.Value = value;
            var queryParameter = parameter.ToQueryParameter();
            var actualType     = EnumMap <BigQueryDbType> .ToValue(queryParameter.ParameterType.Type);

            Assert.Equal(expectedType, actualType);
        }
Esempio n. 14
0
 public void InvalidConversion()
 {
     Assert.Throws <ArgumentException>(() => EnumMap <WriteDisposition> .ToValue("WRITEIFEMPTY"));
     Assert.Throws <ArgumentException>(() => EnumMap <WriteDisposition> .ToValue("Bogus"));
     Assert.Throws <ArgumentException>(() => EnumMap <WriteDisposition> .ToValue("Write_Empty"));
     Assert.Throws <ArgumentException>(() => EnumMap <WriteDisposition> .ToApiValue((WriteDisposition)100));
     Assert.Throws <TypeInitializationException>(() => EnumMap <SchemaUpdateOption> .ToApiValue(SchemaUpdateOption.AllowFieldAddition));
     Assert.Throws <ArgumentException>(() => FlagsEnumMap <SchemaUpdateOption> .ToApiValues((SchemaUpdateOption)100));
     Assert.Throws <TypeInitializationException>(() => FlagsEnumMap <WriteDisposition> .ToApiValues(WriteDisposition.WriteAppend));
 }
Esempio n. 15
0
        /// <summary>
        /// Creates an instance of the given type defined in the given XML-load.
        /// </summary>
        /// <typeparam name="T">The type of the instance to be created.</typeparam>
        /// <param name="sourceElem">The XML-node that contains informations about the instantiation.</param>
        /// <returns>The created instance of type T.</returns>
        public static T CreateInstance <T>(XElement sourceElem)
        {
            /// Get the name of the assembly that contains the class to be instantiated.
            XAttribute assemblyAttr = sourceElem.Attribute(INSTANTIATION_ASSEMBLY_ATTR);

            if (assemblyAttr == null)
            {
                throw new ConfigurationException(string.Format("'{0}' attribute not found!", INSTANTIATION_ASSEMBLY_ATTR));
            }

            /// Get the name of the class to be instantiated.
            XAttribute classElem = sourceElem.Attribute(INSTANTIATION_CLASS_ATTR);

            if (classElem == null)
            {
                throw new ConfigurationException(string.Format("'{0}' attribute not found!", INSTANTIATION_CLASS_ATTR));
            }

            /// Collect the parameters for the constructor.
            List <object> ctorParams = new List <object>();

            foreach (XElement paramElem in sourceElem.Elements(INSTANTIATION_CTORPARAM_ELEM))
            {
                XAttribute paramTypeAttr = paramElem.Attribute(INSTANTIATION_CTORPARAM_TYPE_ATTR);
                if (paramTypeAttr == null)
                {
                    throw new ConfigurationException("No type defined for trace constructor parameter!");
                }

                /// Try to parse the type attribute.
                CtorParamType paramType;
                if (!EnumMap <CtorParamType, string> .TryDemap(paramTypeAttr.Value, out paramType))
                {
                    throw new ConfigurationException(string.Format("Unexpected constructor parameter type '{0}' defined.", paramTypeAttr.Value));
                }

                object parameter = ParseParameterValue(paramElem.Value, paramType);
                ctorParams.Add(parameter);
            }

            /// Load the assembly that contains the class and create an instance of that class.
            Assembly asm = Assembly.Load(assemblyAttr.Value);

            if (asm == null)
            {
                throw new ConfigurationException(string.Format("Unable to load assembly '{0}'!", assemblyAttr.Value));
            }
            Type objType = asm.GetType(classElem.Value);

            if (objType == null)
            {
                throw new ConfigurationException(string.Format("Unable to load type '{0}' from assembly '{1}'!", classElem.Value, assemblyAttr.Value));
            }
            return((T)Activator.CreateInstance(objType, ctorParams.ToArray()));
        }
Esempio n. 16
0
        /// <summary>Calculates mask entries required for the ACL.</summary>
        /// <remarks>
        /// Calculates mask entries required for the ACL.  Mask calculation is performed
        /// separately for each scope: access and default.  This method is responsible
        /// for handling the following cases of mask calculation:
        /// 1. Throws an exception if the caller attempts to remove the mask entry of an
        /// existing ACL that requires it.  If the ACL has any named entries, then a
        /// mask entry is required.
        /// 2. If the caller supplied a mask in the ACL spec, use it.
        /// 3. If the caller did not supply a mask, but there are ACL entry changes in
        /// this scope, then automatically calculate a new mask.  The permissions of
        /// the new mask are the union of the permissions on the group entry and all
        /// named entries.
        /// </remarks>
        /// <param name="aclBuilder">ArrayList<AclEntry> containing entries to build</param>
        /// <param name="providedMask">
        /// EnumMap<AclEntryScope, AclEntry> mapping each scope to
        /// the mask entry that was provided for that scope (if provided)
        /// </param>
        /// <param name="maskDirty">
        /// EnumSet<AclEntryScope> which contains a scope if the mask
        /// entry is dirty (added or deleted) in that scope
        /// </param>
        /// <param name="scopeDirty">
        /// EnumSet<AclEntryScope> which contains a scope if any entry
        /// is dirty (added or deleted) in that scope
        /// </param>
        /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.AclException">if validation fails
        ///     </exception>
        private static void CalculateMasks(IList <AclEntry> aclBuilder, EnumMap <AclEntryScope
                                                                                 , AclEntry> providedMask, EnumSet <AclEntryScope> maskDirty, EnumSet <AclEntryScope
                                                                                                                                                       > scopeDirty)
        {
            EnumSet <AclEntryScope>           scopeFound = EnumSet.NoneOf <AclEntryScope>();
            EnumMap <AclEntryScope, FsAction> unionPerms = Maps.NewEnumMap <AclEntryScope>();
            EnumSet <AclEntryScope>           maskNeeded = EnumSet.NoneOf <AclEntryScope>();

            // Determine which scopes are present, which scopes need a mask, and the
            // union of group class permissions in each scope.
            foreach (AclEntry entry in aclBuilder)
            {
                scopeFound.AddItem(entry.GetScope());
                if (entry.GetType() == AclEntryType.Group || entry.GetName() != null)
                {
                    FsAction scopeUnionPerms = Objects.FirstNonNull(unionPerms[entry.GetScope()], FsAction
                                                                    .None);
                    unionPerms[entry.GetScope()] = scopeUnionPerms.Or(entry.GetPermission());
                }
                if (entry.GetName() != null)
                {
                    maskNeeded.AddItem(entry.GetScope());
                }
            }
            // Add mask entry if needed in each scope.
            foreach (AclEntryScope scope in scopeFound)
            {
                if (!providedMask.Contains(scope) && maskNeeded.Contains(scope) && maskDirty.Contains
                        (scope))
                {
                    // Caller explicitly removed mask entry, but it's required.
                    throw new AclException("Invalid ACL: mask is required and cannot be deleted.");
                }
                else
                {
                    if (providedMask.Contains(scope) && (!scopeDirty.Contains(scope) || maskDirty.Contains
                                                             (scope)))
                    {
                        // Caller explicitly provided new mask, or we are preserving the existing
                        // mask in an unchanged scope.
                        aclBuilder.AddItem(providedMask[scope]);
                    }
                    else
                    {
                        if (maskNeeded.Contains(scope) || providedMask.Contains(scope))
                        {
                            // Otherwise, if there are maskable entries present, or the ACL
                            // previously had a mask, then recalculate a mask automatically.
                            aclBuilder.AddItem(new AclEntry.Builder().SetScope(scope).SetType(AclEntryType.Mask
                                                                                              ).SetPermission(unionPerms[scope]).Build());
                        }
                    }
                }
            }
        }
Esempio n. 17
0
        public static IDictionary <IntegralType, int?> generateMap(string instruction)
        {
            IList <int?> current = map[instruction];
            IDictionary <IntegralType, int?> hmap = new EnumMap <IntegralType, int?>(typeof(IntegralType));

            hmap[IntegralType.jinteger] = current[0];
            hmap[IntegralType.jlong]    = current[1];
            hmap[IntegralType.jfloat]   = current[2];
            hmap[IntegralType.jdouble]  = current[3];
            return(hmap);
        }
Esempio n. 18
0
        /// <summary>
        /// Loads the condition of a conditional branch from the given XML element.
        /// </summary>
        /// <param name="fromElem">The XML element to load from.</param>
        /// <param name="tileset">The tileset being loaded.</param>
        /// <returns>The loaded condition.</returns>
        private static IIsoTileCondition LoadCondition(XElement fromElem, TileSet tileset)
        {
            if (fromElem.Name == XmlTileSetConstants.NEIGHBOURCOND_ELEM)
            {
                /// Load neighbour condition.
                XAttribute whichNeighbourAttr  = fromElem.Attribute(XmlTileSetConstants.NEIGHBOURCOND_WHICH_ATTR);
                XAttribute whatCombinationAttr = fromElem.Attribute(XmlTileSetConstants.NEIGHBOURCOND_COMBINATION_ATTR);
                if (whichNeighbourAttr == null)
                {
                    throw new TileSetException("Neighbour not defined for a neighbour condition!");
                }
                if (whatCombinationAttr == null)
                {
                    throw new TileSetException("Terrain combination not defined for a neighbour condition!");
                }

                TerrainCombination combination;
                if (!EnumMap <TerrainCombination, string> .TryDemap(whatCombinationAttr.Value, out combination))
                {
                    throw new TileSetException(string.Format("Unexpected terrain combination '{0}' defined for neighbour condition!", whatCombinationAttr.Value));
                }

                MapDirection neighbour;
                if (!EnumMap <MapDirection, string> .TryDemap(whichNeighbourAttr.Value, out neighbour))
                {
                    throw new TileSetException(string.Format("Unexpected neighbour direction '{0}' defined for neighbour condition!", whichNeighbourAttr.Value));
                }

                return(new NeighbourCondition(combination, neighbour, tileset));
            }
            else if (fromElem.Name == XmlTileSetConstants.COMPLEXCOND_AND_ELEM ||
                     fromElem.Name == XmlTileSetConstants.COMPLEXCOND_OR_ELEM ||
                     fromElem.Name == XmlTileSetConstants.COMPLEXCOND_NOT_ELEM)
            {
                /// Load complex condition.
                LogicalOp logicalOp;
                if (!EnumMap <LogicalOp, string> .TryDemap(fromElem.Name.LocalName, out logicalOp))
                {
                    throw new TileSetException(string.Format("Unexpected logical operator '{0}' defined for complex condition!", fromElem.Name.LocalName));
                }

                List <IIsoTileCondition> subconditions = new List <IIsoTileCondition>();
                foreach (XElement subconditionElem in fromElem.Elements())
                {
                    subconditions.Add(LoadCondition(subconditionElem, tileset));
                }

                return(new ComplexCondition(subconditions, logicalOp, tileset));
            }
            else
            {
                throw new TileSetException(string.Format("Unexpected condition element: {0}!", fromElem.Name.LocalName));
            }
        }
Esempio n. 19
0
 public void OnAfterDeserialize()
 {
     _colorMap = new EnumMap <Hitbox.Type, Color>();
     _colorMap[Hitbox.Type.Inactive]   = _inactiveHitboxColor;
     _colorMap[Hitbox.Type.Offensive]  = _offensiveHitboxColor;
     _colorMap[Hitbox.Type.Damageable] = _damageableHitboxColor;
     _colorMap[Hitbox.Type.Invincible] = _invincibleHitboxColor;
     _colorMap[Hitbox.Type.Intangible] = _intangibleHitboxColor;
     _colorMap[Hitbox.Type.Absorb]     = _absorbHitboxColor;
     _colorMap[Hitbox.Type.Shield]     = _shieldHitboxColor;
     _colorMap[Hitbox.Type.Reflective] = ReflectHitboxColor;
 }
Esempio n. 20
0
		/// <summary>
		/// Cache the built-in ECMAScript objects to protect them against
		/// modifications by the script.
		/// </summary>
		/// <remarks>
		/// Cache the built-in ECMAScript objects to protect them against
		/// modifications by the script. This method is called automatically by
		/// <see cref="ScriptRuntime.InitStandardObjects(Context, ScriptableObject, bool)">ScriptRuntime.initStandardObjects</see>
		/// if the scope argument is an instance of this class. It only has to be
		/// called by the embedding if a top-level scope is not initialized through
		/// <code>initStandardObjects()</code>.
		/// </remarks>
		public virtual void CacheBuiltins()
		{
			ctors = new EnumMap<TopLevel.Builtins, BaseFunction>(typeof(TopLevel.Builtins));
			foreach (TopLevel.Builtins builtin in TopLevel.Builtins.Values())
			{
				object value = ScriptableObject.GetProperty(this, builtin.ToString());
				if (value is BaseFunction)
				{
					ctors.Put(builtin, (BaseFunction)value);
				}
			}
		}
Esempio n. 21
0
        public void ArrayTypeInference(string name, object value, BigQueryDbType expectedArrayType)
        {
            var parameter = new BigQueryParameter();

            parameter.Value = value;
            var queryParameter = parameter.ToQueryParameter(BigQueryParameterMode.Positional);

            Assert.Equal(BigQueryDbType.Array.ToParameterApiType(), queryParameter.ParameterType.Type);
            var actualArrayType = EnumMap <BigQueryDbType> .ToValue(queryParameter.ParameterType.ArrayType.Type);

            Assert.Equal(expectedArrayType, actualArrayType);
        }
Esempio n. 22
0
 public UInt64EnumJsonConverter(Serializer serializer, PropertyInfo propInfo)
 {
     _map          = EnumMap.For <T>();
     _keyConverter = serializer.GetConverter <Utf8String>(propInfo, true);
     if (typeof(T).GetTypeInfo().GetCustomAttribute <FlagsAttribute>() == null && _map.MaxValue <= Int53Attribute.MaxValue)
     {
         _valueConverter = new UInt53JsonConverter();
     }
     else
     {
         _valueConverter = new UInt64JsonConverter();
     }
 }
Esempio n. 23
0
        public MouseClickDetector(IComponentEventSource <MouseEventData, IWidget> eventSource)
        {
            DragThreshold    = 4;
            DoubleClickDelay = 0.5f;

            queue            = new EventQueue <MouseEventData>();
            this.eventSource = eventSource;

            lastDownTime = new EnumMap <MouseButton, MouseClickRecord>(buttons);
            lastDownTime.Fill(MouseClickRecord.Invalid);

            lastComponentSeen = new WeakReference <IWidget>(null);
        }
Esempio n. 24
0
        /// <summary>
        /// Loads the general data of a scenario element type from the given element.
        /// </summary>
        /// <param name="genDataElem">The XML element to load from.</param>
        /// <param name="elementType">The scenario element type being constructed.</param>
        private static void LoadGeneralData(XElement genDataElem, ScenarioElementType elementType)
        {
            XElement areaElem         = genDataElem.Element(XmlMetadataConstants.GENDATA_AREA_ELEM);
            XElement obstacleAreaElem = genDataElem.Element(XmlMetadataConstants.GENDATA_OBSTACLEAREA_ELEM);
            XElement armorElem        = genDataElem.Element(XmlMetadataConstants.GENDATA_ARMOR_ELEM);
            XElement maxEnergyElem    = genDataElem.Element(XmlMetadataConstants.GENDATA_MAXENERGY_ELEM);
            XElement maxHPElem        = genDataElem.Element(XmlMetadataConstants.GENDATA_MAXHP_ELEM);
            XElement sightRangeElem   = genDataElem.Element(XmlMetadataConstants.GENDATA_SIGHTRANGE_ELEM);
            XElement sizeElem         = genDataElem.Element(XmlMetadataConstants.GENDATA_SIZE_ELEM);
            XElement speedElem        = genDataElem.Element(XmlMetadataConstants.GENDATA_SPEED_ELEM);

            if (areaElem != null)
            {
                elementType.SetArea(XmlHelper.LoadNumRectangle(areaElem.Value));
            }
            if (obstacleAreaElem != null)
            {
                elementType.SetObstacleArea(XmlHelper.LoadIntRectangle(obstacleAreaElem.Value));
            }
            if (armorElem != null)
            {
                elementType.SetArmor(XmlHelper.LoadInt(armorElem.Value));
            }
            if (maxEnergyElem != null)
            {
                elementType.SetMaxEnergy(XmlHelper.LoadInt(maxEnergyElem.Value));
            }
            if (maxHPElem != null)
            {
                elementType.SetMaxHP(XmlHelper.LoadInt(maxHPElem.Value));
            }
            if (sightRangeElem != null)
            {
                elementType.SetSightRange(XmlHelper.LoadInt(sightRangeElem.Value));
            }
            if (speedElem != null)
            {
                elementType.SetSpeed(XmlHelper.LoadNum(speedElem.Value));
            }

            if (sizeElem != null)
            {
                SizeEnum size;
                if (!EnumMap <SizeEnum, string> .TryDemap(sizeElem.Value, out size))
                {
                    throw new SimulatorException(string.Format("Unexpected size '{0}' defined in general data!", sizeElem.Value));
                }
                elementType.SetSize(size);
            }
        }
Esempio n. 25
0
        public void containsKeyLjava_lang_Object()
        {
            EnumMap <Size, Int32> enumSizeMap = new EnumMap <Size, Int32>(typeof(Size));

            Assertion.Assert("Returned true for uncontained key", !enumSizeMap //$NON-NLS-1$
                             .ContainsKey(Size.Small));
            enumSizeMap.Put(Size.Small, 1);
            Assertion.Assert("Returned false for contained key", enumSizeMap //$NON-NLS-1$
                             .ContainsKey(Size.Small));

            /*
             * enumSizeMap.Put(Size.Big, null);
             * Assertion.Assert("Returned false for contained key", enumSizeMap //$NON-NLS-1$
             *      .ContainsKey(Size.Big));*/
        }
Esempio n. 26
0
        /// <summary>
        /// 初始化编辑器文本处理器
        /// </summary>
        private void InitEditorScintillaCtrl()
        {
            m_EditorScintillaCtrl                  = new Scintilla();
            m_EditorScintillaCtrl.Parent           = EditorPanel;
            m_EditorScintillaCtrl.Dock             = DockStyle.Fill;
            m_EditorScintillaCtrl.Margins[0].Width = 16;
            m_EditorScintillaCtrl.TabWidth         = 2;

            m_EditorScintillaCtrl.StyleResetDefault();
            m_EditorScintillaCtrl.Styles[Style.Default].Font      = "Consolas";
            m_EditorScintillaCtrl.Styles[Style.Default].Size      = 10;
            m_EditorScintillaCtrl.Styles[Style.Default].BackColor = Color.FromArgb(219, 227, 227);
            m_EditorScintillaCtrl.StyleClearAll();

            m_EditorScintillaCtrl.Styles[Style.Cpp.Default].ForeColor        = Color.Silver;
            m_EditorScintillaCtrl.Styles[Style.Cpp.Comment].ForeColor        = Color.FromArgb(0, 128, 0);     // Green
            m_EditorScintillaCtrl.Styles[Style.Cpp.CommentLine].ForeColor    = Color.FromArgb(0, 128, 0);     // Green
            m_EditorScintillaCtrl.Styles[Style.Cpp.CommentLineDoc].ForeColor = Color.FromArgb(128, 128, 128); // Gray
            m_EditorScintillaCtrl.Styles[Style.Cpp.Number].ForeColor         = Color.Olive;
            m_EditorScintillaCtrl.Styles[Style.Cpp.Word].ForeColor           = Color.Blue;
            m_EditorScintillaCtrl.Styles[Style.Cpp.Word2].ForeColor          = Color.Blue;
            m_EditorScintillaCtrl.Styles[Style.Cpp.String].ForeColor         = Color.FromArgb(163, 21, 21); // Red
            m_EditorScintillaCtrl.Styles[Style.Cpp.Character].ForeColor      = Color.FromArgb(163, 21, 21); // Red
            m_EditorScintillaCtrl.Styles[Style.Cpp.Verbatim].ForeColor       = Color.FromArgb(163, 21, 21); // Red
            m_EditorScintillaCtrl.Styles[Style.Cpp.StringEol].BackColor      = Color.Pink;
            m_EditorScintillaCtrl.Styles[Style.Cpp.Operator].ForeColor       = Color.Purple;
            m_EditorScintillaCtrl.Styles[Style.Cpp.Preprocessor].ForeColor   = Color.Maroon;

            m_EditorScintillaCtrl.Lexer = Lexer.Cpp;

            // 添加 HLSL 关键字
            StringBuilder sb  = new StringBuilder();
            var           map = new EnumMap <ENUM_ShaderTokenType>();

            map.Load("Content\\Config\\HLSLKeywords.map");
            foreach (var kw in map)
            {
                var str = kw.Key + " ";

                if (str[0] == ':')
                {
                    str = str.Substring(1);
                }

                sb.Append(str);
            }
            m_EditorScintillaCtrl.SetKeywords(0, sb.ToString());
        }
Esempio n. 27
0
        public void ConstructorLjava_util_EnumMap()
        {
            EnumMap <Color, Double> enumColorMap = null;

            enumColorMap = new EnumMap <Color, Double>(typeof(Color));
            Double double1 = 1;

            enumColorMap.Put(Color.Green, 2);
            enumColorMap.Put(Color.Blue, double1);

            EnumMap <Color, Double> enumMap = new EnumMap <Color, Double>(enumColorMap);

            Assertion.AssertEquals("Constructor fails", 2, enumMap.Get(Color.Green));             //$NON-NLS-1$
            Assertion.AssertEquals("Constructor fails", double1, enumMap.Get(Color.Blue));        //$NON-NLS-1$
            Assertion.AssertEquals("Constructor fails", enumMap.Get(Color.Red), default(Double)); //$NON-NLS-1$
            enumMap.Put(Color.Red, 1);
            Assertion.AssertEquals("Wrong value", 1, enumMap.Get(Color.Red));                     //$NON-NLS-1$
        }
Esempio n. 28
0
        public void test_putLjava_lang_ObjectLjava_lang_Object()
        {
            EnumMap <Size, Int32> enumSizeMap = new EnumMap <Size, Int32>(typeof(Size));

            /*try {
             *  enumSizeMap.put(Color.Red, 2);
             *  fail("Expected ClassCastException"); //$NON-NLS-1$
             * } catch (ClassCastException e) {
             *  // Expected
             * }*/
            Assertion.AssertEquals("Return non-null for non mapped key", enumSizeMap.Put( //$NON-NLS-1$
                                       Size.Small, 1), 0);

            EnumMap <Color, Double> enumColorMap = new EnumMap <Color, Double>(typeof(Color));

            /*try {
             *  enumColorMap.put(Size.Big, 2);
             *  fail("Expected ClassCastException"); //$NON-NLS-1$
             * } catch (ClassCastException e) {
             *  // Expected
             * }
             * try {
             *  enumColorMap.put(null, 2);
             *  fail("Expected NullPointerException"); //$NON-NLS-1$
             * } catch (NullPointerException e) {
             *  // Expected
             * }*/
            Assertion.AssertEquals("Return non-null for non mapped key", enumColorMap.Put(   //$NON-NLS-1$
                                       Color.Green, 2), 0);
            Assertion.AssertEquals("Return wrong value", 2, enumColorMap.Put(Color.Green,    //$NON-NLS-1$
                                                                             4));
            Assertion.AssertEquals("Return wrong value", 4, enumColorMap.Put(                //$NON-NLS-1$
                                       Color.Green, Int32.Parse("3")));                      //$NON-NLS-1$
            Assertion.AssertEquals("Return wrong value", Int32.Parse("3"), enumColorMap.Put( //$NON-NLS-1$//$NON-NLS-2$
                                       Color.Green, 0));
            Single f = Single.Parse("3.4");                                                  //$NON-NLS-1$

            Assertion.AssertEquals("Return non-null for non mapped key", enumColorMap.Put(   //$NON-NLS-1$
                                       Color.Green, f), 0);
            Assertion.AssertEquals("Return non-null for non mapped key", enumColorMap.Put(   //$NON-NLS-1$
                                       Color.Blue, 2), 0);
            Assertion.AssertEquals("Return wrong value", 2, enumColorMap.Put(Color.Blue,     //$NON-NLS-1$
                                                                             4));
        }
Esempio n. 29
0
        /// <summary>Completely replaces the ACL with the entries of the ACL spec.</summary>
        /// <remarks>
        /// Completely replaces the ACL with the entries of the ACL spec.  If
        /// necessary, recalculates the mask entries.  If necessary, default entries
        /// are inferred by copying the permissions of the corresponding access
        /// entries.  Replacement occurs separately for each of the access ACL and the
        /// default ACL.  If the ACL spec contains only access entries, then the
        /// existing default entries are retained.  If the ACL spec contains only
        /// default entries, then the existing access entries are retained.  If the ACL
        /// spec contains both access and default entries, then both are replaced.
        /// </remarks>
        /// <param name="existingAcl">List<AclEntry> existing ACL</param>
        /// <param name="inAclSpec">List<AclEntry> ACL spec containing replacement entries</param>
        /// <returns>List<AclEntry> new ACL</returns>
        /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.AclException">if validation fails
        ///     </exception>
        public static IList <AclEntry> ReplaceAclEntries(IList <AclEntry> existingAcl, IList
                                                         <AclEntry> inAclSpec)
        {
            AclTransformation.ValidatedAclSpec aclSpec = new AclTransformation.ValidatedAclSpec
                                                             (inAclSpec);
            AList <AclEntry> aclBuilder = Lists.NewArrayListWithCapacity(MaxEntries);
            // Replacement is done separately for each scope: access and default.
            EnumMap <AclEntryScope, AclEntry> providedMask = Maps.NewEnumMap <AclEntryScope>();
            EnumSet <AclEntryScope>           maskDirty    = EnumSet.NoneOf <AclEntryScope>();
            EnumSet <AclEntryScope>           scopeDirty   = EnumSet.NoneOf <AclEntryScope>();

            foreach (AclEntry aclSpecEntry in aclSpec)
            {
                scopeDirty.AddItem(aclSpecEntry.GetScope());
                if (aclSpecEntry.GetType() == AclEntryType.Mask)
                {
                    providedMask[aclSpecEntry.GetScope()] = aclSpecEntry;
                    maskDirty.AddItem(aclSpecEntry.GetScope());
                }
                else
                {
                    aclBuilder.AddItem(aclSpecEntry);
                }
            }
            // Copy existing entries if the scope was not replaced.
            foreach (AclEntry existingEntry in existingAcl)
            {
                if (!scopeDirty.Contains(existingEntry.GetScope()))
                {
                    if (existingEntry.GetType() == AclEntryType.Mask)
                    {
                        providedMask[existingEntry.GetScope()] = existingEntry;
                    }
                    else
                    {
                        aclBuilder.AddItem(existingEntry);
                    }
                }
            }
            CopyDefaultsIfNeeded(aclBuilder);
            CalculateMasks(aclBuilder, providedMask, maskDirty, scopeDirty);
            return(BuildAndValidateAcl(aclBuilder));
        }
Esempio n. 30
0
        public void getLjava_lang_Object()
        {
            EnumMap <Size, Int32> enumSizeMap = new EnumMap <Size, Int32>(typeof(Size));

            Assertion.AssertEquals("Get returned non-null for non mapped key", enumSizeMap //$NON-NLS-1$
                                   .Get(Size.Big), 0);
            enumSizeMap.Put(Size.Big, 1);
            Assertion.AssertEquals("Get returned incorrect value for given key", 1, //$NON-NLS-1$
                                   enumSizeMap.Get(Size.Big));

            Assertion.AssertEquals("Get returned non-null for non mapped key", enumSizeMap   //$NON-NLS-1$
                                   .Get(Size.Small), 0);
            Assertion.AssertEquals("Get returned non-null for non existent key", enumSizeMap //$NON-NLS-1$
                                   .Get(Color.Red), 0);
            Assertion.AssertEquals("Get returned non-null for non existent key", enumSizeMap //$NON-NLS-1$
                                   .Get(1), 0);
            Assertion.AssertEquals("Get returned non-null for non existent key", enumSizeMap //$NON-NLS-1$
                                   .Get(null), 0);

            EnumMap <Color, Double> enumColorMap = new EnumMap <Color, Double>(typeof(Color));

            Assertion.AssertEquals("Get returned non-null for non mapped key", enumColorMap //$NON-NLS-1$
                                   .Get(Color.Green), 0);
            enumColorMap.Put(Color.Green, 2);
            Assertion.AssertEquals("Get returned incorrect value for given key", 2,         //$NON-NLS-1$
                                   enumColorMap.Get(Color.Green));
            Assertion.AssertEquals("Get returned non-null for non mapped key", enumColorMap //$NON-NLS-1$
                                   .Get(Color.Blue), 0);

            enumColorMap.Put(Color.Green, 4);
            Assertion.AssertEquals("Get returned incorrect value for given key",                   //$NON-NLS-1$
                                   4, enumColorMap.Get(Color.Green));
            enumColorMap.Put(Color.Green, Int32.Parse("3"));                                       //$NON-NLS-1$
            Assertion.AssertEquals("Get returned incorrect value for given key", Int32.Parse(      //$NON-NLS-1$
                                       "3"), enumColorMap.Get(Color.Green));                       //$NON-NLS-1$
            enumColorMap.Put(Color.Green, 0);
            Assertion.AssertEquals("Can not handle null value", enumColorMap.Get(Color.Green), 0); //$NON-NLS-1$
            Single f = Single.Parse("3.4");                                                        //$NON-NLS-1$

            enumColorMap.Put(Color.Green, f);
            Assertion.AssertEquals("Get returned incorrect value for given key", f, //$NON-NLS-1$
                                   enumColorMap.Get(Color.Green), 0.000001);
        }
Esempio n. 31
0
        /// <seealso cref="CountEditLogOpTypes(Sharpen.FilePath)"/>
        /// <exception cref="System.IO.IOException"/>
        public static EnumMap <FSEditLogOpCodes, Holder <int> > CountEditLogOpTypes(EditLogInputStream
                                                                                    elis)
        {
            EnumMap <FSEditLogOpCodes, Holder <int> > opCounts = new EnumMap <FSEditLogOpCodes, Holder
                                                                              <int> >(typeof(FSEditLogOpCodes));
            FSEditLogOp op;

            while ((op = elis.ReadOp()) != null)
            {
                Holder <int> i = opCounts[op.opCode];
                if (i == null)
                {
                    i = new Holder <int>(0);
                    opCounts[op.opCode] = i;
                }
                i.held++;
            }
            return(opCounts);
        }
Esempio n. 32
0
            private string GetStorageAllocationAsString()
            {
                IDictionary <StorageType, int> storageType_countmap = new EnumMap <StorageType, int
                                                                                   >(typeof(StorageType));

                foreach (StorageType storageType in storageTypes)
                {
                    int count = storageType_countmap[storageType];
                    if (count == null)
                    {
                        storageType_countmap[storageType] = 1;
                    }
                    else
                    {
                        storageType_countmap[storageType] = count + 1;
                    }
                }
                return(GetStorageAllocationAsString(storageType_countmap));
            }
Esempio n. 33
0
        // 由于C#中没有static indexer的概念,所以在这里我们用静态方法
        public static string GetStringFromEnum(Enum item)
        {
            if (maps == null)
            {
                maps = new Dictionary<Type, EnumMap>();
            }

            Type enumType = item.GetType();

            EnumMap mapper = null;
            if (maps.ContainsKey(enumType))
            {
                mapper = maps[enumType];
            }
            else
            {
                mapper = new EnumMap(enumType);
                maps.Add(enumType, mapper);
            }
            return mapper[item];
        }
Esempio n. 34
0
 static UNITYShaderTokenProvider()
 {
     map = new EnumMap<ShaderToken>();
     map.Load("UNITYKeywords.map");
 }
 static MAsmHighlighterTokenProvider()
 {
     map = new EnumMap<AsmHighlighterToken>();
     map.Load("MASMKeywords.map");
 }
Esempio n. 36
0
 static HLSLShaderTokenProvider()
 {
     map = new EnumMap<ShaderToken>();
     map.Load("HLSLKeywords.map");
 }
 static ParadoxShaderTokenProvider()
 {
     map = new EnumMap<ShaderToken>();
     map.Load("ParadoxShaderKeywords.map");
 }
 static XenkoShaderTokenProvider()
 {
     map = new EnumMap<ShaderToken>();
     map.Load("XenkoShaderKeywords.map");
 }
Esempio n. 39
0
 public EnumMapExample(EnumMap<Number, String> numbers) {
    this.numbers = numbers;
 }