sets.tcl

Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------*/
00002 /* */
00003 /*  sets.tcl --*/
00004 /* */
00005 /*  Definitions for the processing of sets.*/
00006 /* */
00007 /*  Copyright (c) 2004-2007 by Andreas Kupries.*/
00008 /* */
00009 /*  See the file "license.terms" for information on usage and redistribution*/
00010 /*  of this file, and for a DISCLAIMER OF ALL WARRANTIES.*/
00011 /* */
00012 /*  RCS: @(#) $Id: sets.tcl,v 1.15 2007/08/29 22:10:31 andreas_kupries Exp $*/
00013 /* */
00014 /* ----------------------------------------------------------------------*/
00015 
00016 /*  @mdgen EXCLUDE: sets_c.tcl*/
00017 
00018 package require Tcl 8.2
00019 
00020 namespace ::struct:: {}
00021 
00022 # ### ### ### ######### ######### #########
00023 ## Management =  of  implementations = .
00024 
00025 /*  ::struct::set::LoadAccelerator --*/
00026 /* */
00027 /*  Loads a named implementation, if possible.*/
00028 /* */
00029 /*  Arguments:*/
00030 /*  key Name of the implementation to load.*/
00031 /* */
00032 /*  Results:*/
00033 /*  A boolean flag. True if the implementation*/
00034 /*  was successfully loaded; and False otherwise.*/
00035 
00036 ret  ::struct::set::LoadAccelerator (type key) {
00037     variable accel
00038     set r 0
00039     switch -exact -- $key {
00040     critcl {
00041         # Critcl implementation of set requires Tcl 8.4.
00042         if {![package vsatisfies [package provide Tcl] 8.4]} {return 0}
00043         if {[catch {package require tcllibc}]} {return 0}
00044         set r [llength [info commands ::struct::set_critcl]]
00045     }
00046     tcl {
00047         variable selfdir
00048         source [file join $selfdir sets_tcl.tcl]
00049         set r 1
00050     }
00051         default {
00052             return -code error "invalid accelerator/impl. package $key:\
00053                 must be one of [join [KnownImplementations] {, }]"
00054         }
00055     }
00056     set accel($key) $r
00057     return $r
00058 }
00059 
00060 /*  ::struct::set::SwitchTo --*/
00061 /* */
00062 /*  Activates a loaded named implementation.*/
00063 /* */
00064 /*  Arguments:*/
00065 /*  key Name of the implementation to activate.*/
00066 /* */
00067 /*  Results:*/
00068 /*  None.*/
00069 
00070 ret  ::struct::set::SwitchTo (type key) {
00071     variable accel
00072     variable loaded
00073 
00074     if {[string equal $key $loaded]} {
00075     # No change, nothing to do.
00076     return
00077     } elseif {![string equal $key ""]} {
00078     # Validate the target implementation of the switch.
00079 
00080     if {![info exists accel($key)]} {
00081         return -code error "Unable to activate unknown implementation \"$key\""
00082     } elseif {![info exists accel($key)] || !$accel($key)} {
00083         return -code error "Unable to activate missing implementation \"$key\""
00084     }
00085     }
00086 
00087     # Deactivate the previous implementation, if there was any.
00088 
00089     if {![string equal $loaded ""]} {
00090     rename ::struct::set ::struct::set_$loaded
00091     }
00092 
00093     # Activate the new implementation, if there is any.
00094 
00095     if {![string equal $key ""]} {
00096     rename ::struct::set_$key ::struct::set
00097     }
00098 
00099     # Remember the active implementation, for deactivation by future
00100     # switches.
00101 
00102     set loaded $key
00103     return
00104 }
00105 
00106 ret  ::struct::set::Loaded () {
00107     variable loaded
00108     return  $loaded
00109 }
00110 
00111 /*  ::struct::set::Implementations --*/
00112 /* */
00113 /*  Determines which implementations are*/
00114 /*  present, i.e. loaded.*/
00115 /* */
00116 /*  Arguments:*/
00117 /*  None.*/
00118 /* */
00119 /*  Results:*/
00120 /*  A list of implementation keys.*/
00121 
00122 ret  ::struct::set::Implementations () {
00123     variable accel
00124     set res {}
00125     foreach n [array names accel] {
00126     if {!$accel($n)} continue
00127     lappend res $n
00128     }
00129     return $res
00130 }
00131 
00132 /*  ::struct::set::KnownImplementations --*/
00133 /* */
00134 /*  Determines which implementations are known*/
00135 /*  as possible implementations.*/
00136 /* */
00137 /*  Arguments:*/
00138 /*  None.*/
00139 /* */
00140 /*  Results:*/
00141 /*  A list of implementation keys. In the order*/
00142 /*  of preference, most prefered first.*/
00143 
00144 ret  ::struct::set::KnownImplementations () {
00145     return {critcl tcl}
00146 }
00147 
00148 ret  ::struct::set::Names () {
00149     return {
00150     critcl {tcllibc based}
00151     tcl    {pure Tcl}
00152     }
00153 }
00154 
00155 /*  ### ### ### ######### ######### #########*/
00156 /*  Initialization: Data structures.*/
00157 
00158 namespace ::struct:: {
00159     variable =   selfdir [file dirname [info script]]
00160     variable  accel
00161     array  accel =    {tcl 0 critcl 0}
00162     variable  
00163 }
00164 
00165 /*  ### ### ### ######### ######### #########*/
00166 /*  Initialization: Choose an implementation,*/
00167 /*  most prefered first. Loads only one of the*/
00168 /*  possible implementations. And activates it.*/
00169 
00170 namespace ::struct:: {
00171     variable =  e
00172     foreach e [KnownImplementations] {
00173     if {[LoadAccelerator $e]} {
00174         SwitchTo $e
00175         break
00176     }
00177     }
00178     un e = 
00179 }
00180 
00181 /*  ### ### ### ######### ######### #########*/
00182 /*  Ready*/
00183 
00184 namespace ::struct {
00185     /*  Export the constructor command.*/
00186     namespace export 
00187 }
00188 
00189 package =  provide struct:: 2.2.1
00190 

Generated on 21 Sep 2010 for Gui by  doxygen 1.6.1