-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaolist__define.pro
More file actions
73 lines (64 loc) · 1.71 KB
/
aolist__define.pro
File metadata and controls
73 lines (64 loc) · 1.71 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
;+
;
; A list of heap variables (including reference to object)
;
; NOTES
; IDL8.0 introduced the object list that make this one obsolete...
;
;-
function aolist::Init
self._nelems = 0
return,1
end
function aolist::count
return, self._nelems
end
function aolist::Get, pos=pos, all=all
if self->count() eq 0 then return, obj_new()
if n_elements(pos) ne 0 then begin
if max(pos) ge self->count() then begin
message, 'AOLIST::Get: Index is out of range', /info
return, obj_new()
endif
return, (*self._values)[pos]
endif
return, *self._values
end
pro aolist::Add, value
if self->count() gt 0 then begin
values = self->Get()
ptr_free, self._values
self._values = ptr_new( [values, value], /no_copy)
endif else begin
self._values = ptr_new([value], /no_copy)
endelse
self._nelems += 1
end
function aolist::Remove, idx
vals = self->Get()
nobj = self->count()
if idx ge nobj then message, 'AOLIST::REMOVE: Index is out of range', /info
res = vals[idx]
ptr_free, self._values
case idx of
0: newvals = vals[1:*]
nobj-1: newvals = vals[0:nobj-2]
else: newvals = [ vals[0:idx-1], vals[idx+1:*] ]
endcase
self._values = ptr_new( newvals, /no_copy)
; decrement counter
self._nelems -= 1
return, res
end
pro aolist::Cleanup
ptr_free, self._values
end
pro aolist__define
struct = { aolist, $
_values : ptr_new() , $
_values_type : "", $
_nelems : 0L, $
_allocated_size : 0L $
;_multiple : 0B $
}
end