1 //
2 // Copyright (c) 2010-2024 Antmicro
3 // Copyright (c) 2011-2015 Realtime Embedded
4 //
5 // This file is licensed under the MIT License.
6 // Full license text is available in 'licenses/MIT.txt'.
7 //
8 using Antmicro.Renode.Core.Structure;
9 using System.Collections.Generic;
10 using System.Linq;
11 
12 namespace Antmicro.Renode.Peripherals.Bus
13 {
14     public interface IBusRegistered<out T> : IRegistered<T, BusRangeRegistration> where T : IBusPeripheral
15     {
16     }
17 
18     public static class IRegisteredExtensions
19     {
20         public static IBusRegistered<TTo> Convert<TFrom, TTo>(this IBusRegistered<TFrom> conversionSource) where TTo : TFrom where TFrom : IBusPeripheral
21         {
22             return new BusRegistered<TTo>((TTo)conversionSource.Peripheral, new BusRangeRegistration(conversionSource.RegistrationPoint.Range,
23                                           conversionSource.RegistrationPoint.Offset, conversionSource.RegistrationPoint.Initiator));
24         }
25 
26         public static IEnumerable<IBusRegistered<TTo>> Convert<TFrom, TTo>(this IEnumerable<IBusRegistered<TFrom>> sourceCollection) where TTo : TFrom where TFrom : IBusPeripheral
27         {
28             return sourceCollection.Select(x => x.Convert<TFrom, TTo>());
29         }
30     }
31 }
32 
33