Data Structures Using Shelves

[Previous] [Next]

OmniMark provides a data structure named a shelf. You can refer to each item on a shelf either by position or by a textual key. Shelves can be either fixed or variable in size. All OmniMark variables are in fact shelves, though an ordinary variable is a fixed-size shelf with one item, so the fact that it is a shelf is not particularly significant.

A global stream shelf declaration that creates a shelf of variable size named quotations looks like this:

 global stream quotations variable 

The default size of a variable-size shelf is zero items. A local integer shelf declaration that creates an integer shelf named totals with a fixed size of 3 looks like this:

 local integer totals size 3 

If you want to create a shelf with initial values that are different from the defaults, add an initial keyword to the declaration, followed by the values you want on the shelf enclosed in brackets. For example:

 global integer sizes size 4 initial {1, 2, 3, 4} 

This declaration creates a global integer shelf named sizes that can hold four values with initial values of 1, 2, 3, and 4. You could also create a variable-size shelf that contains a number of initial values, like this:

 global integer sizes variable initial {1, 2, 3, 4} 

The only difference between these two shelves is that while the first is a fixed-size shelf holding four values, the second begins with four values and can expand or contract to hold as many values as required.

Additionally, you can create shelves of a particular size without having to assign initial values to the shelf items. Do this by using the initial-size keyword:

 global integer sizes variable initial-size 4 

This declaration creates an integer shelf that starts with four items and can expand or contract as required.

To add the string "Now is the winter of our discontent" in the variable stream shelf quotations, use the following action:

 set new quotation to "Now is the winter of our discontent" 

To access an item on a shelf, you must supply an indexer: either an item number or a key. Square brackets indicate item numbers; braces indicate keys.

 set quotation[3] to "Words, words, words." output quotation{"Hamlet"} 

You can assign a key to an existing item:

 set key of quotation[2] to "Richard iii" 

You can set a key on a shelf item in the same action in which you create the new item. For example, to create a new item on the quotes shelf that has a value of "Alas, poor Yorick." with the key "Hamlet", use the following action:

 set new quotes{"Hamlet"} to "Alas, poor Yorick." 

By default, new items are created at the end of a shelf. You can use the before or after keywords to create a new item somewhere else on a shelf. For example, to create a new item that will exist immediately before the second item on a shelf, use the following action:

 set new quotes before [2] to "A horse!" 

This action creates a new item containing the value "A horse!" between the first and second items on the quotes shelf. Since the item numbers are based on shelf position, this new item would become item 2, and the item that was number 2 would become number 3.

If you want to create a new item on a shelf just after an item that had the key "Macbeth", use the action:

 set new quotes{"Richard iii"} after {"Macbeth"} to "A horse!" 

To help illustrate the concept of OmniMark shelves, the following program creates a stream shelf and sets the first item on that shelf to a value. Next the program gives that first item a key. Then three other items are created: one at the default end of the shelf, another before the second item on the shelf, and the third after a value with a set key.

 process local stream quotes variable set new quotes{"Hamlet"} to "To be or not to be?" set new quotes{"Macbeth"} to "Is this a dagger?" set new quotes{"Richard iii"} before [2] to "A horse!" set new quotes{"Romeo"} after {"Richard iii"} to "Hark, what light through yonder window breaks?" repeat over quotes output key of quotes || " - " || quotes || "%n" again 

This program has the following output:

 Hamlet - To be or not to be? Richard III - A horse! Romeo - Hark, what light through yonder window breaks? Macbeth - Is this a dagger? 



XML and SOAP Programming for BizTalk Servers
XML and SOAP Programming for BizTalk(TM) Servers (DV-MPS Programming)
ISBN: 0735611262
EAN: 2147483647
Year: 2000
Pages: 150

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net