-
Notifications
You must be signed in to change notification settings - Fork 5
/
GlobalState.m
50 lines (44 loc) · 1.54 KB
/
GlobalState.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
%% Global State
% Backup and restore the global variables.
classdef GlobalState < matlab.mixin.Copyable
properties (Access = private)
builder_id = 0;
entity_id = 0;
slice_id = 0;
event_id = 0;
rand_state;
end
methods
function this = GlobalState()
this.rand_state = rng;
end
function Save(this)
this.builder_id = EntityBuilder.getGlobalBuilderId();
this.entity_id = Entity.getGlobalEntityId();
this.slice_id = SliceEntity.getGlobalSliceId();
this.event_id = Event.getGlobalEventId();
this.rand_state = rng;
end
function Restore(this)
EntityBuilder.setGlobalBuilderId(this.builder_id);
Entity.setGlobalEntityId(this.entity_id);
SliceEntity.setGlobalSliceId(this.slice_id);
Event.setGlobalEventId(this.event_id);
rng(this.rand_state);
end
function Display(this)
for i=1:length(this)
fprintf('Builder ID: %d, Entity ID: %d, Event ID: %d, Slice ID: %d, Random Seed: %d.\n',...
this(i).builder_id, this(i).entity_id, this(i).event_id, this(i).slice_id, this(i).rand_state.Seed);
end
end
end
methods (Static)
function Initialize()
EntityBuilder.setGlobalBuilderId(0);
Entity.setGlobalEntityId(0);
SliceEntity.setGlobalSliceId(0);
Event.setGlobalEventId(0);
end
end
end