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