LexatomLoader (9307B)
1 /* -*- C++ -*- vim: set syntax=cpp: */ 2 #ifndef __QUEX_INCLUDE_GUARD__BUFFER__LEXATOMS__LEXATOM_LOADER 3 #define __QUEX_INCLUDE_GUARD__BUFFER__LEXATOMS__LEXATOM_LOADER 4 5 #include "definitions" 6 #include "bufferBuffer" 7 #include "ByteLoader" 8 9 QUEX_NAMESPACE_MAIN_OPEN 10 11 struct QUEX_NAME(Converter_tag); 12 struct QUEX_NAME(Buffer_tag); 13 14 typedef struct QUEX_SETTING_USER_CLASS_DECLARATION_EPILOG QUEX_NAME(LexatomLoader_tag) { 15 /* This is the interface that the buffer sees of the buffer filler. Its 16 * task is to coordinate the filling of buffer content from a stream in the 17 * background. Some fillers may convert lexatoms or filter. All fillers 18 * must provide functions for the following pointers. The pointers are set 19 * with the function 20 * 21 * LexatomLoader_setup(...) 22 * 23 * which shall be called in any '_construct' function of a filler. Note, 24 * that filler types shall inherit this class. This means, that the first 25 * element of the derived struct is to be of this type and best called 26 * 'base'. For example, please, consider the 'plain' and 'iconv' 27 * implementations in the correspondent sub directories. */ 28 E_Ownership ownership; 29 30 QUEX_NAME(ByteLoader)* byte_loader; 31 32 /* -- 'Tell': Character index of the next lexatom to be loaded into 33 * the buffer, when 'derived.load()' is called. 34 * */ 35 QUEX_TYPE_STREAM_POSITION 36 (*input_lexatom_tell)(struct QUEX_NAME(LexatomLoader_tag)*); 37 38 /* -- 'Seek': Sets the lexatom index of the next lexatom to be loaded 39 * into the buffer, when 'derived.load()' is 40 * called. 41 * */ 42 bool (*input_lexatom_seek)(struct QUEX_NAME(LexatomLoader_tag)*, 43 const QUEX_TYPE_STREAM_POSITION Index); 44 45 /* -- 'Stomach Byte Number': is the number of bytes that have been read 46 * from the stream but not yet converted. 47 * */ 48 ptrdiff_t (*stomach_byte_n)(struct QUEX_NAME(LexatomLoader_tag)*); 49 50 /* -- 'Clear': Undo any internal state-dependency. Conversion or what- 51 * soever starts from a clean page. 52 * */ 53 void (*stomach_clear)(struct QUEX_NAME(LexatomLoader_tag)*); 54 55 /* -- 'Delete Operator': There are derived 'classes' from this one. User 56 * only stores a pointer to LexatomLoader, and requires a 57 * way to delete the whole object. 58 * */ 59 void (*delete_self)(struct QUEX_NAME(LexatomLoader_tag)*); 60 61 62 /* -- byte order (i.e little- vs. big-endian) reversion: enable/disable 63 * the reversion of byte order. 64 * */ 65 bool _byte_order_reversion_active_f; 66 67 QUEX_TYPE_STREAM_POSITION lexatom_index_next_to_fill; 68 69 /* Byte number per lexatom. If != -1 => there is a linear relationship 70 * between lexatom position and lexatom 71 * index. */ 72 ptrdiff_t byte_n_per_lexatom; 73 74 struct { 75 /* PASSIVE API: Lexical analyzer requests LexatomLoader to fill its 76 * buffer. */ 77 78 /* -- 'Read' reads N lexatoms from a stream into a buffer 79 * (independent of their size) */ 80 size_t (*load_lexatoms)(struct QUEX_NAME(LexatomLoader_tag)*, 81 QUEX_TYPE_LEXATOM* memory, 82 const size_t N, 83 bool* end_of_stream_f, 84 bool* encoding_error_f); 85 86 /* ACTIVE: User fills the buffer manually 87 * 88 * To be implemented by the derived class ... */ 89 void (*fill_prepare)(struct QUEX_NAME(LexatomLoader_tag)* me, 90 QUEX_NAME(Buffer)* buffer, 91 void** begin_p, 92 const void** end_p); 93 ptrdiff_t (*fill_finish)(struct QUEX_NAME(LexatomLoader_tag)* me, 94 QUEX_TYPE_LEXATOM* BeginP, 95 const QUEX_TYPE_LEXATOM* EndP, 96 const void* FilledEndP); 97 void (*get_fill_boundaries)(struct QUEX_NAME(LexatomLoader_tag)* alter_ego, 98 QUEX_NAME(Buffer)* buffer, 99 void** begin_p, 100 const void** end_p); 101 102 /* destruct_self: Free resources occupied by 'me' BUT NOT 'myself'. 103 * delete_self: Free resources occupied by 'me' AND 'myself'. */ 104 void (*destruct_self)(struct QUEX_NAME(LexatomLoader_tag)*); 105 } derived; 106 } QUEX_NAME(LexatomLoader); 107 108 QUEX_INLINE QUEX_NAME(LexatomLoader)* 109 QUEX_NAME(LexatomLoader_new)(QUEX_NAME(ByteLoader)* byte_loader, 110 struct QUEX_NAME(Converter_tag)* converter, 111 const size_t TranslationBufferMemorySize); 112 113 QUEX_INLINE QUEX_NAME(LexatomLoader)* 114 QUEX_NAME(LexatomLoader_new_DEFAULT)(QUEX_NAME(ByteLoader)* byte_loader, 115 const char* InputCodecName); 116 117 QUEX_INLINE void 118 QUEX_NAME(LexatomLoader_setup)(QUEX_NAME(LexatomLoader)* me, 119 size_t (*load_lexatoms)(QUEX_NAME(LexatomLoader)*, 120 QUEX_TYPE_LEXATOM*, 121 const size_t, bool*, bool*), 122 ptrdiff_t (*stomach_byte_n)(QUEX_NAME(LexatomLoader)*), 123 void (*stomach_clear)(QUEX_NAME(LexatomLoader)*), 124 void (*destruct_self)(QUEX_NAME(LexatomLoader)*), 125 void (*derived_fill_prepare)(QUEX_NAME(LexatomLoader)* me, 126 QUEX_NAME(Buffer)* buffer, 127 void** begin_p, 128 const void** end_p), 129 ptrdiff_t (*derived_fill_finish)(QUEX_NAME(LexatomLoader)* me, 130 QUEX_TYPE_LEXATOM* BeginP, 131 const QUEX_TYPE_LEXATOM* EndP, 132 const void* FilledEndP), 133 void (*derived_get_fill_boundaries)(QUEX_NAME(LexatomLoader)* alter_ego, 134 QUEX_NAME(Buffer)* buffer, 135 void** begin_p, 136 const void** end_p), 137 QUEX_NAME(ByteLoader)* byte_loader, 138 ptrdiff_t ByteNPerCharacter); 139 140 QUEX_INLINE ptrdiff_t 141 QUEX_NAME(LexatomLoader_load)(QUEX_NAME(LexatomLoader)* me, 142 QUEX_TYPE_LEXATOM* RegionBeginP, 143 const ptrdiff_t Size, 144 QUEX_TYPE_STREAM_POSITION CharacterIndexBegin, 145 bool* end_of_stream_f, 146 bool* encoding_error_f); 147 148 QUEX_INLINE void 149 QUEX_NAME(LexatomLoader_reset)(QUEX_NAME(LexatomLoader)* me, 150 QUEX_NAME(ByteLoader)* new_byte_loader); 151 152 QUEX_INLINE void 153 QUEX_NAME(LexatomLoader_lexatom_index_reset)(QUEX_NAME(LexatomLoader)* me); 154 155 QUEX_NAMESPACE_MAIN_CLOSE 156 157 #include "LexatomLoader_Converter" 158 #include "LexatomLoader_Plain" 159 160 #endif /* __QUEX_INCLUDE_GUARD__BUFFER__BUFFERFILLER */