Index: xotcl/generic/predefined.xotcl =================================================================== diff -u -r20e421dc641dc39b53106b1296ac7e09d0b206f2 -r99a7a21854051cd691029b15ef8877aa9e86cf44 --- xotcl/generic/predefined.xotcl (.../predefined.xotcl) (revision 20e421dc641dc39b53106b1296ac7e09d0b206f2) +++ xotcl/generic/predefined.xotcl (.../predefined.xotcl) (revision 99a7a21854051cd691029b15ef8877aa9e86cf44) @@ -1,103 +1,82 @@ -# $Id: predefined.xotcl,v 1.12 2006/10/04 20:40:23 neumann Exp $ -if {[info command oo::object] ne ""} { - ::xotcl::alias ::oo::class alloc ::xotcl::cmd::Class::alloc - oo::class alloc ::xotcl::Object - oo::class alloc ::xotcl::Class - ::xotcl::setrelation ::xotcl::Class superclass {::oo::class ::xotcl::Object} - ::xotcl::setrelation ::xotcl::Object class ::xotcl::Class - ::xotcl::setrelation ::xotcl::Class class ::xotcl::Class -} - +# $Id: predefined.xotcl,v 1.13 2007/08/06 11:35:56 neumann Exp $ # provide the standard command set for ::xotcl::Object -foreach cmd [info command ::xotcl::cmd::Object::*] { +foreach cmd [info command ::xotcl::Object::instcmd::*] { ::xotcl::alias ::xotcl::Object [namespace tail $cmd] $cmd } -# provide some Tcl-commands as methods for ::xotcl::Object +# provide some Tcl-commands as methods for Objects foreach cmd {array append eval incr lappend trace subst unset} { ::xotcl::alias ::xotcl::Object $cmd -objscope ::$cmd } # provide the standard command set for ::xotcl::Class -foreach cmd [info command ::xotcl::cmd::Class::*] { +foreach cmd [info command ::xotcl::Class::instcmd::*] { ::xotcl::alias ::xotcl::Class [namespace tail $cmd] $cmd } -# "init" must exist on Object. per default it is empty. -::xotcl::Object instproc init args {} -# use low level interface of slots (defined later) for providing a -# default value for superclass (when no superclass is specified explicitely) -::xotcl::Class array set __defaults {__default_superclass ::xotcl::Object} -::xotcl::Class instparametercmd __default_superclass -::xotcl::Class set __default_superclass ::xotcl::Object -# -# create class and object for nonpositional argument processing -::xotcl::Class create ::xotcl::NonposArgs -foreach cmd [info command ::xotcl::cmd::NonposArgs::*] { - ::xotcl::alias ::xotcl::NonposArgs [namespace tail $cmd] $cmd -} -::xotcl::NonposArgs create ::xotcl::nonposArgs unset cmd +# init must exist on Object. per default it is empty. +::xotcl::Object instproc init args {} + # documentation stub object -> just ignore # all documentations if xoDoc is not loaded ::xotcl::Object create ::xotcl::@ ::xotcl::@ proc unknown args {} proc ::xotcl::myproc {args} {linsert $args 0 [::xotcl::self]} proc ::xotcl::myvar {var} {::xotcl::my requireNamespace; return [::xotcl::self]::$var} -namespace eval ::xotcl { namespace export Object Class @ myproc myvar Attribute} +namespace eval ::xotcl { namespace export @ myproc myvar Attribute} ######################## # Parameter definitions ######################## -# ::xotcl::setrelation ::xotcl::Class::Parameter superclass ::xotcl::Class -# ::xotcl::Class::Parameter instproc mkParameter {obj name args} { -# #puts "[::xotcl::self proc] $obj $name <$args>" -# if {[$obj exists $name]} { -# eval [$obj set $name] configure $args -# } else { -# $obj set $name [eval ::xotcl::my new -childof $obj $args] -# } -# } -# ::xotcl::Class::Parameter instproc getParameter {obj name args} { -# #puts "[::xotcl::self proc] $obj $name <$args>" -# [$obj set $name] -# } -# ::xotcl::Class::Parameter proc Class {param args} { -# #puts "*** [::xotcl::self] parameter: [::xotcl::self proc] '$param' <$args>" -# ::xotcl::my set access [lindex $param 0] -# ::xotcl::my set setter mkParameter -# ::xotcl::my set getter getParameter -# ::xotcl::my set extra {[::xotcl::self]} -# ::xotcl::my set defaultParam [lrange $param 1 end] -# } -# ::xotcl::Class::Parameter proc default {val} { -# [::xotcl::my set cl] set __defaults([::xotcl::my set name]) $val -# } -# ::xotcl::Class::Parameter proc setter x { -# ::xotcl::my set setter $x -# } -# ::xotcl::Class::Parameter proc getter x { -# ::xotcl::my set getter $x -# } -# ::xotcl::Class::Parameter proc access obj { -# ::xotcl::my set access $obj -# ::xotcl::my set extra \[::xotcl::self\] -# foreach v [$obj info vars] {::xotcl::my set $v [$obj set $v]} -# } -# ::xotcl::Class::Parameter proc values {param args} { -# set cl [::xotcl::my set cl] -# set ci [$cl info instinvar] -# set valueTest {} -# foreach a $args { -# ::lappend valueTest "\[\$cl set $param\] == [list $a]" -# } -# ::lappend ci [join $valueTest " || "] -# $cl instinvar $ci -# } +::xotcl::setrelation ::xotcl::Class::Parameter superclass ::xotcl::Class +::xotcl::Class::Parameter instproc mkParameter {obj name args} { + #puts "[::xotcl::self proc] $obj $name <$args>" + if {[$obj exists $name]} { + eval [$obj set $name] configure $args + } else { + $obj set $name [eval ::xotcl::my new -childof $obj $args] + } +} +::xotcl::Class::Parameter instproc getParameter {obj name args} { + #puts "[::xotcl::self proc] $obj $name <$args>" + [$obj set $name] +} +::xotcl::Class::Parameter proc Class {param args} { + #puts "*** [::xotcl::self] parameter: [::xotcl::self proc] '$param' <$args>" + ::xotcl::my set access [lindex $param 0] + ::xotcl::my set setter mkParameter + ::xotcl::my set getter getParameter + ::xotcl::my set extra {[::xotcl::self]} + ::xotcl::my set defaultParam [lrange $param 1 end] +} +::xotcl::Class::Parameter proc default {val} { + [::xotcl::my set cl] set __defaults([::xotcl::my set name]) $val +} +::xotcl::Class::Parameter proc setter x { + ::xotcl::my set setter $x +} +::xotcl::Class::Parameter proc getter x { + ::xotcl::my set getter $x +} +::xotcl::Class::Parameter proc access obj { + ::xotcl::my set access $obj + ::xotcl::my set extra \[::xotcl::self\] + foreach v [$obj info vars] {::xotcl::my set $v [$obj set $v]} +} +::xotcl::Class::Parameter proc values {param args} { + set cl [::xotcl::my set cl] + set ci [$cl info instinvar] + set valueTest {} + foreach a $args { + ::lappend valueTest "\[\$cl set $param\] == [list $a]" + } + ::lappend ci [join $valueTest " || "] + $cl instinvar $ci +} ################## # Slot definitions ################## # bootstrap code; we cannot use -parameter yet ::xotcl::Class create ::xotcl::MetaSlot ::xotcl::setrelation ::xotcl::MetaSlot superclass ::xotcl::Class -::xotcl::MetaSlot initslots ::xotcl::MetaSlot instproc new args { set slotobject [self callingobject]::slot if {![my isobject $slotobject]} {Object create $slotobject} @@ -224,11 +203,11 @@ ::xotcl::Attribute instproc __default_from_cmd {obj cmd var sub op} { #puts "GETVAR [self proc] obj=$obj cmd=$cmd, var=$var, op=$op" $obj trace remove variable $var $op [list [self] [self proc] $obj $cmd] - $obj set $var [eval $cmd] + $obj set $var [$obj eval $cmd] } ::xotcl::Attribute instproc __value_from_cmd {obj cmd var sub op} { #puts "GETVAR [self proc] obj=$obj cmd=$cmd, var=$var, op=$op" - $obj set $var [eval $cmd] + $obj set $var [$obj eval $cmd] } ::xotcl::Attribute instproc __value_changed_cmd {obj cmd var sub op} { #puts stderr "**************************" @@ -389,15 +368,15 @@ } elseif {$l == 2} { #puts stderr "parameter $name has default '[lindex $arg 1]'" - ::xotcl::Attribute create [::xotcl::self]::slot::$name -default [lindex $arg 1] + ::xotcl::Attribute create [::xotcl::self]::slot::$name [list -default [lindex $arg 1]] } elseif {$l == 3 && [lindex $arg 1] eq "-default"} { - ::xotcl::Attribute create [::xotcl::self]::slot::$name -default [lindex $arg 2] + ::xotcl::Attribute create [::xotcl::self]::slot::$name [list -default [lindex $arg 2]] } else { set paramstring [string range $arg [expr {[string length $name]+1}] end] #puts stderr "remaining arg = '$paramstring'" if {[string match {[$\[]*} $paramstring]} { #puts stderr "match, $cl set __defaults($name) $paramstring" - ::xotcl::Attribute create [::xotcl::self]::slot::$name -default $paramstring + ::xotcl::Attribute create [::xotcl::self]::slot::$name [list -default $paramstring] continue } @@ -457,6 +436,7 @@ return $set } + # Exit Handler ::xotcl::Object proc unsetExitHandler {} { ::xotcl::Object proc __exitHandler {} { @@ -472,10 +452,7 @@ ::xotcl::Object proc getExitHandler {} { ::xotcl::Object info body __exitHandler } -# provide a global handler to avoid a proc on the global object. -proc ::xotcl::__exitHandler {} { - ::xotcl::Object __exitHandler -} + ::xotcl::Object instproc abstract {methtype methname arglist} { if {$methtype ne "proc" && $methtype ne "instproc"} { error "invalid method type '$methtype', \ @@ -547,7 +524,7 @@ # class object set obj $cl $cl superclass [$origin info superclass] - #$cl parameterclass [$origin info parameterclass] + $cl parameterclass [$origin info parameterclass] $cl instinvar [$origin info instinvar] $cl instfilter [$origin info instfilter -guards] $cl instmixin [$origin info instmixin] @@ -881,3 +858,22 @@ my instproc $name $arguments $body } } + +# setup a temp directory +proc ::xotcl::tmpdir {} { + foreach e [list TMPDIR TEMP TMP] { + if {[info exists ::env($e)] \ + && [file isdirectory $::env($e)] \ + && [file iswritable $::env($e)]} { + return $::env($e) + } + } + if {$::tcl_platform(platform) eq "windows"} { + foreach d [list "C:\\TEMP" "C:\\TMP" "\\TEMP" "\\TMP"] { + if {[file isdirectory $d] && [file iswritable $d]} { + return $d + } + } + } + return /tmp +}