Annotation of parser3/src/classes/table.C, revision 1.1

1.1     ! paf         1: /*
        !             2:        Parser
        !             3:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
        !             4:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
        !             5: 
        !             6:        $Id: table.C,v 1.7 2001/03/12 09:08:46 paf Exp $
        !             7: */
        !             8: 
        !             9: #include "pa_request.h"
        !            10: #include "_table.h"
        !            11: #include "pa_vtable.h"
        !            12: 
        !            13: // global var
        !            14: 
        !            15: VClass *table_class;
        !            16: 
        !            17: // methods
        !            18: 
        !            19: 
        !            20: // TODO: проверить ^set в ^menu & co
        !            21: 
        !            22: static void _set(Request& r, const String& method_name, Array *params) {
        !            23:        Pool& pool=r.pool();
        !            24:        // data is last parameter
        !            25:        Value *vdata=static_cast<Value *>(params->get(params->size()-1));
        !            26:        if(vdata->get_junction())
        !            27:                R_THROW(0, 0,
        !            28:                        &method_name,
        !            29:                        "body must not be a junction");
        !            30: 
        !            31:        // data string
        !            32:        char *data=vdata->as_string().cstr();
        !            33: 
        !            34:        // parse columns
        !            35:        Array *columns;
        !            36: #ifndef NO_STRING_ORIGIN
        !            37:        const Origin& origin=method_name.origin();
        !            38:        const char *file=0;//origin.file;
        !            39:        uint line=origin.line;
        !            40: #endif
        !            41:        if(params->size()==2) {
        !            42:                columns=0;
        !            43:        } else {
        !            44:                columns=new(pool) Array(pool);
        !            45: 
        !            46:                if(char *row_chars=getrow(&data)) 
        !            47:                        do {
        !            48:                                String *name=new(pool) String(pool);
        !            49:                                name->APPEND(lsplit(&row_chars, '\t'), 0, file, line++);
        !            50:                                *columns+=name;
        !            51:                        } while(row_chars);
        !            52:        }
        !            53: 
        !            54:        // parse cells
        !            55:        Table& table=*new(pool) Table(pool, method_name, columns);
        !            56:        char *row_chars;
        !            57:        while(row_chars=getrow(&data)) {
        !            58:                Array *row=new(pool) Array(pool);
        !            59:                while(char *cell_chars=lsplit(&row_chars, '\t')) {
        !            60:                        String *cell=new(pool) String(pool);
        !            61:                        cell->APPEND(cell_chars, 0, file, line);
        !            62:                        *row+=cell;
        !            63:                }
        !            64:                line++;
        !            65:                table+=row;
        !            66:        };
        !            67: 
        !            68:        // replace any previous table value
        !            69:        r.self->as_vtable().set_table(table);
        !            70: }
        !            71: 
        !            72: void initialize_table_class(Pool& pool, VClass& vclass) {
        !            73:        // ^table.create[data]  ^table.create[nameless;data]
        !            74:        vclass.add_native_method("set", _set, 1, 2);
        !            75: }      

E-mail: