00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _STATICTYPE_HPP
00023 #define _STATICTYPE_HPP
00024
00025 #include <xqilla/framework/XQillaExport.hpp>
00026 #include <xqilla/items/AnyAtomicType.hpp>
00027 #include <xqilla/framework/XPath2MemoryManager.hpp>
00028
00029 #include <xercesc/framework/XMLBuffer.hpp>
00030 #include <xercesc/util/XMemory.hpp>
00031
00035 class XQILLA_API StaticType : public XERCES_CPP_NAMESPACE_QUALIFIER XMemory {
00036 public:
00040 enum StaticTypeFlags {
00041 DOCUMENT_TYPE = 0x00000001,
00042 ELEMENT_TYPE = 0x00000002,
00043 ATTRIBUTE_TYPE = 0x00000004,
00044 TEXT_TYPE = 0x00000008,
00045 PI_TYPE = 0x00000010,
00046 COMMENT_TYPE = 0x00000020,
00047 NAMESPACE_TYPE = 0x00000040,
00048
00049 ANY_SIMPLE_TYPE = 0x00000080,
00050 ANY_URI_TYPE = 0x00000100,
00051 BASE_64_BINARY_TYPE = 0x00000200,
00052 BOOLEAN_TYPE = 0x00000400,
00053 DATE_TYPE = 0x00000800,
00054 DATE_TIME_TYPE = 0x00001000,
00055 DAY_TIME_DURATION_TYPE = 0x00002000,
00056 DECIMAL_TYPE = 0x00004000,
00057 DOUBLE_TYPE = 0x00008000,
00058 DURATION_TYPE = 0x00010000,
00059 FLOAT_TYPE = 0x00020000,
00060 G_DAY_TYPE = 0x00040000,
00061 G_MONTH_TYPE = 0x00080000,
00062 G_MONTH_DAY_TYPE = 0x00100000,
00063 G_YEAR_TYPE = 0x00200000,
00064 G_YEAR_MONTH_TYPE = 0x00400000,
00065 HEX_BINARY_TYPE = 0x00800000,
00066 NOTATION_TYPE = 0x01000000,
00067 QNAME_TYPE = 0x02000000,
00068 STRING_TYPE = 0x04000000,
00069 TIME_TYPE = 0x08000000,
00070 UNTYPED_ATOMIC_TYPE = 0x10000000,
00071 YEAR_MONTH_DURATION_TYPE = 0x20000000,
00072
00073 FUNCTION_TYPE = 0x40000000,
00074
00075 NODE_TYPE = (DOCUMENT_TYPE | ELEMENT_TYPE | ATTRIBUTE_TYPE | TEXT_TYPE | PI_TYPE | COMMENT_TYPE |
00076 NAMESPACE_TYPE),
00077
00078 NUMERIC_TYPE = (DECIMAL_TYPE | FLOAT_TYPE | DOUBLE_TYPE),
00079
00080 TIMEZONE_TYPE = (DATE_TYPE | DATE_TIME_TYPE | G_DAY_TYPE | G_MONTH_TYPE | G_MONTH_DAY_TYPE |
00081 G_YEAR_TYPE | G_YEAR_MONTH_TYPE | TIME_TYPE),
00082
00083 TYPED_ATOMIC_TYPE = (NUMERIC_TYPE | TIMEZONE_TYPE | ANY_SIMPLE_TYPE | ANY_URI_TYPE | BASE_64_BINARY_TYPE |
00084 BOOLEAN_TYPE | DAY_TIME_DURATION_TYPE | DURATION_TYPE | HEX_BINARY_TYPE |
00085 NOTATION_TYPE | QNAME_TYPE | STRING_TYPE | YEAR_MONTH_DURATION_TYPE),
00086
00087 ANY_ATOMIC_TYPE = (TYPED_ATOMIC_TYPE | UNTYPED_ATOMIC_TYPE),
00088
00089 ITEM_TYPE = (NODE_TYPE | ANY_ATOMIC_TYPE | FUNCTION_TYPE),
00090
00091 EMPTY_TYPE = 0
00092 };
00093
00094 static const unsigned int UNLIMITED;
00095
00097 StaticType();
00098
00099 StaticType(StaticTypeFlags f, unsigned int min = 1, unsigned int max = 1);
00101 StaticType(XPath2MemoryManager *mm, unsigned int numArgs, const StaticType &returnType, unsigned int min = 1, unsigned int max = 1);
00103 StaticType(XPath2MemoryManager *mm, unsigned int minArgs, unsigned int maxArgs, const StaticType &returnType,
00104 unsigned int min = 1, unsigned int max = 1);
00105
00106 StaticType(const StaticType &o);
00107 StaticType &operator=(const StaticType &o);
00108 ~StaticType();
00109
00110 static StaticType create(const XMLCh *uri, const XMLCh *name, const StaticContext *context,
00111 bool &isExact);
00112 static StaticType create(AnyAtomicType::AtomicObjectType primitiveType);
00113
00114 void typeUnion(const StaticType &st);
00115 void typeIntersect(const StaticType &st);
00116 void typeExcept(const StaticType &st);
00117
00118 void typeConcat(const StaticType &st);
00119 void typeNodeIntersect(const StaticType &st);
00120
00121 StaticType operator|(const StaticType &st) const;
00122 StaticType &operator|=(const StaticType &st);
00123
00124 StaticType operator&(const StaticType &st) const;
00125 StaticType &operator&=(const StaticType &st);
00126
00127 StaticType &substitute(const StaticType &from, const StaticType &to);
00128 StaticType &multiply(unsigned int min, unsigned int max);
00129 void setCardinality(unsigned int min, unsigned int max);
00130
00131 bool containsType(const StaticType &type) const;
00132 bool containsType(StaticType::StaticTypeFlags flags) const;
00133 bool isType(const StaticType &type) const;
00134
00135 enum TypeMatchEnum {
00136 NEVER = 0,
00137 PROBABLY_NOT = 1,
00138 MAYBE = 2,
00139 ALWAYS = 3
00140 };
00141
00142 struct TypeMatch
00143 {
00144 TypeMatchEnum type, cardinality;
00145 };
00146
00147 TypeMatch matches(const StaticType &actual) const;
00148
00149 unsigned int getMin() const { return min_; }
00150 unsigned int getMax() const { return max_; }
00151
00152 unsigned int getMinArgs() const { return minArgs_; }
00153 unsigned int getMaxArgs() const { return maxArgs_; }
00154 const StaticType *getReturnType() const { return returnType_; }
00155
00156 void typeToBuf(XERCES_CPP_NAMESPACE_QUALIFIER XMLBuffer &buf) const;
00157
00158 private:
00159 TypeMatchEnum matchesFunctionType(const StaticType &type) const;
00160 TypeMatchEnum matchesType(const StaticType &type) const;
00161
00162 unsigned int flags_;
00163 unsigned int min_;
00164 unsigned int max_;
00165
00166 XPath2MemoryManager *mm_;
00167 unsigned int minArgs_;
00168 unsigned int maxArgs_;
00169 StaticType *returnType_;
00170 };
00171
00172 XQILLA_API StaticType::StaticTypeFlags operator|(StaticType::StaticTypeFlags a, StaticType::StaticTypeFlags b);
00173 XQILLA_API StaticType::StaticTypeFlags operator&(StaticType::StaticTypeFlags a, StaticType::StaticTypeFlags b);
00174
00175 #endif