(file) Return to WQLOperand.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / WQL

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2