The first step in building an application to run under Shore is to define the data types of all persistent data that will be used by the application. These declarations are written in a type-definition language called SDL (for Shore Data-definition Language). The file stree.sdl contains the type definitions for the binary search tree example. This file contains one module, called stree, which defines four types: SearchTree, Word, Document, and Cite. These types are defined by interface definitions, which are quite similar to class definitions in C++.
SearchTree is the top-level object. The example program will create exactly one object of this type. Its public interface consists of three operations: initialize, insert, and find. It also defines one private operation, an alternate (overloaded) version of insert, and one attribute, a ref (persistent pointer) to the Word object that is the root of the tree. The comments in stree.sdl explain the semantics of the operations and attributes; we will remark here only on aspects of the definition that illustrate features of SDL.
The initialize operation of a SearchTree should be invoked once immediately after it is created. SDL does not yet have the counterpart of constructors and destructors in C++. (This deficiency may be rectified in a future version.) The insert operation is intended to be invoked with one argument, which is a (transient) C++ character string. We use type type lref<char>, which translates to char * in the C++ binding. This is a bit of a kludge. Future versions of SDL will probably have a more general mechanism for declaring operations whose parameters have "opaque" (i.e., non-SDL) types.
Word represents a node in the search tree. The private part of the interface is similar to the way one might define a binary search tree node in C++ or C. A Word has a string value and pointers to its left and right subtrees. The type string is a pre-defined type in SDL representing an arbitrary-length character string. The relationship declaration indicates that Words participate in an N-M (many-to-many) relationship with Cites. That is, for each instance w of Word, w.cited_by is a set of zero or more references to Cite objects. Moreover, Word::cited_by and Cite::cites are to be kept consistent: w.cited_by should contain a reference to an instance c of Cite if and only if c.cites contains a reference to w. The operations find_or_add and find are intended only to be called from the operations of SearchTree. They would be in the private part of the interface if SDL had the equivalent of the friend declaration of C++.
A Cite object represents a citation (an occurrence of a word in a line of a document). The offset attribute indicates the offset of the cited line from the beginning of the document, in bytes. If SDL supported first class relationships in the sense of the entity-relationship model-that is, if relationships could have attributes-Cite would have been declared as a relationship between Word and Document with attribute offset. Instead, a Cite is represented by a separate object, with a many-to-many relationship to Word (each word may occur on many lines and each line may cite several words) and a many-to-one relationship to Documment (a document may have many lines, but each line cites a unique document).
Finally, Document represents an actual document stored in the repository. The type text of the attribute body is the same as string, but has the additional function of declaring that when a Document is accessed through the Unix compatibility interface, it will appear to be a file whose contents are the contents of this field.