csharpdeeb25a2 | 1 | namespace CascadeIDE.Cockpit.Composition.HostSurface; |
| 2 | |
| 3 | internal readonly record struct InstrumentPlacementContext( |
| 4 | string SurfaceId, |
| 5 | string SlotId, |
| 6 | string InstrumentId, |
| 7 | string SafetyLevel); |
| 8 | |
| 9 | internal interface IInstrumentPlacementSpecification |
| 10 | { |
| 11 | bool IsSatisfiedBy(in InstrumentPlacementContext context); |
| 12 | } |
| 13 | |
| 14 | internal sealed class AllowedSurfaceSpecification(params string[] allowedSurfaces) : IInstrumentPlacementSpecification |
| 15 | { |
| 16 | private readonly HashSet<string> _allowed = new(allowedSurfaces, StringComparer.OrdinalIgnoreCase); |
| 17 | |
| 18 | public bool IsSatisfiedBy(in InstrumentPlacementContext context) => _allowed.Contains(context.SurfaceId); |
| 19 | } |
| 20 | |
| 21 | internal sealed class AllowedSlotSpecification(params string[] allowedSlots) : IInstrumentPlacementSpecification |
| 22 | { |
| 23 | private readonly HashSet<string> _allowed = new(allowedSlots, StringComparer.OrdinalIgnoreCase); |
| 24 | |
| 25 | public bool IsSatisfiedBy(in InstrumentPlacementContext context) => _allowed.Contains(context.SlotId); |
| 26 | } |
| 27 | |
| 28 | internal sealed class AllowedSafetyLevelsSpecification(params string[] allowedSafetyLevels) : IInstrumentPlacementSpecification |
| 29 | { |
| 30 | private readonly HashSet<string> _allowed = new(allowedSafetyLevels, StringComparer.OrdinalIgnoreCase); |
| 31 | |
| 32 | public bool IsSatisfiedBy(in InstrumentPlacementContext context) => _allowed.Contains(context.SafetyLevel); |
| 33 | } |
| 34 | |
| 35 | internal sealed class AndInstrumentPlacementSpecification(params IInstrumentPlacementSpecification[] specifications) |
| 36 | : IInstrumentPlacementSpecification |
| 37 | { |
| 38 | public bool IsSatisfiedBy(in InstrumentPlacementContext context) |
| 39 | { |
| 40 | foreach (var specification in specifications) |
| 41 | { |
| 42 | if (!specification.IsSatisfiedBy(in context)) |
| 43 | return false; |
| 44 | } |
| 45 | |
| 46 | return true; |
| 47 | } |
| 48 | } |
| 49 | |
View only · write via MCP/CIDE