SourceForge.net Logo
AnyAtomicType.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 _ANYATOMICTYPE_HPP
21 #define _ANYATOMICTYPE_HPP
22 
23 #include <xqilla/framework/XQillaExport.hpp>
24 #include <xqilla/items/Item.hpp>
25 #include <xercesc/util/XercesDefs.hpp>
26 
27 class DynamicContext;
28 class StaticContext;
29 
30 class XQILLA_API AnyAtomicType: public Item
31 {
32 
33 public:
35  ANY_SIMPLE_TYPE = 0,
36  ANY_URI = 1,
37  BASE_64_BINARY = 2,
38  BOOLEAN = 3,
39  DATE = 4,
40  DATE_TIME = 5,
41  DAY_TIME_DURATION = 6,
42  DECIMAL = 7,
43  DOUBLE = 8,
44  DURATION = 9,
45  FLOAT = 10,
46  G_DAY = 11,
47  G_MONTH = 12,
48  G_MONTH_DAY = 13,
49  G_YEAR = 14,
50  G_YEAR_MONTH = 15,
51  HEX_BINARY = 16,
52  NOTATION = 17,
53  QNAME = 18,
54  STRING = 19,
55  TIME = 20,
56  UNTYPED_ATOMIC = 21,
57  YEAR_MONTH_DURATION= 22,
58  NumAtomicObjectTypes= 23
59  };
60 
62 
63  /* isAtomicValue from Item */
64  virtual bool isAtomicValue() const;
65 
66  /* isNode from Item */
67  virtual bool isNode() const;
68 
69  virtual bool isFunction() const;
70 
71  /* is this type numeric? Return false by default */
72  virtual bool isNumericValue() const;
73 
74  /* is this type date or time based? Return false by default */
75  virtual bool isDateOrTimeTypeValue() const;
76 
77  /* Get the namespace uri of the primitive type (basic type) of this type */
78  virtual const XMLCh* getPrimitiveTypeURI() const;
79 
80  /* Get the name of the primitive type (basic type) of this type (ie "decimal" for xs:decimal) */
81  virtual const XMLCh* getPrimitiveTypeName() const = 0;
82 
83  /* Get the namespace URI for this type */
84  virtual const XMLCh* getTypeURI() const = 0;
85 
86  /* Get the name of this type (ie "integer" for xs:integer) */
87  virtual const XMLCh* getTypeName() const = 0;
88 
89  virtual void generateEvents(EventHandler *events, const DynamicContext *context,
90  bool preserveNS = true, bool preserveType = true) const;
91 
92  /* If possible, cast this type to the target type -- no casting table lookup made */
93  AnyAtomicType::Ptr castAs(AtomicObjectType targetIndex, const DynamicContext* context) const;
94 
95  /* If possible, cast this type to the target type -- no casting table lookup made */
96  AnyAtomicType::Ptr castAsNoCheck(AtomicObjectType targetIndex, const XMLCh* targetURI, const XMLCh* targetType,
97  const DynamicContext* context) const;
98 
99  /* If possible, cast this type to the target type -- not virtual, this is the single entry point for casting */
100  AnyAtomicType::Ptr castAs(AtomicObjectType targetIndex, const XMLCh* targetURI, const XMLCh* targetType,
101  const DynamicContext* context) const;
102 
103  /* Test if this type can be cast to the target type */
104  virtual bool castable(AtomicObjectType targetIndex, const XMLCh* targetURI, const XMLCh* targetType,
105  const DynamicContext* context) const;
106 
107  /* returns the XMLCh* (canonical) representation of this type */
108  virtual const XMLCh* asString(const DynamicContext* context) const = 0;
109 
110  /* returns true if the two objects are equal (whatever that means
111  * in the context of the datatype), false otherwise */
112  virtual bool equals(const AnyAtomicType::Ptr &target, const DynamicContext* context) const = 0;
113 
114  /* Returns true if this typeName and uri match the given typeName and uri */
115  virtual bool isOfType(const XMLCh* targetURI, const XMLCh* targetType, const DynamicContext* context) const;
116 
117  /* Returns true if this typeName and uri match the given typeName and uri,
118  * or if any of this type's parents match the given typeName and uri */
119  virtual bool isInstanceOfType(const XMLCh* targetURI, const XMLCh* targetType, const StaticContext* context) const;
120 
121  virtual void typeToBuffer(DynamicContext *context, XERCES_CPP_NAMESPACE_QUALIFIER XMLBuffer &buffer) const;
122 
135  bool castIsSupported(AtomicObjectType targetIndex, const DynamicContext* context) const;
136 
137  virtual AtomicObjectType getPrimitiveTypeIndex() const = 0;
138 
139  static const XMLCh fgDT_ANYATOMICTYPE[];
140 
141 protected:
142  /* internal castAs method. This one is virtual and does the real work */
143  virtual AnyAtomicType::Ptr castAsInternal(AtomicObjectType targetIndex, const XMLCh* targetURI,
144  const XMLCh* targetType, const DynamicContext* context) const;
145 
146 private:
147 
148  //friend class CastTable;
149  //template <class TYPE> friend class DatatypeFactoryTemplate;
150 
151  // class that implements the Casting Table
152  class CastTable {
153  public:
154  CastTable();
155  bool getCell(AtomicObjectType source,
156  AtomicObjectType target) const;
157  private:
158  bool staticCastTable[NumAtomicObjectTypes][NumAtomicObjectTypes];
159  };
160 
161 
162  // reproduction of the XPath2 casting table: http://www.w3.org/TR/xquery-operators/#casting
163  static const CastTable staticCastTable;
164 };
165 
166 #endif
virtual const XMLCh * getTypeName() const =0
virtual bool isAtomicValue() const =0
virtual bool isNode() const =0
Definition: EventHandler.hpp:29
RefCountPointer< const AnyAtomicType > Ptr
Definition: AnyAtomicType.hpp:61
virtual bool isFunction() const =0
Super class of all the reference counted wrappers for Items.
Definition: ReferenceCounted.hpp:61
The parse time static context interface.
Definition: StaticContext.hpp:57
AtomicObjectType
Definition: AnyAtomicType.hpp:34
Definition: AnyAtomicType.hpp:30
Definition: Item.hpp:36
virtual void generateEvents(EventHandler *events, const DynamicContext *context, bool preserveNS=true, bool preserveType=true) const =0
Generate events for this Item to the given EventHandler.
virtual void typeToBuffer(DynamicContext *context, xercesc::XMLBuffer &buffer) const =0
Debug method to output the type of the item in SequenceType notation.
The execution time dynamic context interface.
Definition: DynamicContext.hpp:38
virtual const XMLCh * getTypeURI() const =0
virtual const XMLCh * asString(const DynamicContext *context) const =0