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$ +       #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,
pike.git/lib/modules/ADT.pmod/Table.pmod:20:   class table {    protected private mapping fieldmap;    protected private array table, fields, types;       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(undefinedp(intp(f)?f:fieldmap[lower_case(f)])) {    if(!forgive)    TABLE_ERR("Unknown field '"+f+"'");    } else    v += ({ intp(f)?f:fieldmap[lower_case(f)] });    return ap?v:v[0];    }       this_program copy(array|void tab, array|void fie, array|void typ)    {    return this_program(tab||table,fie||fields,typ||types);
pike.git/lib/modules/ADT.pmod/Table.pmod:48:    }       //! This method returns a table object from a binary string    //! representation of a table, as returned by @[encode()].    object decode(string s)    {    mapping m = decode_value(s);    return copy(m->table, m->fields, m->types);    }    -  mixed cast(string type) +  protected mixed cast(string type)    {    switch(type) {    case "array":    return copy_value(table);    case "string":    return ASCII->encode(this);    } -  +  return UNDEFINED;    }       //! This method returns the column names for the table. The case used when    //! the table was created will be returned.    array(string) _indices()    {    return copy_value(fields);    }       //! This method returns the contents of a table as a two dimensional array.
pike.git/lib/modules/ADT.pmod/Table.pmod:110:    return col(column);    }       //! This method compares two tables. They are equal if the contents    //! of the tables and the column names are equal. The column name    //! comparison is case insensitive.    int `==(object table)    {    return (equal(Array.map(fields, lower_case),    Array.map(indices(table), lower_case)) && -  equal(this_program::table, values(table))); +  equal(this::table, values(table)));    }       //! This method appends two tables. The table given as an argument will be    //! added at the bottom of the current table. Note, the column names must    //! be equal. The column name comparison is case insensitive.    object append_bottom(object table)    {    if(!equal(Array.map(indices(table), lower_case),    Array.map(fields, lower_case)))    TABLE_ERR("Table fields are not equal."); -  return copy(this_program::table+values(table), fields, types); +  return copy(this::table+values(table), fields, types);    }       //! This method appends two tables. The table given as an argument will be    //! added on the right side of the current table. Note that the number of    //! rows in both tables must be equal.    object append_right(object table)    { -  if(sizeof(table) != sizeof(this_program::table)) +  if(sizeof(table) != sizeof(this::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]; +  for(int r = 0; r < sizeof(this::table); r++) +  v[r] = this::table[r] + v[r];    return copy(v, fields+indices(table), types+table->all_types());    }       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;
pike.git/lib/modules/ADT.pmod/Table.pmod:394:    if(!arrayp(table))    TABLE_ERR("Table not array");    if(!arrayp(column_names))    TABLE_ERR("Fields not array");    if(sizeof(table) && sizeof(table[0]) != sizeof(column_names))    TABLE_ERR("Table and field sizes differ");    foreach(column_names, string s)    if(!stringp(s))    TABLE_ERR("Field name not string");    -  this_program::table = copy_value(table); +  this::table = copy_value(table);    fields = copy_value(column_names);    types = allocate(sizeof(column_names));       if(column_types)    for(int i = 0; i < sizeof(fields); i++)    if(!column_types[i] || mappingp(column_types[i]))    types[i] = copy_value(column_types[i]);    else    TABLE_ERR("Field type not mapping");