qname.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2006-2008 The FLWOR Foundation.
00003  * 
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  * 
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef ZORBA_INTERNAL_QNAME_H
00018 #define ZORBA_INTERNAL_QNAME_H
00019 
00020 #include <zorba/config.h>
00021 #include <zorba/diagnostic.h>
00022 
00023 #include "ztd.h"
00024 
00025 namespace zorba {
00026 
00027 namespace internal {
00028   template<typename StringType>
00029   class ZORBA_DLL_PUBLIC VariableQName;
00030 }
00031 namespace serialization {
00032   class Archiver;
00033   template<typename StringType>
00034   void operator&( serialization::Archiver&,
00035                   internal::VariableQName<StringType>& );
00036 }
00037 
00038 namespace internal {
00039 
00040 ///////////////////////////////////////////////////////////////////////////////
00041 
00042 /**
00043  * A %FixedQName is-an diagnostic::QName that has a fixed namespace and prefix,
00044  * but a variable local-name.
00045  *
00046  * @tparam QNameTraits A class that contains static \c NAMESPACE and \c PREFIX
00047  * members.
00048  * @tparam LocalnameType The type to use to store the local-name.  Note that
00049  * this can be either a string type or <code>char const*</code>.  If the
00050  * latter, then it must be guaranteed that the pointed-to C strings will exist
00051  * for the entire lifetime of this object.
00052  */
00053 template<class QNameTraits,typename LocalnameType>
00054 class ZORBA_DLL_PUBLIC FixedQName : public zorba::diagnostic::QName {
00055 public:
00056 
00057   /**
00058    * Constructs a %FixedQName.
00059    *
00060    * @param localname The QName's local-name.
00061    */
00062   FixedQName( char const *localname ) : localname_( localname ) {
00063   }
00064 
00065   // inherited
00066   char const* ns() const { return ztd::c_str( QNameTraits::NAMESPACE ); }
00067   char const* prefix() const { return ztd::c_str( QNameTraits::PREFIX ); }
00068   char const* localname() const { return ztd::c_str( localname_ ); }
00069 
00070 private:
00071   LocalnameType localname_;
00072 };
00073 
00074 /**
00075  * A %VariableQName is-an diagnostic::QName that has a variable namespace,
00076  * prefix, and local-name.
00077  *
00078  * @tparam StringType The type to use to store the namespace, prefix, and
00079  * local-name.  Note that this can be either a string type or <code>char
00080  * const*</code>.  If the latter, then it must be guaranteed that the
00081  * pointed-to C strings will exist for the entire lifetime of this object.
00082  */
00083 template<typename StringType>
00084 class ZORBA_DLL_PUBLIC VariableQName : public zorba::diagnostic::QName {
00085 public:
00086 
00087   /**
00088    * Constructs a %VariableQName.
00089    */
00090   VariableQName( char const *ns, char const *prefix, char const *localname ) :
00091     ns_( ns ), prefix_( prefix ), localname_( localname )
00092   {
00093   }
00094 
00095   // inherited
00096   char const* ns() const { return ztd::c_str( ns_ ); }
00097   char const* prefix() const { return ztd::c_str( prefix_ ); }
00098   char const* localname() const { return ztd::c_str( localname_ ); }
00099 
00100 private:
00101   StringType ns_;
00102   StringType prefix_;
00103   StringType localname_;
00104 
00105   // for plan serialization
00106 public:
00107   VariableQName( serialization::Archiver& ) { }
00108 private:
00109   friend void serialization::operator&<>( serialization::Archiver&,
00110                                           VariableQName& );
00111 };
00112 
00113 ///////////////////////////////////////////////////////////////////////////////
00114 
00115 /**
00116  * A %ZorbaErrQName is-a FixedQName for Zorba errors.
00117  */
00118 class ZORBA_DLL_PUBLIC ZorbaErrQName :
00119   public FixedQName<ZorbaErrQName,char const*>
00120 {
00121   typedef FixedQName<ZorbaErrQName,char const*> base_type;
00122 public:
00123   static char const NAMESPACE[];
00124   static char const PREFIX[];
00125 
00126   /**
00127    * Constructs a %ZorbaErrQName.
00128    *
00129    * @param localname The local-name of the error.
00130    */
00131   ZorbaErrQName( char const *localname ) : base_type( localname ) { }
00132 
00133   /**
00134    * Gets the category of error this QName represents.
00135    *
00136    * @return Returns said kind.
00137    */
00138   zorba::diagnostic::category category() const;
00139 
00140   /**
00141    * Gets the kind of error this QName represents.
00142    *
00143    * @return Returns said kind.
00144    */
00145   zorba::diagnostic::kind kind() const;
00146 };
00147 
00148 ///////////////////////////////////////////////////////////////////////////////
00149 
00150 /**
00151  * An %XQueryErrQName is-a FixedQName for standard XQuery errors.
00152  */
00153 class ZORBA_DLL_PUBLIC XQueryErrQName :
00154   public FixedQName<XQueryErrQName,char const*>
00155 {
00156   typedef FixedQName<XQueryErrQName,char const*> base_type;
00157 public:
00158   static char const NAMESPACE[];
00159   static char const PREFIX[];
00160 
00161   /**
00162    * Constructs an %XQueryErrQName.
00163    *
00164    * @param localname The local-name of the error.
00165    */
00166   XQueryErrQName( char const *localname ) : base_type( localname ) { }
00167 
00168   /**
00169    * Gets the category of error this QName represents.
00170    *
00171    * @return Returns said kind.
00172    */
00173   zorba::diagnostic::category category() const;
00174 
00175   /**
00176    * Gets the kind of error this QName represents.
00177    *
00178    * @return Returns said kind.
00179    */
00180   zorba::diagnostic::kind kind() const;
00181 };
00182 
00183 ///////////////////////////////////////////////////////////////////////////////
00184 
00185 /**
00186  * An %ZorbaWarningQName is-a FixedQName for Zorba warnings.
00187  */
00188 class ZORBA_DLL_PUBLIC ZorbaWarningQName :
00189   public FixedQName<ZorbaWarningQName,char const*>
00190 {
00191   typedef FixedQName<ZorbaWarningQName,char const*> base_type;
00192 public:
00193   static char const NAMESPACE[];
00194   static char const PREFIX[];
00195 
00196   /**
00197    * Constructs a %ZorbaWarningQName.
00198    *
00199    * @param localname The local-name of the warning.
00200    */
00201   ZorbaWarningQName( char const *localname ) : base_type( localname ) { }
00202 
00203   /**
00204    * Gets the category of warning this QName represents.
00205    *
00206    * @return Returns said kind.
00207    */
00208   zorba::diagnostic::category category() const;
00209 
00210   /**
00211    * Gets the kind of warning this QName represents.
00212    *
00213    * @return Returns said kind.
00214    */
00215   zorba::diagnostic::kind kind() const;
00216 };
00217 
00218 ///////////////////////////////////////////////////////////////////////////////
00219 
00220 } // namespace internal
00221 } // namespace zorba
00222 #endif /* ZORBA_INTERNAL_QNAME_H */
00223 /* vim:set et sw=2 ts=2: */
blog comments powered by Disqus