graph.tcl
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 package require Tcl 8.2
00015
00016 namespace ::struct::graph {}
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 ret ::struct::graph::LoadAccelerator (type key) {
00033 variable accel
00034 set r 0
00035 switch -exact -- $key {
00036 critcl {
00037 # Critcl implementation of graph requires Tcl 8.4.
00038 if {![package vsatisfies [package provide Tcl] 8.4]} {return 0}
00039 if {[catch {package require tcllibc}]} {return 0}
00040 set r [llength [info commands ::struct::graph_critcl]]
00041 }
00042 tcl {
00043 variable selfdir
00044 source [file join $selfdir graph_tcl.tcl]
00045 set r 1
00046 }
00047 default {
00048 return -code error "invalid accelerator/impl. package $key:\
00049 must be one of [join [KnownImplementations] {, }]"
00050 }
00051 }
00052 set accel($key) $r
00053 return $r
00054 }
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 ret ::struct::graph::SwitchTo (type key) {
00067 variable accel
00068 variable loaded
00069
00070 if {[string equal $key $loaded]} {
00071 # No change, nothing to do.
00072 return
00073 } elseif {![string equal $key ""]} {
00074 # Validate the target implementation of the switch.
00075
00076 if {![info exists accel($key)]} {
00077 return -code error "Unable to activate unknown implementation \"$key\""
00078 } elseif {![info exists accel($key)] || !$accel($key)} {
00079 return -code error "Unable to activate missing implementation \"$key\""
00080 }
00081 }
00082
00083 # Deactivate the previous implementation, if there was any.
00084
00085 if {![string equal $loaded ""]} {
00086 rename ::struct::graph ::struct::graph_$loaded
00087 }
00088
00089 # Activate the new implementation, if there is any.
00090
00091 if {![string equal $key ""]} {
00092 rename ::struct::graph_$key ::struct::graph
00093 }
00094
00095 # Remember the active implementation, for deactivation by future
00096 # switches.
00097
00098 set loaded $key
00099 return
00100 }
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 ret ::struct::graph::Implementations () {
00114 variable accel
00115 set res {}
00116 foreach n [array names accel] {
00117 if {!$accel($n)} continue
00118 lappend res $n
00119 }
00120 return $res
00121 }
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 ret ::struct::graph::KnownImplementations () {
00136 return {critcl tcl}
00137 }
00138
00139 ret ::struct::graph::Names () {
00140 return {
00141 critcl {tcllibc based}
00142 tcl {pure Tcl}
00143 }
00144 }
00145
00146
00147
00148
00149 namespace ::struct::graph {
00150 variable selfdir [file dirname [info script]]
00151 variable accel
00152 array accel = {tcl 0 critcl 0}
00153 variable
00154 }
00155
00156
00157
00158
00159
00160
00161 namespace ::struct::graph {
00162 variable e
00163 foreach e [KnownImplementations] {
00164 if {[LoadAccelerator $e]} {
00165 SwitchTo $e
00166 break
00167 }
00168 }
00169 un e =
00170 }
00171
00172
00173
00174
00175 namespace ::struct {
00176
00177 namespace export graph
00178 }
00179
00180 package provide struct::graph 2.2
00181