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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2