|
The Stack PROTO stores information
of the type MFString in LiFo order.
This means that it implements a storage that gives you the most recently stored
piece of data when you read from the storage. It's like a stack of books.
When you put books onto the stack and then take one book after another from the
stack you get them in reverse order.
EXTERNPROTO Stack
[
eventIn MFString dataToStore
eventIn SFTime retreiveData
eventOut MFString retreivedData
eventOut SFTime nothingAvail
eventOut SFInt32 length
exposedField SFInt32 maxLength # -1
eventIn SFTime clear
eventOut SFBool isLoaded
]
"Stack.wrl#Stack"
|
|
|
Explanation of the fields:
eventIn MFString dataToStore
eventIn SFTime retreiveData
eventOut MFString retreivedData
eventOut SFTime nothingAvail
These fields perform the main access to the stack. If you send some data to dataToStore,
this data is put on top of the stack. If you send a value to retreiveData, one
piece of data is read from the stack. For a simple implementation the actual time value you send is irrelevant. If data could
be read, this is indicated at retreivedData. If no data could be read,
a time value is sent on nothingAvail.
eventOut SFInt32 length
This indicates the length of the stack, i.e. the number of data items stored in the stack.
Each time the length of the stack changes this indicates the new value.
exposedField SFInt32 maxLength -1
This field allows for limitting the maximum length of the stack. If maxLength is
-1, there is no limit on the number of items stored in the stack.
If maxLength is 0 or greater than 0,
this is the maximum number of data items stored in the stack. maxLength
can be changed on the fly. If it is set to a value lesser then the number
of items currently stored in the stack, the oldest ones are removed.
They don't come back if the limit is increased afterwards.
eventIn SFTime clear
This field allows for clearing the stack. When this receives a value, the
content of the stack is cleared immediately.
eventOut SFBool isLoaded
This field allows for load management of the EXTERNPROTO. Because VRML
browsers should ignore events that are routed to an EXTERNPROTO node that
is not yet loaded, some may get lost. The isLoaded
sends TRUE when the node has been loaded and
initialized.
The Demo:
On the top left there is a menu that lets you create new nodes. Right to them
there are some sliders that
allow you to modify the size of the node. On the bottom there
is a line of text showing an MFString
value that describes the node and its properties. Below this line you
can push this string onto the stack or pop a previous one from it.
Between the Push and Pop button the number of elements in the stack are
displeayed.
When you push the MFString
describing the current node onto the stack, the node itself is destroyed.
Popping an MFString from the stack
recreates the node with the parameters
described in the MFString.
Thus this file also demonstrates how the MFString
data type can be used to express compound information, that other
programming languages would store in a
struct/
Record/etc.
This principle does not only
apply to the Stack PROTO, but for all cases where structured data has to be
transported over a single ROUTE. Because an MFString instead of an
SFString is used, no parsing
into words on the receivers end has to be done and no quoting of spaces is necessary.
The JavaScript functions parseInt(.) and parseFloat(.) help converting numbers
back to SFInt32,
SFFloat,
SFVec3f, etc.
Popping from an empty stack is indicated by the string "-/-"
instead of an MFString
value.
Interoperability
I didn't make much effort to make the demo run in Cortona or Pivoron.
In Cortona the sliders don't show up for some reason, but you can at least verify that the
Stack PROTO works.
Pivoron has problems with the name length
for an eventOut. If you want to use the Stack
PROTO with Cosmo or Pivoron, you'd have to change the name of that field to
something else in your copy of the file. (I didn't verify whether Stack
works at all in Cosmo/Pivoron.)
__.-.__ end of document
|