DeviceDependentGenerator extended to allow generation of enum dependent templates. Name suffix separate to its own attribute.

This commit is contained in:
mlemanczyk committed 2025-12-19 19:01:38 +01:00
1 parent a21ab3134e
commit d32eea0212
5 files changed
+375 -112

No files matched your search

@@ -3,7 +3,8 @@ using PerfectNumbers.Core.Gpu.Accelerators;
namespace PerfectNumbers.Core.Cpu;
[DeviceDependentTemplate(typeof(ComputationDevice), suffix: "Order")]
[DeviceDependentTemplate(typeof(ComputationDevice))]
[NameSuffix("Order")]
internal struct MersenneCpuDivisorScanSessionWithTemplate() : IMersenneNumberDivisorByDivisorTester.IDivisorScanSession
{
#if DEVICE_GPU || DEVICE_HYBRID
@@ -6,7 +6,8 @@ using PerfectNumbers.Core.Gpu.Accelerators;
namespace PerfectNumbers.Core.Cpu;
[DeviceDependentTemplate(typeof(ComputationDevice), suffix: "Order")]
[DeviceDependentTemplate(typeof(ComputationDevice))]
[NameSuffix("Order")]
public struct MersenneNumberDivisorByDivisorCpuTesterWithTemplate() : IMersenneNumberDivisorByDivisorTester
{
public BigInteger DivisorLimit;
@@ -5,13 +5,32 @@ namespace PerfectNumbers.Core;
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)]
public sealed class DeviceDependentTemplateAttribute : Attribute
{
public DeviceDependentTemplateAttribute(Type enumType, string? suffix = null)
public DeviceDependentTemplateAttribute(Type enumType)
{
EnumType = enumType ?? throw new ArgumentNullException(nameof(enumType));
Suffix = suffix;
}
public Type EnumType { get; }
}
public string? Suffix { get; }
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = true)]
public sealed class EnumDependentTemplateAttribute : Attribute
{
public EnumDependentTemplateAttribute(Type enumType)
{
EnumType = enumType ?? throw new ArgumentNullException(nameof(enumType));
}
public Type EnumType { get; }
}
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)]
public sealed class NameSuffixAttribute : Attribute
{
public NameSuffixAttribute(string suffix)
{
Suffix = suffix ?? throw new ArgumentNullException(nameof(suffix));
}
public string Suffix { get; }
}