Changeset 103 for trunk/src


Ignore:
Timestamp:
Apr 16, 2008, 12:32:45 PM (11 years ago)
Author:
cameron
Message:

X8_Buffer<C> to unify 8-bit byteplex classes for ASCII and EBCDIC families.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/byteplex.c

    r100 r103  
    2121const int SENTINEL_PACKS = 1;
    2222
    23 template <CodeUnit_Base C>
    24 XML_Buffer<C>::XML_Buffer()
    25         : Byteplex() {
     23
     24
     25template <CodeUnit_Base C>
     26X8_Buffer<C>::X8_Buffer() : Byteplex() {
    2627        /* For 8-bit code units, the input buffer is a also used directly
    2728           as the pseudo-ASCII buffer; make sure that there is room for
    2829           sentinels. */
    2930        src_buffer = simd_new(BYTEPLEX_SIZE/PACKSIZE+SENTINEL_PACKS);
    30 }
    31 template <CodeUnit_Base C>
    32 XML_Buffer<C>::~XML_Buffer() {
    33   simd_delete((SIMD_type *) src_buffer);
    34 }
    35 
    36 Extended_ASCII_8_Buffer::Extended_ASCII_8_Buffer()
    37         : XML_Buffer<ASCII>() {
    3831        x8data = src_buffer;
    3932        // Set the sentinel for ScanToQuote,ScanWS in reading XML/text decls.
    40         ((unsigned char *) x8data)[BYTEPLEX_SIZE] = '"';
    41 }
    42 
    43 EBCDIC_Buffer::EBCDIC_Buffer()
    44         : XML_Buffer<EBCDIC>() {
    45         x8data = src_buffer;
    46         // Set the sentinel for ScanToQuote,ScanWS in reading XML/text decls.
    47         ((unsigned char *) x8data)[BYTEPLEX_SIZE] = '"';
     33        ((unsigned char *) x8data)[BYTEPLEX_SIZE] = Ord<C, '"'>::value;
     34}
     35
     36
     37template <CodeUnit_Base C>
     38X8_Buffer<C>::~X8_Buffer() {
     39  simd_delete((SIMD_type *) src_buffer);
    4840}
    4941
    5042U16_Buffer::U16_Buffer()
    51         : XML_Buffer<ASCII>() {
     43        : Byteplex() {
    5244
    5345        src_buffer = simd_new((BYTEPLEX_SIZE/PACKSIZE)*2);
     
    7567
    7668U32_Buffer::U32_Buffer()
    77         : XML_Buffer<ASCII>() {
     69        : Byteplex() {
    7870
    7971        src_buffer = simd_new((BYTEPLEX_SIZE/PACKSIZE)*4);
     
    120112*/
    121113
    122 void Extended_ASCII_8_Buffer::DoByteplex() {
    123         x8data = src_buffer;
    124 }
    125 
    126 void EBCDIC_Buffer::DoByteplex() {
     114template <CodeUnit_Base C>
     115void X8_Buffer<C>::DoByteplex() {
    127116        x8data = src_buffer;
    128117}
     
    204193/* Pseudo-ASCII stream methods */
    205194
    206 void Extended_ASCII_8_Buffer::PreparePseudoASCII_Stream() {
    207         x8data = src_buffer;
    208 }
    209 
    210 void EBCDIC_Buffer::PreparePseudoASCII_Stream() {
     195template <CodeUnit_Base C>
     196void X8_Buffer<C>::PreparePseudoASCII_Stream() {
    211197        x8data = src_buffer;
    212198}
     
    229215}
    230216
    231 template <CodeUnit_Base C>
    232 int XML_Buffer<C>::CopyAndFill(unsigned char * bytes_to_copy, int lgth, int bytes_to_read) {
     217
     218int Byteplex::CopyAndFill(unsigned char * bytes_to_copy, int lgth, int bytes_to_read) {
    233219        memcpy(src_buffer, bytes_to_copy, lgth);
    234220        int bytes_read = fread(&((unsigned char *)src_buffer)[lgth], 1, bytes_to_read, infile);
     
    242228}
    243229
    244 void Extended_ASCII_8_Buffer::InitializeBuffer(unsigned char * src, int lgth){ 
    245         int byte_advance = BYTEPLEX_SIZE - lgth;       
    246         int bytes_read = CopyAndFill(src, lgth, byte_advance);
    247         Set_limits(bytes_read + lgth);
    248 }
    249 
    250 void EBCDIC_Buffer::InitializeBuffer(unsigned char * src, int lgth){
     230template <CodeUnit_Base C>
     231void X8_Buffer<C>::InitializeBuffer(unsigned char * src, int lgth){     
    251232        int byte_advance = BYTEPLEX_SIZE - lgth;       
    252233        int bytes_read = CopyAndFill(src, lgth, byte_advance);
     
    276257
    277258
    278 
    279 void Extended_ASCII_8_Buffer::AdvanceInputBuffer(int advance_amt){     
    280         int bytes_to_keep = units_in_buffer - advance_amt;     
    281         int bytes_read = CopyAndFill(&((unsigned char *)src_buffer)[advance_amt],
    282                                         bytes_to_keep, advance_amt);
    283         Set_limits(bytes_read + bytes_to_keep);
    284 }
    285 
    286 void EBCDIC_Buffer::AdvanceInputBuffer(int advance_amt){       
     259template <CodeUnit_Base C>
     260void X8_Buffer<C>::AdvanceInputBuffer(int advance_amt){
    287261        int bytes_to_keep = units_in_buffer - advance_amt;     
    288262        int bytes_read = CopyAndFill(&((unsigned char *)src_buffer)[advance_amt],
     
    317291        if (likely(e->code_unit_size == SingleByte)) {
    318292                if (likely(e->code_unit_base == ASCII))
    319                         b = new Extended_ASCII_8_Buffer();
    320                 else b = new EBCDIC_Buffer();
     293                        b = new X8_Buffer<ASCII>();
     294                else b = new X8_Buffer<EBCDIC>();
    321295        }
    322296        else if (likely(e->code_unit_size == DoubleByte)) {
  • trunk/src/byteplex.h

    r100 r103  
    9191        FILE * infile;
    9292        int packs_in_buffer;
     93        int CopyAndFill(unsigned char * bytes_to_copy, int lgth, int bytes_to_read);
    9394        void Set_limits(int units_in_buffer);
    9495
    9596};
    9697
     98
     99/*  The X8_Buffer template class is used for either ASCII- or EBCDIC-
     100    based 8-bit code units.
     101    The X8_Buffer<ASCII> class includes 7-bit ASCII
     102    (with high-order bit 0), the ISO-8859 character sets and UTF-8.
     103
     104    The family of 8-bit EBCDIC based character sets are processed using
     105    the X8_Buffer<EBCDIC> class.
     106*/
     107
    97108template <CodeUnit_Base C>
    98 class XML_Buffer : public Byteplex {
     109class X8_Buffer : public Byteplex {
    99110public:
    100         XML_Buffer ();
    101         ~XML_Buffer();
     111        X8_Buffer();
     112        ~X8_Buffer();
    102113       
    103         virtual void DoByteplex() = 0;
    104         virtual void PreparePseudoASCII_Stream() = 0;
    105         virtual void AdvanceInputBuffer(int advance_amt) = 0;
    106         virtual void InitializeBuffer(unsigned char * src, int lgth) = 0;
    107 protected:
    108         int CopyAndFill(unsigned char * bytes_to_copy, int lgth, int bytes_to_read);
    109 };
    110 
    111 
    112 /*  Various ASCII based character sets using 8-bit code units are processed
    113     using the Extended_ASCII_8_Buffer class.   This includes 7-bit ASCII
    114     itself (with high-order bit 0), the ISO-8859 character sets and UTF-8.
    115 */
    116 class Extended_ASCII_8_Buffer : public XML_Buffer<ASCII> {
    117 public:
    118         Extended_ASCII_8_Buffer();
    119         void DoByteplex();
    120         void PreparePseudoASCII_Stream();
    121         void AdvanceInputBuffer(int advance_amt);
    122         void InitializeBuffer(unsigned char * src, int lgth);
    123 };
    124 
    125 /*  The family of 8-bit EBCDIC based character sets are processed using
    126     the EBCDIC_Buffer class.
    127 */
    128 class EBCDIC_Buffer : public XML_Buffer<EBCDIC> {
    129 public:
    130         EBCDIC_Buffer();
    131114        void DoByteplex();
    132115        void PreparePseudoASCII_Stream();
     
    136119
    137120
    138 
    139 /*  UTF-16 and UCS-4 character set families in BE and LE byte orders.
     121/*  UTF-16 and UCS-2 character set families in BE and LE byte orders.
    140122    The U16LE and U16BE subclasses each provide a distinct byteplexer to
    141123    produce 2 parallel byte streams for the high and low bytes of each
     
    143125    conversion routine can be applied at the U16_Buffer level. */
    144126
    145 class U16_Buffer : public XML_Buffer<ASCII> {
     127class U16_Buffer : public Byteplex {
    146128public:
    147129        U16_Buffer();
     
    174156    byteplexing is complete, a generic pseudoASCII routine can
    175157    be applied. */
    176 class U32_Buffer : public XML_Buffer<ASCII> {
     158class U32_Buffer : public Byteplex {
    177159public:
    178160        U32_Buffer();
Note: See TracChangeset for help on using the changeset viewer.