diff options
-rw-r--r-- | raul/List.hpp | 22 | ||||
-rw-r--r-- | raul/ListImpl.hpp | 36 | ||||
-rw-r--r-- | wscript | 2 |
3 files changed, 53 insertions, 7 deletions
diff --git a/raul/List.hpp b/raul/List.hpp index 05fdb1e..a3f63a2 100644 --- a/raul/List.hpp +++ b/raul/List.hpp @@ -69,11 +69,17 @@ public: }; - List() : _size(0), _end_iter(this), _const_end_iter(this) { + List(size_t size=0, Node* head=NULL, Node* tail=NULL) + : _size(size) + , _end_iter(this) + , _const_end_iter(this) + { + _head = head; + _tail = tail; _end_iter._listnode = NULL; _const_end_iter._listnode = NULL; } - + ~List(); void push_back(Node* elem); ///< Realtime Safe @@ -106,6 +112,9 @@ public: inline bool operator==(const const_iterator& iter) const; inline bool operator==(const iterator& iter) const; + inline typename List<T>::Node* node() { return _listnode; } + inline const typename List<T>::Node* node() const { return _listnode; } + friend class List<T>; private: @@ -126,7 +135,7 @@ public: inline bool operator!=(const const_iterator& iter) const; inline bool operator==(const iterator& iter) const; inline bool operator==(const const_iterator& iter) const; - + friend class List<T>; friend class List<T>::const_iterator; @@ -135,6 +144,7 @@ public: typename List<T>::Node* _listnode; }; + void chop_front(List<T>& front, size_t front_size, Node* new_head); Node* erase(const iterator iter); @@ -147,6 +157,9 @@ public: T& front() { return *begin(); } const T& front() const { return *begin(); } + Node* head() { return _head.get(); } + const Node* head() const { return _head.get(); } + private: AtomicPtr<Node> _head; AtomicPtr<Node> _tail; ///< writer only @@ -158,6 +171,7 @@ private: } // namespace Raul +#endif // RAUL_LIST_HPP + #include "ListImpl.hpp" -#endif // RAUL_LIST_HPP diff --git a/raul/ListImpl.hpp b/raul/ListImpl.hpp index ec1fde4..815afcb 100644 --- a/raul/ListImpl.hpp +++ b/raul/ListImpl.hpp @@ -109,7 +109,6 @@ List<T>::push_back(T& elem) * * This operation is fast ( O(1) ). * The appended list is not safe to use concurrently with this call. - * * The appended list will be empty after this call. * * Thread safe (may be called while another thread is reading the list). @@ -123,6 +122,9 @@ List<T>::append(List<T>& list) Node* const my_tail = _tail.get(); Node* const other_head = list._head.get(); Node* const other_tail = list._tail.get(); + + assert((my_head && my_tail) || (!my_head && !my_tail)); + assert((other_head && other_tail) || (!other_head && !other_tail)); // Appending to an empty list if (my_head == NULL && my_tail == NULL) { @@ -178,7 +180,6 @@ List<T>::erase(const iterator iter) Node* const n = iter._listnode; if (n) { - Node* const prev = n->prev(); Node* const next = n->next(); @@ -199,10 +200,41 @@ List<T>::erase(const iterator iter) --_size; } + assert((_head.get() && _tail.get()) || (!_head.get() && !_tail.get())); return n; } +template <typename T> +void +List<T>::chop_front(List<T>& front, size_t front_size, Node* new_head) +{ + assert(new_head != _head.get()); + assert((front._head.get() && front._tail.get()) || (!front._head.get() && !front._tail.get())); + assert((_head.get() && _tail.get()) || (!_head.get() && !_tail.get())); + if (!new_head) { + assert(front_size == static_cast<size_t>(_size.get())); + front._size = _size; + front._head = _head; + front._tail = _tail; + _size = 0; + _head = NULL; + _tail = NULL; + } else { + front._size = front_size; + front._head = _head; + front._tail = new_head->_prev; + if (new_head->prev()) + new_head->prev()->_next = NULL; + _head = new_head; + new_head->_prev = NULL; + _size -= front_size; + } + assert((front._head.get() && front._tail.get()) || (!front._head.get() && !front._tail.get())); + assert((_head.get() && _tail.get()) || (!_head.get() && !_tail.get())); +} + + //// Iterator stuff //// template <typename T> @@ -51,7 +51,7 @@ def build(bld): src/Symbol.cpp src/Thread.cpp ''' - obj.includes = '.' + obj.includes = ['.','./raul'] obj.name = 'libraul' obj.target = 'raul' obj.uselib = 'GLIBMM GTHREAD' |