eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'Structure':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: Structure


Inheritance:

   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

Description:


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.

copyright

COPYRIGHT (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.

Class protocol:

initialization
o  initializeOneInstance
check if the first few instvars correspond to Behavior's definition:

instance creation
o  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)

o  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')

o  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'

o  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'

o  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'

o  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'

o  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'

o  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'

o  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
o  primAddSelector: newSelector withMethod: newMethod
must reinit myself when methods are accepted.


Instance protocol:

accessing
o  flags
return the flags - required class protocol

o  flags: anInteger
set the flags - required class protocol

o  i1
prototype method to return the first instance variable

o  i10
prototype method to return the 10th instance variable

o  i10: something
prototype method to set the 10th instance variable

o  i11
return i11

o  i11: something
prototype method to set the 11th instance variable

o  i12
return i12

o  i12: something
set i12

o  i13
return i13

o  i13: something
set i13

o  i14
return i14

o  i14: something
set i14

o  i15
return i15

o  i15: something
set i15

o  i16
return i16

o  i16: something
set i16

o  i17
return i17

o  i17: something
set i17

o  i18
return i18

o  i18: something
set i18

o  i19
return i19

o  i19: something
set i19

o  i1: something
prototype method to set the 1st instance variable

o  i2
prototype method to return the 2nd instance variable

o  i20
return i20

o  i20: something
set i20

o  i21
return i21

o  i21: something
set i21

o  i22
return i22

o  i22: something
set i22

o  i23
return i23

o  i23: something
set i23

o  i24
return i24

o  i24: something
set i24

o  i25
return i25

o  i25: something
set i25

o  i26
return i26

o  i26: something
set i26

o  i27
return i27

o  i27: something
set i27

o  i28
return i28

o  i28: something
set i28

o  i29
return i29

o  i29: something
set i29

o  i2: something
prototype method to set the 2nd instance variable

o  i3
prototype method to return the 3rd instance variable

o  i30: something
set i30

o  i31
return i31

o  i31: something
set i31

o  i32
return i32

o  i32: something
set i32

o  i33
return i33

o  i33: something
set i33

o  i34
return i34

o  i34: something
set i34

o  i35
return i35

o  i35: something
set i35

o  i36
return i36

o  i36: something
set i36

o  i37
return i37

o  i37: something
set i37

o  i38
return i38

o  i38: something
set i38

o  i39
return i39

o  i39: something
set i39

o  i3: something
prototype method to set the 3rd instance variable

o  i4
prototype method to return the 4th instance variable

o  i40
return the value of the instance variable 'i40' (automatically generated)

o  i40: something
prototype method

o  i41
prototype method

o  i41: something
prototype method

o  i42
prototype method

o  i42: something
prototype method

o  i43
prototype method

o  i43: something
prototype method

o  i44
prototype method

o  i44: something
prototype method

o  i45
prototype method

o  i45: something
prototype method

o  i46
prototype method

o  i46: something
prototype method

o  i47
prototype method

o  i47: something
prototype method

o  i48
prototype method

o  i48: something
prototype method

o  i49
prototype method

o  i49: something
prototype method

o  i4: something
prototype method to set the 4th instance variable

o  i5
prototype method to return the 5th instance variable

o  i50
prototype method

o  i50: something
prototype method

o  i5: something
prototype method to set the 5th instance variable

o  i6
prototype method to return the 6th instance variable

o  i6: something
prototype method to set the 6th instance variable

o  i7
prototype method to return the 7th instance variable

o  i7: something
prototype method to set the 7th instance variable

o  i8
prototype method to return the 8th instance variable

o  i8: something
prototype method to set the 8th instance variable

o  i9
prototype method to return the 9th instance variable

o  i9: something
prototype method to set the 9th instance variable

o  instSize
return instSize - required class protocol

o  instSize: anInteger
set instSize - required class protocol

o  methodDictionary
return the methodDictionary - required class protocol

o  superclass
return superclass - required class protocol

o  superclass: aClass
set superclass - required class protocol

stubs
o  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.


Examples:


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


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Mon, 18 Nov 2024 04:44:33 GMT