options.h
Go to the documentation of this file.
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_OPTIONS_H
00017 #define ZORBA_OPTIONS_H
00018 #include <zorba/config.h>
00019 
00020 #ifdef __cplusplus
00021 #include <vector>
00022 #include <zorba/zorba_string.h>
00023 #endif
00024 
00025 
00026 /** \brief The optimization level used for optimizing the query. */
00027 typedef enum {
00028   ZORBA_OPT_LEVEL_O0, /**< Don't use any optimization. */
00029   ZORBA_OPT_LEVEL_O1,  /**< Use basic optimizations
00030                            (e.g.\ removing sorting, removing duplicate elimination,
00031                            or constant folding). */
00032   ZORBA_OPT_LEVEL_O2  /** Use basic optimizations (like O1) and some
00033                         * more optimizations (like not to generate an iterator
00034                         * for inlined functions) - call stacks in case of
00035                         * an exception are not generated.
00036                         */
00037 } Zorba_opt_level_t;
00038 
00039 #if !defined(__cplusplus)
00040   typedef enum { false = 0, true = 1 } bool;
00041 #endif
00042 
00043 /** \brief Set of hints that can be passed to the query compiler.
00044  *
00045  * An instance of this class can be passed to the compileQuery function
00046  * of the Zorba class or the compile function of this class.
00047  * The members of this class represent hints that are passed to the
00048  * query compiler. For example, whether optimization of the query
00049  * should be done (O1) or not (O0).
00050  *
00051  * example_6 in file \link simple.cpp \endlink shows an example
00052  * how CompilerHints can be used.
00053  */
00054 typedef struct Zorba_CompilerHints 
00055 {
00056   /** \brief The optimization level that is used */
00057   Zorba_opt_level_t opt_level;
00058   /** \brief Treat the query as a library module */
00059   bool lib_module;
00060 
00061   /**
00062    * \brief By default, this flag is set to false. Applications may set it to
00063    * true if they plan to execute the query only via one of the methods that 
00064    * serialize the query result.
00065    */
00066   bool for_serialization_only;
00067 
00068 #ifdef __cplusplus
00069   /** \brief Default constructor for CompilerHints which assigns default values to all hints (C++ only).
00070    *
00071    * Default values:
00072    *   - optimization level: O1
00073    *   - library module: false
00074    */
00075   ZORBA_DLL_PUBLIC Zorba_CompilerHints();
00076 #endif
00077 } Zorba_CompilerHints_t;
00078 
00079 
00080 typedef enum 
00081 {
00082   ZORBA_SERIALIZATION_METHOD_XML,
00083   ZORBA_SERIALIZATION_METHOD_HTML,
00084   ZORBA_SERIALIZATION_METHOD_XHTML,
00085   ZORBA_SERIALIZATION_METHOD_TEXT,
00086   ZORBA_SERIALIZATION_METHOD_BINARY
00087 } Zorba_serialization_method_t;
00088 
00089 
00090 typedef enum 
00091 {
00092   ZORBA_BYTE_ORDER_MARK_YES,
00093   ZORBA_BYTE_ORDER_MARK_NO
00094 } Zorba_byte_order_mark_t;
00095 
00096 
00097 typedef enum 
00098 {
00099   ZORBA_ESCAPE_URI_ATTRIBUTES_YES,
00100   ZORBA_ESCAPE_URI_ATTRIBUTES_NO
00101 } Zorba_escape_uri_attributes_t;
00102 
00103 typedef enum {
00104   ZORBA_INCLUDE_CONTENT_TYPE_YES,
00105   ZORBA_INCLUDE_CONTENT_TYPE_NO
00106 } Zorba_include_content_type_t;
00107 
00108 typedef enum {
00109   ZORBA_INDENT_YES,
00110   ZORBA_INDENT_NO
00111 } Zorba_indent_t;
00112 
00113 typedef enum {
00114   ZORBA_NORMALIZATION_FORM_NFC,
00115   ZORBA_NORMALIZATION_FORM_NFD,
00116   ZORBA_NORMALIZATION_FORM_NFKC,
00117   ZORBA_NORMALIZATION_FORM_NFKD,
00118   ZORBA_NORMALIZATION_FORM_FULLY_normalized,
00119   ZORBA_NORMALIZATION_FORM_NONE
00120 } Zorba_normalization_form_t;
00121 
00122 typedef enum {
00123   ZORBA_OMIT_XML_DECLARATION_YES,
00124   ZORBA_OMIT_XML_DECLARATION_NO
00125 } Zorba_omit_xml_declaration_t;
00126 
00127 typedef enum {
00128   ZORBA_STANDALONE_YES,
00129   ZORBA_STANDALONE_NO,
00130   ZORBA_STANDALONE_OMIT
00131 } Zorba_standalone_t;
00132 
00133 typedef enum {
00134   ZORBA_UNDECLARE_PREFIXES_YES,
00135   ZORBA_UNDECLARE_PREFIXES_NO
00136 } Zorba_undeclare_prefixes_t;
00137 
00138 typedef enum {
00139   ZORBA_ENCODING_UTF8,
00140   ZORBA_ENCODING_UTF16
00141 } Zorba_encoding_t;
00142 
00143 typedef enum {
00144   ZORBA_USE_BINARY_ARCHIVE,
00145   ZORBA_USE_XML_ARCHIVE
00146 } Zorba_binary_plan_format_t;
00147 
00148 typedef enum {
00149   DONT_SAVE_UNUSED_FUNCTIONS = 0,
00150   SAVE_UNUSED_FUNCTIONS = 1
00151 } Zorba_save_plan_options_t;
00152 /** \brief Options that configure the serialization process of a query result.
00153 *         See http://www.w3.org/TR/2005/CR-xslt-xquery-serialization-20051103/.
00154 *
00155 * This struct defines options that can be passed to the serialization process of a query
00156 * result. An instance of this class can be passed to the serialize function.
00157 *
00158 * File \link serialization.cpp \endlink contains examples that show how to use
00159 * the SerializerOptions.
00160 */
00161 #ifdef __cplusplus
00162 typedef struct ZORBA_DLL_PUBLIC Zorba_SerializerOptions
00163 {
00164   Zorba_serialization_method_t  ser_method;
00165   Zorba_byte_order_mark_t       byte_order_mark;
00166   Zorba_escape_uri_attributes_t escape_uri_attributes;
00167   Zorba_include_content_type_t  include_content_type;
00168   Zorba_indent_t                indent;
00169   Zorba_normalization_form_t    normalization_form;
00170   Zorba_omit_xml_declaration_t  omit_xml_declaration;
00171   Zorba_standalone_t            standalone;
00172   Zorba_undeclare_prefixes_t    undeclare_prefixes;
00173   Zorba_encoding_t              encoding;
00174 
00175   zorba::String                 media_type;
00176   zorba::String                 doctype_system;
00177   zorba::String                 doctype_public;
00178   zorba::String                 cdata_section_elements;
00179   zorba::String                 version;
00180 
00181 
00182   /** \brief Default constructor for SerializerOptions which assigns default values to all
00183    *         options (C++ only).
00184    *
00185    * Default values:
00186    *   - serialization method: XML
00187    *   - byte-order-mark: NO
00188    *   - esacpe-uri-attributes: NO
00189    *   - include-content-type: NO
00190    *   - indent: NO
00191    *   - normalization-form: none
00192    *   - omit-xml-declaration: NO
00193    *   - standalone: omit
00194    *   - undeclare-prefixes: NO
00195    */
00196 
00197   Zorba_SerializerOptions();
00198 
00199   /** \brief Helper function to set a serializer parameter value from a key / value string pair.
00200    *
00201    *
00202    * \retval None
00203    */
00204   void SetSerializerOption(const char* parameter, const char* value);
00205 
00206   /** \brief Helper function to create a Zorba_SerializerOptions from a vector of key / value
00207    *         string pairs
00208    *
00209    * \retval The created Zorba_SerializerOptions structure
00210    */
00211   static Zorba_SerializerOptions SerializerOptionsFromStringParams(const std::vector<std::pair<std::string,std::string> >& params);
00212 
00213 } Zorba_SerializerOptions_t;
00214 #endif
00215 
00216 
00217 #ifndef __cplusplus
00218 struct Zorba_SerializerOptions;
00219 typedef struct Zorba_SerializerOptions Zorba_SerializerOptions_t;
00220 #endif
00221 
00222 
00223 #ifdef __cplusplus
00224 extern "C" {
00225 #endif
00226 
00227 /** \brief Helper function for C to set default values ComplilerHints struct.
00228  *
00229  * \retval Zorba_CompilerHints_t with default member values
00230  */
00231 ZORBA_DLL_PUBLIC void Zorba_CompilerHints_default(Zorba_CompilerHints_t*);
00232 
00233 /** \brief Helper function to create a Zorba_SerializerOptions_t struct because
00234  *         of missing default constructor. C++ code can delete the
00235  *         returned Zorba_SerializerOptions_t* struct, while C code
00236  *         must call Zorba_SerializerOptions_free().
00237  *
00238  * \retval Zorba_CompilerHints_t with default member values
00239  */
00240 ZORBA_DLL_PUBLIC Zorba_SerializerOptions_t* Zorba_SerializerOptions_default();
00241 
00242 /** \brief Helper function to delete a Zorba_SerializerOptions_t struct
00243  *
00244  * \retval Zorba_CompilerHints_t with default member values
00245  */
00246 ZORBA_DLL_PUBLIC void Zorba_SerializerOptions_free(Zorba_SerializerOptions_t* serializerOptions);
00247 
00248 /** \brief Helper function to set an option in a Zorba_SerializerOptions_t structure
00249  *
00250  * \param serializerOptions serializer options
00251  * \param parameter the serializer parameter to be configured
00252  * \param value the value to which the parameter should be set
00253  * \retval Zorba_CompilerHints_t with default member values
00254  */
00255 ZORBA_DLL_PUBLIC void Zorba_SerializerOptions_set(Zorba_SerializerOptions_t* serializerOptions, const char* parameter, const char* value);
00256 
00257 
00258 #ifdef __cplusplus
00259 }
00260 #endif
00261 
00262 #endif
00263 
00264 /* vim:set et sw=2 ts=2: */
blog comments powered by Disqus