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