/usr/include/raul/List.hpp is in libraul-dev 0.8.0+dfsg0-0.1+b1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | /* This file is part of Raul.
* Copyright (C) 2007-2009 David Robillard <http://drobilla.net>
*
* Raul is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* Raul is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef RAUL_LIST_HPP
#define RAUL_LIST_HPP
#include <cstddef>
#include <cassert>
#include <boost/utility.hpp>
#include "raul/AtomicInt.hpp"
#include "raul/AtomicPtr.hpp"
#include "raul/Deletable.hpp"
namespace Raul {
/** A realtime safe, (partially) thread safe doubly-linked list.
*
* Elements can be added safely while another thread is reading the list.
* Like a typical ringbuffer, this is single-reader single-writer threadsafe
* only. See documentation for specific functions for specifics.
* \ingroup raul
*/
template <typename T>
class List : public Raul::Deletable, public boost::noncopyable
{
public:
/** A node in a List.
*
* This is exposed so the user can allocate Nodes in different thread
* than the list reader, and insert (e.g. via an Event) it later in the
* reader thread.
*/
class Node : public Raul::Deletable {
public:
explicit Node(T elem) : _elem(elem) {}
virtual ~Node() {}
template <typename Y>
explicit Node(const typename List<Y>::Node& copy)
: _elem(copy._elem), _prev(copy._prev), _next(copy._next)
{}
Node* prev() const { return _prev.get(); }
void prev(Node* ln) { _prev = ln; }
Node* next() const { return _next.get(); }
void next(Node* ln) { _next = ln; }
T& elem() { return _elem;}
const T& elem() const { return _elem; }
private:
T _elem;
AtomicPtr<Node> _prev;
AtomicPtr<Node> _next;
};
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
void push_back(T& elem); ///< NOT Realtime Safe
void append(List<T>& list);
void clear();
/// Valid only in the write thread
unsigned size() const { return static_cast<unsigned>(_size.get()); }
/// Valid for any thread
bool empty() { return (_head.get() == NULL); }
class iterator;
/** Realtime safe const iterator for a List. */
class const_iterator {
public:
explicit const_iterator(const List<T>* const list);
const_iterator(const iterator& i)
: _list(i._list), _listnode(i._listnode) {}
inline const T& operator*();
inline const T* operator->();
inline const_iterator& operator++();
inline bool operator!=(const const_iterator& iter) const;
inline bool operator!=(const iterator& iter) const;
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:
const List<T>* _list;
const typename List<T>::Node* _listnode;
};
/** Realtime safe iterator for a List. */
class iterator {
public:
explicit iterator(List<T>* const list);
inline T& operator*();
inline T* operator->();
inline iterator& operator++();
inline bool operator!=(const iterator& iter) const;
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;
private:
const List<T>* _list;
typename List<T>::Node* _listnode;
};
void chop_front(List<T>& front, size_t front_size, Node* front_tail);
Node* erase(const iterator iter);
iterator find(const T& val);
iterator begin();
const_iterator begin() const;
const iterator end() const;
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
AtomicInt _size;
iterator _end_iter;
const_iterator _const_end_iter;
};
} // namespace Raul
#endif // RAUL_LIST_HPP
#include "ListImpl.hpp"
|