classdef CodedItem < handle & matlab.mixin.Heterogeneous
    
    properties
        filename
        filesize
        mColl % metrics collection
        hReference % handle to ReferenceItem
        coderparams
        metrics
        score
        ismetricsvalid
    end
    
    methods (Abstract)
        show(obj)
    end
    
    methods
        % public
        function obj=CodedItem(filename,coderparams,referenceitem)
            % checking if file exists ? only meaningful after coding
            % finished
            obj.filename=filename;
            obj.coderparams=coderparams;
            obj.hReference=referenceitem;
            fl=dir(filename);
            if isempty(fl)
                error('File does not yet exist');
            end
            obj.filesize=fl.bytes;
            obj.ismetricsvalid=0;
            obj.score=0;
        end
        
        function setscore(obj,score)
            obj.score=score;
        end
        
        function score=getscore(obj)
            score=obj.score;
        end
        
        function addmetrics(obj,mcoll)
             obj.mColl=mcoll;
        end
        
        function metrics=getmetrics(obj)
            if obj.ismetricsvalid
                metrics=obj.metrics;
            else
                obj.calcmetrics;
                metrics=obj.metrics;
            end
        end
        
        function calcmetrics(obj)
            obj.metrics=obj.mColl.calc(obj.hReference,obj);
            obj.ismetricsvalid=1;
        end
        
        function p=getcoderparams(obj)
            p=obj.coderparams;
        end
        
        function n=getfilename(obj)
            n=obj.filename;
        end
        
        function s=getfilesize(obj)
            s=obj.filesize;
        end
        
        function m=getmetricscollection(obj)
            m=obj.mColl;
        end
        
        function hr=getreference(obj)
            hr=obj.hReference;
        end
        
        
        
    end
end