From 5e9cab834474fb11acfbb87b29653f549f7d7555 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net> Date: Sun, 18 Jul 1999 00:09:51 -0700 Subject: [PATCH] added encode/decode for storing SGML in caches Rev: tutorial/Sgml.pmod:1.15 --- tutorial/Sgml.pmod | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tutorial/Sgml.pmod b/tutorial/Sgml.pmod index 1b9f841c01..bbc02aa99f 100644 --- a/tutorial/Sgml.pmod +++ b/tutorial/Sgml.pmod @@ -273,6 +273,52 @@ string get_text(SGML data) } +class Codec +{ + string nameof(mixed o) + { + if(objectp(o)) return ([])[0]; + if(o==Tag) return "TAG"; + error("Cannot encode that!\n"); + } + + program functionof(string p) + { + if(p=="TAG") return Tag; + } + + mixed encode_object(object o) + { + return ({ + o->tag, + o->pos, + o->params, + o->data, + o->file + }); + } + + void decode_object(object o, mixed data) + { + [ o->tag, + o->pos, + o->params, + o->data, + o->file ] = data; + } +} + +string encode(SGML data) +{ + return encode_value(data,Codec()); +} + +SGML decode(string data) +{ + return decode_value(data,Codec()); +} + + #ifdef TEST int main() { -- GitLab