Ignore:
Timestamp:
Oct 8, 2002, 12:25:52 AM (16 years ago)
Author:
kevin
Message:

Make property accessor actual virtual functions.
(Targets will likely want to override some cases of 'set' to do neat things.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/base/src/port1.0/portutil.tcl

    r960 r989  
    931931set depspec_vtbl(test) depspec_test
    932932set depspec_vtbl(run) depspec_run
     933set depspec_vtbl(get) depspec_get
     934set depspec_vtbl(set) depspec_set
     935set depspec_vtbl(has) depspec_has
     936set depspec_vtbl(append) depspec_append
    933937
    934938# constructor for abstract depspec class
     
    953957}
    954958
    955 # is the only proc to get access to the object's data
    956 # so the get/set routines are defined here.  this lets
    957 # the virtual members get a real "this" object.
     959proc depspec_get {this prop} {
     960        set data [$this _data]
     961        global $data
     962        if {[eval info exists ${data}($prop)]} {
     963                eval return $${data}($prop)
     964        } else {
     965                return ""
     966        }
     967}
     968
     969proc depspec_set {this prop args} {
     970        set data [$this _data]
     971        global $data
     972        eval set ${data}($prop) $args
     973}
     974
     975proc depspec_has {this prop} {
     976        set data [$this _data]
     977        global $data
     978        eval return \[info exists ${data}($prop)\]
     979}
     980
     981proc depspec_append {this prop args} {
     982        set data [$this _data]
     983        global $data
     984        set vals [join $args " "]
     985        eval lappend ${data}($prop) $vals
     986}
     987
     988# is the only proc to get direct access to the object's data
     989# so the _data accessor has to be defined here.  all other
     990# methods are looked up in the virtual function table,
     991# and are called with {$this $args}.
    958992proc depspec_dispatch {this data method args} {
    959993    global $data
    960     switch $method {
    961         get {
    962             set prop [lindex $args 0]
    963             if {[eval info exists ${data}($prop)]} {
    964                 eval return $${data}($prop)
    965             } else {
    966                 return ""
    967             }
    968         }
    969         set {
    970             set prop [lindex $args 0]
    971             eval "set ${data}($prop) [lrange $args 1 end]"
    972         }
    973         has {
    974             set prop [lindex $args 0]
    975             return [info exists ${data}($prop)]
    976         }
    977         append {
    978             set prop [lindex $args 0]
    979             set vals [join [lrange $args 1 end] " "]
    980             eval "lappend ${data}($prop) $vals"
    981         }
    982         default {
    983             eval set vtbl $${data}(_vtbl)
    984             global $vtbl
    985             if {[info exists ${vtbl}($method)]} {
     994        if {$method == "_data"} { return $data }
     995        eval set vtbl $${data}(_vtbl)
     996        global $vtbl
     997        if {[info exists ${vtbl}($method)]} {
    986998                eval set function $${vtbl}($method)
    987999                eval "return \[$function $this $args\]"
    988             } else {
     1000        } else {
    9891001                ui_error "unknown method: $method"
    990             }
    991         }
    992     }
     1002        }
    9931003    return ""
    9941004}
Note: See TracChangeset for help on using the changeset viewer.