forked from ImortisInglorian/fbrtLib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharray_clearobj.bas
56 lines (46 loc) · 1.34 KB
/
array_clearobj.bas
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
/' ERASE for static arrays of objects: re-init the elements '/
#include "fb.bi"
extern "C"
sub fb_hArrayCtorObj( array as FBARRAY ptr, ctor as FB_DEFCTOR, base_idx as size_t )
dim as size_t i, elements, element_len
dim as FBARRAYDIM ptr _dim
dim as ubyte ptr this_
if ( array->_ptr = NULL ) then
exit sub
end if
_dim = @array->dimTB(0)
elements = _dim->elements - base_idx
_dim += 1
for i = 1 to array->dimensions
elements *= _dim->elements
_dim += 1
next
/' call ctors '/
element_len = array->element_len
this_ = array->_ptr
while( elements > 0 )
/' !!!FIXME!!! check exceptions (only if rewritten in C++) '/
ctor( this_ )
this_ += element_len
elements -= 1
wend
end sub
function fb_ArrayClearObj FBCALL ( array as FBARRAY ptr, ctor as FB_DEFCTOR, dtor as FB_DEFCTOR, dofill as long ) as long /' dofill = legacy '/
/' destruct all objects in the array
(dtor can be NULL if there only is a ctor) '/
if ( dtor ) then
fb_ArrayDestructObj( array, dtor )
end if
if( dofill ) then
/' re-initialize (ctor can be NULL if there only is a dtor) '/
if( ctor ) then
/' if a ctor exists, it should handle the whole initialization '/
fb_hArrayCtorObj( array, ctor, 0 )
else
/' otherwise, just clear '/
fb_ArrayClear( array, 0 )
end if
end if
return fb_ErrorSetNum( FB_RTERROR_OK )
end function
end extern