-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathpopfrombuffer.m
52 lines (47 loc) · 1.01 KB
/
popfrombuffer.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
50
51
52
function v = popfrombuffer(f)
%V = POPFROMBUFFER(F). Where F is the field to pop from. When buffer is
%empty an empty value is returned.
%
%See also CLEARBUFFER, PUSHTOBUFFER.
%Einar Heiberg
global DATA
try
buffer = DATA.Buffer.(f);
isacell = iscell(buffer);
if isempty(buffer)
if isacell
v = {}; %Empty => return empty
else
v = [];
end;
else
if isacell
v = buffer{1}; %Return first element
else
v = buffer(1); %Return first element
end;
%Update stored buffer
if isacell
%Cell buffers
if length(buffer)>1
if length(buffer)==2
buffer = buffer(2);
else
buffer = buffer(2:end);
end
else
buffer = {};
end;
else
%vector buffers
buffer = buffer(2:end);
if isempty(buffer)
buffer = []; %make is nice format
end;
end;
%Store it.
DATA.Buffer.(f) = buffer;
end;
catch
v = [];
end;