Mercurial > repos > public > matlab_path_manager
changeset 22:29da718b8e7f
Add class for managing state file
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 18 Sep 2018 11:41:39 +0200 |
parents | 02c290e2018c |
children | 0b4be0d4e207 |
files | +mpm/PersistentState.m |
diffstat | 1 files changed, 28 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/+mpm/PersistentState.m Tue Sep 18 11:41:39 2018 +0200 @@ -0,0 +1,28 @@ +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