--- parser3/src/main/pa_table.C 2001/03/12 13:13:21 1.13 +++ parser3/src/main/pa_table.C 2001/03/26 10:36:56 1.19 @@ -1,9 +1,11 @@ -/* - Parser +/** @file + Parser: table class. + Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexander Petrosyan (http://design.ru/paf) - $Id: pa_table.C,v 1.13 2001/03/12 13:13:21 paf Exp $ + $Id: pa_table.C,v 1.19 2001/03/26 10:36:56 paf Exp $ */ #include @@ -12,12 +14,12 @@ #include "pa_pool.h" Table::Table(Pool& apool, - const String& asource, + const String *aorigin_string, Array *acolumns, int initial_rows) : Array(apool, initial_rows), - fsource(asource), + forigin_string(aorigin_string), fcurrent(0), fcolumns(acolumns), name2number(pool(), false) { @@ -30,7 +32,7 @@ Table::Table(Pool& apool, } const Array &Table::at(int index) { - return *static_cast(get(index)); + return *const_cast(static_cast(get(index))); } const String *Table::item(const String& column_name) { @@ -54,3 +56,44 @@ const String *Table::item(const String& return item(column_index); } + +void Table::save(bool nameless_save, const String& file_spec) { + String sdata(pool()); + if(!nameless_save) { // not nameless=named output + // write out names line + if(fcolumns) { // named table + for(int column=0; columnsize(); column++) { + if(column) + sdata.APPEND_CONST("\t"); + sdata.append(*static_cast(fcolumns->quick_get(column)), + String::UL_TABLE); + } + } else { // nameless table + int lsize=size()?static_cast(get(0))->size():0; + if(lsize) + for(int column=0; column(quick_get(index)); + for(int column=0; columnsize(); column++) { + if(column) + sdata.APPEND_CONST("\t"); + sdata.append(*static_cast(row->quick_get(column)), + String::UL_TABLE); + } + sdata.APPEND_CONST("\n"); + } + + // write + char *cdata=sdata.cstr(); + file_write(pool(), file_spec, cdata, strlen(cdata), true); +} \ No newline at end of file