"Fossies" - the Fresh Open Source Software Archive

Member "calcurse-4.5.1/src/vector.h" (5 Jan 2019, 2809 Bytes) of package /linux/privat/calcurse-4.5.1.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. For more information about "vector.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 4.2.1_vs_4.2.2.

    1 /*
    2  * Calcurse - text-based organizer
    3  *
    4  * Copyright (c) 2004-2017 calcurse Development Team <misc@calcurse.org>
    5  * All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  *
   11  *      - Redistributions of source code must retain the above
   12  *        copyright notice, this list of conditions and the
   13  *        following disclaimer.
   14  *
   15  *      - Redistributions in binary form must reproduce the above
   16  *        copyright notice, this list of conditions and the
   17  *        following disclaimer in the documentation and/or other
   18  *        materials provided with the distribution.
   19  *
   20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
   24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
   30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   31  *
   32  * Send your feedback or comments to : misc@calcurse.org
   33  * Calcurse home page : http://calcurse.org
   34  *
   35  */
   36 
   37 #include "calcurse.h"
   38 
   39 typedef struct vector vector_t;
   40 struct vector {
   41     unsigned count;
   42     unsigned size;
   43     void **data;
   44 };
   45 
   46 typedef int (*vector_fn_cmp_t) (const void *, const void *);
   47 typedef void (*vector_fn_free_t) (void *);
   48 
   49 /* Initialization and deallocation. */
   50 void vector_init(vector_t *, unsigned);
   51 void vector_free(vector_t *);
   52 void vector_free_inner(vector_t *, vector_fn_free_t);
   53 
   54 #define VECTOR_INIT(v, n) vector_init(v, n)
   55 #define VECTOR_FREE(v) vector_free(v)
   56 #define VECTOR_FREE_INNER(v, fn_free) \
   57     vector_free_inner(v, (vector_fn_free_t)fn_free)
   58 
   59 /* Retrieving vector items. */
   60 void *vector_first(vector_t *);
   61 void *vector_nth(vector_t *, int);
   62 unsigned vector_count(vector_t *);
   63 
   64 #define VECTOR_FIRST(v) vector_first(v)
   65 #define VECTOR_NTH(v, n) vector_nth(v, n)
   66 #define VECTOR_COUNT(v) vector_count(v)
   67 
   68 #define VECTOR_FOREACH(v, i) for (i = 0; i < VECTOR_COUNT(v); i++)
   69 
   70 /* Vector manipulation. */
   71 void vector_add(vector_t *, void *);
   72 void vector_sort(vector_t *, vector_fn_cmp_t);
   73 void vector_remove(vector_t *, unsigned);
   74 
   75 #define VECTOR_ADD(v, data) vector_add(v, data)
   76 #define VECTOR_SORT(v, fn_cmp) vector_sort(v, (vector_fn_cmp_t)fn_cmp)
   77 #define VECTOR_REMOVE(v, i) vector_remove(v, i)