1 mike 1.2 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001 BMC Software, Hewlett-Packard Company, IBM,
4 // The Open Group, Tivoli Systems
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to
8 // deal in the Software without restriction, including without limitation the
9 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 // sell copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
14 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
15 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
16 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 //
22 mike 1.2 //==============================================================================
23 //
24 // Author: Mike Brasher (mbrasher@bmc.com)
25 //
26 // Modified By:
27 //
28 //%/////////////////////////////////////////////////////////////////////////////
29
30 #ifndef Pegasus_WQLOperand_h
31 #define Pegasus_WQLOperand_h
32
|
34 mike 1.2 #include <Pegasus/Common/Config.h>
35 #include <Pegasus/Common/String.h>
36 #include <Pegasus/Common/Exception.h>
37 #include <Pegasus/WQL/Linkage.h>
38
39 PEGASUS_NAMESPACE_BEGIN
40
41 /** Tag used to force invocation of the integer value form of the WQLOperand
42 Constructor.
43 */
44 enum WQLIntegerValueTag
45 {
46 WQL_INTEGER_VALUE_TAG
47 };
48
49 /** Tag used to force invocation of the double value form of the WQLOperand
50 Constructor.
51 */
52 enum WQLDoubleValueTag
53 {
54 WQL_DOUBLE_VALUE_TAG
55 mike 1.2 };
56
57 /** Tag used to force invocation of the boolean value form of the WQLOperand
58 Constructor.
59 */
60 enum WQLBooleanValueTag
61 {
62 WQL_BOOLEAN_VALUE_TAG
63 };
64
65 /** Tag used to force invocation of the string value form of the WQLOperand
66 Constructor.
67 */
68 enum WQLStringValueTag
69 {
70 WQL_STRING_VALUE_TAG
71 };
72
73 /** Tag used to force invocation of the property name form of the WQLOperand
74 Constructor.
75 */
76 mike 1.2 enum WQLPropertyNameTag
77 {
78 WQL_PROPERTY_NAME_TAG
79 };
80
81 /** Used to represent SQL where clause operands.
82
83 Instances of WQLOperand are used to represent the operands of the
84 SQL where clause. Instances of this class are created while parsing
85 a SQL where clause and added to the WQLSelectStatement by calling the
86 WQLSelectStatement::appendOperand() method. Consider the following
87 example:
88
89 <pre>
90 SELECT ratio, size, name, str
91 FROM MyClass
92 WHERE ratio > 1.4 AND size = 3 AND name = "Hello" AND str IS NULL
93 </pre>
94
95 In this example, the following are operands:
96
97 mike 1.2 <pre>
98 ratio
99 1.4
100 size
101 3
102 name
103 "Hello"
104 str
105 </pre>
106
107 Operands are of one of the following types:
108
109 <ul>
110 <li>NULL_VALUE - contains a null value of any type</li>
111 <li>INTEGER_VALUE - an integer literal (e.g., 10, -22)</li>
112 <li>DOUBLE_VALUE - a double literal (e.g., 1.4, 1.375e-5)</li>
113 <li>BOOLEAN_VALUE - a boolean literal (e.g., TRUE or FALSE)</li>
114 <li>STRING_VALUE - a string literal (e.g., "Hello World")</li>
115 <li>PROPERTY_NAME- the name of a property (e.g., count, size)</li>
116 </ul>
117 */
118 mike 1.2 class PEGASUS_WQL_LINKAGE WQLOperand
119 {
120 public:
121
122 /** Defines allowed types of WQL operands (NULL_VALUE, INTEGER_VALUE,
123 DOUBLE_VALUE, BOOLEAN_VALUE, STRING_VALUE, PROPERTY_NAME).
124 */
125 enum Type
126 {
127 NULL_VALUE,
128 INTEGER_VALUE,
129 DOUBLE_VALUE,
130 BOOLEAN_VALUE,
131 STRING_VALUE,
132 PROPERTY_NAME
133 };
134
135 /** Desfault constructor. Initializes to null value.
136 */
137 WQLOperand();
138
139 mike 1.2 /** Copy constructor.
140 */
141 WQLOperand(const WQLOperand& x);
142
143 /** Initializes object as INTEGER_VALUE.
144 */
145 WQLOperand(Sint32 x, WQLIntegerValueTag)
146 {
147 _integerValue = x;
148 _type = INTEGER_VALUE;
149 }
150
151 /** Initializes object as DOUBLE_VALUE.
152 */
153 WQLOperand(Real64 x, WQLDoubleValueTag)
154 {
155 _doubleValue = x;
156 _type = DOUBLE_VALUE;
157 }
158
159 /** Initializes object as BOOLEAN_VALUE.
160 mike 1.2 */
161 WQLOperand(Boolean x, WQLBooleanValueTag)
162 {
163 _booleanValue = x;
164 _type = BOOLEAN_VALUE;
165 }
166
167 /** Initializes object as STRING_VALUE.
168 */
169 WQLOperand(const String& x, WQLStringValueTag)
170 {
171 new(_stringValue) String(x);
172 _type = STRING_VALUE;
173 }
174
175 /** Initializes object as PROPERTY_NAME.
176 */
177 WQLOperand(const String& x, WQLPropertyNameTag)
178 {
179 new(_propertyName) String(x);
180 _type = PROPERTY_NAME;
181 mike 1.2 }
182
183 /** Destructor.
184 */
185 ~WQLOperand();
186
187 /** Assignment operator.
188 */
189 WQLOperand& operator=(const WQLOperand& x);
190
191 /** Clears this object and sets its type to NULL_VALUE.
192 */
193 void clear();
194
195 /** Assigns object from the given operand.
196 */
197 void assign(const WQLOperand& x);
198
199 /** Accessor for getting the type of the operand.
200 */
201 Type getType() const { return _type; }
202 mike 1.2
203 /** Sets this object to an INTEGER_VALUE.
204 */
205 void setIntegerValue(Sint32 x)
206 {
207 clear();
208 _integerValue = x;
209 _type = INTEGER_VALUE;
210 }
211
212 /** Sets this object to an DOUBLE_VALUE.
213 */
214 void setDoubleValue(Real64 x)
215 {
216 clear();
217 _doubleValue = x;
218 _type = DOUBLE_VALUE;
219 }
220
221 /** Sets this object to a BOOLEAN_VALUE.
222 */
223 mike 1.2 void setBooleanValue(Boolean x)
224 {
225 clear();
226 _booleanValue = x;
227 _type = BOOLEAN_VALUE;
228 }
229
230 /** Sets this object to a STRING_VALUE.
231 */
232 void setStringValue(const String& x)
233 {
234 clear();
235 new(_stringValue) String(x);
236 _type = STRING_VALUE;
237 }
238
239 /** Sets this object to a PROPERTY_NAME.
240 */
241 void setPropertyName(const String& x)
242 {
243 clear();
244 mike 1.2 new(_propertyName) String(x);
245 _type = PROPERTY_NAME;
246 }
247
248 /** Gets this object as an INTEGER_VALUE.
249 */
250 Sint32 getIntegerValue() const
251 {
252 if (_type != INTEGER_VALUE)
253 throw TypeMismatch();
254
255 return _integerValue;
256 }
257
258 /** Gets this object as an DOUBLE_VALUE.
259 @exception TypeMismatch is not the expected type.
260 */
261 Real32 getDoubleValue() const
262 {
263 if (_type != DOUBLE_VALUE)
264 throw TypeMismatch();
265 mike 1.2
266 return _doubleValue;
267 }
268
269 /** Gets this object as an BOOLEAN_VALUE.
270 @exception TypeMismatch is not the expected type.
271 */
272 Boolean getBooleanValue() const
273 {
274 if (_type != BOOLEAN_VALUE)
275 throw TypeMismatch();
276
277 return _booleanValue;
278 }
279
280 /** Gets this object as a STRING_VALUE.
281 @exception TypeMismatch is not the expected type.
282 */
283 const String& getStringValue() const
284 {
285 if (_type != STRING_VALUE)
286 mike 1.2 throw TypeMismatch();
287
288 return *((String*)_stringValue);
289 }
290
291 /** Gets this object as a PROPERTY_NAME.
292 @exception TypeMismatch is not the expected type.
293 */
294 const String& getPropertyName() const
295 {
296 if (_type != PROPERTY_NAME)
297 throw TypeMismatch();
298
299 return *((String*)_propertyName);
300 }
301
302 /** Converts this object to a string for output purposes.
303 */
304 String toString() const;
305
306 private:
307 mike 1.2
308 union
309 {
310 Sint32 _integerValue;
311 Real64 _doubleValue;
312 Boolean _booleanValue;
313 char _stringValue[sizeof(String)];
314 char _propertyName[sizeof(String)];
315 };
316
317 Type _type;
318 };
319
320 PEGASUS_NAMESPACE_END
321
322 #endif /* Pegasus_WQLOperand_h */
|