Enhanced C#
Loyc library documentation
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Public Member Functions | Protected Member Functions | Protected fields | List of all members
Loyc.SymbolPool< SymbolE > Class Template Reference

This type of SymbolPool helps create more strongly typed Symbols that simulate enums, but provide extensibility. Specifically, it creates SymbolE objects, where SymbolE is some derived class of Symbol. More...


Source file:
Inheritance diagram for Loyc.SymbolPool< SymbolE >:
Loyc.SymbolPool

Remarks

This type of SymbolPool helps create more strongly typed Symbols that simulate enums, but provide extensibility. Specifically, it creates SymbolE objects, where SymbolE is some derived class of Symbol.

Template Parameters
SymbolEA derived class of Symbol that owns the pool. See the example below.

public class ShapeType : Symbol { private ShapeType(Symbol prototype) : base(prototype) { } public static new readonly SymbolPool<ShapeType> Pool = new SymbolPool<ShapeType>(p => new ShapeType(p));

public static readonly ShapeType Circle = Pool.Get("Circle"); public static readonly ShapeType Rect = Pool.Get("Rect"); public static readonly ShapeType Line = Pool.Get("Line"); public static readonly ShapeType Polygon = Pool.Get("Polygon"); }

Type Constraints
SymbolE :Symbol 

Public Member Functions

delegate SymbolE SymbolFactory (Symbol prototype)
 
 SymbolPool (SymbolFactory factory)
 
 SymbolPool (SymbolFactory factory, int firstID)
 
new SymbolE Get (string name)
 
new SymbolE Get (UString name)
 
new SymbolE Get (UString name, int id)
 
new SymbolE GetIfExists (UString name)
 
new SymbolE GetById (int id)
 
new IEnumerator< SymbolE > GetEnumerator ()
 
- Public Member Functions inherited from Loyc.SymbolPool
 SymbolPool (int firstID)
 
Symbol Get (UString name)
 Gets a symbol from this pool, or creates it if it does not exist in this pool already. More...
 
Symbol Get (string?name)
 
Symbol Get (UString name, int id)
 Creates a Symbol in this pool with a specific ID, or verifies that the requested Name-Id pair is present in the pool. More...
 
Symbol GetIfExists (UString name)
 Gets a symbol from this pool, if the name exists already. More...
 
Symbol GetGlobalOrCreateHere (string name)
 Gets a symbol from the global pool, if it exists there already; otherwise, creates a Symbol in this pool. More...
 
Symbol GetById (int id)
 Gets a symbol by its ID, or null if there is no such symbol. More...
 
IEnumerator< SymbolGetEnumerator ()
 

Protected Member Functions

override Symbol NewSymbol (int id, string name)
 Factory method to create a new Symbol. More...
 
- Protected Member Functions inherited from Loyc.SymbolPool
virtual void Get (UString name, out Symbol?sym)
 Workaround for lack of covariant return types in C# More...
 
virtual void Get (UString name, int id, out Symbol sym)
 Workaround for lack of covariant return types in C# More...
 

Protected fields

SymbolFactory _factory
 
- Protected fields inherited from Loyc.SymbolPool
readonly int _poolId
 

Additional Inherited Members

- Public fields inherited from Loyc.SymbolPool
Symbol this[UString name] => Get(name)
 
- Properties inherited from Loyc.SymbolPool
bool UsesStrongReferences [get]
 
int TotalCount [get]
 Returns the number of Symbols created in this pool. More...
 
- Static Public Member Functions inherited from Loyc.SymbolPool
static SymbolPool new ()
 
static SymbolPool new (int firstID, bool useStrongRefs)
 
static SymbolPool new (int firstID, bool useStrongRefs, int poolId)
 Initializes a new Symbol pool. More...
 
- Protected static fields inherited from Loyc.SymbolPool
static int _nextPoolId = 1
 

Member Function Documentation

override Symbol Loyc.SymbolPool< SymbolE >.NewSymbol ( int  id,
string  name 
)
inlineprotectedvirtual

Factory method to create a new Symbol.

Reimplemented from Loyc.SymbolPool.