[Xotcl] Re: XOTcl 0.83 questions (continued...)
uwe.zdun at uni-essen.de
uwe.zdun at uni-essen.de
Tue Nov 21 14:36:57 CET 2000
Hi Zoran,
we have an mailing list set up for XOTcl ... I'll cross-post this
mail to the list, because it might be of general interest. Perhaps you
like to CC general questions/comments to the list and/or subscribe:
http://wi.wu-wien.ac.at/mailman/listinfo/xotcl
We will announce the list publicly with 0.83 ...
here, is some example code that shows two ways how to retrieve all
instances, classes, and metaclasses in the system:
--Uwe
###################################################################
# set up some classes for testing
#
# some meta classes
#
Class Meta -superclass Class
Class Meta2 -superclass Meta
Class Meta3 -superclass Meta2
#
# some classes
#
Class X
Class Y
Meta Z
Meta2 A
Meta2 B
#
# some objs
#
X x
Object o
Y y1
Y y1
A a1
A a2
#
# if you only use the global namespace it is quite simple to retrieve
# the instances, like:
# (you can also traverse the namespaces ... but then the
# variant down below is more elegant)
set objects ""
foreach c [info commands] {
if {[Object isobject $c]} {lappend objects $c}
}
puts "Global Objects are: $objects"
#
# we can also go along the class hierarchy
#
# we define a separate class that computes the instances (could
# also be instprocs on Object ... but then we won't have the ability
# to use the code on a subclass)
#
Class InstanceRetrieval
InstanceRetrieval instproc getAllSubClasses cl {
set result ""
set sc [$cl info subclass]
foreach c $sc {
lappend result $c
set result [concat $result [[self] getAllSubClasses $c]]
}
return $result
}
InstanceRetrieval instproc getAllInstances {} {
set result ""
# get all subclasses of this class
set subclasses [[self] getAllSubClasses [self]]
# now get the instances of every subclass
foreach sc $subclasses {
set result [concat $result [$sc info instances]]
}
return $result
}
# now we register that class on Object as a mixin
# -> we can all instances of the object class (including the
# nested objects
Object mixinappend InstanceRetrieval
set allObjs [Object getAllInstances]
puts "All objects are: $allObjs"
#
# with isclass and ismetaclass we can additionally sort out the
# classes and metaclasses
#
foreach o $allObjs {
if {[Object isclass $o]} {
lappend classes $o
if {[Object ismetaclass $o]} {lappend metaclasses $o}
}
}
puts "All classes are: $classes"
puts "All metaclasses are: $metaclasses"
###################################################################
>>>>> "ZV" == Zoran Vasiljevic <zoran at munich.com> writes:
ZV> Hi Gustaf and Uwe !
ZV> First of all, many, many thanks for your time and patience.
ZV> I think I'm getting the (XOTcl) picture slowly.
ZV> I could need a helping hand again, though, 'cause I'm stuck
ZV> a little bit.
ZV> -------
ZV> Given an initialized interpreter I would like to generate
ZV> a script to re-make *all* classes/objects found there.
ZV> But how to get them ? I would not like to resort to
ZV> "namespace is a object/class" assumption....
ZV> Consider this:
ZV> % Class TC
ZV> % TC tobj
ZV> Now get all defined classes ...
ZV> % Class info instances
ZV> ::Class::Parameter ::Class ::Object ::Object::CopyHandler ::TC
ZV> Fine. The "TC" is there.
ZV> % Object info instances
ZV> ::@
ZV> Where is my "tobj" ? What am I doing wrong ?
ZV> I cannot find the "tobj" anywhere.
ZV> Also, If I somehow manage to properly collect all classes
ZV> (and objects) I should somehow follow the class graph,
ZV> when recreating classes, right ? Using (super/sub)class info
ZV> and traversing the class tree/graph, right ?
ZV> I think I could use some example, if you have some lying arround.
ZV> Sincerely,
ZV> Zoran Vasiljevic.
ZV> ______________________________________________
ZV> FREE Personalized Email at Mail.com
ZV> Sign up at http://www.mail.com/?sr=signup
--
Uwe Zdun
Specification of Software Systems, University of Essen
Phone: +49 201 81 00 332, Fax: +49 201 81 00 398
zdun at xotcl.org, uwe.zdun at uni-essen.de
More information about the Xotcl
mailing list