view +mpm/PersistentState.m @ 31:769d1d252a3c

Change name of todo.txt to notes.txt
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 18 Sep 2018 14:17:13 +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