Skip to content
Snippets Groups Projects
SCDclass_taskcontainer.m 2.89 KiB
Newer Older
classdef SCDclass_taskcontainer
    % This class is a container class
    % for tasks object, a task object is a 
    % generic object customizable for
    % specifying tasks at init and 
    % terminate phases
    
    properties                            
        numtasks            % number of configured tasks
        tasks               % tasks list
    end
    
    methods
        function obj = SCDclass_taskcontainer()
            % contructor, empty container
            obj.numtasks=0;                        
        end
        
        function obj = addtask(obj, task)
            % Adds a parameter object
            if obj.numtasks==0
                obj.tasks=task;
            else
                obj.tasks=[obj.tasks; task];
            end 
            obj.numtasks=obj.numtasks+1;
        end
        
        function obj = printtasks(obj)
            % prints the parameters object list
            if obj.numtasks>0
               for ii=1:obj.numtasks
                  obj.tasks(ii).printinfo();
               end
            end
        end
        
        function obj = exectasksoninit(obj, shot)
            % execs the init method of all configurted task
            if obj.numtasks>0
               for ii=1:obj.numtasks
                  obj.tasks(ii).init(shot);
               end
            end
        end
        
        function obj = exectasksonterm(obj, shot)
            % execs the term method of all configurted task
            if obj.numtasks>0
               for ii=1:obj.numtasks
                  obj.tasks(ii).term(shot);
               end
            end
        end        
        
        function obj = bindlasttask(obj, modelname, datadictionary)
            if obj.numtasks>0   
               obj.tasks(end)=obj.tasks(end).setmodelname(modelname);
               obj.tasks(end)=obj.tasks(end).setdatadictionary(datadictionary);
            end        
        end
        
            
        function obj = importtaskobjects(obj, source)
            % parameters import

            desttasktargets={};
            if obj.numtasks>0             
                for ii=1:obj.numtasks
                    desttasktargets{end+1}=obj.tasks(ii).getid;
                end
            end
                           
            numtaskstoimport = source.numtasks;
            taskstoimport = source.tasks;
            
            if numtaskstoimport>0
                for ii=1:numtaskstoimport
                    if ~ismember(taskstoimport(ii).getid, desttasktargets)
                        obj=obj.addtask(taskstoimport(ii));
                    else
                        warning('SCDclass_taskcontainer:importtaskobjects','A task object with target ''%s'' is already present in the dest. expcode, skipping!',taskstoimport(ii).getid);
                    end
                end
            end
                       
        end
        
               
                
    end
end