1 /* 2 * Copyright 2006-2008 The FLWOR Foundation. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #pragma once 17 #ifndef ZORBA_TYPEMANAGERIMPL_H 18 #define ZORBA_TYPEMANAGERIMPL_H 19 20 #include "types/typemanager.h" 21 //#include "types/schema/schema.h" 22 #include "store/api/item.h" 23 24 #include "system/globalenv.h" 25 26 namespace zorba { 27 28 class NodeTest; 29 class Schema; 30 31 32 class qname_hash_equals 33 { 34 public: hash(const store::Item * qn)35 static uint32_t hash(const store::Item* qn) 36 { 37 return qn->hash(); 38 } 39 equal(const store::Item * qn1,const store::Item * qn2)40 static bool equal(const store::Item* qn1, const store::Item* qn2) 41 { 42 return qn1->equals(qn2); 43 } 44 }; 45 46 47 /***************************************************************************//** 48 A type manager acts as a factory and manager of XQType instances. 49 50 Multiple type managers may participate in an xquery program, each corresponding 51 to a different xml schema. These type managers are arranged in a tree hierarchy. 52 There is always a root type manager (see root_typemanager.h) that is created 53 during system initialization and manages the built-in types of XQDM. Other 54 type managers are allocated dynamically during the processing of schema import 55 statements inside an xquery program. 56 57 Each XQType instance has a pointer back to the type manager that created that 58 XQType. 59 ********************************************************************************/ 60 class TypeManagerImpl : public TypeManager 61 { 62 protected: 63 TypeManager * m_parent; 64 Schema * m_schema; 65 66 public: 67 SERIALIZABLE_CLASS(TypeManagerImpl) 68 SERIALIZABLE_CLASS_CONSTRUCTOR2_NULL_PARAM1(TypeManagerImpl, TypeManager,m_schema) 69 void serialize(::zorba::serialization::Archiver& ar); 70 71 public: TypeManagerImpl(TypeManager * parent)72 TypeManagerImpl(TypeManager* parent) 73 : 74 TypeManager(parent ? parent->level() + 1 : 0), 75 m_parent(parent), 76 m_schema(NULL) 77 { 78 } 79 80 virtual ~TypeManagerImpl(); 81 get_parent_type_manager()82 TypeManager* get_parent_type_manager() const { return m_parent; } 83 getSchema()84 Schema* getSchema() const { return m_schema; } 85 86 void initializeSchema(); 87 88 void terminateSchema(); 89 90 xqtref_t create_any_type() const; 91 92 xqtref_t create_untyped_type() const; 93 94 xqtref_t create_any_simple_type() const; 95 96 xqtref_t create_empty_type() const; 97 98 xqtref_t create_none_type() const; 99 100 xqtref_t create_any_item_type(TypeConstants::quantifier_t q) const; 101 102 xqtref_t create_any_function_type(TypeConstants::quantifier_t q) const; 103 104 xqtref_t create_function_type( 105 const std::vector<xqtref_t>& aArgs, 106 const xqtref_t& aReturn, 107 TypeConstants::quantifier_t aQuant) const; 108 109 xqtref_t create_builtin_atomic_type( 110 store::SchemaTypeCode type_code, 111 TypeConstants::quantifier_t quant) const; 112 113 xqtref_t create_named_atomic_type( 114 store::Item* qname, 115 TypeConstants::quantifier_t quant, 116 const QueryLoc& loc, 117 const Error& error = zerr::ZXQP0000_NO_ERROR) const; 118 119 xqtref_t create_named_type( 120 store::Item* qname, 121 TypeConstants::quantifier_t quant, 122 const QueryLoc& loc, 123 const Error& error = zerr::ZXQP0000_NO_ERROR) const; 124 125 xqtref_t create_structured_item_type(TypeConstants::quantifier_t q) const; 126 127 #ifdef ZORBA_WITH_JSON 128 xqtref_t create_json_type( 129 store::StoreConsts::JSONItemKind kind, 130 TypeConstants::quantifier_t quantifier) const; 131 #endif 132 133 xqtref_t create_node_type( 134 store::StoreConsts::NodeKind nodeKind, 135 const store::Item_t& nodeName, 136 const xqtref_t& contentType, 137 TypeConstants::quantifier_t quant, 138 bool nillable, 139 bool schematest) const; 140 141 xqtref_t create_value_type( 142 const store::Item* item, 143 const QueryLoc& loc = QueryLoc::null) const; 144 145 xqtref_t create_type(const TypeIdentifier& ident) const; 146 147 #ifndef ZORBA_NO_XMLSCHEMA 148 149 xqtref_t create_schema_element_type( 150 const store::Item_t& elemName, 151 TypeConstants::quantifier_t quant, 152 const QueryLoc& loc) const; 153 154 void get_schema_element_typename( 155 const store::Item* elemName, 156 store::Item_t& typeName, 157 const QueryLoc& loc); 158 159 xqtref_t create_schema_attribute_type( 160 const store::Item_t& attrName, 161 TypeConstants::quantifier_t quant, 162 const QueryLoc& loc) const; 163 164 void get_schema_attribute_typename( 165 const store::Item* attrName, 166 store::Item_t& typeName, 167 const QueryLoc& loc); 168 #endif 169 170 xqtref_t create_type( 171 const XQType& type, 172 TypeConstants::quantifier_t quant) const; 173 174 xqtref_t create_type_x_quant( 175 const XQType& type, 176 TypeConstants::quantifier_t quant) const; 177 178 private: 179 xqtref_t create_builtin_node_type( 180 store::StoreConsts::NodeKind nodeKind, 181 TypeConstants::quantifier_t quantifier, 182 bool untyped) const; 183 }; 184 185 } 186 187 #endif /* ZORBA_TYPEMANAGER_H */ 188 189 /* 190 * Local variables: 191 * mode: c++ 192 * End: 193 */ 194 /* vim:set et sw=2 ts=2: */ 195