sheepy

build system (sheepy) and package manager (spm) for C
git clone https://spartatek.se/git/sheepy.git
Log | Files | Refs | README | LICENSE

ByteLoader (5191B)


      1 /* vim: set ft=c: 
      2  * (C) Frank-Rene Schaefer */
      3 #ifndef  __QUEX_INCLUDE_GUARD__BUFFER__BYTES__BYTE_LOADER
      4 #define  __QUEX_INCLUDE_GUARD__BUFFER__BYTES__BYTE_LOADER
      5 
      6 #include "definitions"
      7 #include "MemoryManager"
      8 
      9 QUEX_NAMESPACE_MAIN_OPEN
     10 
     11 typedef struct QUEX_SETTING_USER_CLASS_DECLARATION_EPILOG QUEX_NAME(ByteLoader_tag) {
     12     QUEX_TYPE_STREAM_POSITION (*tell)(struct QUEX_NAME(ByteLoader_tag)* me);
     13     void                      (*seek)(struct QUEX_NAME(ByteLoader_tag)* me, 
     14                                       QUEX_TYPE_STREAM_POSITION Pos);
     15     size_t                    (*load)(struct QUEX_NAME(ByteLoader_tag)*, 
     16                                       void*, const size_t,
     17                                       bool*  end_of_stream_f);
     18     void                      (*delete_self)(struct QUEX_NAME(ByteLoader_tag)*);
     19 
     20     /* .compare_handle(A, B):
     21      *
     22      * Quex checks whether A and B are of the same class (comparing the
     23      * function pointer '.load'). The derived class can safely cast both
     24      * to its pointer type.
     25      *
     26      * Upon reset, the the new input handle might be the same as the old one.
     27      * Such a usage is against the design of the reset functions! To detect
     28      * these situations, the byte loader provides '.compare_handle()'.
     29      *
     30      * In case of doubt, return always 'false'. The only disadvantage is that
     31      * if the user makes the aforementioned error, he will not get a nice hint
     32      * upon crash.                                                           
     33      *
     34      * ByteLoader_FILE, ByteLoader_stream, and ByteLoader_POSIX implement the
     35      * function propperly.                                                   */
     36     bool  (*compare_handle)(const struct QUEX_NAME(ByteLoader_tag)* A, 
     37                             const struct QUEX_NAME(ByteLoader_tag)* B);
     38 
     39     /* .on_nothing(...)
     40      * 
     41      * When '.load' cannot provide anymore data, customized actions may be 
     42      * performed. 
     43      *
     44      * -- If '.on_nothing' is not defined, '.load' returns zero and the
     45      *    caller must assume that the stream terminated. 
     46      * -- Else, the user defined '.no_nothing()' function is called. If it
     47      *    returns 'true', '.load' tries again to load data. Else, '.load()'
     48      *    returns with zero. Then, the caller, again, must assume that the
     49      *    end of stream has been reached.                                    */
     50     bool  (*on_nothing)(struct QUEX_NAME(ByteLoader_tag)*, size_t TryN, size_t RequestN);
     51 
     52     E_Ownership  handle_ownership;
     53     E_Ownership  ownership;
     54 
     55     /* Upon construction, the stream handle may be setup to a particular 
     56      * position in the stream. This is going to be the reference position.   
     57      * The consideration of offsets is handled in this base class' functions.
     58      * The derived class does not need to know about an initial offset.      */
     59     QUEX_TYPE_STREAM_POSITION initial_position;
     60 
     61     /* It is crucial for 'seeking' in the stream whether the stream is in 
     62      * binary mode or not. If not, then character/byte number is not const.  */
     63     bool                      binary_mode_f;      /* In doubt, say 'false'.  */
     64 
     65     struct {
     66         QUEX_TYPE_STREAM_POSITION (*tell)(struct QUEX_NAME(ByteLoader_tag)*);
     67         void                      (*seek)(struct QUEX_NAME(ByteLoader_tag)*, 
     68                                           QUEX_TYPE_STREAM_POSITION);
     69         size_t                    (*load)(struct QUEX_NAME(ByteLoader_tag)*, void*, const size_t, 
     70                                           bool*);
     71     } derived;
     72 } QUEX_NAME(ByteLoader);
     73 
     74 QUEX_INLINE void  QUEX_NAME(ByteLoader_construct)(QUEX_NAME(ByteLoader)*                me, 
     75                                        QUEX_TYPE_STREAM_POSITION  (*tell)(QUEX_NAME(ByteLoader)* me),
     76                                        void                       (*seek)(QUEX_NAME(ByteLoader)* me, QUEX_TYPE_STREAM_POSITION Pos),
     77                                        size_t                     (*load)(QUEX_NAME(ByteLoader)*, void*, const size_t, bool*),
     78                                        void                       (*delete_self)(QUEX_NAME(ByteLoader)*),
     79                                        bool                       (*compare_handle)(const QUEX_NAME(ByteLoader)*, 
     80                                                                                     const QUEX_NAME(ByteLoader)*));
     81 QUEX_INLINE void  QUEX_NAME(ByteLoader_seek_disable)(QUEX_NAME(ByteLoader)* me);
     82 QUEX_INLINE bool  QUEX_NAME(ByteLoader_seek_is_enabled)(QUEX_NAME(ByteLoader)* me);
     83 QUEX_INLINE bool  QUEX_NAME(ByteLoader_is_equivalent)(const QUEX_NAME(ByteLoader)* A, 
     84                                                       const QUEX_NAME(ByteLoader)* B);
     85 QUEX_INLINE void  QUEX_NAME(ByteLoader_delete)(QUEX_NAME(ByteLoader)** me);
     86 
     87 QUEX_NAMESPACE_MAIN_CLOSE
     88 
     89 #include "ByteLoader_FILE"
     90 #include "ByteLoader_stream"
     91 #ifdef QUEX_OPTION_POSIX
     92 #   include <quex/code_base/buffer/bytes/ByteLoader_POSIX>    /* (tm) */
     93 #endif
     94 #if 0
     95 #   include <quex/code_base/buffer/bytes/ByteLoader_FreeRTOS> /* (tm) */
     96 #   include <quex/code_base/buffer/bytes/ByteLoader_PalmOS>   /* (tm) */
     97 #endif
     98 
     99 #endif /*  __QUEX_INCLUDE_GUARD__BUFFER__BYTES__BYTE_LOADER */