--- parser3/src/main/Attic/pa_array.C 2001/02/11 11:27:25 1.13 +++ parser3/src/main/Attic/pa_array.C 2003/02/21 10:36:25 1.54.2.4 @@ -1,108 +1,15 @@ -/* - $Id: pa_array.C,v 1.13 2001/02/11 11:27:25 paf Exp $ -*/ +/** @file + Parser: Array classe impl. -#include + Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexandr Petrosian (http://paf.design.ru) +*/ -#include "pa_pool.h" #include "pa_array.h" -#include "pa_exception.h" - -Array::Array(Pool& apool, int initial_rows) : - Pooled(apool) { - head=tail=static_cast( - pool.malloc(sizeof(int)+sizeof(Chunk::Row)*initial_rows+sizeof(Chunk *))); - head->count=initial_rows; - append_here=head->rows; - link_row=&head->rows[initial_rows]; - link_row->link=0; - fused_rows=0; - - cache_chunk_base=0; - cache_chunk=head; -} - -void Array::expand(int chunk_rows) { - Chunk *chunk=tail=static_cast( - pool.malloc(sizeof(int)+sizeof(Chunk::Row)*chunk_rows+sizeof(Chunk *))); - chunk->count=chunk_rows; - link_row->link=chunk; - append_here=chunk->rows; - link_row=&chunk->rows[chunk_rows]; - link_row->link=0; -} - - -Array& Array::operator += (const Item *src) { - if(chunk_is_full()) - expand(tail->count*CR_GROW_PERCENT/100); - - append_here->item=src; - append_here++; fused_rows++; - - return *this; -} - -const Array::Item *Array::get(int index) const { - if(!(index>=0 && index=cache_chunk_base && indexcount)) { - int count=cache_chunk->count; - cache_chunk_base+=count; - cache_chunk=cache_chunk->rows[count].link; - } - - return cache_chunk->rows[index-cache_chunk_base].item; -} - -Array& Array::append_array(const Array& src) { - int src_used_rows=src.fused_rows; - int last_chunk_rows_left=link_row-append_here; - - // our last chunk too small for src to fit? - if(src_used_rows>last_chunk_rows_left) { - // shrink last chunk to used rows - tail->count-=last_chunk_rows_left; - link_row=append_here; - - // append new src_used_rows-ed chunk - expand(src_used_rows); - } - - Chunk *src_chunk=src.head; - Chunk::Row *dest_rows=append_here; - int rows_left_to_copy=src_used_rows; - while(true) { - int src_count=src_chunk->count; - Chunk *next_chunk=src_chunk->rows[src_count].link; - if(next_chunk) { - // not last source chunk - // taking it all - memcpy(dest_rows, src_chunk->rows, sizeof(Chunk::Row)*src_count); - dest_rows+=src_count; - rows_left_to_copy-=src_count; - - src_chunk=next_chunk; - } else { - // the last source chunk - // taking only those rows of chunk that _left_to_copy - memcpy(dest_rows, src_chunk->rows, sizeof(Chunk::Row)*rows_left_to_copy); - break; - } - } - append_here+=src_used_rows; - fused_rows+=src_used_rows; +#include "pa_types.h" +#include "pa_common.h" - return *this; -} +char* Pool::format_integer(int value) { + char local[MAX_NUMBER]; + return copy(local, snprintf(local, MAX_NUMBER, "%d", value)+1/*for terminating 0*/); +};