|
|
| version 1.39, 2001/03/29 20:53:02 | version 1.41, 2001/03/30 09:58:57 |
|---|---|
| Line 20 | Line 20 |
| VStateless_class *table_class; | VStateless_class *table_class; |
| // methods | // methods |
| /// @todo now remove CONFIG untaint, make pos() searches in String | |
| static void set_or_load( | static void set_or_load( |
| Request& r, | Request& r, |
| const String& method_name, Array *params, | const String& method_name, Array *params, |
| bool is_load) { | bool is_load) { |
| if(r.self==table_class) | |
| RTHROW(0, 0, | |
| &method_name, | |
| "method of 'table' is not static"); | |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| // data is last parameter | // data is last parameter |
| Value *vdata_or_filename=static_cast<Value *>(params->get(params->size()-1)); | Value *vdata_or_filename=static_cast<Value *>(params->get(params->size()-1)); |
| Line 92 static void set_or_load( | Line 87 static void set_or_load( |
| // replace any previous table value | // replace any previous table value |
| static_cast<VTable *>(r.self)->set_table(table); | static_cast<VTable *>(r.self)->set_table(table); |
| } | } |
| static void _set(Request& r, const String& method_name, Array *params) { | static void _set(Request& r, const String& method_name, Array *params) { |
| set_or_load(r, method_name, params, false); | set_or_load(r, method_name, params, false); |
| } | } |
| static void _load(Request& r, const String& method_name, Array *params) { | static void _load(Request& r, const String& method_name, Array *params) { |
| set_or_load(r, method_name, params, true); | set_or_load(r, method_name, params, true); |
| } | } |
| static void _save(Request& r, const String& method_name, Array *params) { | static void _save(Request& r, const String& method_name, Array *params) { |
| if(r.self==table_class) | |
| RTHROW(0, 0, | |
| &method_name, | |
| "method of 'table' is not static"); | |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Value *vtable_name=static_cast<Value *>(params->get(params->size()-1)); | Value *vtable_name=static_cast<Value *>(params->get(params->size()-1)); |
| // forcing | // forcing |
| Line 162 static void _save(Request& r, const Stri | Line 149 static void _save(Request& r, const Stri |
| } | } |
| static void _count(Request& r, const String&method_name, Array *) { | static void _count(Request& r, const String&method_name, Array *) { |
| if(r.self==table_class) | |
| RTHROW(0, 0, | |
| &method_name, | |
| "method of 'table' is not static"); | |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Value& value=*new(pool) VInt(pool, static_cast<VTable *>(r.self)->table().size()); | Value& value=*new(pool) VInt(pool, static_cast<VTable *>(r.self)->table().size()); |
| r.write_no_lang(value); | r.write_no_lang(value); |
| } | } |
| static void _line(Request& r, const String& method_name, Array *) { | static void _line(Request& r, const String& method_name, Array *) { |
| if(r.self==table_class) | |
| RTHROW(0, 0, | |
| &method_name, | |
| "method of 'table' is not static"); | |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Value& value=*new(pool) VInt(pool, 1+static_cast<VTable *>(r.self)->table().current()); | Value& value=*new(pool) VInt(pool, 1+static_cast<VTable *>(r.self)->table().current()); |
| r.write_no_lang(value); | r.write_no_lang(value); |
| } | } |
| static void _offset(Request& r, const String& method_name, Array *params) { | static void _offset(Request& r, const String& method_name, Array *params) { |
| if(r.self==table_class) | |
| RTHROW(0, 0, | |
| &method_name, | |
| "method of 'table' is not static"); | |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Table& table=static_cast<VTable *>(r.self)->table(); | Table& table=static_cast<VTable *>(r.self)->table(); |
| if(params->size()) | if(params->size()) |
| Line 200 static void _offset(Request& r, const St | Line 172 static void _offset(Request& r, const St |
| } | } |
| static void _menu(Request& r, const String& method_name, Array *params) { | static void _menu(Request& r, const String& method_name, Array *params) { |
| if(r.self==table_class) | |
| RTHROW(0, 0, | |
| &method_name, | |
| "method of 'table' is not static"); | |
| Value& body_code=*static_cast<Value *>(params->get(0)); | Value& body_code=*static_cast<Value *>(params->get(0)); |
| // forcing ^menu{this param type} | // forcing ^menu{this param type} |
| r.fail_if_junction_(false, body_code, | r.fail_if_junction_(false, body_code, |
| Line 231 static void _menu(Request& r, const Stri | Line 198 static void _menu(Request& r, const Stri |
| } | } |
| static void _empty(Request& r, const String& method_name, Array *params) { | static void _empty(Request& r, const String& method_name, Array *params) { |
| if(r.self==table_class) | |
| RTHROW(0, 0, | |
| &method_name, | |
| "method of 'table' is not static"); | |
| Table& table=static_cast<VTable *>(r.self)->table(); | Table& table=static_cast<VTable *>(r.self)->table(); |
| if(table.size()==0) { | if(table.size()==0) { |
| Value& value=r.process(*static_cast<Value *>(params->get(0))); | Value& value=r.process(*static_cast<Value *>(params->get(0))); |
| Line 263 static void store_column_item_to_hash(Ar | Line 225 static void store_column_item_to_hash(Ar |
| ri.hash->put(column_name, value); | ri.hash->put(column_name, value); |
| } | } |
| static void _record(Request& r, const String& method_name, Array *params) { | static void _record(Request& r, const String& method_name, Array *params) { |
| if(r.self==table_class) | |
| RTHROW(0, 0, | |
| &method_name, | |
| "method of 'table' is not static"); | |
| Table& table=static_cast<VTable *>(r.self)->table(); | Table& table=static_cast<VTable *>(r.self)->table(); |
| if(const Array *columns=table.columns()) { | if(const Array *columns=table.columns()) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Line 303 static int sort_cmp_double(const void *a | Line 260 static int sort_cmp_double(const void *a |
| return 0; | return 0; |
| } | } |
| static void _sort(Request& r, const String& method_name, Array *params) { | static void _sort(Request& r, const String& method_name, Array *params) { |
| if(r.self==table_class) | |
| RTHROW(0, 0, | |
| &method_name, | |
| "method of 'table' is not static"); | |
| Value& key_maker=*(Value *)params->get(0); | Value& key_maker=*(Value *)params->get(0); |
| // forcing ^sort{this} ^sort(or this) param type | // forcing ^sort{this} ^sort(or this) param type |
| r.fail_if_junction_(false, key_maker, method_name, "key-maker must be junction"); | r.fail_if_junction_(false, key_maker, method_name, "key-maker must be junction"); |
| Line 358 static void _sort(Request& r, const Stri | Line 310 static void _sort(Request& r, const Stri |
| } | } |
| static void _locate(Request& r, const String& method_name, Array *params) { | static void _locate(Request& r, const String& method_name, Array *params) { |
| if(r.self==table_class) | |
| RTHROW(0, 0, | |
| &method_name, | |
| "method of 'table' is not static"); | |
| VTable& vtable=*static_cast<VTable *>(r.self); | VTable& vtable=*static_cast<VTable *>(r.self); |
| Table& table=vtable.table(); | Table& table=vtable.table(); |
| vtable.last_locate_was_successful=table.locate( | vtable.last_locate_was_successful=table.locate( |
| Line 371 static void _locate(Request& r, const St | Line 318 static void _locate(Request& r, const St |
| } | } |
| static void _found(Request& r, const String& method_name, Array *params) { | static void _found(Request& r, const String& method_name, Array *params) { |
| if(r.self==table_class) | |
| RTHROW(0, 0, | |
| &method_name, | |
| "method of 'table' is not static"); | |
| if(static_cast<VTable *>(r.self)->last_locate_was_successful) { | if(static_cast<VTable *>(r.self)->last_locate_was_successful) { |
| Value& then_code=*static_cast<Value *>(params->get(0)); | Value& then_code=*static_cast<Value *>(params->get(0)); |
| // forcing ^found{this param type} | // forcing ^found{this param type} |
| Line 393 static void _found(Request& r, const Str | Line 335 static void _found(Request& r, const Str |
| static void _flip(Request& r, const String& method_name, Array *params) { | static void _flip(Request& r, const String& method_name, Array *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| if(r.self==table_class) | |
| RTHROW(0, 0, | |
| &method_name, | |
| "method of 'table' is not static"); | |
| VTable& vtable=*static_cast<VTable *>(r.self); | VTable& vtable=*static_cast<VTable *>(r.self); |
| Table& old_table=*vtable.get_table(); | Table& old_table=*vtable.get_table(); |
| Line 417 static void _flip(Request& r, const Stri | Line 353 static void _flip(Request& r, const Stri |
| vtable.set_table(new_table); | vtable.set_table(new_table); |
| } | } |
| /// @todo now require \t to be clean [UL_NO] | |
| static void _append(Request& r, const String& method_name, Array *params) { | |
| Pool& pool=r.pool(); | |
| // data is last parameter | |
| Value *value=static_cast<Value *>(params->get(0)); | |
| // forcing [this body type] | |
| r.fail_if_junction_(true, *value, method_name, "body must not be junction"); | |
| const String& string=static_cast<VString *>(value)->as_string(); | |
| // parse cells | |
| Array& row=*new(pool) Array(pool); | |
| size_t pos_after=0; | |
| int pos_before; | |
| while((pos_before=string.pos("\t", pos_after))>=0) { | |
| row+=&string.piece(pos_after, pos_before); | |
| pos_after=pos_before+1/*\t*/; | |
| } | |
| // last piece | |
| if(pos_after<string.size()) | |
| row+=&string.piece(pos_after, string.size()); | |
| static_cast<VTable *>(r.self)->table()+=&row; | |
| } | |
| // initialize | // initialize |
| void initialize_table_class(Pool& pool, VStateless_class& vclass) { | void initialize_table_class(Pool& pool, VStateless_class& vclass) { |
| // ^table.set{data} | // ^table.set{data} |
| // ^table.set[nameless]{data} | // ^table.set[nameless]{data} |
| vclass.add_native_method("set", _set, 1, 2); | vclass.add_native_method("set", Method::CT_DYNAMIC, _set, 1, 2); |
| // ^table.load[file] | // ^table.load[file] |
| // ^table.load[nameless;file] | // ^table.load[nameless;file] |
| vclass.add_native_method("load", _load, 1, 2); | vclass.add_native_method("load", Method::CT_DYNAMIC, _load, 1, 2); |
| // ^table.save[file] | // ^table.save[file] |
| // ^table.save[nameless;file] | // ^table.save[nameless;file] |
| vclass.add_native_method("save", _save, 1, 2); | vclass.add_native_method("save", Method::CT_DYNAMIC, _save, 1, 2); |
| // ^table.count[] | // ^table.count[] |
| vclass.add_native_method("count", _count, 0, 0); | vclass.add_native_method("count", Method::CT_DYNAMIC, _count, 0, 0); |
| // ^table.line[] | // ^table.line[] |
| vclass.add_native_method("line", _line, 0, 0); | vclass.add_native_method("line", Method::CT_DYNAMIC, _line, 0, 0); |
| // ^table.offset[] | // ^table.offset[] |
| // ^table.offset[offset] | // ^table.offset[offset] |
| vclass.add_native_method("offset", _offset, 0, 1); | vclass.add_native_method("offset", Method::CT_DYNAMIC, _offset, 0, 1); |
| // ^table.menu{code} | // ^table.menu{code} |
| // ^table.menu{code}[delim] | // ^table.menu{code}[delim] |
| vclass.add_native_method("menu", _menu, 1, 2); | vclass.add_native_method("menu", Method::CT_DYNAMIC, _menu, 1, 2); |
| // ^table.empty{code-when-empty} | // ^table.empty{code-when-empty} |
| // ^table.empty{code-when-empty}{code-when-not} | // ^table.empty{code-when-empty}{code-when-not} |
| vclass.add_native_method("empty", _empty, 1, 2); | vclass.add_native_method("empty", Method::CT_DYNAMIC, _empty, 1, 2); |
| // ^table.record[] | // ^table.record[] |
| vclass.add_native_method("record", _record, 0, 0); | vclass.add_native_method("record", Method::CT_DYNAMIC, _record, 0, 0); |
| // ^table.sort{string-key-maker} ^table.sort{string-key-maker}[asc|desc] | // ^table.sort{string-key-maker} ^table.sort{string-key-maker}[asc|desc] |
| // ^table.sort(numeric-key-maker) ^table.sort(numeric-key-maker)[asc|desc] | // ^table.sort(numeric-key-maker) ^table.sort(numeric-key-maker)[asc|desc] |
| vclass.add_native_method("sort", _sort, 1, 2); | vclass.add_native_method("sort", Method::CT_DYNAMIC, _sort, 1, 2); |
| // ^table.locate[field;value] | // ^table.locate[field;value] |
| vclass.add_native_method("locate", _locate, 2, 2); | vclass.add_native_method("locate", Method::CT_DYNAMIC, _locate, 2, 2); |
| // ^table.found{when-found} | // ^table.found{when-found} |
| // ^table.found{when-found}{when-not-found} | // ^table.found{when-found}{when-not-found} |
| vclass.add_native_method("found", _found, 1, 2); | vclass.add_native_method("found", Method::CT_DYNAMIC, _found, 1, 2); |
| // ^table.flip[] | // ^table.flip[] |
| vclass.add_native_method("flip", _flip, 0, 0); | vclass.add_native_method("flip", Method::CT_DYNAMIC, _flip, 0, 0); |
| } | |
| // ^table.append{r{tab}e{tab}c{tab}o{tab}r{tab}d} | |
| vclass.add_native_method("append", Method::CT_DYNAMIC, _append, 1, 1); | |
| } |