function rc = getMappedDrives(varargin)
% GETMAPPEDDRIVES This is a Windows only function which returns a
% struct with 4 vectors, one for the drive letter, and a second for
% the UNC path the drive is mapped to, and a third with the full name
% of the map, which is usually the same as the map, and a fourth
% vector with the alternate version of the path the drive is mapped
% to.  If called from a non Windows platform, [] is returned.
%
%   RTW.getMappedDrives(...)
%
% Argument         description
% 'reset'          this is an optional argument which will cause the internal
%                  cache of the mapped drives to be cleared, then re-calculated.
%                  This argument should only be used once after a drive has
%                  been mapped or unmapped. Other calls should rely on the
%                  cache for better performance.

%   Copyright 2008-2017 The MathWorks, Inc.


    persistent driveMap;
    rc = [];
    
    if ~ispc
        return;
    end

    % check for a reset arg
    if ((nargin > 0) && strcmp(varargin{1},'reset'))
        driveMap = [];
    end
    
    % if driveMap is empty, call the mex file to get the information
    if isempty(driveMap)
        driveLetters = {'A:'; 'B:'; 'C:'; 'D:'; 'E:';...
                        'F:'; 'G:'; 'H:'; 'I:'; 'J:';...
                        'K:'; 'L:'; 'M:'; 'N:'; 'O:';...
                        'P:'; 'Q:'; 'R:'; 'S:'; 'T:';...
                        'U:'; 'V:'; 'W:'; 'X:'; 'Y:';...
                        'Z:'};
        
        driveMaps = getDriveMappings();
        
        % reduce the list to only the mapped drives.  If the mapping is empty,
        % then it is either a local drive or has not been mapped.
        emptyIdx         = cellfun(@isempty,driveMaps);
        driveMap.drives  = driveLetters(~emptyIdx);
        driveMaps        = driveMaps(~emptyIdx);
        driveMap.maps    = getPathName(driveMaps,false,true);
        driveMap.altMaps = getPathName(driveMaps,true,true);      
    end
    
    
    rc = driveMap;
