Mercurial > repos > public > matlab_path_manager
comparison +mpm/PersistentState.m @ 22:29da718b8e7f
Add class for managing state file
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 18 Sep 2018 11:41:39 +0200 |
parents | |
children | 16d56bf04117 |
comparison
equal
deleted
inserted
replaced
21:02c290e2018c | 22:29da718b8e7f |
---|---|
1 classdef PersistentState < handle | |
2 properties | |
3 filepath | |
4 subpaths | |
5 end | |
6 | |
7 methods | |
8 function obj = PersistentState(filepath) | |
9 obj.filepath = filepath; | |
10 | |
11 try | |
12 % Read state from file | |
13 s = load(filepath); | |
14 obj.subpaths = s.subpaths; | |
15 catch | |
16 % If reading the file failed, create an empty state | |
17 obj.subpaths = containers.Map(); | |
18 end | |
19 end | |
20 | |
21 function s = saveState(obj) | |
22 s = struct(); | |
23 s.subpaths = obj.subpaths; | |
24 | |
25 save(obj.filepath, '-struct', 's'); | |
26 end | |
27 end | |
28 end |