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 #ifndef ZORBA_TYPES_TYPEIDENT_H
17 #define ZORBA_TYPES_TYPEIDENT_H
18 
19 #include <zorba/config.h>
20 #include <zorba/api_shared_types.h>
21 #include <zorba/identtypes.h>
22 #include <zorba/zorba_string.h>
23 #include <iostream>
24 
25 namespace zorba {
26 
27 /** \brief Type identifiers
28  *
29  * The type identifiers are not used, yet.
30  *
31  * Note: This class is reference counted. When writing multi-threaded clients,
32  * it is the responibility of the client code to synchronize assignments to the
33  * SmartPtr holding this object.
34  */
35 class ZORBA_DLL_PUBLIC TypeIdentifier : public SmartObject
36 {
37  public:
38   /** \brief Destructor
39    */
40   ~TypeIdentifier();
41 
42   static TypeIdentifier_t
43   createNamedType(
44       const String& uri,
45       const String& localName,
46       IdentTypes::quantifier_t quantifier = IdentTypes::QUANT_ONE);
47 
48   static TypeIdentifier_t
49   createElementType(
50       const String& uri,
51       bool uriWildcard,
52       const String& localName,
53       bool localNameWildcard,
54       TypeIdentifier_t contentType,
55       IdentTypes::quantifier_t quantifier = IdentTypes::QUANT_ONE);
56 
57   static TypeIdentifier_t
58   createAttributeType(
59       const String& uri,
60       bool uriWildcard,
61       const String& localName,
62       bool localNameWildcard,
63       TypeIdentifier_t contentType,
64       IdentTypes::quantifier_t q = IdentTypes::QUANT_ONE);
65 
66   static TypeIdentifier_t
67   createDocumentType(
68       TypeIdentifier_t contentType,
69       IdentTypes::quantifier_t q = IdentTypes::QUANT_ONE);
70 
71   static TypeIdentifier_t
72   createPIType(IdentTypes::quantifier_t q = IdentTypes::QUANT_ONE);
73 
74   static TypeIdentifier_t
75   createTextType(IdentTypes::quantifier_t q = IdentTypes::QUANT_ONE);
76 
77   static TypeIdentifier_t
78   createCommentType(IdentTypes::quantifier_t q = IdentTypes::QUANT_ONE);
79 
80   static TypeIdentifier_t
81   createAnyNodeType(IdentTypes::quantifier_t q = IdentTypes::QUANT_ONE);
82 
83   static TypeIdentifier_t
84   createStructuredItemType(IdentTypes::quantifier_t q = IdentTypes::QUANT_ONE);
85 
86 #ifdef ZORBA_WITH_JSON
87   static TypeIdentifier_t
88   createJSONItemType(IdentTypes::quantifier_t q = IdentTypes::QUANT_ONE);
89 
90   static TypeIdentifier_t
91   createJSONObjectType(IdentTypes::quantifier_t q = IdentTypes::QUANT_ONE);
92 
93   static TypeIdentifier_t
94   createJSONArrayType(IdentTypes::quantifier_t q = IdentTypes::QUANT_ONE);
95 #endif
96 
97   static TypeIdentifier_t
98   createItemType(IdentTypes::quantifier_t q = IdentTypes::QUANT_ONE);
99 
100   static TypeIdentifier_t
101   createEmptyType();
102 
103   static TypeIdentifier_t
104   createSchemaElementType(
105       const String& uri,
106       const String& localName,
107       IdentTypes::quantifier_t quantifier = IdentTypes::QUANT_ONE);
108 
109   static TypeIdentifier_t
110   createSchemaAttributeType(
111       const String& uri,
112       const String& localName,
113       IdentTypes::quantifier_t quantifier = IdentTypes::QUANT_ONE);
114 
115   IdentTypes::kind_t
116   getKind() const;
117 
118   IdentTypes::quantifier_t
119   getQuantifier() const;
120 
121   const String&
122   getUri() const;
123 
124   bool
125   isUriWildcard() const;
126 
127   const String&
128   getLocalName() const;
129 
130   bool
131   isLocalNameWildcard() const;
132 
133   TypeIdentifier_t
134   getContentType() const;
135 
136   std::ostream&
137   emit(std::ostream&) const;
138 
139  private:
140   TypeIdentifier();
141 
142   std::ostream&
143   emitItemType(std::ostream&) const;
144 
145   std::ostream&
146   emitName(std::ostream&) const;
147 
148   IdentTypes::kind_t m_kind;
149   IdentTypes::quantifier_t m_quantifier;
150   String m_uri;
151   bool m_uriWildcard;
152   String m_localName;
153   bool m_localNameWildcard;
154   TypeIdentifier_t m_contentType;
155 };
156 
157 #ifdef WIN32
158   template class ZORBA_DLL_PUBLIC  zorba::SmartPtr<TypeIdentifier>;
159 #endif
160 
161 
162 } /* namespace zorba */
163 
164 namespace std {
165 
166 ZORBA_DLL_PUBLIC ostream& operator<<(ostream& o, const zorba::TypeIdentifier& ti);
167 ZORBA_DLL_PUBLIC ostream& operator<<(ostream& o, const zorba::TypeIdentifier_t ti);
168 
169 }
170 
171 #endif /* ZORBA_TYPES_TYPEIDENT_H */
172 /* vim:set et sw=2 ts=2: */
173