SourceForge.net Logo
StaticType.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2008
3  * DecisionSoft Limited. All rights reserved.
4  * Copyright (c) 2004-2008
5  * Oracle. All rights reserved.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * $Id$
20  */
21 
22 #ifndef _STATICTYPE_HPP
23 #define _STATICTYPE_HPP
24 
25 #include <xqilla/framework/XQillaExport.hpp>
28 
29 #include <xercesc/framework/XMLBuffer.hpp>
30 #include <xercesc/util/XMemory.hpp>
31 
35 class XQILLA_API StaticType : public XERCES_CPP_NAMESPACE_QUALIFIER XMemory {
36 public:
41  DOCUMENT_TYPE = 0x00000001,
42  ELEMENT_TYPE = 0x00000002,
43  ATTRIBUTE_TYPE = 0x00000004,
44  TEXT_TYPE = 0x00000008,
45  PI_TYPE = 0x00000010,
46  COMMENT_TYPE = 0x00000020,
47  NAMESPACE_TYPE = 0x00000040,
48 
49  ANY_SIMPLE_TYPE = 0x00000080,
50  ANY_URI_TYPE = 0x00000100,
51  BASE_64_BINARY_TYPE = 0x00000200,
52  BOOLEAN_TYPE = 0x00000400,
53  DATE_TYPE = 0x00000800,
54  DATE_TIME_TYPE = 0x00001000,
55  DAY_TIME_DURATION_TYPE = 0x00002000,
56  DECIMAL_TYPE = 0x00004000,
57  DOUBLE_TYPE = 0x00008000,
58  DURATION_TYPE = 0x00010000,
59  FLOAT_TYPE = 0x00020000,
60  G_DAY_TYPE = 0x00040000,
61  G_MONTH_TYPE = 0x00080000,
62  G_MONTH_DAY_TYPE = 0x00100000,
63  G_YEAR_TYPE = 0x00200000,
64  G_YEAR_MONTH_TYPE = 0x00400000,
65  HEX_BINARY_TYPE = 0x00800000,
66  NOTATION_TYPE = 0x01000000,
67  QNAME_TYPE = 0x02000000,
68  STRING_TYPE = 0x04000000,
69  TIME_TYPE = 0x08000000,
70  UNTYPED_ATOMIC_TYPE = 0x10000000,
71  YEAR_MONTH_DURATION_TYPE = 0x20000000,
72 
73  FUNCTION_TYPE = 0x40000000,
74 
75  NODE_TYPE = (DOCUMENT_TYPE | ELEMENT_TYPE | ATTRIBUTE_TYPE | TEXT_TYPE | PI_TYPE | COMMENT_TYPE |
76  NAMESPACE_TYPE),
77 
78  NUMERIC_TYPE = (DECIMAL_TYPE | FLOAT_TYPE | DOUBLE_TYPE),
79 
80  TIMEZONE_TYPE = (DATE_TYPE | DATE_TIME_TYPE | G_DAY_TYPE | G_MONTH_TYPE | G_MONTH_DAY_TYPE |
81  G_YEAR_TYPE | G_YEAR_MONTH_TYPE | TIME_TYPE),
82 
83  TYPED_ATOMIC_TYPE = (NUMERIC_TYPE | TIMEZONE_TYPE | ANY_SIMPLE_TYPE | ANY_URI_TYPE | BASE_64_BINARY_TYPE |
84  BOOLEAN_TYPE | DAY_TIME_DURATION_TYPE | DURATION_TYPE | HEX_BINARY_TYPE |
85  NOTATION_TYPE | QNAME_TYPE | STRING_TYPE | YEAR_MONTH_DURATION_TYPE),
86 
87  ANY_ATOMIC_TYPE = (TYPED_ATOMIC_TYPE | UNTYPED_ATOMIC_TYPE),
88 
89  ITEM_TYPE = (NODE_TYPE | ANY_ATOMIC_TYPE | FUNCTION_TYPE),
90 
91  EMPTY_TYPE = 0
92  };
93 
94  static const unsigned int UNLIMITED;
95 
97  StaticType();
98  // Constructor for normal types
99  StaticType(StaticTypeFlags f, unsigned int min = 1, unsigned int max = 1);
101  StaticType(XPath2MemoryManager *mm, unsigned int numArgs, const StaticType &returnType, unsigned int min = 1, unsigned int max = 1);
103  StaticType(XPath2MemoryManager *mm, unsigned int minArgs, unsigned int maxArgs, const StaticType &returnType,
104  unsigned int min = 1, unsigned int max = 1);
105 
106  StaticType(const StaticType &o);
107  StaticType &operator=(const StaticType &o);
108  ~StaticType();
109 
110  static StaticType create(const XMLCh *uri, const XMLCh *name, const StaticContext *context,
111  bool &isExact);
112  static StaticType create(AnyAtomicType::AtomicObjectType primitiveType);
113 
114  void typeUnion(const StaticType &st);
115  void typeIntersect(const StaticType &st);
116  void typeExcept(const StaticType &st);
117 
118  void typeConcat(const StaticType &st);
119  void typeNodeIntersect(const StaticType &st);
120 
121  StaticType operator|(const StaticType &st) const;
122  StaticType &operator|=(const StaticType &st);
123 
124  StaticType operator&(const StaticType &st) const;
125  StaticType &operator&=(const StaticType &st);
126 
127  StaticType &substitute(const StaticType &from, const StaticType &to);
128  StaticType &multiply(unsigned int min, unsigned int max);
129  void setCardinality(unsigned int min, unsigned int max);
130 
131  bool containsType(const StaticType &type) const;
132  bool containsType(StaticType::StaticTypeFlags flags) const;
133  bool isType(const StaticType &type) const;
134 
136  NEVER = 0,
137  PROBABLY_NOT = 1,
138  MAYBE = 2,
139  ALWAYS = 3
140  };
141 
142  struct TypeMatch
143  {
144  TypeMatchEnum type, cardinality;
145  };
146 
147  TypeMatch matches(const StaticType &actual) const;
148 
149  unsigned int getMin() const { return min_; }
150  unsigned int getMax() const { return max_; }
151 
152  unsigned int getMinArgs() const { return minArgs_; }
153  unsigned int getMaxArgs() const { return maxArgs_; }
154  const StaticType *getReturnType() const { return returnType_; }
155 
156  void typeToBuf(XERCES_CPP_NAMESPACE_QUALIFIER XMLBuffer &buf) const;
157 
158 private:
159  TypeMatchEnum matchesFunctionType(const StaticType &type) const;
160  TypeMatchEnum matchesType(const StaticType &type) const;
161 
162  unsigned int flags_;
163  unsigned int min_;
164  unsigned int max_;
165 
166  XPath2MemoryManager *mm_;
167  unsigned int minArgs_;
168  unsigned int maxArgs_;
169  StaticType *returnType_;
170 };
171 
174 
175 #endif