view m-toolbox/classes/+utils/@xml/getNumber.m @ 52:daf4eab1a51e database-connection-manager tip

Fix. Default password should be [] not an empty string
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 07 Dec 2011 17:29:47 +0100
parents f0afece42f48
children
line wrap: on
line source


function values = getNumber(node)
  
  shape = utils.xml.getShape(node);
  type  = utils.xml.getType(node);
  
  if any(shape==0)
    
    % Special case for an empty double.
    values = zeros(shape);
    
  else
    
    if  strcmp(type, 'double') || strncmp(type, 'uint', 4) || strncmp(type, 'int', 3) || ...
        strcmp(type, 'single') || strcmp(type, 'float') || strcmp(type, 'logical')
      
      % Get the values direct from the node content
      numberStr = utils.xml.mchar(node.getTextContent());
      if (numberStr(1) == '[')
        values = eval(numberStr);
      else
        values = sscanf(numberStr, '%g ');
      end
      
      % Cast to correct type
      if ~strcmp(type, 'double')
        values = cast(values, type);
      end
      
    elseif strcmp(type, 'doubleVector')
      
      % Get vector
      values = utils.xml.getVector(node);
      
    elseif strcmp(type, 'doubleMatrix')
      
      % Get matrix
      values = utils.xml.getMatrix(node);
      
    else
      
      error('### Unknown number type [%s]', type);
      
    end
    
    % Reshape the values
    values = reshape(values, shape);
    
  end
  
end