pike.git / lib / modules / ADT.pmod / Table.pmod

version» Context lines:

pike.git/lib/modules/ADT.pmod/Table.pmod:1:   // Table.pmod by Fredrik Noring, 1998 - // $Id: Table.pmod,v 1.28 2004/09/25 02:51:20 nilsson Exp $ + // $Id: Table.pmod,v 1.29 2008/06/28 16:36:53 nilsson Exp $      #pike __REAL_VERSION__   #define TABLE_ERR(msg) error("(Table) "+msg+"\n")      //! ADT.Table is a generic module for manipulating tables.   //!   //! Each table contains one or several columns.   //! Each column is associated with a name, the column name.   //! Optionally, one can provide a column type. The Table module can do a number   //! of operations on a given table, like computing the sum of a column,   //! grouping, sorting etc.   //!   //! All column references are case insensitive. A column can be referred to by   //! its position (starting from zero). All operations are non-destructive. That   //! means that a new table object will be returned after, for example, a sort.      //! The table base-class.   class table { -  static private mapping fieldmap; -  static private array table, fields, types; +  protected private mapping fieldmap; +  protected private array table, fields, types;    -  static private array|int remap(array|string|int cs, int|void forgive) +  protected private array|int remap(array|string|int cs, int|void forgive)    {    array v = ({});    int ap = arrayp(cs);    if(!ap) cs = ({ cs });    foreach(cs, string|int f)    if(zero_type(intp(f)?f:fieldmap[lower_case(f)])) {    if(!forgive)    TABLE_ERR("Unknown field '"+f+"'");    } else    v += ({ intp(f)?f:fieldmap[lower_case(f)] });
pike.git/lib/modules/ADT.pmod/Table.pmod:137:    object append_right(object table)    {    if(sizeof(table) != sizeof(this_program::table))    TABLE_ERR("Table sizes are not equal.");    array v = values(table);    for(int r = 0; r < sizeof(this_program::table); r++)    v[r] = this_program::table[r] + v[r];    return copy(v, fields+indices(table), types+table->all_types());    }    -  static private mixed op_col(function f, int|string c, mixed ... args) +  protected private mixed op_col(function f, int|string c, mixed ... args)    {    c = remap(c);    mixed x = table[0][c];    for(int r = 1; r < sizeof(table); r++)    f(x, table[r][c], @args);    return x;    }       mixed sum_col(int|string c)    {
pike.git/lib/modules/ADT.pmod/Table.pmod:273:    if(arrayp(v))    for(int i = 0; i < sizeof(v); i++)    t[r][columns[i]] = v[i];    else    t[r][columns[0]] = v;    }    }    return copy(t, fields, types);    }    -  static private this_program _sort(int is_reversed, int|string ... cs) +  protected private this_program _sort(int is_reversed, int|string ... cs)    {    if(!sizeof(cs))    return this;    int c;    array t = copy_value(table);    if(!catch(c = remap(cs[-1])))    {    mapping m = ([]);    for(int r = 0; r < sizeof(t); r++)    {
pike.git/lib/modules/ADT.pmod/Table.pmod:411:    types[i] = copy_value(column_types[i]);    else    TABLE_ERR("Field type not mapping");       array(int) a = indices(allocate(sizeof(fields)));    fieldmap = mkmapping(Array.map(fields, lower_case), a);    }   }      object Separated = class { -  static private string _string(mixed x) { return (string)x; } +  protected private string _string(mixed x) { return (string)x; }       object decode(string s, void|mapping options)    {    string rowsep = options->rowsep||"\n";    string colsep = options->colsep||"\t";    array t = Array.map(s/rowsep, `/, colsep);    return table(t[1..], t[0], options->types);    }       mixed encode(object t, void|mapping options)