/usr/include/sbml/util/List.h is in libsbml5-dev 5.16.0+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 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 | /**
* @file List.h
* @brief Simple, generic list utility class.
* @author Ben Bornstein
*
* <!--------------------------------------------------------------------------
* This file is part of libSBML. Please visit http://sbml.org for more
* information about SBML, and the latest version of libSBML.
*
* Copyright (C) 2013-2017 jointly by the following organizations:
* 1. California Institute of Technology, Pasadena, CA, USA
* 2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
* 3. University of Heidelberg, Heidelberg, Germany
*
* Copyright (C) 2009-2013 jointly by the following organizations:
* 1. California Institute of Technology, Pasadena, CA, USA
* 2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
*
* Copyright (C) 2006-2008 by the California Institute of Technology,
* Pasadena, CA, USA
*
* Copyright (C) 2002-2005 jointly by the following organizations:
* 1. California Institute of Technology, Pasadena, CA, USA
* 2. Japan Science and Technology Agency, Japan
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution and
* also available online as http://sbml.org/software/libsbml/license.html
* ------------------------------------------------------------------------ -->
*
* @class List
* @sbmlbrief{core} Simple, plain, generic lists.
*
* @htmlinclude not-sbml-warning.html
*
* This class implements basic vanilla lists for libSBML. It was developed
* in the time before libSBML was converted to C++ and used C++ STL library
* classes more extensively. At some point in the future, this List class
* may be removed in favor of using standard C++ classes.
*
* This class is distinct from ListOf because the latter is derived from
* the SBML SBase class, whereas this List class is not. ListOf can only
* be used when a list is actually intended to implement an SBML ListOfX
* class. This is why libSBML has both a List and a ListOf.
*/
#ifndef List_h
#define List_h
#include <sbml/common/extern.h>
#include <string.h>
LIBSBML_CPP_NAMESPACE_BEGIN
/**
* A @sbmlconstant{ListItemComparator,} is a typedef for a pointer to a function that compares two list
* items. The return value semantics are the same as for the C library
* function @c strcmp:
* <ul>
* <li> -1: @p item1 < @p item2
* <li> 0: @p item1 == @p item2
* <li> 1: @p item1 > @p item2
* </ul>
* @see List_find()
*
* @if conly
* @memberof List_t
* @endif
*/
typedef int (*ListItemComparator) (const void *item1, const void *item2);
/**
* A @sbmlconstant{ListItemPredicate,} is a typedef for a pointer to a function that takes a List item and
* returns @c 1 (true) or @c 0 (false).
*
* @see List_countIf()
*
* @if conly
* @memberof List_t
* @endif
*/
typedef int (*ListItemPredicate) (const void *item);
/** @cond doxygenLibsbmlInternal */
/**
* A @sbmlconstant{ListDeleteItemFunc,} is a typedef for a pointer to a function that takes a List item and
* deletes / frees it as apropriate.
*
* @if conly
* @memberof List_t
* @endif
*/
typedef void (*ListDeleteItemFunc) (void *item);
/** @endcond */
#ifdef __cplusplus
class List;
class ListNode;
class ListIterator;
#ifndef SWIG
/**
* @cond doxygenLibsbmlInternal
*
*
* @class ListNode
* @sbmlbrief{core} A node in a plain List.
*
* @htmlinclude not-sbml-warning.html
*
* This class implements the children of the List class, storing the
* item itself, and a pointer to the next item in the list.
*/
class ListNode
{
public:
ListNode (void* x): item(x), next(NULL) { }
void* item;
ListNode* next;
friend class List;
friend class ListIterator;
void * getItem() { return item;} ;
};
class ListIterator
{
/* Helper class to provide pointer like facilities around a node */
friend class List;
ListNode* position; //The node oriented with this instance of ListIterator.
ListIterator(ListNode* _pNode) : position(_pNode) {}
public:
void operator++(){ position = position->next; }
void operator++(int){ position = position->next; }
bool operator!=(ListIterator rval){ return !(position == rval.position); }
bool operator==(ListIterator rval){ return (position == rval.position); }
void * operator*(){ return position->getItem(); }
};
/** @endcond */
#endif /* !SWIG */
class LIBSBML_EXTERN List
{
public:
/**
* Creates a new List object.
*/
List ();
/**
* Destroys this List object.
*
* This function does not delete List items. It destroys only the List
* and its constituent ListNodes (if any).
*
* Presumably, you either i) have pointers to the individual list items
* elsewhere in your program and you want to keep them around for awhile
* longer or ii) the list has no items (<code>List.size() == 0</code>).
* If neither are true, try the macro List_freeItems() instead.
*/
virtual ~List ();
/**
* Adds @p item to the end of this List.
*
* @param item a pointer to the item to be added.
*/
void add (void *item);
/**
* Return the count of items in this list satisfying a given predicate
* function.
*
* The typedef for @sbmlconstant{ListItemPredicate,} is:
* @code
* int (*ListItemPredicate) (const void *item);
* @endcode
* where a return value of @c 1 represents true and @c 0 represents
* false.
*
* @param predicate the function applied to each item in this list.
*
* @return the number of items in this List for which
* <code>predicate(item)</code> returns @c 1 (true).
*/
unsigned int countIf (ListItemPredicate predicate) const;
/**
* Find the first occurrence of an item in a list according to a given
* comparator function.
*
* The typedef for @sbmlconstant{ListItemComparator,} is:
* @code
* int (*ListItemComparator) (void *item1, void *item2);
* @endcode
* The return value semantics are the same as for the C library function
* @c strcmp:
* <ul>
* <li> -1: @p item1 < @p item2
* <li> 0: @p item1 == @p item2
* <li> 1: @p item1 > @p item2
* </ul>
*
* @param item1 a pointer to the item being sought.
*
* @param comparator a pointer to a @sbmlconstant{ListItemComparator,} function used to
* find the item of interest in this list.
*
* @return the first occurrence of @p item1 in this List or @c NULL if
* @p item1 was not found.
*/
void* find (const void *item1, ListItemComparator comparator) const;
/**
* Find all items in this list satisfying a given predicate function.
*
* The typedef for @sbmlconstant{ListItemPredicate,} is:
* @code
* int (*ListItemPredicate) (const void *item);
* @endcode
* where a return value of @c 1 represents true and @c 0 represents
* false.
*
* The caller owns the returned list (but not its constituent items) and
* is responsible for deleting it.
*
* @param predicate the function applied to each item in this list.
*
* @return a new List containing (pointers to) all items in this List for
* which <code>predicate(item)</code> returned nonzero (true). The
* returned list may be empty if none of the items satisfy the @p
* predicate.
*/
List* findIf (ListItemPredicate predicate) const;
/**
* Get the nth item in this List.
*
* If @p n > <code>List.size()</code>, this method returns @c 0.
*
* @return the nth item in this List.
*
* @see remove()
*/
void* get (unsigned int n) const;
/**
* Adds a given item to the beginning of this List.
*
* @param item a pointer to the item to be added to this list.
*/
void prepend (void *item);
/**
* Removes the nth item from this List and returns a pointer to it.
*
* If @p n > <code>List.size()</code>, this method returns @c 0.
*
* @return the nth item in this List.
*
* @see get()
*/
void* remove (unsigned int n);
/**
* Get the number of items in this List.
*
* @return the number of elements in this List.
*/
unsigned int getSize () const;
/**
* Merge this elements of the second list into this list (by pointing the last ListNode to the first ListNode in the supplied List).
*
*/
void transferFrom(List* list);
/** @cond doxygenLibsbmlInternal */
/**
* Delete all child elements of the given list, and then the list itself.
*
* The child elements are to be deleted by the @sbmlconstant{ListDeleteItemFunc,} predicate, that will be called with
* each element.
*
*/
static void deleteListAndChildrenWith(List* list, ListDeleteItemFunc delteFunc);
/** @endcond */
/** @cond doxygenLibsbmlInternal */
ListIterator begin();
ListIterator end();
/** @endcond */
protected:
/** @cond doxygenLibsbmlInternal */
unsigned int size;
ListNode* head;
ListNode* tail;
/** @endcond */
};
#endif /* __cplusplus */
/**
* @def List_freeItems(list, free_item, type)
* Frees the items in the given List.
*
* Iterates over the items in this List and frees each one in turn by
* calling the passed-in 'void free_item(type *)' function.
*
* The List itself will not be freed and so may be re-used. To free
* the List, use the destructor.
*
* While the function prototype cannot be expressed precisely in C syntax,
* it is roughly:
* @code
* List_freeItems(List_t *lst, void (*free_item)(type *), type)
* @endcode
* where @c type is a C type resolved at compile time.
*
* Believe it or not, defining List_freeItems() as a macro is actually more
* type safe than can be acheived with straight C. That is, in C, the
* free_item() function would need to take a void pointer argument,
* requiring any type safe XXX_free() functions to be re-written to be less
* safe.
*
* As with all line-continuation macros, compile-time errors will still
* report the correct line number.
*
* @if conly
* @memberof List_t
* @endif
*/
#define List_freeItems(list, free_item, type) \
{ \
unsigned int size = List_size(list); \
while (size--) free_item( (type *) List_remove(list, 0) ); \
}
LIBSBML_CPP_NAMESPACE_END
#ifndef SWIG
/*BEGIN_C_DECLS */
#include <sbml/common/sbmlfwd.h>
/* END_C_DECLS */
LIBSBML_CPP_NAMESPACE_BEGIN
BEGIN_C_DECLS
/**
* Creates a new List_t and returns a pointer to it.
*
* The pointer that is returned by this function is owned by the caller,
* who is responsible for deleting it.
*
* @if conly
* @memberof List_t
* @endif
*/
LIBSBML_EXTERN
List_t *
List_create (void);
/**
* @cond doxygenLibsbmlInternal
*
* Creates a new ListNode_t (with @p item) and returns a pointer to the node.
*
* @param item the item to create a ListNode_t for.
*
* The pointer that is returned by this function is owned by the caller,
* who is responsible for deleting it.
*
* @if conly
* @memberof ListNode_t
* @endif
*/
LIBSBML_EXTERN
ListNode_t *
ListNode_create (void *item);
/** @endcond */
/**
* Frees the given List_t.
*
* This function does not free List_t items. It frees only the List_t
* structure and its constituent internal structures (if any).
*
* Presumably, you either i) have pointers to the individual list items
* elsewhere in your program and you want to keep them around for awhile
* longer or ii) the list has no items ( List_size() == @c 0 ). If neither
* are true, try List_freeItems() instead.
*
* @param lst the List_t structure.
*
* @if conly
* @memberof List_t
* @endif
*/
LIBSBML_EXTERN
void
List_free (List_t *lst);
/**
* @cond doxygenLibsbmlInternal
*
* Frees the given ListNode_t.
*
* @param node the ListNode_t structure.
*
* @memberof ListNode_t
*/
LIBSBML_EXTERN
void
ListNode_free (ListNode_t *node);
/** @endcond */
/**
* Adds a pointer to @p item to the end of this List_t.
*
* @param lst the List_t structure.
* @param item the item to add to the end of the list.
*
* @if conly
* @memberof List_t
* @endif
*/
LIBSBML_EXTERN
void
List_add (List_t *lst, void *item);
/**
* @return the number of items in this List_t for which
* <code>predicate(item)</code> returns true.
*
* The typedef for @sbmlconstant{ListItemPredicate,} is:
*
* int (*ListItemPredicate) (const void *item);
*
* where a return value of @c 1 represents true and @c 0 represents
* false.
*
* @param lst the List_t structure.
* @param predicate the predicate to test the elements of the list against.
*
* @if conly
* @memberof List_t
* @endif
*/
LIBSBML_EXTERN
unsigned int
List_countIf (const List_t *lst, ListItemPredicate predicate);
/**
* Searches the List_t for an entry that matches @p item1, according
* to @p comparator.
*
* The @sbmlconstant{ListItemComparator,} is a pointer to a function used to find
* a matching entry. The typedef for @sbmlconstant{ListItemComparator,} is:
*
* int (*ListItemComparator) (void *item1, void *item2);
*
* The return value semantics are the same as for strcmp:
* <ul>
* <li> -1 item1 < item2,
* <li> 0 item1 == item 2
* <li> 1 item1 > item2
* </ul>
*
* @param lst the List_t structure.
* @param item1 the item to look for.
* @param comparator the pointer to the function used to find the item.
*
* @return the first occurrence of an entry matching @p item1 in this
* List_t or @c NULL if item was not found.
*
* The pointer that is returned by this function is not owned by the caller,
* but may be queried and modified.
*
* @if conly
* @memberof List_t
* @endif
*/
LIBSBML_EXTERN
void *
List_find ( const List_t *lst,
const void *item1,
ListItemComparator comparator );
/**
* Create and return a new List_t with the subset of items for which
* <code>predicate(item)</code> returns true. The returned list may be empty.
*
* The caller owns the returned list (but not its constituent items) and is
* responsible for freeing it with List_free().
*
* @param lst the List_t structure.
* @param predicate the predicate to test the elements of the list against.
*
* @return a new List_t containing (pointers to) all items in this List_t for
* which <code>predicate(item)</code> was true.
*
* @if conly
* @memberof List_t
* @endif
*/
LIBSBML_EXTERN
List_t *
List_findIf (const List_t *lst, ListItemPredicate predicate);
/**
* Returns the nth item in this List_t. If n > List_size() returns NULL.
*
* @param lst the List_t structure.
* @param n the index of the item to find.
*
* @if conly
* @memberof List_t
* @endif
*/
LIBSBML_EXTERN
void *
List_get (const List_t *lst, unsigned int n);
/**
* Adds item to the beginning of this List_t.
*
* @param lst the List_t structure.
* @param item the item to add to the list.
*
* @if conly
* @memberof List_t
* @endif
*/
LIBSBML_EXTERN
void
List_prepend (List_t *lst, void *item);
/**
* Removes the nth item from this List_t and returns a pointer to it. If n >
* List_size() returns NULL.
*
* @param lst the List_t structure.
* @param n the index of the item to remove.
*
* Unlike other 'remove' functions in libsbml, the caller does not own the
* returned item: it continues to be owned by whoever owned it before being
* put on the List_t. It may be queried or changed by the caller, like other
* elements of the List_t.
*
* @if conly
* @memberof List_t
* @endif
*/
LIBSBML_EXTERN
void *
List_remove (List_t *lst, unsigned int n);
/**
* The number of elements in @p lst.
*
* @param lst the List_t structure.
*
* @return the number of elements in the given List_t.
*
* @if conly
* @memberof List_t
* @endif
*/
LIBSBML_EXTERN
unsigned int
List_size (const List_t *lst);
END_C_DECLS
LIBSBML_CPP_NAMESPACE_END
#endif /* !SWIG */
#endif /* List_h */
|