Re: [gdome]user_data and language bindings



> I would like to understand what you are doing, but I am not familiar with
> ocaml and its pre-methods. Are you saying that you wrap all nodes of a DOM
> tree at once, and that your wrapper objects duplicate the navigational
> methods of the gdome layer? 

 Example. At the "pre-method" level the Node interface appears as:

 get_nodeName : this:[> `Node] GdomeT.t -> TDOMString.t
 get_nodeValue : this:[> `Node] GdomeT.t -> TDOMString.t
 insertBefore : this:[> `Node] GdomeT.t -> newchild:[> `Node] GDomeT.t ->
  refChild:[> `Node] GdomeT.t option -> TNode.t
 ...

 [ Quick explanation on the notation:
  
   1) f : foo1:T1 -> .... -> foon:Tn -> R

      means
  
      R f(T1 foo1, ...., Tn foon) 

      in C notation. Note that the first argument is always labelled
      this. So these are pre-methods, i.e. functions taking in input
      this and performing some operation.
   2) [> `X] GdomeT.t

      means a subclass of X. So, for example, [> `Node] GdomeT.t means
      any subclass of the Node class.
   3) There is no NULL value of type any pointer in Ocaml.
      
      X option
      
      is the type of values of type X plus a "NULL"-like value.
 ]

 So, all the above pre-methods are just plain bindings to the Gdome
 methods, plus some additional typing constraints. (Ocaml is strongly
 typed, of course ;-)


 The OO level is implemented in this way:

 class node (obj : [> `TNode.t] GdomeT.t) =
  object
   method as_obj = obj
   method get_nodeName =
    let obj' = INode.get_nodeName ~this:obj in
     new domString obj'
   method get_nodeValue =
    let obj' = INode.set_nodeName ~this:obj in
     new domString obj'
   method insertBefore ~newChild ~refChild =
    let obj' = INode.insertBefore ~this:obj
     ~newChild:(newChild#as_Node)
     ~refChild:(match refChild with
                   None -> None
		 | Some refChild -> Some (refChild#as_Node))
    in
     new node obj'
   ...
  end

 Some explanation:

 1) This defines a class whose name is node. The constructor of the
    class has one parameter, whose name is obj and whose type is the
    same of the "this" parameters of the pre-method. So, for example,
    if foo is a pre-method this, then

     new node foo

    builds a new object of type node.
 2) obj#foo is the invocation of method foo on object obj.
    It is obj.foo() in  C notation.
 3) The pattern should be clear. Let's examine the insertBefore method:
    a) First of all, the method has two parameters. Both of them are
       of type node (i.e. the class node)
    b) From the two parameters, we extract their "this" using the
       as_node method. (i.e. newChild#as_node returns the reference to
       "this" of the object newChild). These references are the one
       requested in input from the functions of the pre-method level.
    c) INode.insertBefore, which is the pre-method, is called on
       the "this" of our class and on the "this"s of the parameters.
       It returns the "this" of a class of type Node, which is name obj'.
    d) Finally, obj' is raised to the OO level by constructing a new
       class of type node whose "this" becomes obj': new node obj'
    
    To sum up, we have two "functions" (the constructor and as_node)
    to map "this" of the pre-method level to objects at the OO-level.
    A method M at the OO level is the composition of a constructor
    with the pre-method M' with the as_node method.

 As you can see we don't need to store any information in the user_data field.
 Moreover, we can always add more information at the OO-level. How? We
 simply add new fileds to the OO-level classes. An hash-table can finally
 be used to map this to OO objects, so that when we rebuild (using new)
 an OO object corresponding to a this we can also retrieve from the
 hash-table the additional information that was associated to the class.


 I hope at least 5% of what I have written is understandable from
 members of the non-ocaml community ;-|

 					Regards,
					C.S.C.

-- 
----------------------------------------------------------------
Real name: Claudio Sacerdoti Coen
PhD Student in Computer Science at University of Bologna
E-mail: sacerdot cs unibo it
http://caristudenti.cs.unibo.it/~sacerdot
----------------------------------------------------------------



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]