Annotation of parser3/src/main/pa_array.C, revision 1.1

1.1     ! paf         1: /*
        !             2:   $Id: pa_Array.C,v 1.9 2001/01/27 13:09:45 paf Exp $
        !             3: */
        !             4: 
        !             5: #include <string.h>
        !             6: 
        !             7: #include "pa_pool.h"
        !             8: 
        !             9: void *Array::operator new(size_t size, Pool *apool) {
        !            10:        return apool->malloc(size);
        !            11: }
        !            12: 
        !            13: void Array::construct(Pool *apool, int initial_rows) {
        !            14:        pool=apool;
        !            15:        curr_chunk_rows=initial_rows;
        !            16:        head=static_cast<Chunk *>(
        !            17:                pool->malloc(sizeof(int)+sizeof(Chunk::Row)*curr_chunk_rows+sizeof(Chunk *)));
        !            18:        append_here=head->rows;
        !            19:        link_row=&head->rows[curr_chunk_rows];
        !            20:        link_row->link=0;
        !            21:        fused_rows=0;
        !            22: }
        !            23: 
        !            24: void Array::expand() {
        !            25:        curr_chunk_rows+=curr_chunk_rows*CR_GROW_PERCENT/100;
        !            26:        Chunk *chunk=static_cast<Chunk *>(
        !            27:                pool->malloc(sizeof(int)+sizeof(Chunk::Row)*curr_chunk_rows+sizeof(Chunk *)));
        !            28:        chunk->count=curr_chunk_rows;
        !            29:        link_row->link=chunk;
        !            30:        append_here=chunk->rows;
        !            31:        link_row=&chunk->rows[curr_chunk_rows];
        !            32:        link_row->link=0;
        !            33: }
        !            34: 
        !            35: 
        !            36: Array& Array::operator += (Item src) {
        !            37:        if(chunk_is_full())
        !            38:                expand();
        !            39: 
        !            40:        append_here->item=src;
        !            41:        append_here++; fused_rows++;
        !            42: 
        !            43:        return *this;
        !            44: }
        !            45: 
        !            46: /*
        !            47: char *Array::c_str() {
        !            48:        char *result=static_cast<char *>(pool->malloc(size()+1));
        !            49: 
        !            50:        char *copy_here=result;
        !            51:        Chunk *chunk=&head; 
        !            52:        do {
        !            53:                Chunk::Row *row=chunk->rows;
        !            54:                for(int i=0; i<chunk->count; i++) {
        !            55:                        if(row==append_here)
        !            56:                                goto break2;
        !            57: 
        !            58:                        memcpy(copy_here, row->item.ptr, row->item.size);
        !            59:                        copy_here+=row->item.size;
        !            60:                        row++;
        !            61:                }
        !            62:                chunk=row->link;
        !            63:        } while(chunk);
        !            64: break2:
        !            65:        *copy_here=0;
        !            66:        return result;
        !            67: }
        !            68: */

E-mail: