view +mpm/PersistentState.m @ 28:0842a1b2ac7e

Factor out function for checking if a subpath is active
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 18 Sep 2018 13:18:02 +0200
parents 29da718b8e7f
children 16d56bf04117
line wrap: on
line source

classdef PersistentState < handle
    properties
        filepath
        subpaths
    end

    methods
        function obj = PersistentState(filepath)
            obj.filepath = filepath;

            try
                % Read state from file
                s = load(filepath);
                obj.subpaths = s.subpaths;
            catch
                % If reading the file failed, create an empty state
                obj.subpaths = containers.Map();
            end
        end

        function s = saveState(obj)
            s = struct();
            s.subpaths = obj.subpaths;

            save(obj.filepath, '-struct', 's');
        end
    end
end