%Metadata Collection of information about an array
%
%  The distributedutil.Metadata class stores 
%
%  This is a handle class so that it can be updated in-place on an array
%  that is input to an expression if extra information about it is
%  discovered.

% Copyright 2016-2022 The MathWorks, Inc.

classdef Metadata < handle
    
    properties (SetAccess=private)
        IsReal
        FillPattern
        Bandwidth
        Symmetry
        TableTemplate
        HasNaN
        HasInf
        IsDiagonallyDominant
        IsPermutedTriangular
        Nnz
    end
    
    methods 
        function obj = Metadata()
            % Create a new metadata object and initialize all fields to
            % "unknown"
            
            validator = @(x) ismember(x,{'NotTriangular','LowerTriangular','UpperTriangular','Diagonal','ZeroMatrix'});
            obj.FillPattern = distributedutil.GuardedValue(validator);
            
            validator = @(x) ismember(x,{'AllZero','NoSymmetry','Symmetric','SkewSymmetric', ...
                'Hermitian','SkewHermitian','HermitianSymmetric','SkewHermitianSymmetric'});
            obj.Symmetry = distributedutil.GuardedValue(validator);
            
            % Bandwidth is [lower upper] where lower and upper and
            % non-negative integer scalars.
            validator = @(x) isrow(x) && isnumeric(x) && numel(x)==2 && all(round(x)==x) && all(x>=0);
            obj.Bandwidth = distributedutil.GuardedValue(validator);
            
            validator = @(x) istable(x) || istimetable(x);
            obj.TableTemplate = distributedutil.GuardedValue(validator);
            
            % Scalar logical flags
            validator = @(x) islogical(x) && isscalar(x);
            obj.IsReal = distributedutil.GuardedValue(validator);
            obj.HasNaN = distributedutil.GuardedValue(validator);
            obj.HasInf = distributedutil.GuardedValue(validator);
            obj.IsDiagonallyDominant = distributedutil.GuardedValue(validator);
            obj.IsPermutedTriangular = distributedutil.GuardedValue(validator);
            
            % Scalar double flags
            validator = @(x) isa(x, 'double') && isscalar(x);
            obj.Nnz = distributedutil.GuardedValue(validator);
            
        end 
        
        function reset(obj)
            % Reset all meta-data to be unknown
            obj.IsReal.reset();
            obj.FillPattern.reset();
            obj.Bandwidth.reset();
            obj.Symmetry.reset();
            obj.TableTemplate.reset();
            obj.HasNaN.reset();
            obj.HasInf.reset();
            obj.IsDiagonallyDominant.reset();
            obj.Nnz.reset();
        end
    end
        
end % classdef
