Simple data structures / objects in plain C Snapshot
dring.c
Go to the documentation of this file.
00001 /* Copyright (c) Michael Moser (2011) . 3-clause BSD License applies */
00002 
00003 #include <cutils/dring.h>
00004 
00005 
00006 
00007  void DRING_foreach( DRING *lst, DRING_VISITOR_V eval, void *data, int save_from_del)
00008 {
00009     DRING *cur, *next;
00010 
00011         if (!eval) {
00012           return;
00013         }
00014 
00015         if (save_from_del) {
00016                 DRING_FOREACH_SAVE( cur, next, lst) {
00017                         eval( cur, data );
00018                 }
00019         } else {
00020                 DRING_FOREACH(  cur, lst ) {
00021                         eval( cur, data );
00022                 }
00023         }
00024                 
00025 }
00026 
00027 
00028  void DRING_foreach_reverse( DRING *lst, DRING_VISITOR_V eval, void *data, int save_from_delete)
00029 {
00030         DRING *cur, *next;
00031 
00032         if (!eval) {
00033           return ;
00034         }
00035 
00036         if ( save_from_delete ) {
00037                 DRING_FOREACH_REVERSE_SAVE( cur, next, lst ) {
00038 
00039                         eval( cur, data );
00040                 }
00041         } else {
00042                 DRING_FOREACH_REVERSE( cur, lst ) {
00043 
00044                         eval( cur, data );
00045                 }
00046         }
00047 }
00048 
00049 
00050 
00051 
00052  void DRING_insert_sorted( DRING *list, DRING_COMPARE compare, DRING *newentry) 
00053 {
00054         DRING *cur;
00055         
00056         DRING_FOREACH(  cur, list ) {
00057                 if (compare(cur,newentry) > 0) {
00058                         DRING_insert_before(cur,newentry);
00059                         return;
00060                 }
00061         }
00062 
00063         DRING_push_back( list, newentry );
00064 }
00065