"Fossies" - the Fresh Open Source Software Archive

Member "ponyc-0.33.0/src/libponyrt/ds/list.h" (1 Nov 2019, 5594 Bytes) of package /linux/misc/ponyc-0.33.0.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 "list.h" see the Fossies "Dox" file reference documentation.

    1 #ifndef ds_list_h
    2 #define ds_list_h
    3 
    4 #include "fun.h"
    5 #include "../pony.h"
    6 #include <stdint.h>
    7 #include <stdbool.h>
    8 #include <platform.h>
    9 
   10 PONY_EXTERN_C_BEGIN
   11 
   12 typedef struct list_t
   13 {
   14   void* data;
   15   struct list_t* next;
   16 } list_t;
   17 
   18 list_t* ponyint_list_pop(list_t* list, void** data);
   19 
   20 list_t* ponyint_list_push(list_t* list, void* data);
   21 
   22 list_t* ponyint_list_append(list_t* list, void* data);
   23 
   24 list_t* ponyint_list_next(list_t* list);
   25 
   26 list_t* ponyint_list_index(list_t* list, ssize_t index);
   27 
   28 void* ponyint_list_data(list_t* list);
   29 
   30 void* ponyint_list_find(list_t* list, cmp_fn f, void* data);
   31 
   32 ssize_t ponyint_list_findindex(list_t* list, cmp_fn f, void* data);
   33 
   34 bool ponyint_list_subset(list_t* a, list_t* b, cmp_fn f);
   35 
   36 bool ponyint_list_equals(list_t* a, list_t* b, cmp_fn f);
   37 
   38 list_t* ponyint_list_map(list_t* list, map_fn f, void* arg);
   39 
   40 list_t* ponyint_list_reverse(list_t* list);
   41 
   42 size_t ponyint_list_length(list_t* list);
   43 
   44 void ponyint_list_free(list_t* list, free_fn f);
   45 
   46 void ponyint_list_serialise_trace(pony_ctx_t* ctx, void* object,
   47   pony_type_t* list_type, pony_type_t* elem_type);
   48 
   49 void ponyint_list_serialise(pony_ctx_t* ctx, void* object, void* buf,
   50   size_t offset);
   51 
   52 void ponyint_list_deserialise(pony_ctx_t* ctx, void* object,
   53   pony_type_t* list_type, pony_type_t* elem_type);
   54 
   55 #define DECLARE_LIST(name, name_t, elem) \
   56   typedef struct name_t name_t; \
   57   typedef bool (*name##_cmp_fn)(elem* a, elem* b); \
   58   typedef elem* (*name##_map_fn)(elem* a, void* arg); \
   59   typedef void (*name##_free_fn)(elem* a); \
   60   name_t* name##_pop(name_t* list, elem** data); \
   61   name_t* name##_push(name_t* list, elem* data); \
   62   name_t* name##_append(name_t* list, elem* data); \
   63   name_t* name##_next(name_t* list); \
   64   name_t* name##_index(name_t* list, ssize_t index); \
   65   elem* name##_data(name_t* list); \
   66   elem* name##_find(name_t* list, elem* data); \
   67   ssize_t name##_findindex(name_t* list, elem* data); \
   68   bool name##_subset(name_t* a, name_t* b); \
   69   bool name##_equals(name_t* a, name_t* b); \
   70   name_t* name##_map(name_t* list, name##_map_fn f, void* arg); \
   71   name_t* name##_reverse(name_t* list); \
   72   size_t name##_length(name_t* list); \
   73   void name##_free(name_t* list); \
   74 
   75 #define DECLARE_LIST_SERIALISE(name, name_t, type) \
   76   DECLARE_LIST(name, name_t, type) \
   77   void name##_serialise_trace(pony_ctx_t* ctx, void* object); \
   78   void name##_serialise(pony_ctx_t* ctx, void* object, void* buf, \
   79     size_t offset, int mutability); \
   80   void name##_deserialise(pony_ctx_t* ctx, void* object); \
   81   const pony_type_t* name##_pony_type(); \
   82 
   83 #define DEFINE_LIST(name, name_t, elem, cmpf, freef) \
   84   struct name_t {list_t contents;}; \
   85   \
   86   name_t* name##_pop(name_t* list, elem** data) \
   87   { \
   88     return (name_t*)ponyint_list_pop((list_t*)list, (void**)data); \
   89   } \
   90   name_t* name##_push(name_t* list, elem* data) \
   91   { \
   92     return (name_t*)ponyint_list_push((list_t*)list, (void*)data); \
   93   } \
   94   name_t* name##_append(name_t* list, elem* data) \
   95   { \
   96     return (name_t*)ponyint_list_append((list_t*)list, (void*)data); \
   97   } \
   98   name_t* name##_next(name_t* list) \
   99   { \
  100     return (name_t*)ponyint_list_next((list_t*)list); \
  101   } \
  102   name_t* name##_index(name_t* list, ssize_t index) \
  103   { \
  104     return (name_t*)ponyint_list_index((list_t*)list, index); \
  105   } \
  106   elem* name##_data(name_t* list) \
  107   { \
  108     return (elem*)ponyint_list_data((list_t*)list); \
  109   } \
  110   elem* name##_find(name_t* list, elem* data) \
  111   { \
  112     name##_cmp_fn cmp = cmpf; \
  113     return (elem*)ponyint_list_find((list_t*)list, (cmp_fn)cmp, (void*)data); \
  114   } \
  115   ssize_t name##_findindex(name_t* list, elem* data) \
  116   { \
  117     name##_cmp_fn cmp = cmpf; \
  118     return ponyint_list_findindex((list_t*)list, (cmp_fn)cmp, (void*)data); \
  119   } \
  120   bool name##_subset(name_t* a, name_t* b) \
  121   { \
  122     name##_cmp_fn cmp = cmpf; \
  123     return ponyint_list_subset((list_t*)a, (list_t*)b, (cmp_fn)cmp); \
  124   } \
  125   bool name##_equals(name_t* a, name_t* b) \
  126   { \
  127     name##_cmp_fn cmp = cmpf; \
  128     return ponyint_list_equals((list_t*)a, (list_t*)b, (cmp_fn)cmp); \
  129   } \
  130   name_t* name##_map(name_t* list, name##_map_fn f, void* arg) \
  131   { \
  132     return (name_t*)ponyint_list_map((list_t*)list, (map_fn)f, arg); \
  133   } \
  134   name_t* name##_reverse(name_t* list) \
  135   { \
  136     return (name_t*)ponyint_list_reverse((list_t*)list); \
  137   } \
  138   size_t name##_length(name_t* list) \
  139   { \
  140     return ponyint_list_length((list_t*)list); \
  141   } \
  142   void name##_free(name_t* list) \
  143   { \
  144     name##_free_fn free = freef; \
  145     ponyint_list_free((list_t*)list, (free_fn)free); \
  146   } \
  147 
  148 #define DEFINE_LIST_SERIALISE(name, name_t, elem, cmpf, freef, elem_type) \
  149   DEFINE_LIST(name, name_t, elem, cmpf, freef) \
  150   void name##_serialise_trace(pony_ctx_t* ctx, void* object) \
  151   { \
  152     ponyint_list_serialise_trace(ctx, object, name##_pony_type(), elem_type); \
  153   } \
  154   void name##_serialise(pony_ctx_t* ctx, void* object, void* buf, \
  155     size_t offset, int mutability) \
  156   { \
  157     (void)mutability; \
  158     ponyint_list_serialise(ctx, object, buf, offset); \
  159   } \
  160   void name##_deserialise(pony_ctx_t* ctx, void* object) \
  161   { \
  162     ponyint_list_deserialise(ctx, object, name##_pony_type(), elem_type); \
  163   } \
  164   static pony_type_t name##_pony = \
  165   { \
  166     0, \
  167     sizeof(name_t), \
  168     0, \
  169     0, \
  170     NULL, \
  171     NULL, \
  172     name##_serialise_trace, \
  173     name##_serialise, \
  174     name##_deserialise, \
  175     NULL, \
  176     NULL, \
  177     NULL, \
  178     NULL, \
  179     0, \
  180     NULL, \
  181     NULL, \
  182     NULL, \
  183   }; \
  184   const pony_type_t* name##_pony_type() \
  185   { \
  186     return &name##_pony; \
  187   } \
  188 
  189 PONY_EXTERN_C_END
  190 
  191 #endif