3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 - 2014 Christian Schoenebeck * |
* Copyright (C) 2005 - 2016 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
207 |
return !(current && current->data); |
return !(current && current->data); |
208 |
} |
} |
209 |
|
|
210 |
|
/** |
211 |
|
* Moves the element pointed by this Iterator from its current |
212 |
|
* list to the beginning of the destination list @a pDstList. |
213 |
|
* |
214 |
|
* @b CAUTION: When this method returns, this Iterator does |
215 |
|
* @b NOT point to the element on the new list anymore, instead it |
216 |
|
* points at a completely different element! In case of a |
217 |
|
* forward Iterator this Iterator object will point to the |
218 |
|
* previous element on the source list, in case of a backward |
219 |
|
* Iterator it will point to the subsequent element on the |
220 |
|
* source list. This behavior is enforced to avoid breaking an |
221 |
|
* active loop code working with this Iterator object. |
222 |
|
* |
223 |
|
* Thus if you intend to continue working with the same element, |
224 |
|
* you should do like this: |
225 |
|
* @code |
226 |
|
* it = it.moveToEndOf(anotherList); |
227 |
|
* @endcode |
228 |
|
* |
229 |
|
* @param pDstList - destination list |
230 |
|
* @returns Iterator object pointing at the moved element on |
231 |
|
* the destination list |
232 |
|
*/ |
233 |
inline _Iterator moveToEndOf(RTListBase<T1>* pDstList) { |
inline _Iterator moveToEndOf(RTListBase<T1>* pDstList) { |
234 |
detach(); |
detach(); |
235 |
pDstList->append(*this); |
pDstList->append(*this); |
238 |
return iterOnDstList; |
return iterOnDstList; |
239 |
} |
} |
240 |
|
|
241 |
|
/** |
242 |
|
* Moves the element pointed by this Iterator from its current |
243 |
|
* list to the end of destination list @a pDstList. |
244 |
|
* |
245 |
|
* @b CAUTION: When this method returns, this Iterator does |
246 |
|
* @b NOT point to the element on the new list anymore, instead it |
247 |
|
* points at a completely different element! In case of a |
248 |
|
* forward Iterator this Iterator object will point to the |
249 |
|
* previous element on the source list, in case of a backward |
250 |
|
* Iterator it will point to the subsequent element on the |
251 |
|
* source list. This behavior is enforced to avoid breaking an |
252 |
|
* active loop code working with this Iterator object. |
253 |
|
* |
254 |
|
* Thus if you intend to continue working with the same element, |
255 |
|
* you should do like this: |
256 |
|
* @code |
257 |
|
* it = it.moveToBeginOf(anotherList); |
258 |
|
* @endcode |
259 |
|
* |
260 |
|
* @param pDstList - destination list |
261 |
|
* @returns Iterator object pointing at the moved element on |
262 |
|
* the destination list |
263 |
|
*/ |
264 |
inline _Iterator moveToBeginOf(RTListBase<T1>* pDstList) { |
inline _Iterator moveToBeginOf(RTListBase<T1>* pDstList) { |
265 |
detach(); |
detach(); |
266 |
pDstList->prepend(*this); |
pDstList->prepend(*this); |
269 |
return iterOnDstList; |
return iterOnDstList; |
270 |
} |
} |
271 |
|
|
272 |
|
/** |
273 |
|
* Moves the element pointed by this Iterator from its current |
274 |
|
* position to the position right before @a itDst. That move |
275 |
|
* may either be from and to the same list, or to a another |
276 |
|
* list. |
277 |
|
* |
278 |
|
* @b CAUTION: When this method returns, this Iterator does |
279 |
|
* @b NOT point to the element on the new list anymore, instead it |
280 |
|
* points at a completely different element! In case of a |
281 |
|
* forward Iterator this Iterator object will point to the |
282 |
|
* previous element on the source list, in case of a backward |
283 |
|
* Iterator it will point to the subsequent element on the |
284 |
|
* source list. This behavior is enforced to avoid breaking an |
285 |
|
* active loop code working with this Iterator object. |
286 |
|
* |
287 |
|
* Thus if you intend to continue working with the same element, |
288 |
|
* you should do like this: |
289 |
|
* @code |
290 |
|
* itSourceElement = itSourceElement.moveBefore(itDestinationElement); |
291 |
|
* @endcode |
292 |
|
* |
293 |
|
* @param itDst - destination element to be inserted before |
294 |
|
* @returns Iterator object pointing at the moved element on |
295 |
|
* the destination list |
296 |
|
*/ |
297 |
|
inline _Iterator moveBefore(_Iterator<T1> itDst) { |
298 |
|
detach(); |
299 |
|
RTList<T1>::prependBefore(*this, itDst); |
300 |
|
_Iterator iterOnDstList = _Iterator(current); |
301 |
|
current = fallback; |
302 |
|
return iterOnDstList; |
303 |
|
} |
304 |
|
|
305 |
|
/** |
306 |
|
* Moves the element pointed by this Iterator from its current |
307 |
|
* position to the position right after @a itDst. That move |
308 |
|
* may either be from and to the same list, or to a another |
309 |
|
* list. |
310 |
|
* |
311 |
|
* @b CAUTION: When this method returns, this Iterator does |
312 |
|
* @b NOT point to the element on the new list anymore, instead it |
313 |
|
* points at a completely different element! In case of a |
314 |
|
* forward Iterator this Iterator object will point to the |
315 |
|
* previous element on the source list, in case of a backward |
316 |
|
* Iterator it will point to the subsequent element on the |
317 |
|
* source list. This behavior is enforced to avoid breaking an |
318 |
|
* active loop code working with this Iterator object. |
319 |
|
* |
320 |
|
* Thus if you intend to continue working with the same element, |
321 |
|
* you should do like this: |
322 |
|
* @code |
323 |
|
* itSourceElement = itSourceElement.moveAfter(itDestinationElement); |
324 |
|
* @endcode |
325 |
|
* |
326 |
|
* @param itDst - destination element to be inserted after |
327 |
|
* @returns Iterator object pointing at the moved element on |
328 |
|
* the destination list |
329 |
|
*/ |
330 |
|
inline _Iterator moveAfter(_Iterator<T1> itDst) { |
331 |
|
detach(); |
332 |
|
RTList<T1>::appendAfter(*this, itDst); |
333 |
|
_Iterator iterOnDstList = _Iterator(current); |
334 |
|
current = fallback; |
335 |
|
return iterOnDstList; |
336 |
|
} |
337 |
|
|
338 |
#if CONFIG_DEVMODE |
#if CONFIG_DEVMODE |
339 |
inline bool isValid() const { |
inline bool isValid() const { |
340 |
return current->list == list; |
return current->list == list; |
500 |
#endif // CONFIG_DEVMODE |
#endif // CONFIG_DEVMODE |
501 |
} |
} |
502 |
|
|
503 |
|
static inline void prependBefore(Iterator itSrc, Iterator itDst) { |
504 |
|
Node* src = itSrc.current; |
505 |
|
Node* dst = itDst.current; |
506 |
|
Node* prev = dst->prev; |
507 |
|
prev->next = src; |
508 |
|
dst->prev = src; |
509 |
|
src->prev = prev; |
510 |
|
src->next = dst; |
511 |
|
#if CONFIG_DEVMODE |
512 |
|
src->list = this; |
513 |
|
#endif // CONFIG_DEVMODE |
514 |
|
} |
515 |
|
|
516 |
|
static inline void appendAfter(Iterator itSrc, Iterator itDst) { |
517 |
|
Node* src = itSrc.current; |
518 |
|
Node* dst = itDst.current; |
519 |
|
Node* next = dst->next; |
520 |
|
next->prev = src; |
521 |
|
dst->next = src; |
522 |
|
src->prev = dst; |
523 |
|
src->next = next; |
524 |
|
#if CONFIG_DEVMODE |
525 |
|
src->list = this; |
526 |
|
#endif // CONFIG_DEVMODE |
527 |
|
} |
528 |
|
|
529 |
static inline void detach(Iterator itElement) { |
static inline void detach(Iterator itElement) { |
530 |
Node* pNode = itElement.node(); |
Node* pNode = itElement.node(); |
531 |
Node* prev = pNode->prev; // if a segfault happens here, then because 'itElement' Iterator became invalidated |
Node* prev = pNode->prev; // if a segfault happens here, then because 'itElement' Iterator became invalidated |
630 |
return pPool->fromID(id); |
return pPool->fromID(id); |
631 |
} |
} |
632 |
|
|
633 |
|
inline Iterator fromPtr(const T* obj) const { |
634 |
|
return pPool->fromPtr(obj); |
635 |
|
} |
636 |
|
|
637 |
protected: |
protected: |
638 |
Pool<T>* pPool; |
Pool<T>* pPool; |
639 |
}; |
}; |
771 |
return Iterator(node); |
return Iterator(node); |
772 |
} |
} |
773 |
|
|
774 |
|
/** |
775 |
|
* Returns an Iterator object for the object pointed by @a obj. This |
776 |
|
* method will check whether the supplied object is actually part of |
777 |
|
* this pool, and if it is not part of this pool an invalid Iterator is |
778 |
|
* returned instead. |
779 |
|
* |
780 |
|
* @param obj - raw pointer to an object managed by this pool |
781 |
|
* @returns Iterator object pointing to the supplied object, invalid |
782 |
|
* Iterator in case object is not part of this pool |
783 |
|
*/ |
784 |
|
Iterator fromPtr(const T* obj) const { |
785 |
|
if (!poolsize) return Iterator(); // invalid iterator |
786 |
|
int index = obj - &data[0]; |
787 |
|
if (index < 0 || index >= poolsize) return Iterator(); // invalid iterator |
788 |
|
return Iterator(&nodes[index]); |
789 |
|
} |
790 |
|
|
791 |
protected: |
protected: |
792 |
// caution: assumes pool (that is freelist) is not empty! |
// caution: assumes pool (that is freelist) is not empty! |
793 |
inline Iterator alloc() { |
inline Iterator alloc() { |