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/zorbastring.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_t;
00033 
00034 /** \brief Set of hints that can be passed to the query compiler.
00035  *
00036  * An instance of this class can be passed to the compileQuery function
00037  * of the Zorba class or the compile function of this class.
00038  * The members of this class represent hints that are passed to the
00039  * query compiler. For example, whether optimization of the query
00040  * should be done (O1) or not (O0).
00041  *
00042  * example_6 in file \link simple.cpp \endlink shows an example
00043  * how CompilerHints can be used.
00044  */
00045 typedef struct Zorba_CompilerHints {
00046   /** \brief The optimization level that is used */
00047   Zorba_opt_level_t opt_level;
00048 #ifdef __cplusplus
00049   /** \brief Default constructor for CompilerHints which assigns default values to all hints (C++ only).
00050    *
00051    * Default values:
00052    *   - optimization level: O1 
00053    */
00054   ZORBA_DLL_PUBLIC Zorba_CompilerHints();
00055 #endif
00056 } Zorba_CompilerHints_t;
00057 
00058 typedef enum {
00059   ZORBA_SERIALIZATION_METHOD_XML, 
00060   ZORBA_SERIALIZATION_METHOD_HTML,
00061   ZORBA_SERIALIZATION_METHOD_XHTML,
00062   ZORBA_SERIALIZATION_METHOD_TEXT
00063 } Zorba_serialization_method_t;
00064 
00065 typedef enum {
00066   ZORBA_BYTE_ORDER_MARK_YES, 
00067   ZORBA_BYTE_ORDER_MARK_NO
00068 } Zorba_byte_order_mark_t;
00069 
00070 typedef enum {
00071   ZORBA_ESCAPE_URI_ATTRIBUTES_YES, 
00072   ZORBA_ESCAPE_URI_ATTRIBUTES_NO
00073 } Zorba_escape_uri_attributes_t;
00074 
00075 typedef enum {
00076   ZORBA_INCLUDE_CONTENT_TYPE_YES, 
00077   ZORBA_INCLUDE_CONTENT_TYPE_NO
00078 } Zorba_include_content_type_t;
00079 
00080 typedef enum {
00081   ZORBA_INDENT_YES, 
00082   ZORBA_INDENT_NO
00083 } Zorba_indent_t;
00084 
00085 typedef enum {
00086   ZORBA_NORMALIZATION_FORM_NFC, 
00087   ZORBA_NORMALIZATION_FORM_NFD, 
00088   ZORBA_NORMALIZATION_FORM_NFKC, 
00089   ZORBA_NORMALIZATION_FORM_NFKD, 
00090   ZORBA_NORMALIZATION_FORM_FULLY_normalized, 
00091   ZORBA_NORMALIZATION_FORM_NONE
00092 } Zorba_normalization_form_t;
00093 
00094 typedef enum {
00095   ZORBA_OMIT_XML_DECLARATION_YES, 
00096   ZORBA_OMIT_XML_DECLARATION_NO
00097 } Zorba_omit_xml_declaration_t;
00098 
00099 typedef enum {
00100   ZORBA_STANDALONE_YES, 
00101   ZORBA_STANDALONE_NO, 
00102   ZORBA_STANDALONE_OMIT
00103 } Zorba_standalone_t;
00104 
00105 typedef enum {
00106   ZORBA_UNDECLARE_PREFIXES_YES, 
00107   ZORBA_UNDECLARE_PREFIXES_NO
00108 } Zorba_undeclare_prefixes_t;
00109 
00110 /** \brief Options that configure the serialization process of a query result.
00111 *         See http://www.w3.org/TR/2005/CR-xslt-xquery-serialization-20051103/.
00112 *
00113 * This struct defines options that can be passed to the serialization process of a query
00114 * result. An instance of this class can be passed to the serialize function.
00115 *
00116 * File \link serialization.cpp \endlink contains examples that show how to use
00117 * the SerializerOptions.
00118 */
00119 #ifdef __cplusplus
00120 typedef struct ZORBA_DLL_PUBLIC Zorba_SerializerOptions 
00121 {
00122   Zorba_serialization_method_t  ser_method;
00123   Zorba_byte_order_mark_t       byte_order_mark;
00124   Zorba_escape_uri_attributes_t escape_uri_attributes;
00125   Zorba_include_content_type_t  include_content_type;
00126   Zorba_indent_t                indent;
00127   Zorba_normalization_form_t    normalization_form;
00128   Zorba_omit_xml_declaration_t  omit_xml_declaration;
00129   Zorba_standalone_t            standalone; 
00130   Zorba_undeclare_prefixes_t    undeclare_prefixes;
00131   
00132   zorba::String                 doctype_system;
00133   zorba::String                 doctype_public;
00134   zorba::String                 cdata_section_elements;
00135 
00136 
00137   /** \brief Default constructor for SerializerOptions which assigns default values to all 
00138    *         options (C++ only).
00139    *
00140    * Default values:
00141    *   - serialization method: XML
00142    *   - byte-order-mark: NO
00143    *   - esacpe-uri-attributes: NO
00144    *   - include-content-type: NO
00145    *   - indent: NO
00146    *   - normalization-form: none
00147    *   - omit-xml-declaration: NO
00148    *   - standalone: omit
00149    *   - undeclare-prefixes: NO
00150    */
00151 
00152   Zorba_SerializerOptions();
00153   
00154   /** \brief Helper function to set a serializer parameter value from a key / value string pair.
00155    *
00156    *
00157    * \retval None
00158    */
00159   void SetSerializerOption(const char* parameter, const char* value);
00160 
00161   /** \brief Helper function to create a Zorba_SerializerOptions from a vector of key / value 
00162    *         string pairs 
00163    *
00164    * \retval The created Zorba_SerializerOptions structure
00165    */
00166   static Zorba_SerializerOptions SerializerOptionsFromStringParams(const std::vector<std::pair<std::string,std::string> >& params);
00167   
00168 } Zorba_SerializerOptions_t;
00169 #endif
00170 
00171 
00172 #ifndef __cplusplus
00173 struct Zorba_SerializerOptions;
00174 typedef struct Zorba_SerializerOptions Zorba_SerializerOptions_t;
00175 #endif
00176 
00177 
00178 #ifdef __cplusplus
00179 extern "C" {
00180 #endif
00181 
00182 /** \brief Helper function for C to set default values ComplilerHints struct.
00183  *
00184  * \retval Zorba_CompilerHints_t with default member values 
00185  */
00186 ZORBA_DLL_PUBLIC void Zorba_CompilerHints_default(Zorba_CompilerHints_t*);
00187 
00188 /** \brief Helper function to create a Zorba_SerializerOptions_t struct because 
00189  *         of missing default constructor. C++ code can delete the
00190  *         returned Zorba_SerializerOptions_t* struct, while C code 
00191  *         must call Zorba_SerializerOptions_free().  
00192  *
00193  * \retval Zorba_CompilerHints_t with default member values 
00194  */
00195 ZORBA_DLL_PUBLIC Zorba_SerializerOptions_t* Zorba_SerializerOptions_default();
00196 
00197 /** \brief Helper function to delete a Zorba_SerializerOptions_t struct
00198  *
00199  * \retval Zorba_CompilerHints_t with default member values 
00200  */
00201 ZORBA_DLL_PUBLIC void Zorba_SerializerOptions_free(Zorba_SerializerOptions_t* serializerOptions);
00202 
00203 /** \brief Helper function to set an option in a Zorba_SerializerOptions_t structure
00204  * 
00205  * \param parameter the serializer parameter to be configured
00206  * \param value the value to which the parameter should be set
00207  * \retval Zorba_CompilerHints_t with default member values 
00208  */
00209 ZORBA_DLL_PUBLIC void Zorba_SerializerOptions_set(Zorba_SerializerOptions_t* serializerOptions, const char* parameter, const char* value);
00210 
00211 
00212 #ifdef __cplusplus
00213 }
00214 #endif
00215 
00216 #endif
00217