system_diagnostic.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_SYSTEM_DIAGNOSTIC_H
18 #define ZORBA_INTERNAL_SYSTEM_DIAGNOSTIC_H
19 
20 #include <map>
21 
22 #include <zorba/diagnostic.h>
23 
24 #include "ztd.h"
25 
26 namespace zorba {
27 namespace internal {
28 
29 ///////////////////////////////////////////////////////////////////////////////
30 
31 class ZORBA_DLL_PUBLIC SystemDiagnosticBase : public Diagnostic {
32 public:
33  /**
34  * Given a diagnostic's local-name, finds its corresponding %Diagnostic
35  * object.
36  *
37  * @param localname The local-name.
38  * @return Returns the corresponding %Diagnostic object or \c NULL if not
39  * found.
40  */
41  static Diagnostic const* find( char const *localname ) {
42  map_type const &m = get_map();
43  map_type::const_iterator const i = m.find( localname );
44  return i != m.end() ? i->second : 0;
45  }
46 
47 private:
48  typedef std::map<char const*,Diagnostic const*,ztd::less<char const*> >
49  map_type;
50 
51  static map_type& get_map();
52 
53  SystemDiagnosticBase( char const *localname ) {
54  get_map()[ localname ] = this;
55  }
56 
57  // Only a SystemDiagnostic can derive from SystemDiagnosticBase.
58  template<class QNameType> friend class SystemDiagnostic;
59 };
60 
61 /**
62  * \internal
63  * A %SystemDiagnostic is-a Diagnostic for built-in diagnostics.
64  *
65  * @tparam QNameType The QName type.
66  */
67 template<class QNameType>
68 class ZORBA_DLL_PUBLIC SystemDiagnostic : public SystemDiagnosticBase {
69 public:
70 
71  /**
72  * Constructs a %SystemDiagnostic.
73  *
74  * @param localname The local-name of the diagnostic.
75  */
76  SystemDiagnostic( char const *localname ) :
77  SystemDiagnosticBase( localname ), qname_( localname )
78  {
79  }
80 
81  // inherited
82  zorba::diagnostic::category category() const { return qname_.category(); }
83  zorba::diagnostic::kind kind() const { return qname_.kind(); }
84  zorba::diagnostic::QName const& qname() const { return qname_; }
85 
86 protected:
87  // inherited
88  Diagnostic const* clone() const { return this; }
89  void destroy() const { /* do nothing */ }
90 
91 private:
92  QNameType qname_;
93 };
94 
95 ///////////////////////////////////////////////////////////////////////////////
96 
97 } // namespace internal
98 } // namespace zorba
99 #endif /* ZORBA_INTERNAL_SYSTEM_DIAGNOSTIC_H */
100 /* vim:set et sw=2 ts=2: */
A QName is the abstract base class for a QName.
Definition: diagnostic.h:33
static Diagnostic const * find(char const *localname)
Given a diagnostic's local-name, finds its corresponding Diagnostic object.
kind
An diagnostic::kind is the kind of error.
Definition: diagnostic.h:269
Diagnostic const * clone() const
SystemDiagnostic(char const *localname)
Constructs a SystemDiagnostic.
void destroy() const
Destroys a Diagnostic.
A Diagnostic is the base class for all Zorba diagnostics (errors and warnings).
Definition: diagnostic.h:325
zorba::diagnostic::QName const & qname() const
Gets the QName for this diagnostic.
zorba::diagnostic::category category() const
Gets the category of this diagnostic.
zorba::diagnostic::kind kind() const
Gets the kind of this diagnostic.
category
An diagnostic::category is the category of error.
Definition: diagnostic.h:226