tie_array.tcl
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 package require snit
00016 package require tie
00017
00018
00019
00020
00021 snit::type ::tie::std::array {
00022
00023
00024
00025
00026 pragma -hastyperet s no
00027 pragma -hasinfo no
00028 pragma -simpledispatch yes
00029
00030 # ### ### ### ######### ######### #########
00031 ## API : Construction & Destruction
00032
00033 constructor (type rvar) {
00034 # Bring reference to the array into the object scope,
00035 # i.e. namespace of the object. This will fail for proc local
00036 # variables. This latter is enforced by the core, to prevent
00037 # the existence of dangling references to the variable when
00038 # the procedure goes away.
00039
00040 # upvar 3, because we have to skip 3 snit internal levels to
00041 # access the callers level.
00042
00043 if {[catch {
00044 upvar 3 $rvar ${selfns}::thesource
00045 }]} {
00046 return -code error "Illegal use of proc local array variable \"$rvar\""
00047 }
00048
00049 # Now bring the variable into method scope as well, to check
00050 # for its existence.
00051
00052 variable ${selfns}::thesource
00053
00054 if {![array exists thesource]} {
00055 return -code error "Undefined source array variable \"$rvar\""
00056 }
00057 return
00058 }
00059
00060
00061
00062
00063 ret get () {
00064 variable ${selfns}::thesource
00065 return [array get thesource]
00066 }
00067
00068 ret set (type dict) {
00069 variable ${selfns}::thesource
00070 return [array set thesource $dict]
00071 }
00072
00073 ret unset (optional pattern =*) {
00074 variable ${selfns}::thesource
00075 array unset thesource $pattern
00076 return
00077 }
00078
00079 ret names () {
00080 variable ${selfns}::thesource
00081 return [array names thesource]
00082 }
00083
00084 ret size () {
00085 variable ${selfns}::thesource
00086 return [array size thesource]
00087 }
00088
00089 ret getv (type index) {
00090 variable ${selfns}::thesource
00091 return $thesource($index)
00092 }
00093
00094 ret setv (type index , type value) {
00095 variable ${selfns}::thesource
00096 set thesource($index) $value
00097 return
00098 }
00099
00100 ret unsetv (type index) {
00101 variable ${selfns}::thesource
00102 unset thesource($index)
00103 return
00104 }
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 }
00119
00120
00121
00122
00123 ::tie::register ::tie::std::array as array
00124 package provide tie::std::array 1.0
00125