1# -*- tcl -*- 2# -- $Id: reader_treeser.tcl,v 1.1 2005/09/28 04:51:22 andreas_kupries Exp $ --- 3# 4# PAGE plugin - reader - TREESER ~ Serialized TREE 5# 6 7# ### ### ### ######### ######### ######### 8## Imported API 9 10# -----------------+-- 11# page_read | Access to the input stream. 12# page_read_done | 13# page_eof | 14# -----------------+-- 15# page_info | Reporting to the user. 16# page_warning | 17# page_error | 18# -----------------+-- 19# page_log_error | Reporting of internals. 20# page_log_warning | 21# page_log_info | 22# -----------------+-- 23 24# ### ### ### ######### ######### ######### 25## Exported API 26 27# -----------------+-- 28# page_rfeature | Query for special plugin features page might wish to use. 29# page_rtime | Activate collection of timing statistics. 30# page_rgettime | Return the collected timing statistics. 31# page_rlabel | User readable label for the plugin. 32# page_rhelp | Doctools help text for plugin. 33# page_roptions | Options understood by plugin. 34# page_rconfigure | Option (re)configuration. 35# page_rdata | External access to processed input stream. 36# page_rrun | Process input stream per plugin configuration and hardwiring. 37# -----------------+-- 38 39# ### ### ### ######### ######### ######### 40## Requisites 41 42package require struct::tree ; # Data structure. 43 44global usec 45global timed 46set timed 0 47 48# ### ### ### ######### ######### ######### 49## Implementation of exported API 50 51proc page_rlabel {} { 52 return {Serialized Tree} 53} 54 55proc page_rfeature {key} { 56 return [string eq $key timeable] 57} 58 59proc page_rtime {} { 60 global timed 61 set timed 1 62 return 63} 64 65proc page_rgettime {} { 66 global usec 67 return $usec 68} 69 70proc page_rhelp {} { 71 return {} 72} 73 74proc page_roptions {} { 75 return {} 76} 77 78proc page_rconfigure {option value} { 79 return -code error "Cannot set value of unknown option \"$option\"" 80} 81 82## proc page_rdata {} {} 83## Created in 'Initialize' 84 85proc page_rrun {} { 86 global timed usec 87 page_log_info "reader/treeser/run/parse" 88 89 if {$timed} { 90 set usec [lindex [time { 91 set data [page_read] 92 }] 0] ; #{} 93 } else { 94 set data [page_read] 95 } 96 page_read_done 97 98 # Reading and passing it on is trivial. 99 # Here however we validate the we truly got 100 # a sensible serialization. 101 102 struct::tree ::tree 103 ::tree deserialize $data 104 ::tree destroy 105 106 page_log_info "reader/treeser/run/ok" 107 return $data 108} 109 110# ### ### ### ######### ######### ######### 111## Internal helper code. 112 113# ### ### ### ######### ######### ######### 114## Initialization 115 116package provide page::reader::treeser 0.1 117