classdef CSDParameterValue < modelpack.ParameterValue
    %modelpack.CSDParameterValue class
    %   modelpack.CSDParameterValue extends modelpack.ParameterValue.
    %

%   Copyright 2023 The MathWorks, Inc.

    %    modelpack.CSDParameterValue properties:
    %       Description - Property is of type 'ustring'
    %       Name - Property is of type 'string'  (read only)
    %       Value - Property is of type 'MATLAB array'
    %       Format - Property is of type 'double'
    %
    %    modelpack.CSDParameterValue methods:
    %       copy -  method to make a copy of this object
    %       setName - Sets the name of the parameter.


    properties (SetObservable)
        %FORMAT Property is of type 'double'
        Format = 1;
    end


    methods  % constructor block
        function this = CSDParameterValue(parameterID)
            % CSDParameterValue  constructor for CSD parameter value object
            %
            % This constructor takes a parameter identifier object and an optional
            % subscripted name to create a PARAMETERVALUE object.
            %
            % h = modelpack.CSDParameterValue(parameterID);
            %
            % PARAMETERID a CSDParameterID object.

            % Create object

            % No argument constructor call.
            ni = nargin;
            if (ni == 0)
                return
            end

            % Set properties.
            this.Version = 1.0;
            this.setID(parameterID); %Sets the name property

        end  % CSDParameterValue

    end  % constructor block

    methods
        function set.Format(obj,value)
            % DataType = 'double'
            validateattributes(value,{'numeric'}, {'scalar'},'','Format')
            value = double(value); %  convert to double
            obj.Format = value;
        end

    end   % set and get functions

    methods  % public methods
        function newObj = copy(this)
            % COPY  method to make a copy of this object
            %

            for ct=numel(this):-1:1
                newObj(ct) = modelpack.CSDParameterValue;
                newObj(ct).ID                  = this(ct).ID;
                newObj(ct).Name                = this(ct).Name;
                newObj(ct).Dimension           = this(ct).Dimension;  %This must get copied before values are set
                newObj(ct).isDimensionEditable = this(ct).isDimensionEditable;
                newObj(ct).Format              = this(ct).Format;
                newObj(ct).Value               = this(ct).Value;
            end
        end  % copy

        function this = setName(this, name)
            % SETNAME Sets the name of the parameter.

            % Type checking
            if ~ischar(name)
                error(message('SLControllib:modelpack:InvalidStringArgument', ...
                    'NAME', 'setName' ));
            end

            if strcmp(this.getID.getName,name)
                this.Name = name;
            else
                error(message('SLControllib:modelpack:stErrorParameterSubsref'))
            end

            this.setDimensions(this.getID.getDimensions) %Also initializes property sizes

        end  % setName

    end  % public methods

end  % classdef

% LocalWords:  PARAMETERVALUE PARAMETERID
