classdef ConfigSetLock < handle
    %SLDVCONFIGSETLOCK Locks the configuration set.
    % Unlocks the configuration set when the object is deleted
    % Usage:
    % Assign a new object of this class to a variable. This will lock
    % the configuration set of a model. When the variable goes out of
    % scope, the object will be deleted and the configuration set unlocked.
    % Explicitly clearing the variable will also unlock the configuration
    % set.
    % NOTE: 
    % The variable containing this class should not be copied or returned
    % from a function, as the lifetime of the object will then be extended
    % and it will become difficult to predict the point when the
    % configuration set has to be unlocked.
    % 

    % Copyright 2014-2020 The MathWorks, Inc.
    
    properties
        mModelH = []
        mConfigSet = []
    end
    
    methods
        function obj = ConfigSetLock(modelH)
            obj.mModelH = modelH;
            [~,obj.mConfigSet] = sldvprivate('configcomp_get',modelH);
            obj.mConfigSet.lock;
        end
        
        function delete(obj)
            obj.mConfigSet.unlock;
        end
    end
    
end

