function [memberValue] = getMember(pStructure, pMember, pDefaultValue)
%GETMEMBER Returns the given member in the structure if existent, the given default value otherwise.
%   Checks for the existence of the member by using artoa.data.hasMember.
%   If the value exists, it will be returned. Otherwise it will return the
%   default value.
%
%   Parameters:
%       pStructure (struct)   The structure where the member is stored in.
%       pMember (cell)        A 1D cell of chars, each entry representing the
%                             level of the structure.
%       pDefaultValue (mixed) The default value that is returned if the
%                             member does not exist.

%% Initialization
if nargin ~= 3
    pDefaultValue = '';
end

memberValue = pDefaultValue;

%% Return member if it exists
if ~artoa.data.hasMember(pStructure, pMember)
    return;
end

memberValue = pStructure;
for i = 1:length(pMember)
    memberValue = memberValue.(pMember{i});
end

end

