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
