system_diagnostic.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_SYSTEM_DIAGNOSTIC_H
00018 #define ZORBA_INTERNAL_SYSTEM_DIAGNOSTIC_H
00019 
00020 #include <map>
00021 
00022 #include <zorba/diagnostic.h>
00023 
00024 #include "ztd.h"
00025 
00026 namespace zorba {
00027 namespace internal {
00028 
00029 ///////////////////////////////////////////////////////////////////////////////
00030 
00031 class ZORBA_DLL_PUBLIC SystemDiagnosticBase : public Diagnostic {
00032 public:
00033   /**
00034    * Given a diagnostic's local-name, finds its corresponding %Diagnostic
00035    * object.
00036    *
00037    * @param localname The local-name.
00038    * @return Returns the corresponding %Diagnostic object or \c NULL if not
00039    * found.
00040    */
00041   static Diagnostic const* find( char const *localname ) {
00042     map_type const &m = get_map();
00043     map_type::const_iterator const i = m.find( localname );
00044     return i != m.end() ? i->second : 0;
00045   }
00046 
00047 private:
00048   typedef std::map<char const*,Diagnostic const*,ztd::less<char const*> >
00049           map_type;
00050 
00051   static map_type& get_map();
00052 
00053   SystemDiagnosticBase( char const *localname ) {
00054     get_map()[ localname ] = this;
00055   }
00056 
00057   // Only a SystemDiagnostic can derive from SystemDiagnosticBase.
00058   template<class QNameType> friend class SystemDiagnostic;
00059 };
00060 
00061 /**
00062  * \internal
00063  * A %SystemDiagnostic is-a Diagnostic for built-in diagnostics.
00064  *
00065  * @tparam QNameType The QName type.
00066  */
00067 template<class QNameType>
00068 class ZORBA_DLL_PUBLIC SystemDiagnostic : public SystemDiagnosticBase {
00069 public:
00070 
00071   /**
00072    * Constructs a %SystemDiagnostic.
00073    *
00074    * @param localname The local-name of the diagnostic.
00075    */
00076   SystemDiagnostic( char const *localname ) :
00077     SystemDiagnosticBase( localname ), qname_( localname )
00078   {
00079   }
00080 
00081   // inherited
00082   zorba::diagnostic::category category() const { return qname_.category(); }
00083   zorba::diagnostic::kind kind() const { return qname_.kind(); }
00084   zorba::diagnostic::QName const& qname() const { return qname_; }
00085 
00086 protected:
00087   // inherited
00088   Diagnostic const* clone() const { return this; }
00089   void destroy() const { /* do nothing */ }
00090 
00091 private:
00092   QNameType qname_;
00093 };
00094 
00095 ///////////////////////////////////////////////////////////////////////////////
00096 
00097 } // namespace internal
00098 } // namespace zorba
00099 #endif /* ZORBA_INTERNAL_SYSTEM_DIAGNOSTIC_H */
00100 /* vim:set et sw=2 ts=2: */
blog comments powered by Disqus