gate sub-categories

This commit is contained in:
klemek
2020-12-18 19:09:42 +01:00
parent 7208a9ebad
commit 63e8f2c5f6
30 changed files with 999 additions and 258 deletions
@@ -8,9 +8,18 @@ namespace UntitledLogicGame.Workspace.Gates
{
// Static properties
private static Dictionary<GateType, GateDefinition> Definitions;
public static Dictionary<GateCategory, List<GateType>> TypeCategoryList =>
Enum.GetValues(typeof(GateCategory)).Cast<GateCategory>()
.ToDictionary(
c => c,
c => Enum.GetValues(typeof(GateType)).Cast<GateType>()
.Where(t => (GateCategory)((int)t / 100) == c).ToList()
);
// Public properties
public string Name { get; internal set; }
public GateType Type { get; private set; }
public GateCategory Category => (GateCategory)((int)Type / 100);
public string Name => Type.ToString();
public bool HasState => false;
public Dictionary<InputState, OutputState> TruthTable { get; private set; } = new Dictionary<InputState, OutputState>();
@@ -27,9 +36,9 @@ namespace UntitledLogicGame.Workspace.Gates
Definitions = new Dictionary<GateType, GateDefinition>();
foreach (var gateType in Enum.GetValues(typeof(GateType)).Cast<GateType>())
{
var t = Type.GetType($"{typeof(GateDefinition).Namespace}.{gateType}Gate", true);
var t = System.Type.GetType($"{typeof(GateDefinition).Namespace}.{gateType}Gate", true);
Definitions[gateType] = (GateDefinition)t.GetConstructor(new Type[0]).Invoke(new object[0]);
Definitions[gateType].Name = gateType.ToString();
Definitions[gateType].Type = gateType;
}
}
+16 -3
View File
@@ -3,8 +3,8 @@
public enum GateType
{
// 000 - Technical
NONE = 000,
// 100 - Special
None = 000,
// 100 - I/O
IN = 100,
OUT = 110,
// 200 - Basic
@@ -28,7 +28,7 @@
// 500 - Arithmetic
HalfAdd = 500,
FullAdd = 510,
HalSub = 520,
HalfSub = 520,
FullSub = 530,
// 600 - Data
Mux = 610,
@@ -45,4 +45,17 @@
Counter2b = 800,
Counter4b = 810
}
public enum GateCategory
{
None = 00,
IO = 01,
Basic = 02,
Latches = 03,
FlipFlops = 04,
Arithmetic = 05,
Data = 06,
Registers = 07,
Counters = 08
}
}