add declaration & implementation of bloblist_iterate() ENGINE-321
authorRoker <roker@pep-project.org>
Thu, 14 Dec 2017 15:20:49 +0100
branchENGINE-321
changeset 2298640f83c07bbd
parent 2297 a3d936f31f04
child 2299 e69ea613513f
add declaration & implementation of bloblist_iterate()
src/bloblist.c
src/bloblist.h
     1.1 --- a/src/bloblist.c	Thu Dec 14 14:53:59 2017 +0100
     1.2 +++ b/src/bloblist.c	Thu Dec 14 15:20:49 2017 +0100
     1.3 @@ -169,6 +169,17 @@
     1.4      return len;
     1.5  }
     1.6  
     1.7 +
     1.8 +DYNAMIC_API bloblist_t* bloblist_iterate(bloblist_t *bloblist, bool(*func)(bloblist_t* element))
     1.9 +{
    1.10 +    while(bloblist && !func(bloblist))
    1.11 +    {
    1.12 +        bloblist = bloblist->next;
    1.13 +    }
    1.14 +    return bloblist;
    1.15 +}
    1.16 +
    1.17 +
    1.18  DYNAMIC_API void set_blob_disposition(bloblist_t* blob, 
    1.19                                        content_disposition_type disposition) {
    1.20      if (blob)                                    
     2.1 --- a/src/bloblist.h	Thu Dec 14 14:53:59 2017 +0100
     2.2 +++ b/src/bloblist.h	Thu Dec 14 15:20:49 2017 +0100
     2.3 @@ -102,6 +102,26 @@
     2.4  
     2.5  DYNAMIC_API int bloblist_length(const bloblist_t *bloblist);
     2.6  
     2.7 +
     2.8 +// bloblist_iterate() - iterate over the bloblist until given function returns true.
     2.9 +//                      It is inspired by C++'s std::find_if() function.
    2.10 +//
    2.11 +//  parameters:
    2.12 +//      bloblist (in)   bloblist struct to determine length of
    2.13 +//      func(in)        function that is invoked for each bloblist element.
    2.14 +//                      Iteration stops when func() returns "true".
    2.15 +//
    2.16 +//  return value:
    2.17 +//      pointer to the first element where func() returns true.
    2.18 +//      NULL if there is no such element.
    2.19 +//
    2.20 +//  caveat:
    2.21 +//      The function shall not change the bloblist itself, but is allowed to modify
    2.22 +//      the members of each element.
    2.23 +//
    2.24 +DYNAMIC_API bloblist_t* bloblist_iterate(bloblist_t *bloblist, bool(*func)(bloblist_t* element));
    2.25 +
    2.26 +
    2.27  // set_blob_content_disposition() - set blob content disposition and parameters
    2.28  //                                  when necessary
    2.29  //