1: #!/usr/bin/env rexx
2: /**
3: * A small test script to show the use of constrained attributes for
4: * MapCollection subclasses. This can be useful in situations where
5: * a sizable amount of attributes is defined, but only a selection is
6: * actually used in certain cases. An Object's instance methods
7: * will show the actual ones being used. Furthermore it prevents
8: * inadvertent creation of unwanted attributes.
9: *
10: * 2025/10/30 - Added Rony Flatcher's suggestion to use 'ACTIVATE'
11: */----------------------------------------------------------------
12: say "Allowable mixin for a .StringTable or .Directory"
13: trip = .Trip~new("TITLE COMMENT DESCRIPTION INFO MODE WAYPOINTS TRACKS")
14: say "Adding title attribute via Unknown and setEntry"
15: trip~title="Bergen-Lofoten-Oslo"
16: say
17: say "Using putAll to add multiple attributes"
18: multi = .StringTable~new
19: multi~comment="Haha"
20: multi~description="Hihi"
21: trip~putall(multi)
22: say
23: say "Using setEntry directly"
24: trip~setEntry("MODE", "Cycling")
25: say
26: say "Show the result"
27: do attr over trip
28: say attr'='trip[attr]
29: end
30: say
31: say "Delete an attribute via setEntry"
32: trip~setEntry("DESCRIPTION")
33: say
34: say "Show the result again"
35: do attr over trip
36: say attr'='trip[attr]
37: end
38: say
39: say "Allowable mixin for a .Properties"
40: say
41: props = .Settings~new(north east south west)
42: props~setWhole('NORTH',52)
43: props~setLogical(EAST, 1)
44: props~setProperty(WEST, "013°24"||'01.8054" W')
45: say "North:" props[NORTH]", South:" props~south", East:" props~east", West:" props~west
46: say
47: say "Allowable mixin for a .Set or .Bag"
48: say
49: tombola = .Fruit~new("APPLE BANANA PRUNE PEACH STRAWBERRY")
50: tombola[]=apple
51: tombola~put(peach)
52: -- I think PUTALL uses PUT for each list item
53: tombola~putall(.List~of(prune,apple,strawberry,peach))
54: say tombola~allindexes~toString(,', ')
55: say 'Perhaps try some yourself here in interactive Trace mode'
56: trace ?i
57: nop
58: exit
59:
60: ::class Trip public subclass Directory
61: ::method activate class -- conclude setup by applying inherit
62: self~inherit(.AllowableAttributes,.Directory)
63:
64: ::method init
65: self~init:super(arg(1))
66: exit
67:
68: ::class Settings public subclass Properties
69: ::method activate class -- conclude setup by applying inherit
70: self~inherit(.AllowableAttributes,.Properties)
71:
72: ::method init
73: self~init:super(arg(1))
74: exit
75:
76: ::class Fruit public subclass Bag
77: ::method activate class -- conclude setup by applying inherit
78: self~inherit(.AllowableAttributes,.Bag)
79:
80: ::method init
81: self~init:super(arg(1))
82: exit
83:
84: ::requires 'AllowableAttributes.cls'
85:
86: