# XQilla Simple API Documentation

- Main Page
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

# StaticType.hpp

Go to the documentation of this file.

    00001 /*
    00002  * Copyright (c) 2001, 2008,
    00003  *     DecisionSoft Limited. All rights reserved.
    00004  * Copyright (c) 2004, 2015 Oracle and/or its affiliates. All rights reserved.
    00005  *
    00006  *
    00007  * Licensed under the Apache License, Version 2.0 (the "License");
    00008  * you may not use this file except in compliance with the License.
    00009  * You may obtain a copy of the License at
    00010  *
    00011  *     http://www.apache.org/licenses/LICENSE-2.0
    00012  *
    00013  * Unless required by applicable law or agreed to in writing, software
    00014  * distributed under the License is distributed on an "AS IS" BASIS,
    00015  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    00016  * See the License for the specific language governing permissions and
    00017  * limitations under the License.
    00018  */
    00019
    00020 #ifndef _STATICTYPE_HPP
    00021 #define _STATICTYPE_HPP
    00022
    00023 #include <xqilla/framework/XQillaExport.hpp>
    00024 #include <xqilla/items/AnyAtomicType.hpp>
    00025 #include <xqilla/framework/XPath2MemoryManager.hpp>
    00026
    00027 #include <xercesc/framework/XMLBuffer.hpp>
    00028 #include <xercesc/util/XMemory.hpp>
    00029
    00033 class XQILLA_API StaticType : public XERCES_CPP_NAMESPACE_QUALIFIER XMemory {
    00034 public:
    00038   enum StaticTypeFlags {
    00039     DOCUMENT_TYPE            = 0x00000001,
    00040     ELEMENT_TYPE             = 0x00000002,
    00041     ATTRIBUTE_TYPE           = 0x00000004,
    00042     TEXT_TYPE                = 0x00000008,
    00043     PI_TYPE                  = 0x00000010,
    00044     COMMENT_TYPE             = 0x00000020,
    00045     NAMESPACE_TYPE           = 0x00000040,
    00046
    00047     ANY_SIMPLE_TYPE          = 0x00000080,
    00048     ANY_URI_TYPE             = 0x00000100,
    00049     BASE_64_BINARY_TYPE      = 0x00000200,
    00050     BOOLEAN_TYPE             = 0x00000400,
    00051     DATE_TYPE                = 0x00000800,
    00052     DATE_TIME_TYPE           = 0x00001000,
    00053     DAY_TIME_DURATION_TYPE   = 0x00002000,
    00054     DECIMAL_TYPE             = 0x00004000,
    00055     DOUBLE_TYPE              = 0x00008000,
    00056     DURATION_TYPE            = 0x00010000,
    00057     FLOAT_TYPE               = 0x00020000,
    00058     G_DAY_TYPE               = 0x00040000,
    00059     G_MONTH_TYPE             = 0x00080000,
    00060     G_MONTH_DAY_TYPE         = 0x00100000,
    00061     G_YEAR_TYPE              = 0x00200000,
    00062     G_YEAR_MONTH_TYPE        = 0x00400000,
    00063     HEX_BINARY_TYPE          = 0x00800000,
    00064     NOTATION_TYPE            = 0x01000000,
    00065     QNAME_TYPE               = 0x02000000,
    00066     STRING_TYPE              = 0x04000000,
    00067     TIME_TYPE                = 0x08000000,
    00068     UNTYPED_ATOMIC_TYPE      = 0x10000000,
    00069     YEAR_MONTH_DURATION_TYPE = 0x20000000,
    00070
    00071     FUNCTION_TYPE            = 0x40000000,
    00072
    00073     NODE_TYPE                = (DOCUMENT_TYPE | ELEMENT_TYPE | ATTRIBUTE_TYPE | TEXT_TYPE | PI_TYPE | COMMENT_TYPE |
    00074                                 NAMESPACE_TYPE),
    00075
    00076     NUMERIC_TYPE             = (DECIMAL_TYPE | FLOAT_TYPE | DOUBLE_TYPE),
    00077
    00078     TIMEZONE_TYPE            = (DATE_TYPE | DATE_TIME_TYPE | G_DAY_TYPE | G_MONTH_TYPE | G_MONTH_DAY_TYPE |
    00079                                 G_YEAR_TYPE | G_YEAR_MONTH_TYPE | TIME_TYPE),
    00080
    00081     TYPED_ATOMIC_TYPE        = (NUMERIC_TYPE | TIMEZONE_TYPE | ANY_SIMPLE_TYPE | ANY_URI_TYPE | BASE_64_BINARY_TYPE |
    00082                                 BOOLEAN_TYPE | DAY_TIME_DURATION_TYPE | DURATION_TYPE | HEX_BINARY_TYPE |
    00083                                 NOTATION_TYPE | QNAME_TYPE | STRING_TYPE | YEAR_MONTH_DURATION_TYPE),
    00084
    00085     ANY_ATOMIC_TYPE          = (TYPED_ATOMIC_TYPE | UNTYPED_ATOMIC_TYPE),
    00086
    00087     ITEM_TYPE                = (NODE_TYPE | ANY_ATOMIC_TYPE | FUNCTION_TYPE),
    00088
    00089     EMPTY_TYPE               = 0
    00090   };
    00091
    00092   static const unsigned int UNLIMITED;
    00093
    00095   StaticType();
    00096   // Constructor for normal types
    00097   StaticType(StaticTypeFlags f, unsigned int min = 1, unsigned int max = 1);
    00099   StaticType(XPath2MemoryManager *mm, unsigned int numArgs, const StaticType &returnType, unsigned int min = 1, unsigned int max = 1);
    00101   StaticType(XPath2MemoryManager *mm, unsigned int minArgs, unsigned int maxArgs, const StaticType &returnType,
    00102              unsigned int min = 1, unsigned int max = 1);
    00103
    00104   StaticType(const StaticType &o);
    00105   StaticType &operator=(const StaticType &o);
    00106   ~StaticType();
    00107
    00108   static StaticType create(const XMLCh *uri, const XMLCh *name, const StaticContext *context,
    00109                                   bool &isExact);
    00110   static StaticType create(AnyAtomicType::AtomicObjectType primitiveType);
    00111
    00112   void typeUnion(const StaticType &st);
    00113   void typeIntersect(const StaticType &st);
    00114   void typeExcept(const StaticType &st);
    00115
    00116   void typeConcat(const StaticType &st);
    00117   void typeNodeIntersect(const StaticType &st);
    00118
    00119   StaticType operator|(const StaticType &st) const;
    00120   StaticType &operator|=(const StaticType &st);
    00121
    00122   StaticType operator&(const StaticType &st) const;
    00123   StaticType &operator&=(const StaticType &st);
    00124
    00125   StaticType &substitute(const StaticType &from, const StaticType &to);
    00126   StaticType &multiply(unsigned int min, unsigned int max);
    00127   void setCardinality(unsigned int min, unsigned int max);
    00128
    00129   bool containsType(const StaticType &type) const;
    00130   bool containsType(StaticType::StaticTypeFlags flags) const;
    00131   bool isType(const StaticType &type) const;
    00132
    00133   enum TypeMatchEnum {
    00134     NEVER = 0,
    00135     PROBABLY_NOT = 1,
    00136     MAYBE = 2,
    00137     ALWAYS = 3
    00138   };
    00139
    00140   struct TypeMatch
    00141   {
    00142     TypeMatchEnum type, cardinality;
    00143   };
    00144
    00145   TypeMatch matches(const StaticType &actual) const;
    00146
    00147   unsigned int getMin() const { return min_; }
    00148   unsigned int getMax() const { return max_; }
    00149
    00150   unsigned int getMinArgs() const { return minArgs_; }
    00151   unsigned int getMaxArgs() const { return maxArgs_; }
    00152   const StaticType *getReturnType() const { return returnType_; }
    00153
    00154   void typeToBuf(XERCES_CPP_NAMESPACE_QUALIFIER XMLBuffer &buf) const;
    00155
    00156 private:
    00157   TypeMatchEnum matchesFunctionType(const StaticType &type) const;
    00158   TypeMatchEnum matchesType(const StaticType &type) const;
    00159
    00160   unsigned int flags_;
    00161   unsigned int min_;
    00162   unsigned int max_;
    00163
    00164   XPath2MemoryManager *mm_;
    00165   unsigned int minArgs_;
    00166   unsigned int maxArgs_;
    00167   StaticType *returnType_;
    00168 };
    00169
    00170 XQILLA_API StaticType::StaticTypeFlags operator|(StaticType::StaticTypeFlags a, StaticType::StaticTypeFlags b);
    00171 XQILLA_API StaticType::StaticTypeFlags operator&(StaticType::StaticTypeFlags a, StaticType::StaticTypeFlags b);
    00172
    00173 #endif