classdef UserInfo < dynamicprops 
% compiler.UserInfo Get details of logged-in user
%
%	compiler.UserInfo() returns the details of a user 
%   logged-in to the machine running a desktop version of MATLAB®, 
%   or details of a user logged-in to MATLAB Web App Server™, as a 
%   compiler.UserInfo object.
%
%	USER = compiler.UserInfo() 
%     returns a compiler.UserInfo object.
%
%   INPUT ARGUMENTS:
%	None.
%
%   OUTPUT ARGUMENTS:
%
%	- USER (A scalar compiler.UserInfo object)
%        A data object describing the logged-in user's details.
%
%	The property names UserID, DisplayName, and Groups are fixed 
%	and returned always. 
%
%	On Windows, if running the command from the MATLAB desktop, 
%   the property name Domain is displayed with a corresponding property 
%   value.
%
%	On Linux, if running the command from the MATLAB desktop, 
%   the property name Group is displayed with a corresponding property 
%   value.
%
%   If the command is run to query MATLAB Web App Server, additional 
%   property names configured in the userinfo.json file on the server 
%   are returned along with corresponding property values.
%
%	EXAMPLES:
%
%	% Retrieve details of user logged-in to machine running MATLAB 
%	user = compiler.UserInfo()

%   Copyright 2021 The MathWorks, Inc.

    properties(Constant, Access = private)
        NativeUserInfo = compiler.internal.userinfo.userInfo
    end

    methods
        function obj = UserInfo
            if numel(properties(obj)) == 0
                props = properties(obj.NativeUserInfo);
                for n = 1:numel(props)
                    P = addprop(obj,props{n});
                    P.SetAccess = 'private';
                    obj.(props{n}) = obj.NativeUserInfo.(props{n});
                end
            end
        end
    end
end
