/usr/include/pj++/list.hpp is in libpjproject-dev 2.7.2~dfsg-1.
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 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | /* $Id: list.hpp 2394 2008-12-23 17:27:53Z bennylp $ */
/*
* Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
*
* This program 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.
*
* This program 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 more 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __PJPP_LIST_HPP__
#define __PJPP_LIST_HPP__
#include <pj/list.h>
#include <pj++/pool.hpp>
//
// Linked-list.
//
// Note:
// List_Node must have public member next and prev. Normally
// it will be declared like:
//
// struct my_node
// {
// PJ_DECL_LIST_MEMBER(struct my_node);
// ..
// };
//
//
template <class List_Node>
class Pj_List : public Pj_Object
{
public:
//
// List const_iterator.
//
class const_iterator
{
public:
const_iterator()
: node_(NULL)
{}
const_iterator(const List_Node *nd)
: node_((List_Node*)nd)
{}
const List_Node * operator *()
{
return node_;
}
const List_Node * operator -> ()
{
return node_;
}
const_iterator operator++()
{
return const_iterator((const List_Node *)node_->next);
}
bool operator==(const const_iterator &rhs)
{
return node_ == rhs.node_;
}
bool operator!=(const const_iterator &rhs)
{
return node_ != rhs.node_;
}
protected:
List_Node *node_;
};
//
// List iterator.
//
class iterator : public const_iterator
{
public:
iterator()
{}
iterator(List_Node *nd)
: const_iterator(nd)
{}
List_Node * operator *()
{
return node_;
}
List_Node * operator -> ()
{
return node_;
}
iterator operator++()
{
return iterator((List_Node*)node_->next);
}
bool operator==(const iterator &rhs)
{
return node_ == rhs.node_;
}
bool operator!=(const iterator &rhs)
{
return node_ != rhs.node_;
}
};
//
// Default constructor.
//
Pj_List()
{
pj_list_init(&root_);
if (0) compiletest();
}
//
// You can cast Pj_List to pj_list
//
operator pj_list&()
{
return (pj_list&)root_;
}
operator const pj_list&()
{
return (const pj_list&)root_;
}
//
// You can cast Pj_List to pj_list* too
//
operator pj_list*()
{
return (pj_list*)&root_;
}
operator const pj_list*()
{
return (const pj_list*)&root_;
}
//
// Check if list is empty.
//
bool empty() const
{
return pj_list_empty(&root_);
}
//
// Get first element.
//
iterator begin()
{
return iterator(root_.next);
}
//
// Get first element.
//
const_iterator begin() const
{
return const_iterator(root_.next);
}
//
// Get end-of-element
//
const_iterator end() const
{
return const_iterator((List_Node*)&root_);
}
//
// Get end-of-element
//
iterator end()
{
return iterator((List_Node*)&root_);
}
//
// Insert node.
//
void insert_before (iterator &pos, List_Node *node)
{
pj_list_insert_before( *pos, node );
}
//
// Insert node.
//
void insert_after(iterator &pos, List_Node *node)
{
pj_list_insert_after(*pos, node);
}
//
// Merge list.
//
void merge_first(List_Node *list2)
{
pj_list_merge_first(&root_, list2);
}
//
// Merge list.
//
void merge_last(Pj_List *list)
{
pj_list_merge_last(&root_, &list->root_);
}
//
// Insert list.
//
void insert_nodes_before(iterator &pos, Pj_List *list2)
{
pj_list_insert_nodes_before(*pos, &list2->root_);
}
//
// Insert list.
//
void insert_nodes_after(iterator &pos, Pj_List *list2)
{
pj_list_insert_nodes_after(*pos, &list2->root_);
}
//
// Erase an element.
//
void erase(iterator &it)
{
pj_list_erase(*it);
}
//
// Get first element.
//
List_Node *front()
{
return root_.next;
}
//
// Get first element.
//
const List_Node *front() const
{
return root_.next;
}
//
// Remove first element.
//
void pop_front()
{
pj_list_erase(root_.next);
}
//
// Get last element.
//
List_Node *back()
{
return root_.prev;
}
//
// Get last element.
//
const List_Node *back() const
{
return root_.prev;
}
//
// Remove last element.
//
void pop_back()
{
pj_list_erase(root_.prev);
}
//
// Find a node.
//
iterator find(List_Node *node)
{
List_Node *n = pj_list_find_node(&root_, node);
return n ? iterator(n) : end();
}
//
// Find a node.
//
const_iterator find(List_Node *node) const
{
List_Node *n = pj_list_find_node(&root_, node);
return n ? const_iterator(n) : end();
}
//
// Insert a node in the back.
//
void push_back(List_Node *node)
{
pj_list_insert_after(root_.prev, node);
}
//
// Insert a node in the front.
//
void push_front(List_Node *node)
{
pj_list_insert_before(root_.next, node);
}
//
// Remove all elements.
//
void clear()
{
root_.next = &root_;
root_.prev = &root_;
}
private:
struct RootNode
{
PJ_DECL_LIST_MEMBER(List_Node);
} root_;
void compiletest()
{
// If you see error in this line,
// it's because List_Node is not derived from Pj_List_Node.
List_Node *n = (List_Node*)0;
n = (List_Node *)n->next; n = (List_Node *)n->prev;
}
};
#endif /* __PJPP_LIST_HPP__ */
|