classdef CoderItem < handle & matlab.mixin.Heterogeneous
    
    properties
        params
    end
    
    methods (Abstract)
        procItem(obj,item)
    end
    
    
    methods
        % public
        function obj=CoderItem(inputparams)
            obj.params=inputparams;
        end
        
        function cicoll=proc(obj,item)
            
            if isa(item,'ReferenceItem')
                cicoll=obj.procItem(obj,item);
            elseif isa(item,'ReferenceCollection')
                cicoll=obj.procColl(obj,item);
            else
                error('Unvalid object type');
            end
        end
        
        % private
        
        
        function ci=procColl(obj,coll)
            nRef=coll.getnumref;
            %            ci=CodedItemCollection;
            for iRef=1:nRef,
                if iRef==1
                    ci=obj.procItem(coll.getelem(iRef));
                else
                    ci=ci+obj.procItem(coll.getelem(iRef));
                end
            end
        end
        
    end
    
end
