> The XQuery Processor
00001 /* 00002 * Copyright 2006-2008 The FLWOR Foundation. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #ifndef ZORBA_ITEM_API_H 00017 #define ZORBA_ITEM_API_H 00018 00019 #include <ostream> 00020 #include <zorba/config.h> 00021 #include <zorba/api_shared_types.h> 00022 00023 namespace zorba { 00024 00025 namespace store { class Item; } 00026 00027 /** \brief The Zorba Item interface. 00028 * 00029 * This class is the Zorba representation of an Item as defined in the 00030 * XQuery 1.0 and XPath 2.0 Data Model (XDM); see http://www.w3.org/TR/xpath-datamodel/. 00031 * 00032 * Instances of the XDM are a sequence, i.e. an ordered collection of zero or more items. 00033 * In the Zorba API, a sequence is represented by the ItemSequence class. 00034 * 00035 * The Item class is the union of all XQuery node and atomic types. 00036 * The class provides functions to access the information of an Item. Note that not 00037 * all functions are defined on every Item kind. If a function is called on an Item that 00038 * does not provide the called function, an XQP0024_FUNCTION_NOT_IMPLEMENTED_FOR_ITEMTYPE error 00039 * is raised. 00040 * 00041 * Instances of the Item class are always passed by copy. To check whether a given Item is valid 00042 * isNull() can be called which returns true if the given Item is not valid and false otherwise. 00043 * A new atomic Item can be created using the ItemFactory. A new node Item should be created 00044 * by the result of a query. 00045 */ 00046 class ZORBA_EXTERN_DECL Item 00047 { 00048 public: 00049 /** \brief Default constructor 00050 */ 00051 Item(); 00052 00053 /** \brief Copy constructor 00054 */ 00055 Item(const Item& other); 00056 00057 /** \brief Constructor that is used to construct Items in the Zorba engine itself. 00058 * 00059 * This constructor is for internal use only. 00060 */ 00061 Item(store::Item *item); 00062 00063 /** \brief Assingment operator 00064 */ 00065 const Item& operator =(const Item& rhs); 00066 00067 /** \brief Assingment operator that is used in the Zorba engine itself. 00068 * 00069 * This operator is for internal use only. 00070 */ 00071 const Item& operator =(store::Item *rhs); 00072 00073 /** \brief Destructor 00074 */ 00075 ~Item(); 00076 00077 /** \brief Get the type of the Item. 00078 * 00079 * See http://www.w3.org/TR/xpath-datamodel/#types. 00080 * Note that this function is available for all types of Items. 00081 * 00082 * @return Item the type of the Item as a QName Item 00083 * @throw ZorbaException if an error occured. 00084 */ 00085 Item 00086 getType() const; 00087 00088 /** \brief Get the atomization value of the Item. 00089 * 00090 * The atomization value is the value that is returned by atomization 00091 * (see http://www.w3.org/TR/xquery/#id-atomization). 00092 * Note that this function is available for all types of Items. 00093 * 00094 * @return Item the atomization value of the Item. 00095 * @throw ZorbaException if an error occured. 00096 */ 00097 Item 00098 getAtomizationValue() const; 00099 00100 /** \brief Get the string value of the Item. 00101 * 00102 * The string value is the string that is extracted by calling the fn:string function 00103 * on the Item (see http://www.w3.org/TR/xpath-functions/#func-string). 00104 * Note that this function is available for all types of Items. 00105 * 00106 * @return Item the string value of the Item. 00107 * @throw ZorbaException if an error occured. 00108 */ 00109 String 00110 getStringValue() const; 00111 00112 /** \brief Get the effective boolean value of the Item. 00113 * 00114 * The effective boolean value is the result of applying the fn:boolean function on 00115 * the Item (see http://www.w3.org/TR/xpath-functions/#func-boolean). 00116 * Note that this function is available for all types of Items. 00117 * 00118 * @return Item the effective boolean value of the Item 00119 * @throw ZorbaException if an error occured. 00120 */ 00121 Item 00122 getEBV() const; 00123 00124 /** \brief Serialize the Item using the XML output method. 00125 * 00126 * The function writes the result of serializing the Item as XML to 00127 * the given output stream. 00128 * Note that this function is available for all types of Items. 00129 * 00130 * @throw ZorbaException if an error occured. 00131 */ 00132 void 00133 serialize(std::ostream&) const; 00134 00135 /** \brief Check if the Item is a node Item. 00136 * 00137 * Note that this function is available for all types of Items. 00138 * 00139 * @return true if the Item is of type node, false otherwise. 00140 */ 00141 bool 00142 isNode() const; 00143 00144 /** \brief Check if the Item is an atomic Item. 00145 * 00146 * Note that this function is available for all types of Items. 00147 * 00148 * @return true if the Item is an atomic Item, false otherwise. 00149 */ 00150 bool 00151 isAtomic() const; 00152 00153 /** \brief Check if the Item is a numeric Item. 00154 * 00155 * Note that this function is available for all types of Items. 00156 * 00157 * @return true if the Item is a numeric Item, false otherwise 00158 */ 00159 //bool 00160 //isNumeric() const; 00161 00162 /** \brief Check if the Item is null. 00163 * 00164 * If this function returns true, the Item is not valid. 00165 * Note that this function is available for all types of Items. 00166 * 00167 * @return true if the Item is null, false otherwise. 00168 */ 00169 bool 00170 isNull() const; 00171 00172 /** \brief Free all resources aquired by this Item. 00173 * 00174 * After calling close() on an Item the Item is invalidated, i.e. a subsequent call 00175 * to isNull() will return true. 00176 * 00177 * Note that calling this function is usually not necessary because close() is implicitly 00178 * called by the destructor. Calling close() is only necessary if the resources aquired by an 00179 * Item should be released before the Item goes out of scope, i.e. the destructor is called. 00180 * 00181 * Also note that this function is available for all types of Items. 00182 */ 00183 void 00184 close(); 00185 00186 /** \brief Get the (optional) value of a QName's prefix. 00187 * 00188 * Note that this function is only available for Items of type QName. 00189 * 00190 * @return String the prefix of the QName. 00191 * @throw ZorbaException if an error occured, e.g. the Item is not a QName. 00192 */ 00193 String 00194 getPrefix() const; 00195 00196 /** \brief Get the (optional) value of a QName's namespace. 00197 * 00198 * Note that this function is only available for Items of type QName. 00199 * 00200 * @return String the namespace URI of the QName. 00201 * @throw ZorbaException if an error occured, e.g. the Item is not a QName. 00202 */ 00203 String 00204 getNamespace() const; 00205 00206 /** \brief Get the value of a QName's local name. 00207 * 00208 * Note that this function is only available for Items of type QName. 00209 * 00210 * @return String the local name of the QName. 00211 * @throw ZorbaException if an error occured, e.g. the Item is not a QName. 00212 */ 00213 String 00214 getLocalName() const; 00215 00216 /** \brief Check if the value of the Item is not a number (NaN). 00217 * 00218 * Note that this function is only available for numeric Items (e.g. Double or Float). 00219 * 00220 * @return true if the Item is NaN, false otherwise. 00221 * @throw ZorbaException if an error occured, e.g. the Item is not a numeric type. 00222 */ 00223 bool 00224 isNaN() const; 00225 00226 /** \brief Check if the value of the Item is positive or negative infinity. 00227 * 00228 * Note that this function is only available for numeric Items (e.g. Double or Float). 00229 * 00230 * @return true if the Item is +/-INF, false otherwise. 00231 * @throw ZorbaException if an error occured, e.g. the Item is not a numeric type. 00232 */ 00233 bool 00234 isPosOrNegInf() const; 00235 00236 /** \brief Get the bool value of the boolean Item. 00237 * 00238 * Note that this function is only available for Items of type boolean. 00239 * 00240 * @return true if the boolean value is true, false otherwise. 00241 * @throw ZorbaException if an error occured, e.g. the Item is not of type boolean. 00242 */ 00243 bool 00244 getBooleanValue() const; 00245 00246 private: 00247 friend class Unmarshaller; 00248 store::Item *m_item; 00249 }; 00250 00251 } // namespace zorba 00252 00253 #endif