comparison +mpm/PersistentState.m @ 38:16d56bf04117

Change place of storage of the state
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 05 Dec 2018 15:43:13 +0100
parents 29da718b8e7f
children
comparison
equal deleted inserted replaced
37:01e81c77bca1 38:16d56bf04117
1 classdef PersistentState < handle 1 classdef PersistentState < handle
2 properties 2 properties
3 filepath 3 prefGroup
4 subpaths 4 subpaths
5 end 5 end
6 6
7 methods 7 methods
8 function obj = PersistentState(filepath) 8 function obj = PersistentState(prefGroup)
9 obj.filepath = filepath; 9 obj.prefGroup = prefGroup;
10 10
11 try 11 try
12 % Read state from file 12 % Read state from file
13 s = load(filepath); 13 obj.subpaths = getpref(prefGroup, 'state');
14 obj.subpaths = s.subpaths;
15 catch 14 catch
16 % If reading the file failed, create an empty state 15 % If reading the file failed, create an empty state
17 obj.subpaths = containers.Map(); 16 obj.subpaths = containers.Map();
18 end 17 end
19 end 18 end
20 19
21 function s = saveState(obj) 20 function s = saveState(obj)
22 s = struct(); 21 setpref(obj.prefGroup, 'state', obj.subpaths);
23 s.subpaths = obj.subpaths;
24
25 save(obj.filepath, '-struct', 's');
26 end 22 end
27 end 23 end
28 end 24 end