next up previous contents index
Next: Destruction of objects Up: Objects and structures Previous: Aliases of object types   Contents   Index


Objects of undefined data type

This is the type 7 of variables for objects. It is suitable to store the user defined data types. For this kind of object there are no dimensions, but one should put at least one for compatibility reasons. For instance, suppose that the user needs to manipulate some kind of data called Data0 (for instance, it could be a structure). Then in the !def section of the initialization file, one could find

; Objects of undetermined type
defobj3
-1
7
1
Struc0's : 
10
nb_struc0

Here these objects are declared to have 1 dimension, which is 10, but this does not matter. We suppose also that this is the 3rd type of objects that we have in the initialization file. Now the command defobj3 will not create any Data0, but rather some place to store the address of such a data type and a name associated to this address. To really create a Data0 one needs a specific command, say Def_Data0. This command could work as follows :

- interpcom -> Def_Data0 xxx

should create a Data0 whose name is xxx. One could also make a more complicated command, with more arguments such as parameters for the Data0 to be created. The command Def_Data0 can be implemented as follows :

int
Def_Data0_cmd(int argc, char *argv[]) 
{ 
    int i0, iw; 
    char *k[3],**e; 
    Data0 *D; 
    flow_data *flow_interp;

    flow_interp = (flow_data *) argv[-1];
    iw = sketch_obj(argv[1], &i0, flow_interp); 
    if (iw != 0) {
        error_mess(4, flow_interp); 
        return 1; 
    }
    k[0] = (char *) flow_interp;
    k[1] = ch_copy("objdef");
    k[2] = ch_copy("3");
    if (obj_create(3, k + 1) == -1) { 
        error_mess(3, flow_interp);
        return 1;
    }
    D = Data0_create()  /* user-supplied function that creates a Data0 */
    e = (char**) Obj[2][i0].adresse;
    e[0] = (char*) D;
    free(k[1]);
    free(k[2]);
}

Here the function sketch_obj is used to see if the name xxx has not been already used. If it has been used, the error message 4 is printed, and the function exits (this message could be already used name !). Then the object defobj3 is created and associated to the name xxx, using the function obj_create. A new Data0 is then created, and its address is stored in the object.

Some commands manipulating objects are present in the library : const, const_c, const_r, const_th, copy, multiply, substract, svg, restore (cf. 11).


next up previous contents index
Next: Destruction of objects Up: Objects and structures Previous: Aliases of object types   Contents   Index
2009-11-12