container.c--
./world-0.6/src/container.c-- · 2.3 KB
From the archive Glacier-0.6.tar.gz
Download the archive « Back to the archive contents
Container object
This object defines object behavior related to having contents.
Public methods:
contents() Get contents
contains(obj) Determine if object in contents
put(obj) Put object in container
take(obj) Take object from container
Non-overridable calls from $located:
add_sender_to_contents() Add sender to contents
remove_sender_from_contents() Remove sender from contents
Overridable notification calls from $located:
will_arrive(old_place) Notification of impending arrival
will_leave(place) Notification of impending departure
did_arrive(old_place) Notification of completed arrival
did_leave(place) Notification of completed departure
parent vr
object container
var root name 'container
var container contents 0
method init_container
if (caller() != $root)
throw(~perm, "Caller is not $root.");
contents = [];
.
method uninit_container
if (caller() != $root)
throw(~perm, "Caller is not $root.");
// Do something about contents. This isn't it.
contents = 0;
.
eval
.initialize();
.set_vr_name("Generic container object");
.
method environment
return [this()] + contents;
.
method contents
return contents;
.
method contains
arg obj;
return obj in contents ? 1 | 0;
.
method put
arg obj;
obj.move(this());
.
method take
arg obj;
if (!(obj in contents))
throw(~objnf, "Object (" + toliteral(obj) + ") not in contents.");
obj.move(sender());
.
method will_arrive
arg old_place;
if (caller() != $located)
throw(~perm, "Caller is not $located.");
.
method will_leave
arg place;
if (caller() != $located)
throw(~perm, "Caller is not $located.");
.
method did_arrive
arg place;
if (caller() != $located)
throw(~perm, "Caller is not $located.");
.
method did_leave
arg place;
if (caller() != $located)
throw(~perm, "Caller is not $located.");
.
method add_sender_to_contents
disallow_overrides;
if (caller() != $located)
throw(~perm, "Caller is not $located.");
if (sender().location() != this())
throw(~location, "Sorry, but you're not here.");
contents = setadd(contents, sender());
.
method remove_sender_from_contents
disallow_overrides;
if (caller() != $located)
throw(~perm, "Caller is not $located,");
contents = setremove(contents, sender());
.