[UP] Modules |
WDialog API for Objective Caml: Wd_interactor
Module Wd_interactormodule Wd_interactor:This module provides a data type for containers of interactor descriptions. The background of the module is that interactors (such as input elements, hyperlinks, buttons) are referred to by two different naming schemes. On the one hand, the interactor elements in the ui file have a name and and optionally an index; e.g.
or
Often the name/index pair is actually a variable/index pair because the
interactor is bound to a certain instance variable of the uiobject.
- On the other hand, the interactors are transformed to HTML code, and
the HTML/CGI name is different. For example the following HTML output
might have been generated:
or
Obviously, the HTML/CGI names are automatically chosen. Of course, there
is a bijective mapping from the internal names to the HTML/CGI names,
and the task of the Interactor.t type is to manage these mappings.
A value of type Interactor.t contains the following:
Note that the "25" is an automatically created identifier (just the next free number), and that the HTML/CGI name will be composed of a prefix indicating the type of the interactor and the identifier, e.g. "xbutton_25". If we try to add the same name/index pair a second time, the add operation raises an exception:
==> raises Element_exists "25"
When the incoming CGI parameters are analyzed, it must be possible to look up the name/index pair for a given identifier. For example:
There is no reverse lookup operation. However, it is at least possible to test the existence of a given name/index pair:
As a last resort, it is possible to iterate over all members of the ia value:
Selecting the identifier manually
If the ui element contains the
The generated HTML code:
Such an interactor would be added as follows:
I.e. you can determine the identifier by passing it as fourth argument.
Of course, in this case it is checked whether the identifier is still
free; and Representation
Note that the representation of Further information type
The type of interactors
type
Interactors are identified by strings
exception Element_exists of
Raised by some functions if there is already a component with the ID
val create : create x : Creates a new interactor manager. The value x must only
be passed because of typing restrictions.val clear : clear ia : Removes all entries from the interactor. The sequence
generator for the automatic IDs is not reset, however.val add : add ia name index opt_id value : adds the triple (name,index,value) to
ia ; if opt_id is None , the triple gets an automatically selected
numerical ID; if opt_id is Some id , the triple has the ID id .
The function returns the ID.
Fails with val lookup : lookup ia id : looks up the triple (name,index,value) for the ID id
within ia .
Fails with "Interactor.lookup" if the id cannot be associated. val exists : exists ia name index : returns whether the pair (name,index) exists
in ia .val iter : iter f ia : iterates over the elements of ia and invoke the function
f for every element by f id name index value .val serialize : serialize f b ia : Writes the serialization of ia to buffer b .
Contained values are serialized by calling f .val unserialize : unserialize f buf : Reads the serialized string from buf and reconstructs
the interactors. Values are read by calling f . |