Esempio n. 1
0
 static GSymbol()
 {
     Pool  = new SymbolPool(0, false, 0);
     Empty = Pool.Get("");
     Debug.Assert(Empty.Id == 0 && Empty.Name == "");
     Debug.Assert(((Symbol)Empty).Pool == Pool);
 }
Esempio n. 2
0
        public void TestPrivatePools()
        {
            SymbolPool p1  = new SymbolPool();
            SymbolPool p2  = new SymbolPool(3);
            SymbolPool p3  = new SymbolPool(0);
            Symbol     a   = GSymbol.Get("a");
            Symbol     b   = GSymbol.Get("b");
            Symbol     c   = GSymbol.Get("c");
            Symbol     s1a = p1.Get("a");
            Symbol     s1b = p1.Get("b");
            Symbol     s1c = p1.Get("c");
            Symbol     s2a = p2.Get("a");
            Symbol     s3a = p3.Get("a");
            Symbol     s3b = p3.Get("b");

            Assert.That(s1a.Id == 1 && p1.GetById(1) == s1a);
            Assert.That(s1b.Id == 2 && p1.GetById(2) == s1b);
            Assert.That(s1c.Id == 3 && p1.GetById(3) == s1c);
            Assert.That(s2a.Id == 3 && p2.GetById(3) == s2a);
            Assert.That(s3b.Id == 1 && p3.GetById(1) == s3b);
            Assert.That(s3a.Id == 0 && p3.GetById(0) == s3a);
            Assert.AreEqual(GSymbol.Empty, p1.GetById(0));
            Assert.AreEqual(s1c, p1.GetIfExists("c"));
            Assert.AreEqual(3, p1.TotalCount);
            Assert.AreEqual(null, p2.GetIfExists("c"));
            Assert.AreEqual(c, p2.GetGlobalOrCreateHere("c"));
            Assert.AreEqual(p2, p2.GetGlobalOrCreateHere("$!unique^&*").Pool);
        }
Esempio n. 3
0
 /// <summary>For use by a derived class to produce a statically-typed
 /// enumeration in a private pool. See the example under SymbolPool
 /// (of SymbolEnum)</summary>
 /// <param name="prototype">A strictly temporary Symbol that is used
 /// to initialize this object. The derived class should discard the
 /// prototype after calling this constructor.</param>
 protected Symbol(Symbol prototype)
 {
     _id   = prototype._id;
     _name = prototype._name;
     _pool = prototype._pool;
 }
Esempio n. 4
0
 /// <summary>For internal use only. Call GSymbol.Get() instead!</summary>
 internal Symbol(int id, string name, SymbolPool pool)
 {
     _id = id; _name = name; _pool = pool;
 }