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