ucx/cx/collection.h

changeset 471
063a9f29098c
parent 440
7c4b9cba09ca
equal deleted inserted replaced
470:118e2386d5b4 471:063a9f29098c
90 /** 90 /**
91 * Indicates if this list is supposed to store pointers 91 * Indicates if this list is supposed to store pointers
92 * instead of copies of the actual objects. 92 * instead of copies of the actual objects.
93 */ 93 */
94 bool store_pointer; 94 bool store_pointer;
95 /**
96 * Indicates if this collection is guaranteed to be sorted.
97 * Note that the elements can still be sorted, even when the collection is not aware of that.
98 */
99 bool sorted;
95 }; 100 };
96 101
97 /** 102 /**
98 * Use this macro to declare common members for a collection structure. 103 * Use this macro to declare common members for a collection structure.
99 * 104 *
106 * @endcode 111 * @endcode
107 */ 112 */
108 #define CX_COLLECTION_BASE struct cx_collection_s collection 113 #define CX_COLLECTION_BASE struct cx_collection_s collection
109 114
110 /** 115 /**
116 * Returns the number of elements currently stored.
117 *
118 * @param c a pointer to a struct that contains #CX_COLLECTION_BASE
119 * @return (@c size_t) the number of currently stored elements
120 */
121 #define cxCollectionSize(c) ((c)->collection.size)
122
123 /**
124 * Returns the size of one element.
125 *
126 * If #cxCollectionStoresPointers() returns true, this is the size of a pointer.
127 *
128 * @param c a pointer to a struct that contains #CX_COLLECTION_BASE
129 * @return (@c size_t) the size of one element in bytes
130 */
131 #define cxCollectionElementSize(c) ((c)->collection.elem_size)
132
133 /**
134 * Indicates whether this collection only stores pointers instead of the actual data.
135 *
136 * @param c a pointer to a struct that contains #CX_COLLECTION_BASE
137 * @retval true if this collection stores only pointers to data
138 * @retval false if this collection stores the actual element's data
139 */
140 #define cxCollectionStoresPointers(c) ((c)->collection.store_pointer)
141
142 /**
143 * Indicates whether the collection can guarantee that the stored elements are currently sorted.
144 *
145 * This may return false even when the elements are sorted.
146 * It is totally up to the implementation of the collection whether it keeps track of the order of its elements.
147 *
148 * @param c a pointer to a struct that contains #CX_COLLECTION_BASE
149 * @retval true if the elements are currently sorted wrt. the collection's compare function
150 * @retval false if the order of elements is unknown
151 */
152 #define cxCollectionSorted(c) ((c)->collection.sorted)
153
154 /**
111 * Sets a simple destructor function for this collection. 155 * Sets a simple destructor function for this collection.
112 * 156 *
113 * @param c a pointer to a struct that contains #CX_COLLECTION_BASE 157 * @param c a pointer to a struct that contains #CX_COLLECTION_BASE
114 * @param destr the destructor function 158 * @param destr the destructor function
115 */ 159 */

mercurial