-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaocontainer__define.pro
More file actions
89 lines (76 loc) · 2.48 KB
/
aocontainer__define.pro
File metadata and controls
89 lines (76 loc) · 2.48 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
;+
;
;-
function AOcontainer::Init
return, 1
end
pro AOcontainer::Add, object
IF (not PTR_VALID(self._array)) then begin
array = objarr(1)
array[0] = object
self._array = ptr_new(array, /no_copy)
endif else begin
vvv = arrinsert((*self._array), object)
PTR_FREE,self._array
self._array = ptr_new(vvv,/no_copy)
endelse
self._nelem = n_elements(*self._array)
end
; think carefully before implementing it!
;pro AOcontainer::Remove, index
; if not ptr_valid(self._array) then
;end
function AOcontainer::nelem
return, self->IDL_CONTAINER::Count()
end
;
; return {data, indexvalid}
;
function AOcontainer::cerca, cmd
apex = string(39B)
nel = n_elements(*self._array)
cmds = strsplit(cmd, '.', /extr)
isvalid = bytarr(nel)
for i=0, nel-1 do begin
; tmpobj = (*self._array)[i]
; for j=0, n_elements(cmds)-2 do begin
; hasmethod = obj_hasmethod(tmpobj, '$cmds[j]$')
; if (hasmethod) then tmpobj= tmpobj->$cmds[j]$()
; if not obj_valid(tmpobj) then break;
; endfor
; hasmethod = obj_hasmethod(tmpobj, '$cmds[j]$')
; if (hasmethod) then value = tmpobj->$cmds[j]$()
;
tmpobj = (*self._array)[i]
for j=0, n_elements(cmds)-2 do begin
r=execute('hasmethod = obj_hasmethod(tmpobj, '+apex+cmds[j]+apex+')')
r=execute('if (hasmethod) then tmpobj= tmpobj->'+cmds[j]+'()')
if not obj_valid(tmpobj) then break ;
endfor
if j eq n_elements(cmds)-1 then begin
r=execute('hasmethod = obj_hasmethod(tmpobj, '+apex+cmds[j]+apex+')')
r=execute('if (hasmethod) then begin & value = tmpobj->'+cmds[j]+'() & isvalid[i]=1 & endif')
if test_type(value, /obj_ref) eq 0 and obj_valid(value) eq 0 then isvalid[i]=0
endif
if isvalid[i] eq 1 then begin
if n_elements(v) eq 0 then begin ; first time value is valid
v = replicate(value,nel)
endif
v[i]=value
endif
endfor
if n_elements(v) eq 0 then return, {data:0, valid:-1}; if no valid values found, return null data
valid = where(isvalid eq 1)
return, {data:v[valid], valid:valid}
end
pro AOcontainer::Cleanup
heap_free, self._array
self->IDL_CONTAINER::Cleanup
end
pro AOcontainer__define
struct = { AOcontainer, $
_array : ptr_new(), $
_nelem : 0L, $
INHERITS IDL_CONTAINER $
}
end