💾 Archived View for gmi.noulin.net › gitRepositories › ring › file › cRing.h.gmi captured on 2023-01-29 at 13:19:06. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

ring

Log

Files

Refs

LICENSE

cRing.h (3101B)

     1 #pragma once
     2 // Class ring, inherit from smallArrayt
     3 // cast ringt with cAr() macro when calling parent functions
     4 
     5 #include "libsheepyObject.h"
     6 typedef struct ring ringt;
     7 
     8 typedef void            (*freeRingFt)      (ringt *self);
     9 typedef void            (*terminateRingFt) (ringt **self);
    10 typedef char*           (*toStringRingFt)  (ringt *self);
    11 typedef ringt*          (*duplicateRingFt) (ringt *self);
    12 typedef void            (*smashRingFt)     (ringt **self);
    13 
    14 /**
    15  * free container
    16  */
    17 typedef void            (*finishRingFt)    (ringt **self);
    18 
    19 typedef void            (*setSizeRingFt)   (ringt *self, size_t size);
    20 typedef bool            (*isFullRingFt)    (ringt *self);
    21 typedef i64             (*countRingFt)     (ringt *self);
    22 typedef i64             (*maxCountRingFt)  (ringt *self);
    23 typedef baset*          (*lastRingFt)      (ringt *self);
    24 typedef baset*          (*firstRingFt)     (ringt *self);
    25 typedef baset*          (*getFromRingFt)   (ringt *self, intmax_t index);
    26 
    27 /**
    28  * class functions
    29  * allocated once for all objects
    30  *
    31  * freed with finalizeRing or finalizeLibsheepy
    32  */
    33 
    34 #define RINGFUNCTIONST \
    35   SMALLARRAYFUNCTIONST; \
    36   setSizeRingFt           setSize;\
    37   isFullRingFt            isFull;\
    38   countRingFt             count;\
    39   maxCountRingFt          maxCount;\
    40   lastRingFt              last;\
    41   firstRingFt             first;\
    42   pushSmallArrayFt        send;\
    43   dequeueSmallArrayFt     recv;\
    44   getFromRingFt           getFrom;\
    45   /* TODO getHead, ring get should work like staticArrayRef */\
    46   /* saved parent class functions */\
    47   isEmptySmallArrayFt     parentIsEmpty;\
    48   pushSmallArrayFt        parentPush;\
    49   popSmallArrayFt         parentPop;\
    50   prependSmallArrayFt     parentPrepend;\
    51   dequeueSmallArrayFt     parentDequeue\
    52   /* TODO fromSmallArray */\
    53   /* TODO create container */
    54 
    55 typedef struct {
    56   freeRingFt      free;
    57   terminateRingFt terminate;
    58   toStringRingFt  toString;
    59   duplicateRingFt duplicate;
    60   smashRingFt     smash;
    61   finishRingFt    finish;
    62 
    63   RINGFUNCTIONST;
    64 } ringFunctionst;
    65 
    66 /**
    67  * class
    68  */
    69 struct ring {
    70   const char               *type;
    71   ringFunctionst *f;
    72 
    73   // internal
    74   sArrayt *a;
    75   i64 last;
    76   i64 head;
    77   bool isEmpty;
    78 };
    79 
    80 // ring
    81 
    82 #define createRing(obj) ringt obj; initiateRing(&obj)
    83 #define createAllocateRing(obj) ringt *obj; initiateAllocateRing(&obj)
    84 
    85 void initiateRing(ringt *self);
    86 void initiateAllocateRing(ringt **self);
    87 void finalizeRing(void);
    88 
    89 ringt* allocRing(/*INIT DATA */);
    90 
    91 // Generics
    92 #define setSizeO(self, size) (self)->f->setSize(self, size)
    93 #define setSizeG setSizeO
    94 
    95 #define isFullO(self) (self)->f->isFull(self)
    96 #define isFullG isFullO
    97 
    98 #define rCountO(self) (self)->f->count(self)
    99 #define rCountG rCountO
   100 
   101 #define maxCountO(self) (self)->f->maxCount(self)
   102 #define maxCountG maxCountO
   103 
   104 #define lastO(self) (self)->f->last(self)
   105 #define lastG lastO
   106 
   107 #define firstO(self) (self)->f->first(self)
   108 #define firstG firstO
   109 
   110 // end class ring
   111 
   112 #define isRingCompiledWithCurrentLisheepyVersion checkLibsheepyVersionRing(LIBSHEEPY_VERSION)
   113 bool checkLibsheepyVersionRing(const char *currentLibsheepyVersion);