Sack Library Documentation
ContentsIndexReferenceHome
PreviousUpNext
sack::containers::list::LIST_FORALL Macro
C++
#define LIST_FORALL( l, i, t, v ) if(((v)=(t)NULL),(l))            \
                                            for( ((i)=0); ((i) < ((l)->Cnt))? \
                                        (((v)=(t)(PTRSZVAL)(l)->pNode[i]),1):(((v)=(t)NULL),0); (i)++ )  if( v )
Parameters 
Description 
list 
List to iterate through 
index 
variable to use to index the list 
type 
type of the elements stored in the list (for C++) 
pointer 
variable used to get the current member of the list

This is a iterator which can be used to check each member in a PLIST.

This initializes the parameters passed to the macro so that if the list is NULL or empty, then p will be set to NULL. If there are no non-nulll members in the list, p will be set to NULL. If you break in the loop, like in the case of searching the list for something, then p will be non-null at the end of the loop.

POINTER p;  // the pointer to receive the list member pointer (should be a user type)
INDEX idx; // indexer
PLIST pList; // some list.
   
LIST_FORALL( pList, idx, POINTER, p )
{
    // p will never be NULL here.
    // each link stored in the list is set to p here..
   
    // this is a way to remove this item from the list...
    SetLink( &pList, idx, NULL );
   
    if( some condition )
       break;
}
   

Another example that uses data and searches..

PLIST pList = NULL;
INDEX idx;
CTEXTSTR string;
   
AddLink( &pList, (POINTER)"hello" );
AddLink( &pList, (POINTER)"world" );
   
LITS_FORALL( pList, idx, CTEXTSTR, string )
{
    if( strcmp( string, "hello" ) == 0 )
        break;
}
// here 'string' will be NULL if not found, else will be what was found
Created with a commercial version of Doc-O-Matic. In order to make this message disappear you need to register this software. If you have problems registering this software please contact us at support@toolsfactory.com.
Copyright (c) 2000+. All rights reserved.
What do you think about this topic? Send feedback!