classdef PersistentState < handle
    properties
        prefGroup
        subpaths
    end

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

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

        function s = saveState(obj)
            setpref(obj.prefGroup, 'state', obj.subpaths);
        end
    end
end
