classdef (Hidden) TargetRepositoryProcessorParameterMap < RTW.TargetRepositoryParameterMap
%TARGETREPOSITORYPROCESSORPARAMETERMAP Provides a lazy execution conversion
%of targetrepository.physical.Microprocessor properties to the
%RTW.HWDeviceRegistry parameter values.

% Copyright 2018-2022 The MathWorks, Inc.

properties (SetAccess=protected)
BitPerChar;
BitPerShort;
BitPerInt;
BitPerLong;
BitPerLongLong;
WordSize;
Endianess;
IntDivRoundTo;
LargestAtomicInteger;
LargestAtomicFloat;
ShiftRightIntArith;
LongLongMode;
BitPerFloat;
BitPerDouble;
BitPerPointer;
BitPerSizeT;
BitPerPtrDiffT;
Visible;
Enabled;
end

properties (Access=private)
Implementation target.internal.LanguageImplementation;
end

methods
function this = TargetRepositoryProcessorParameterMap(processor)

this.Object = processor;
h = shared.hardware_configset.HardwareImplementation(targetrepository.create);
this.Implementation = h.getImplementation(this.Object);
end

function value = get.BitPerChar(this)
value = double(this.Implementation.DataTypes.Char.Size);
end

function value = get.BitPerShort(this)
value = double(this.Implementation.DataTypes.Short.Size);
end

function value = get.BitPerInt(this)
value = double(this.Implementation.DataTypes.Int.Size);
end

function value = get.BitPerLong(this)
value = double(this.Implementation.DataTypes.Long.Size);
end

function value = get.BitPerLongLong(this)

longlong = this.Implementation.DataTypes.LongLong;
if longlong.IsSupported
value = double(longlong.Size);
else
value = 64;
end
end

function value = get.BitPerFloat(this)
value = double(this.Implementation.DataTypes.Float.Size);
end

function value = get.BitPerDouble(this)
value = double(this.Implementation.DataTypes.Double.Size);
end

function value = get.BitPerPointer(this)
value = double(this.Implementation.DataTypes.Pointer.Size);
end

function value = get.BitPerSizeT(this)
value = double(this.Implementation.DataTypes.SizeT.Size);
end

function value = get.BitPerPtrDiffT(this)
value = double(this.Implementation.DataTypes.PtrDiffT.Size);
end

function value = get.WordSize(this)
value = double(this.Implementation.WordSize);
end

function value = get.LongLongMode(this)
value = this.Implementation.DataTypes.LongLong.IsSupported;
end

function value = get.Endianess(this)

switch char(this.Implementation.Endianess)
case 'Little'
value = 'LittleEndian';
case 'Big'
value = 'BigEndian';
otherwise
value = 'Unspecified';
end
end

function value = get.IntDivRoundTo(this)
value = char(this.Implementation.IntegerDivisionRounding);
end

function value = get.LargestAtomicInteger(this)

datatypes = this.Implementation.DataTypes;

if datatypes.LongLong.IsSupported && datatypes.LongLong.IsAtomic
value = 'LongLong';
elseif datatypes.Long.IsAtomic
value = 'Long';
elseif datatypes.Int.IsAtomic
value = 'Int';
elseif datatypes.Short.IsAtomic
value = 'Short';
else
value = 'Char';
end
end

function value = get.LargestAtomicFloat(this)

datatypes = this.Implementation.DataTypes;

if datatypes.Double.IsAtomic
value = 'Double';
elseif datatypes.Float.IsAtomic
value = 'Float';
else
value = 'None';
end
end

function value = get.ShiftRightIntArith(this)

value = this.Implementation.ArithmeticSignedIntegerRightShift;
end

function value = get.Visible(this)

params = RTW.HWProp.getHardwareParams();
value = false(size(params));
for i = 1:length(params)
param = params{i};
value(i) = this.Implementation.getIsVisible(param);
end
end

function value = get.Enabled(this)

params = RTW.HWProp.getHardwareParams();
value = false(size(params));
for i = 1:length(params)
param = params{i};
value(i) = this.Implementation.getIsEnabled(param);
end
end
end
end