1 /*  Part of XPCE --- The SWI-Prolog GUI toolkit
2 
3     Author:        Jan Wielemaker and Anjo Anjewierden
4     E-mail:        jan@swi.psy.uva.nl
5     WWW:           http://www.swi.psy.uva.nl/projects/xpce/
6     Copyright (c)  1985-2002, University of Amsterdam
7     All rights reserved.
8 
9     Redistribution and use in source and binary forms, with or without
10     modification, are permitted provided that the following conditions
11     are met:
12 
13     1. Redistributions of source code must retain the above copyright
14        notice, this list of conditions and the following disclaimer.
15 
16     2. Redistributions in binary form must reproduce the above copyright
17        notice, this list of conditions and the following disclaimer in
18        the documentation and/or other materials provided with the
19        distribution.
20 
21     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25     COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32     POSSIBILITY OF SUCH DAMAGE.
33 */
34 
35 #include <h/kernel.h>
36 
37 typedef struct assoc *Assoc;
38 
39 NewClass(assoc)
40   ABSTRACT_CODE
41   Name	reference;			/* reference of the object */
42   Any	object;				/* Object to reference */
43 End;
44 
45 
46 static status
initialiseAssoc(Assoc a,Name name,Any object)47 initialiseAssoc(Assoc a, Name name, Any object)
48 { initialiseCode((Code) a);
49 
50   assign(a, reference, name);
51   assign(a, object,    object);
52 
53   succeed;
54 }
55 
56 
57 static status
ExecuteAssoc(Assoc a)58 ExecuteAssoc(Assoc a)
59 { return nameReferenceObject(a->object, a->reference);
60 }
61 
62 		 /*******************************
63 		 *	 CLASS DECLARATION	*
64 		 *******************************/
65 
66 /* Type declarations */
67 
68 static char *T_initialise[] =
69         { "reference=name", "object=object|function" };
70 
71 /* Instance Variables */
72 
73 static vardecl var_assoc[] =
74 { IV(NAME_reference, "name", IV_BOTH,
75      NAME_reference, "Reference to give to the object"),
76   IV(NAME_object, "object|function", IV_BOTH,
77      NAME_reference, "Object to assign reference")
78 };
79 
80 /* Send Methods */
81 
82 static senddecl send_assoc[] =
83 { SM(NAME_Execute, 0, NULL, ExecuteAssoc,
84      DEFAULT, "Assign the reference"),
85   SM(NAME_initialise, 2, T_initialise, initialiseAssoc,
86      DEFAULT, "Create from reference and object")
87 };
88 
89 /* Get Methods */
90 
91 #define get_assoc NULL
92 /*
93 static getdecl get_assoc[] =
94 {
95 };
96 */
97 
98 /* Resources */
99 
100 #define rc_assoc NULL
101 /*
102 static classvardecl rc_assoc[] =
103 {
104 };
105 */
106 
107 /* Class Declaration */
108 
109 static Name assoc_termnames[] = { NAME_reference, NAME_object };
110 
111 ClassDecl(assoc_decls,
112           var_assoc, send_assoc, get_assoc, rc_assoc,
113           2, assoc_termnames,
114           "$Rev$");
115 
116 
117 status
makeClassAssoc(Class class)118 makeClassAssoc(Class class)
119 { return declareClass(class, &assoc_decls);
120 }
121 
122