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 #include <h/trace.h>
37
38 static status
initialiseAttribute(Attribute att,Any name,Any value)39 initialiseAttribute(Attribute att, Any name, Any value)
40 { initialiseProgramObject(att);
41
42 assign(att, name, name);
43 assign(att, value, value);
44
45 succeed;
46 }
47
48
49 static Attribute
getConvertAttribute(Class class,Any name)50 getConvertAttribute(Class class, Any name)
51 { answer(answerObject(ClassAttribute, name, NIL, EAV));
52 }
53
54
55 static status
sendAttribute(Attribute att,Any rec,Any value)56 sendAttribute(Attribute att, Any rec, Any value)
57 { assign(att, value, value);
58
59 succeed;
60 }
61
62
63 static Any
getAttribute(Attribute att,Any rec)64 getAttribute(Attribute att, Any rec)
65 { return att->value;
66 }
67
68
69 /********************************
70 * TRACING *
71 ********************************/
72
73 static Type
getArgumentTypeAttribute(Attribute att,Int n)74 getArgumentTypeAttribute(Attribute att, Int n)
75 { if ( isDefault(n) || n == ONE )
76 answer(TypeAny);
77
78 fail;
79 }
80
81 /*******************************
82 * CLASS DECLARATION *
83 *******************************/
84
85 /* Type declaractions */
86
87 static char *T_send[] =
88 { "context=object", "value=any" };
89 static char *T_initialise[] =
90 { "name=any", "value=any" };
91
92 /* Instance Variables */
93
94 static vardecl var_attribute[] =
95 { IV(NAME_name, "any", IV_BOTH,
96 NAME_storage, "Name of the attribute"),
97 IV(NAME_value, "any", IV_BOTH,
98 NAME_storage, "Value of the attribute")
99 };
100
101 /* Send Methods */
102
103 static senddecl send_attribute[] =
104 { SM(NAME_initialise, 2, T_initialise, initialiseAttribute,
105 DEFAULT, "Create attribute from name and value"),
106 SM(NAME_send, 2, T_send, sendAttribute,
107 NAME_execute, "Invoke (write) object-attribute")
108 };
109
110 /* Get Methods */
111
112 static getdecl get_attribute[] =
113 { GM(NAME_convert, 1, "attribute", "any", getConvertAttribute,
114 DEFAULT, "Converts name to attribute(name, @nil)"),
115 GM(NAME_get, 1, "any", "object", getAttribute,
116 NAME_execute, "Invoke (read) object-attribute"),
117 GM(NAME_argumentType, 1, "type", "index=[int]", getArgumentTypeAttribute,
118 NAME_meta, "Type of n-th1 argument")
119 };
120
121 /* Resources */
122
123 #define rc_attribute NULL
124 /*
125 static classvardecl rc_attribute[] =
126 {
127 };
128 */
129
130 /* Class Declaration */
131
132 static Name attribute_termnames[] = { NAME_name, NAME_value };
133
134 ClassDecl(attribute_decls,
135 var_attribute, send_attribute, get_attribute, rc_attribute,
136 2, attribute_termnames,
137 "$Rev$");
138
139
140 status
makeClassAttribute(Class class)141 makeClassAttribute(Class class)
142 { declareClass(class, &attribute_decls);
143
144 succeed;
145 }
146
147