qname.h
Go to the documentation of this file.
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 
17 #ifndef ZORBA_INTERNAL_QNAME_H
18 #define ZORBA_INTERNAL_QNAME_H
19 
20 #include <zorba/config.h>
21 #include <zorba/diagnostic.h>
22 
23 #include "ztd.h"
24 
25 namespace zorba {
26 
27 namespace internal {
28  template<typename StringType>
29  class ZORBA_DLL_PUBLIC VariableQName;
30 }
31 namespace serialization {
32  class Archiver;
33  template<typename StringType>
34  void operator&( serialization::Archiver&,
36 }
37 
38 namespace internal {
39 
40 ///////////////////////////////////////////////////////////////////////////////
41 
42 /**
43  * A %FixedQName is-an diagnostic::QName that has a fixed namespace and prefix,
44  * but a variable local-name.
45  *
46  * @tparam QNameTraits A class that contains static \c NAMESPACE and \c PREFIX
47  * members.
48  * @tparam LocalnameType The type to use to store the local-name. Note that
49  * this can be either a string type or <code>char const*</code>. If the
50  * latter, then it must be guaranteed that the pointed-to C strings will exist
51  * for the entire lifetime of this object.
52  */
53 template<class QNameTraits,typename LocalnameType>
54 class ZORBA_DLL_PUBLIC FixedQName : public zorba::diagnostic::QName {
55 public:
56 
57  /**
58  * Constructs a %FixedQName.
59  *
60  * @param localname The QName's local-name.
61  */
62  FixedQName( char const *localname ) : localname_( localname ) {
63  }
64 
65  // inherited
66  char const* ns() const { return ztd::c_str( QNameTraits::NAMESPACE ); }
67  char const* prefix() const { return ztd::c_str( QNameTraits::PREFIX ); }
68  char const* localname() const { return ztd::c_str( localname_ ); }
69 
70 private:
71  LocalnameType localname_;
72 };
73 
74 /**
75  * A %VariableQName is-an diagnostic::QName that has a variable namespace,
76  * prefix, and local-name.
77  *
78  * @tparam StringType The type to use to store the namespace, prefix, and
79  * local-name. Note that this can be either a string type or <code>char
80  * const*</code>. If the latter, then it must be guaranteed that the
81  * pointed-to C strings will exist for the entire lifetime of this object.
82  */
83 template<typename StringType>
84 class ZORBA_DLL_PUBLIC VariableQName : public zorba::diagnostic::QName {
85 public:
86 
87  /**
88  * Constructs a %VariableQName.
89  */
90  VariableQName( char const *ns, char const *prefix, char const *localname ) :
91  ns_( ns ), prefix_( prefix ), localname_( localname )
92  {
93  }
94 
95  // inherited
96  char const* ns() const { return ztd::c_str( ns_ ); }
97  char const* prefix() const { return ztd::c_str( prefix_ ); }
98  char const* localname() const { return ztd::c_str( localname_ ); }
99 
100 private:
101  StringType ns_;
102  StringType prefix_;
103  StringType localname_;
104 
105  // for plan serialization
106 public:
107  VariableQName( serialization::Archiver& ) { }
108 private:
109  friend void serialization::operator&<>( serialization::Archiver&,
110  VariableQName& );
111 };
112 
113 ///////////////////////////////////////////////////////////////////////////////
114 
115 /**
116  * A %ZorbaErrQName is-a FixedQName for Zorba errors.
117  */
118 class ZORBA_DLL_PUBLIC ZorbaErrQName :
119  public FixedQName<ZorbaErrQName,char const*>
120 {
122 public:
123  static char const NAMESPACE[];
124  static char const PREFIX[];
125 
126  /**
127  * Constructs a %ZorbaErrQName.
128  *
129  * @param localname The local-name of the error.
130  */
131  ZorbaErrQName( char const *localname ) : base_type( localname ) { }
132 
133  /**
134  * Gets the category of error this QName represents.
135  *
136  * @return Returns said kind.
137  */
139 
140  /**
141  * Gets the kind of error this QName represents.
142  *
143  * @return Returns said kind.
144  */
146 };
147 
148 ///////////////////////////////////////////////////////////////////////////////
149 
150 /**
151  * An %XQueryErrQName is-a FixedQName for standard XQuery errors.
152  */
153 class ZORBA_DLL_PUBLIC XQueryErrQName :
154  public FixedQName<XQueryErrQName,char const*>
155 {
157 public:
158  static char const NAMESPACE[];
159  static char const PREFIX[];
160 
161  /**
162  * Constructs an %XQueryErrQName.
163  *
164  * @param localname The local-name of the error.
165  */
166  XQueryErrQName( char const *localname ) : base_type( localname ) { }
167 
168  /**
169  * Gets the category of error this QName represents.
170  *
171  * @return Returns said kind.
172  */
174 
175  /**
176  * Gets the kind of error this QName represents.
177  *
178  * @return Returns said kind.
179  */
181 };
182 
183 ///////////////////////////////////////////////////////////////////////////////
184 
185 #ifdef ZORBA_WITH_JSON
186 
187 /**
188  * An %JSONiqErrQName is-a FixedQName for standard JSONiq errors.
189  */
190 class ZORBA_DLL_PUBLIC JSONiqErrQName :
191  public FixedQName<JSONiqErrQName,char const*>
192 {
193  typedef FixedQName<JSONiqErrQName,char const*> base_type;
194 public:
195  static char const NAMESPACE[];
196  static char const PREFIX[];
197 
198  /**
199  * Constructs an %JSONiqErrQName.
200  *
201  * @param localname The local-name of the error.
202  */
203  JSONiqErrQName( char const *localname ) : base_type( localname ) { }
204 
205  /**
206  * Gets the category of error this QName represents.
207  *
208  * @return Returns UNKNOWN_CATEGORY as there currently
209  * are no categories for JSONiq errors
210  */
212 
213  /**
214  * Gets the kind of error this QName represents.
215  *
216  * @return Returns said kind.
217  */
219 };
220 
221 #endif
222 
223 ///////////////////////////////////////////////////////////////////////////////
224 
225 /**
226  * An %ZorbaWarningQName is-a FixedQName for Zorba warnings.
227  */
228 class ZORBA_DLL_PUBLIC ZorbaWarningQName :
229  public FixedQName<ZorbaWarningQName,char const*>
230 {
232 public:
233  static char const NAMESPACE[];
234  static char const PREFIX[];
235 
236  /**
237  * Constructs a %ZorbaWarningQName.
238  *
239  * @param localname The local-name of the warning.
240  */
241  ZorbaWarningQName( char const *localname ) : base_type( localname ) { }
242 
243  /**
244  * Gets the category of warning this QName represents.
245  *
246  * @return Returns said kind.
247  */
249 
250  /**
251  * Gets the kind of warning this QName represents.
252  *
253  * @return Returns said kind.
254  */
256 };
257 
258 ///////////////////////////////////////////////////////////////////////////////
259 
260 } // namespace internal
261 } // namespace zorba
262 #endif /* ZORBA_INTERNAL_QNAME_H */
263 /* vim:set et sw=2 ts=2: */
A QName is the abstract base class for a QName.
Definition: diagnostic.h:33
FixedQName(char const *localname)
Constructs a FixedQName.
Definition: qname.h:62
VariableQName(serialization::Archiver &)
Definition: qname.h:107
char const * localname() const
Gets this QName's local name.
Definition: qname.h:68
kind
An diagnostic::kind is the kind of error.
Definition: diagnostic.h:269
char const * ns() const
Gets this QName's namespace URI.
Definition: qname.h:66
StringType::const_pointer c_str(StringType const &s)
Definition: ztd.h:179
An XQueryErrQName is-a FixedQName for standard XQuery errors.
Definition: qname.h:153
char const * localname() const
Gets this QName's local name.
Definition: qname.h:98
XQueryErrQName(char const *localname)
Constructs an XQueryErrQName.
Definition: qname.h:166
char const * ns() const
Gets this QName's namespace URI.
Definition: qname.h:96
A FixedQName is-an diagnostic::QName that has a fixed namespace and prefix, but a variable local-name...
Definition: qname.h:54
VariableQName(char const *ns, char const *prefix, char const *localname)
Constructs a VariableQName.
Definition: qname.h:90
ZorbaErrQName(char const *localname)
Constructs a ZorbaErrQName.
Definition: qname.h:131
A ZorbaErrQName is-a FixedQName for Zorba errors.
Definition: qname.h:118
A VariableQName is-an diagnostic::QName that has a variable namespace, prefix, and local-name...
Definition: qname.h:84
char const * prefix() const
Gets this QName's prefix.
Definition: qname.h:97
category
An diagnostic::category is the category of error.
Definition: diagnostic.h:226
void operator&(serialization::Archiver &, const Diagnostic *&)
An ZorbaWarningQName is-a FixedQName for Zorba warnings.
Definition: qname.h:228
char const * prefix() const
Gets this QName's prefix.
Definition: qname.h:67
ZorbaWarningQName(char const *localname)
Constructs a ZorbaWarningQName.
Definition: qname.h:241