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