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, 2015 Oracle and/or its affiliates. All rights reserved.
5  *
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 
20 #ifndef _STATICTYPE_HPP
21 #define _STATICTYPE_HPP
22 
23 #include <xqilla/framework/XQillaExport.hpp>
26 
27 #include <xercesc/framework/XMLBuffer.hpp>
28 #include <xercesc/util/XMemory.hpp>
29 
33 class XQILLA_API StaticType : public XERCES_CPP_NAMESPACE_QUALIFIER XMemory {
34 public:
39  DOCUMENT_TYPE = 0x00000001,
40  ELEMENT_TYPE = 0x00000002,
41  ATTRIBUTE_TYPE = 0x00000004,
42  TEXT_TYPE = 0x00000008,
43  PI_TYPE = 0x00000010,
44  COMMENT_TYPE = 0x00000020,
45  NAMESPACE_TYPE = 0x00000040,
46 
47  ANY_SIMPLE_TYPE = 0x00000080,
48  ANY_URI_TYPE = 0x00000100,
49  BASE_64_BINARY_TYPE = 0x00000200,
50  BOOLEAN_TYPE = 0x00000400,
51  DATE_TYPE = 0x00000800,
52  DATE_TIME_TYPE = 0x00001000,
53  DAY_TIME_DURATION_TYPE = 0x00002000,
54  DECIMAL_TYPE = 0x00004000,
55  DOUBLE_TYPE = 0x00008000,
56  DURATION_TYPE = 0x00010000,
57  FLOAT_TYPE = 0x00020000,
58  G_DAY_TYPE = 0x00040000,
59  G_MONTH_TYPE = 0x00080000,
60  G_MONTH_DAY_TYPE = 0x00100000,
61  G_YEAR_TYPE = 0x00200000,
62  G_YEAR_MONTH_TYPE = 0x00400000,
63  HEX_BINARY_TYPE = 0x00800000,
64  NOTATION_TYPE = 0x01000000,
65  QNAME_TYPE = 0x02000000,
66  STRING_TYPE = 0x04000000,
67  TIME_TYPE = 0x08000000,
68  UNTYPED_ATOMIC_TYPE = 0x10000000,
69  YEAR_MONTH_DURATION_TYPE = 0x20000000,
70 
71  FUNCTION_TYPE = 0x40000000,
72 
73  NODE_TYPE = (DOCUMENT_TYPE | ELEMENT_TYPE | ATTRIBUTE_TYPE | TEXT_TYPE | PI_TYPE | COMMENT_TYPE |
74  NAMESPACE_TYPE),
75 
76  NUMERIC_TYPE = (DECIMAL_TYPE | FLOAT_TYPE | DOUBLE_TYPE),
77 
78  TIMEZONE_TYPE = (DATE_TYPE | DATE_TIME_TYPE | G_DAY_TYPE | G_MONTH_TYPE | G_MONTH_DAY_TYPE |
79  G_YEAR_TYPE | G_YEAR_MONTH_TYPE | TIME_TYPE),
80 
81  TYPED_ATOMIC_TYPE = (NUMERIC_TYPE | TIMEZONE_TYPE | ANY_SIMPLE_TYPE | ANY_URI_TYPE | BASE_64_BINARY_TYPE |
82  BOOLEAN_TYPE | DAY_TIME_DURATION_TYPE | DURATION_TYPE | HEX_BINARY_TYPE |
83  NOTATION_TYPE | QNAME_TYPE | STRING_TYPE | YEAR_MONTH_DURATION_TYPE),
84 
85  ANY_ATOMIC_TYPE = (TYPED_ATOMIC_TYPE | UNTYPED_ATOMIC_TYPE),
86 
87  ITEM_TYPE = (NODE_TYPE | ANY_ATOMIC_TYPE | FUNCTION_TYPE),
88 
89  EMPTY_TYPE = 0
90  };
91 
92  static const unsigned int UNLIMITED;
93 
95  StaticType();
96  // Constructor for normal types
97  StaticType(StaticTypeFlags f, unsigned int min = 1, unsigned int max = 1);
99  StaticType(XPath2MemoryManager *mm, unsigned int numArgs, const StaticType &returnType, unsigned int min = 1, unsigned int max = 1);
101  StaticType(XPath2MemoryManager *mm, unsigned int minArgs, unsigned int maxArgs, const StaticType &returnType,
102  unsigned int min = 1, unsigned int max = 1);
103 
104  StaticType(const StaticType &o);
105  StaticType &operator=(const StaticType &o);
106  ~StaticType();
107 
108  static StaticType create(const XMLCh *uri, const XMLCh *name, const StaticContext *context,
109  bool &isExact);
110  static StaticType create(AnyAtomicType::AtomicObjectType primitiveType);
111 
112  void typeUnion(const StaticType &st);
113  void typeIntersect(const StaticType &st);
114  void typeExcept(const StaticType &st);
115 
116  void typeConcat(const StaticType &st);
117  void typeNodeIntersect(const StaticType &st);
118 
119  StaticType operator|(const StaticType &st) const;
120  StaticType &operator|=(const StaticType &st);
121 
122  StaticType operator&(const StaticType &st) const;
123  StaticType &operator&=(const StaticType &st);
124 
125  StaticType &substitute(const StaticType &from, const StaticType &to);
126  StaticType &multiply(unsigned int min, unsigned int max);
127  void setCardinality(unsigned int min, unsigned int max);
128 
129  bool containsType(const StaticType &type) const;
130  bool containsType(StaticType::StaticTypeFlags flags) const;
131  bool isType(const StaticType &type) const;
132 
134  NEVER = 0,
135  PROBABLY_NOT = 1,
136  MAYBE = 2,
137  ALWAYS = 3
138  };
139 
140  struct TypeMatch
141  {
142  TypeMatchEnum type, cardinality;
143  };
144 
145  TypeMatch matches(const StaticType &actual) const;
146 
147  unsigned int getMin() const { return min_; }
148  unsigned int getMax() const { return max_; }
149 
150  unsigned int getMinArgs() const { return minArgs_; }
151  unsigned int getMaxArgs() const { return maxArgs_; }
152  const StaticType *getReturnType() const { return returnType_; }
153 
154  void typeToBuf(XERCES_CPP_NAMESPACE_QUALIFIER XMLBuffer &buf) const;
155 
156 private:
157  TypeMatchEnum matchesFunctionType(const StaticType &type) const;
158  TypeMatchEnum matchesType(const StaticType &type) const;
159 
160  unsigned int flags_;
161  unsigned int min_;
162  unsigned int max_;
163 
164  XPath2MemoryManager *mm_;
165  unsigned int minArgs_;
166  unsigned int maxArgs_;
167  StaticType *returnType_;
168 };
169 
172 
173 #endif
unsigned int getMin() const
Definition: StaticType.hpp:147
Definition: XPath2MemoryManager.hpp:45
unsigned int getMaxArgs() const
Definition: StaticType.hpp:151
static const unsigned int UNLIMITED
Definition: StaticType.hpp:92
StaticType::StaticTypeFlags operator|(StaticType::StaticTypeFlags a, StaticType::StaticTypeFlags b)
The parse time static context interface.
Definition: StaticContext.hpp:57
AtomicObjectType
Definition: AnyAtomicType.hpp:34
Definition: StaticType.hpp:140
TypeMatchEnum type
Definition: StaticType.hpp:142
unsigned int getMinArgs() const
Definition: StaticType.hpp:150
const StaticType * getReturnType() const
Definition: StaticType.hpp:152
unsigned int getMax() const
Definition: StaticType.hpp:148
Class that represents the static type of an expression.
Definition: StaticType.hpp:33
StaticTypeFlags
Flags that determine what item types are returned from an expression.
Definition: StaticType.hpp:38
StaticType::StaticTypeFlags operator &(StaticType::StaticTypeFlags a, StaticType::StaticTypeFlags b)
TypeMatchEnum
Definition: StaticType.hpp:133