classdef BuildInfoString < RTW.BuildInfoClass & handle & matlab.mixin.SetGet
%RTW.BuildInfoString class
%   RTW.BuildInfoString extends RTW.BuildInfoClass.
%
%    RTW.BuildInfoString properties:
%       Settings - Property is of type 'handle'  
%       DisplayLabel - Property is of type 'ustring'  
%       Group - Property is of type 'ustring'  
%       Value - Property is of type 'ustring'  

%   Copyright 2017-2019 The MathWorks, Inc.


    properties (SetObservable)
        Value = '';
    end


    methods
        function h = BuildInfoString(varargin)
            
        %  when the object is read in from a mat file, this is called with no args to
        %  load the class
            if (nargin == 0)
                return;
            end
            
            %check the args to make sure they all conform to the expected format
            [args_ok,StartVal, Group, DisplayLabel,Settings] = locCheckArgs(varargin{:});
            if ~(args_ok)
                DAStudio.error('RTW:buildInfo:badMethodArguments',...
                               'RTW.BuildInfoString');
            end
            
            % Instantiate class
            % set the properties
            h.Value        = StartVal;
            h.Group        = Group;
            h.Settings     = Settings;
            h.DisplayLabel = DisplayLabel;
        end
    end

    methods
        function val = getPreferredProperties(h)
        %GETPREFERREDPROPERTIES - Returns the preferred properties for the DA Studio
        %Explorer
        % the base class has properties which should be in the
        % preferred properties list.  Since there is no way to call a
        % base class method from a derived class, call a surrogate
        % getPreferredProperties from the base class.
            base_props = h.getBaseBuildInfoClassProperties();
            additional_props = {'Value'};
            val = [base_props additional_props];
        end
        
        function val = isHierarchical(~)
        %ISHIERARCHICAL - returns true if this class has hierarchical child properties.
            val = false;
        end
    end
end

function [args_ok,StartVal,Group,DisplayLabel,Settings]= locCheckArgs(varargin)
    args_ok      = true;
    StartVal     = '';
    Group        = '';
    DisplayLabel = '';
    Settings     = [];

    % First arg is the starting value
    if (nargin >= 1)
        if ~ischar(varargin{1})
            args_ok = false;
            return;
        end
        StartVal = varargin{1};
    end

    % second arg is the group
    if (nargin >= 2)
        if ~ischar(varargin{2})
            args_ok = false;
            return;
        end
        Group = varargin{2};
    end

    % third arg is the display label for the viewer
    if (nargin >= 3)
        if ~ischar(varargin{3})
            args_ok = false;
            return;
        end
        DisplayLabel = varargin{3};
    end

    % final arg is a handle to a settings object, or [].
    if (nargin >= 4)
        if ~isempty(varargin{4}) && ~isa(varargin{4}, 'RTW.BuildInfoSettings')
            args_ok = false;
            return;
        end
        Settings = varargin{4};
    end
end
