|
Class: Structure
Object
|
+--Behavior
|
+--Structure
- Package:
- stx:libcomp
- Category:
- Kernel-Classes
- Version:
- rev:
1.49
date: 2022/07/20 12:08:41
- user: stefan
- file: Structure.st directory: libcomp
- module: stx stc-classLibrary: libcomp
This is an experimental class, stressing the metaObject capabilities.
Structures are objects which are class-less,
only holding some values, and provide a protocol to access
those fields. In addition, they support the array-protocol,
so they can be used as backward compatible replacements in
places where arrays were returned.
(However, we recommend using private classes, since they are easier
to understand and maintain).
For example, some structure object can be create with:
^ Structure with:#foo->'someFooValue' with:#bar->'someBarValue'
and access these values either as:
retVal at:1 -> returns the foo instvar value
retVal at:2 -> returns the bar instvar value
or (much more convenient and readable) as:
retVal foo
retVal bar
Implementation note:
this is a very tricky (but fully legal) implementation,
creating an object which is its own class.
Therefore, no additional overhead by extra (class) objects is involved.
These are very lightweight objects.
Another prove that smalltalk is a powerful & flexible programming language.
However, some smalltalk systems crash if your try this ;-)
CAVEAT:
tricky implementation - not the full object protocol is supported;
a maximum of 50 instance variables is allowed.
copyrightCOPYRIGHT (c) 1996 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
initialization
-
initializeOneInstance
-
check if the first few instvars correspond to Behavior's definition:
instance creation
-
newWith: names
-
return a new structure containing fields as passed in the names collection.
The argument must be a sequenceable collection of symbols.
The new structures values are all initialized to nil.
Usage example(s):
Structure newWith:#(foo bar)
|
-
newWith: names values: values
-
return a new structure containing fields as passed in the names collection.
The argument must be a sequenceable collection of symbols.
The new structures values are set to corresponding values from the second argument, values.
Usage example(s):
Structure newWith:#(foo bar) values:#('foo' 'bar')
|
-
with: assoc
-
return a new structure with a single field, named to the assocs key,
and initialized with assocs value.
Usage example(s):
Structure with:#foo->'foo'
|
-
with: assoc1 with: assoc2
-
return a new structure with two fields, named as defined by the arguments'
keys, and and initialized with the assocs' values.
Usage example(s):
Structure with:#foo->'foo' with:#bar->'bar'
|
-
with: assoc1 with: assoc2 with: assoc3
-
return a new structure with three fields, named as defined by the arguments'
keys, and and initialized with the assocs' values.
Usage example(s):
Structure with:#foo->'foo' with:#bar->'bar' with:#baz->'baz'
|
-
with: assoc1 with: assoc2 with: assoc3 with: assoc4
-
return a new structure with four fields, named as defined by the arguments'
keys, and and initialized with the assocs' values.
Usage example(s):
Structure with:#foo->'foo' with:#bar->'bar' with:#baz->'baz' with:#hello->'hello'
|
-
with: assoc1 with: assoc2 with: assoc3 with: assoc4 with: assoc5
-
return a new structure with five fields, named as defined by the arguments'
keys, and and initialized with the assocs' values.
Usage example(s):
Structure with:#foo->'foo' with:#bar->'bar' with:#baz->'baz' with:#hello->'hello' with:#world->'world'
|
-
with: assoc1 with: assoc2 with: assoc3 with: assoc4 with: assoc5 with: assoc6
-
return a new structure with five fields, named as defined by the arguments'
keys, and and initialized with the assocs' values.
Usage example(s):
Structure with:#foo->'foo' with:#bar->'bar' with:#baz->'baz' with:#hello->'hello' with:#world->'world'
|
-
with: assoc1 with: assoc2 with: assoc3 with: assoc4 with: assoc5 with: assoc6 with: assoc7
-
return a new structure with five fields, named as defined by the arguments'
keys, and and initialized with the assocs' values.
Usage example(s):
Structure with:#foo->'foo' with:#bar->'bar' with:#baz->'baz' with:#hello->'hello' with:#world->'world'
|
special
-
primAddSelector: newSelector withMethod: newMethod
-
must reinit myself when methods are accepted.
accessing
-
flags
-
return the flags - required class protocol
-
flags: anInteger
-
set the flags - required class protocol
-
i1
-
prototype method to return the first instance variable
-
i10
-
prototype method to return the 10th instance variable
-
i10: something
-
prototype method to set the 10th instance variable
-
i11
-
return i11
-
i11: something
-
prototype method to set the 11th instance variable
-
i12
-
return i12
-
i12: something
-
set i12
-
i13
-
return i13
-
i13: something
-
set i13
-
i14
-
return i14
-
i14: something
-
set i14
-
i15
-
return i15
-
i15: something
-
set i15
-
i16
-
return i16
-
i16: something
-
set i16
-
i17
-
return i17
-
i17: something
-
set i17
-
i18
-
return i18
-
i18: something
-
set i18
-
i19
-
return i19
-
i19: something
-
set i19
-
i1: something
-
prototype method to set the 1st instance variable
-
i2
-
prototype method to return the 2nd instance variable
-
i20
-
return i20
-
i20: something
-
set i20
-
i21
-
return i21
-
i21: something
-
set i21
-
i22
-
return i22
-
i22: something
-
set i22
-
i23
-
return i23
-
i23: something
-
set i23
-
i24
-
return i24
-
i24: something
-
set i24
-
i25
-
return i25
-
i25: something
-
set i25
-
i26
-
return i26
-
i26: something
-
set i26
-
i27
-
return i27
-
i27: something
-
set i27
-
i28
-
return i28
-
i28: something
-
set i28
-
i29
-
return i29
-
i29: something
-
set i29
-
i2: something
-
prototype method to set the 2nd instance variable
-
i3
-
prototype method to return the 3rd instance variable
-
i30: something
-
set i30
-
i31
-
return i31
-
i31: something
-
set i31
-
i32
-
return i32
-
i32: something
-
set i32
-
i33
-
return i33
-
i33: something
-
set i33
-
i34
-
return i34
-
i34: something
-
set i34
-
i35
-
return i35
-
i35: something
-
set i35
-
i36
-
return i36
-
i36: something
-
set i36
-
i37
-
return i37
-
i37: something
-
set i37
-
i38
-
return i38
-
i38: something
-
set i38
-
i39
-
return i39
-
i39: something
-
set i39
-
i3: something
-
prototype method to set the 3rd instance variable
-
i4
-
prototype method to return the 4th instance variable
-
i40
-
return the value of the instance variable 'i40' (automatically generated)
-
i40: something
-
prototype method
-
i41
-
prototype method
-
i41: something
-
prototype method
-
i42
-
prototype method
-
i42: something
-
prototype method
-
i43
-
prototype method
-
i43: something
-
prototype method
-
i44
-
prototype method
-
i44: something
-
prototype method
-
i45
-
prototype method
-
i45: something
-
prototype method
-
i46
-
prototype method
-
i46: something
-
prototype method
-
i47
-
prototype method
-
i47: something
-
prototype method
-
i48
-
prototype method
-
i48: something
-
prototype method
-
i49
-
prototype method
-
i49: something
-
prototype method
-
i4: something
-
prototype method to set the 4th instance variable
-
i5
-
prototype method to return the 5th instance variable
-
i50
-
prototype method
-
i50: something
-
prototype method
-
i5: something
-
prototype method to set the 5th instance variable
-
i6
-
prototype method to return the 6th instance variable
-
i6: something
-
prototype method to set the 6th instance variable
-
i7
-
prototype method to return the 7th instance variable
-
i7: something
-
prototype method to set the 7th instance variable
-
i8
-
prototype method to return the 8th instance variable
-
i8: something
-
prototype method to set the 8th instance variable
-
i9
-
prototype method to return the 9th instance variable
-
i9: something
-
prototype method to set the 9th instance variable
-
instSize
-
return instSize - required class protocol
-
instSize: anInteger
-
set instSize - required class protocol
-
methodDictionary
-
return the methodDictionary - required class protocol
-
superclass
-
return superclass - required class protocol
-
superclass: aClass
-
set superclass - required class protocol
stubs
-
doesNotUnderstand: aMessage
-
catch unimplemented messages - pass some to the superclass.
Notice that although this method calls super messages,
actual instances will have no valid superClass.
access is possibly by name:
Transcript showCR:
(Structure with:#foo->'foo value') foo
|
AND also by index (for backward compatibility):
Transcript showCR:
((Structure with:#foo->'foo value') at:1)
|
it can be inspected:
(Structure with:#foo->'foo value') inspect
|
and presents its contents nicely:
(Structure with:#foo->'foo value' with:#bar->'bar value') inspect
|
(Structure with:#foo->'hello' with:#bar->true with:#baz->'world') inspect
|
|