"Fossies" - the Fresh Open Source Software Archive

Member "ftwin-master/src/napr_list.h" (15 Feb 2015, 4552 Bytes) of package /linux/privat/ftwin-master.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2  * Copyright (C) 2007 Fran├žois Pesce : francois.pesce (at) gmail (dot) com
    3  *
    4  * Licensed under the Apache License, Version 2.0 (the "License");
    5  * you may not use this file except in compliance with the License.
    6  * You may obtain a copy of the License at
    7  * 
    8  *  http://www.apache.org/licenses/LICENSE-2.0
    9  * 
   10  * Unless required by applicable law or agreed to in writing, software
   11  * distributed under the License is distributed on an "AS IS" BASIS,
   12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   13  * See the License for the specific language governing permissions and
   14  * limitations under the License.
   15  */
   16 
   17 /*
   18  * List to use with apr lib environment.
   19  * TODO during _make, may create it's own pool, then * provide an allocator
   20  * (via napr_list.h api), to allocate elements you want to put in, then provide
   21  * a "delete function" (because list are memory intensive).
   22  */
   23 /**
   24  * @file napr_list.h
   25  * @brief Not APR chained list
   26  */
   27 #ifndef NAPR_LIST_H
   28 #define NAPR_LIST_H
   29 #include <apr_pools.h>
   30 
   31 typedef struct napr_list_t napr_list_t;
   32 typedef struct napr_cell_t napr_cell_t;
   33 
   34 /**
   35  * Return the allocator associated to the heap, thus you can allow elements
   36  * that will be automatically freed when the heap will be.
   37  * @param heap The heap you are working with.
   38  * @return Return a pointer to the allcator of type apr_pool_t.
   39  */
   40 apr_pool_t *napr_list_get_allocator(const napr_list_t *list);
   41 /* APR_POOL_DECLARE_ACCESSOR(list); */
   42 
   43 /**
   44  * Fill a napr_list structure with needed fields.
   45  * @param p Associated pool.
   46  * @return NULL if an allocation error occured.
   47  */
   48 napr_list_t *napr_list_make(apr_pool_t *p);
   49 
   50 /** 
   51  * Add an element to a napr_list
   52  * @param napr_list The list where you want to add the element.
   53  * @param element Allocated element that will be put in the beggining of a napr_list.
   54  * @return 0 if no error occured -1 otherwise.
   55  */
   56 int napr_list_cons(napr_list_t *napr_list, void *element);
   57 
   58 /** 
   59  * Remove the first element of a napr_list.
   60  * @param napr_list The list where you want to remove the first element.
   61  */
   62 void napr_list_cdr(napr_list_t *napr_list);
   63 
   64 /** 
   65  * Destroy all the elements of a list.
   66  * @param napr_list The list where you want to remove the elements.
   67  */
   68 void napr_list_delete(napr_list_t *napr_list);
   69 
   70 /** 
   71  * Check if an element is equal to an element of a list.
   72  * @param napr_list The list you are working on.
   73  * @param element The element you want to compare.
   74  * @param compare The function used to compare two elements.
   75  * @return 1 if the element is in a napr_list 0 otherwise.
   76  */
   77 int napr_list_member(napr_list_t *napr_list, void *element, int (*compare) (const void *key1, const void *key2));
   78 
   79 /** 
   80  * Insert an element in a napr_list, if no element is equal to the one you want to insert (using function to compare)
   81  * @param napr_list The list you are working on.
   82  * @param element The element you want to insert.
   83  * @param compare The function used to compare two elements.
   84  * @return 1 if the element is in a napr_list, -1 if an error occured during insertion, 0 otherwise.
   85  */
   86 int napr_list_insert(napr_list_t *napr_list, void *element, int (*compare) (const void *key1, const void *key2));
   87 
   88 /**
   89  * Insert an element at the end of a list.
   90  * @param napr_list The list you are working on.
   91  * @param element The element you want to insert.
   92  * @return 0 if no error occured -1 otherwise.
   93  */
   94 int napr_list_enqueue(napr_list_t *napr_list, void *element);
   95 
   96 /**
   97  * Get the first element of a list.
   98  * @param napr_list The list you are working on.
   99  * @return The first element, NULL if the list is empty.
  100  */
  101 napr_cell_t *napr_list_first(napr_list_t *napr_list);
  102 
  103 /**
  104  * Get the last element of a list.
  105  * @param napr_list The list you are working on.
  106  * @return The last element, NULL if the list is empty.
  107  */
  108 napr_cell_t *napr_list_last(napr_list_t *napr_list);
  109 
  110 /**
  111  * Get the following element of an element.
  112  * @param cell The current element.
  113  * @return The following element of a cell, NULL if cell was the last of the list.
  114  */
  115 napr_cell_t *napr_list_next(napr_cell_t *cell);
  116 
  117 #ifdef DOUBLY_LINK
  118 /**
  119  * Get the previous element of an element.
  120  * @param cell The current element.
  121  * @return The previous element of a cell, NULL if cell was the first of the list.
  122  */
  123 napr_cell_t *napr_list_prev(napr_cell_t *cell);
  124 #endif /* DOUBLY_LINK */
  125 
  126 /**
  127  * Get the content of an element.
  128  * @param cell The current element.
  129  * @return The content of an element of type cell_t, NULL if cell is empty.
  130  */
  131 void *napr_list_get(napr_cell_t *cell);
  132 #endif /* NAPR_LIST_H */