docs/Writerside/topics/collection.h.md

changeset 1605
55b13f583356
parent 1464
9a10af83cfab
equal deleted inserted replaced
1604:68b75c091028 1605:55b13f583356
42 cxCollectionSorted(c) 42 cxCollectionSorted(c)
43 ``` 43 ```
44 44
45 In each case the argument `c` is a pointer to your collection. The macro will then access the base data with `c->collection`. 45 In each case the argument `c` is a pointer to your collection. The macro will then access the base data with `c->collection`.
46 46
47 Similar to the above macros, the `cxCollectionCompareFunc(c,f)` macro can be used to set the compare function. 47 On the other hand, the following macros can be used to set the properties of a collection:
48
49 ```C
50 cxSetCompareFunc(c, func)
51 cxSetDestructor(c, destr)
52 cxSetAdvancedDestructor(c, destr, data)
53 ```
54
55 More details on the destructor functions follow in the next section.
48 56
49 ## Destructor Functions 57 ## Destructor Functions
50 58
51 For working with destructors, the following macros are defined: 59 For working with destructors, the following macros are defined:
52 60
53 ```C 61 ```C
54 cxDefineDestructor(c, destr) 62 cxSetDestructor(c, destr)
55 cxDefineAdvancedDestructor(c, destr, data) 63 cxSetAdvancedDestructor(c, destr, data)
56 64
57 // use in your collection's implementation 65 // use in your collection's implementation
58 cx_invoke_destructor(c, elem) 66 cx_invoke_destructor(c, elem)
59 67
60 // the following two should not be used 68 // the following two should not be used
61 cx_invoke_simple_destructor(c, elem) 69 cx_invoke_simple_destructor(c, elem)
62 cx_invoke_advanced_destructor(c, elem) 70 cx_invoke_advanced_destructor(c, elem)
63 ``` 71 ```
64 72
65 With `cxDefineDestructor()` you can assign a simple [destructor function](allocator.h.md#destructor-functions) 73 With `cxSetDestructor()` you can assign a simple [destructor function](allocator.h.md#destructor-functions)
66 to an _instance_ of your collection. 74 to an _instance_ of your collection.
67 Similarly, you can assign an advanced destructor with custom `data` by using `cxDefineAdvancedDestructor`. 75 Similarly, you can assign an advanced destructor with custom `data` by using `cxSetAdvancedDestructor`.
68 76
69 Your collection _should_ be supporting destructors by invoking `cx_invoke_destructor()` whenever an element 77 Your collection _should_ be supporting destructors by invoking `cx_invoke_destructor()` whenever an element
70 is removed from your collection _without_ being returned to the caller. 78 is removed from your collection _without_ being returned to the caller.
71 This macro will invoke a simple destructor, if one is assigned, first, and then the advanced destructor (again, if assigned). 79 This macro will invoke a simple destructor, if one is assigned, first, and then the advanced destructor (again, if assigned).
72 80

mercurial