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 
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 
107 
108  static StaticType create(const XMLCh *uri, const XMLCh *name, const StaticContext *context,
109  bool &isExact);
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;
121 
122  StaticType operator&(const StaticType &st) const;
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;
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
StaticType::operator|
StaticType operator|(const StaticType &st) const
StaticType::getMin
unsigned int getMin() const
Definition: StaticType.hpp:147
StaticType::operator=
StaticType & operator=(const StaticType &o)
StaticType::typeConcat
void typeConcat(const StaticType &st)
StaticType::typeNodeIntersect
void typeNodeIntersect(const StaticType &st)
StaticType::matches
TypeMatch matches(const StaticType &actual) const
StaticType::StaticType
StaticType(XPath2MemoryManager *mm, unsigned int numArgs, const StaticType &returnType, unsigned int min=1, unsigned int max=1)
Constructor for a function type.
StaticType::getMaxArgs
unsigned int getMaxArgs() const
Definition: StaticType.hpp:151
StaticContext
The parse time static context interface.
Definition: StaticContext.hpp:58
AnyAtomicType::AtomicObjectType
AtomicObjectType
Definition: AnyAtomicType.hpp:34
StaticType::operator&
StaticType operator&(const StaticType &st) const
StaticType::TypeMatchEnum
TypeMatchEnum
Definition: StaticType.hpp:133
StaticType::typeUnion
void typeUnion(const StaticType &st)
StaticType::~StaticType
~StaticType()
StaticType::setCardinality
void setCardinality(unsigned int min, unsigned int max)
StaticType::StaticType
StaticType(const StaticType &o)
StaticType::substitute
StaticType & substitute(const StaticType &from, const StaticType &to)
StaticType::getReturnType
const StaticType * getReturnType() const
Definition: StaticType.hpp:152
StaticType::isType
bool isType(const StaticType &type) const
XPath2MemoryManager.hpp
StaticType::StaticType
StaticType(StaticTypeFlags f, unsigned int min=1, unsigned int max=1)
StaticType::typeIntersect
void typeIntersect(const StaticType &st)
XPath2MemoryManager
Definition: XPath2MemoryManager.hpp:46
StaticType::StaticType
StaticType(XPath2MemoryManager *mm, unsigned int minArgs, unsigned int maxArgs, const StaticType &returnType, unsigned int min=1, unsigned int max=1)
Constructor for a function type.
operator&
StaticType::StaticTypeFlags operator&(StaticType::StaticTypeFlags a, StaticType::StaticTypeFlags b)
StaticType::getMinArgs
unsigned int getMinArgs() const
Definition: StaticType.hpp:150
StaticType::operator|=
StaticType & operator|=(const StaticType &st)
StaticType::create
static StaticType create(AnyAtomicType::AtomicObjectType primitiveType)
StaticType::UNLIMITED
static const unsigned int UNLIMITED
Definition: StaticType.hpp:92
AnyAtomicType.hpp
StaticType::TypeMatch::type
TypeMatchEnum type
Definition: StaticType.hpp:142
StaticType
Class that represents the static type of an expression.
Definition: StaticType.hpp:33
operator|
StaticType::StaticTypeFlags operator|(StaticType::StaticTypeFlags a, StaticType::StaticTypeFlags b)
StaticType::create
static StaticType create(const XMLCh *uri, const XMLCh *name, const StaticContext *context, bool &isExact)
StaticType::typeToBuf
void typeToBuf(xercesc::XMLBuffer &buf) const
StaticType::multiply
StaticType & multiply(unsigned int min, unsigned int max)
StaticType::StaticType
StaticType()
Constructor for an empty type.
StaticType::containsType
bool containsType(const StaticType &type) const
StaticType::TypeMatch
Definition: StaticType.hpp:141
StaticType::StaticTypeFlags
StaticTypeFlags
Flags that determine what item types are returned from an expression.
Definition: StaticType.hpp:38
StaticType::getMax
unsigned int getMax() const
Definition: StaticType.hpp:148
StaticType::containsType
bool containsType(StaticType::StaticTypeFlags flags) const
StaticType::operator&=
StaticType & operator&=(const StaticType &st)
StaticType::typeExcept
void typeExcept(const StaticType &st)
XMemory.hpp