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 #pragma once 18 #ifndef ZORBA_XQUERY_DIAGNOSTICS_H 19 #define ZORBA_XQUERY_DIAGNOSTICS_H 20 21 #include <vector> 22 23 #include <zorba/config.h> 24 #include <zorba/internal/unique_ptr.h> 25 26 // TODO: this #include is temporary 27 #include <zorba/diagnostic_list.h> 28 29 #include "util/error_util.h" 30 31 #include "diagnostic.h" 32 #include "dict.h" 33 #include "xquery_exception.h" 34 #include "xquery_warning.h" 35 #include "zorba_exception.h" 36 37 namespace zorba { 38 39 /////////////////////////////////////////////////////////////////////////////// 40 41 /** 42 * An %XQueryDiagnostics is used to collect errors and warnings that can not be 43 * issued immediately and must be deferred until some later time. 44 */ 45 class ZORBA_DLL_PUBLIC XQueryDiagnostics { 46 public: 47 typedef std::vector<ZorbaException const*> errors_type; 48 typedef std::vector<XQueryWarning const*> warnings_type; 49 50 XQueryDiagnostics(); 51 ~XQueryDiagnostics(); 52 53 ////////// Errors /////////////////////////////////////////////////////////// 54 55 /** 56 * Adds an exception to the list of exceptions. 57 * 58 * @param exception The exception to add. The %XQueryDiagnostics takes 59 * ownership of the exception. 60 */ add_error(ZorbaException const * exception)61 void add_error( ZorbaException const *exception ) { 62 errors_.push_back( exception ); 63 } 64 65 /** 66 * Adds an exception to the list of exceptions. 67 * 68 * @param exception The exception to add. The %XQueryDiagnostics takes 69 * ownership of the exception. 70 */ add_error(std::unique_ptr<ZorbaException> exception)71 void add_error( std::unique_ptr<ZorbaException> exception ) { 72 add_error( exception.release() ); 73 } 74 75 /** 76 * Adds an exception to the list of exceptions. 77 * 78 * @param exception The exception to add. The exception is cloned. 79 */ add_error(ZorbaException const & exception)80 void add_error( ZorbaException const &exception ) { 81 add_error( clone( exception ) ); 82 } 83 84 /** 85 * Gets the list of exceptions. 86 * 87 * @return Returns said exceptions. 88 */ errors()89 errors_type const& errors() const { 90 return errors_; 91 } 92 93 ////////// Warnings ///////////////////////////////////////////////////////// 94 95 /** 96 * Adds a warning to the list of warnings. 97 * 98 * @param exception The exception to add. The %XQueryDiagnostics takes 99 * ownership of the exception. 100 */ add_warning(XQueryWarning const * warning)101 void add_warning( XQueryWarning const *warning ) { 102 warnings_.push_back( warning ); 103 } 104 105 /** 106 * Gets the list of warnings. 107 * 108 * @return Returns said warnings. 109 */ warnings()110 warnings_type const& warnings() const { 111 return warnings_; 112 } 113 114 /** 115 * Clears the list of warnings. This function should be called after the 116 * warnings have been given to the diagnostics handler so that they are not 117 * reported multiple times. 118 */ 119 void clear_warnings(); 120 121 private: 122 errors_type errors_; 123 warnings_type warnings_; 124 }; 125 126 ////////// TEMPORARY TRANSITION MACROS: THESE WILL BE REMOVED ///////////////// 127 128 #define ZORBA_ERROR_DESC_OSS(LOCALNAME,MSG) \ 129 do { \ 130 std::ostringstream oss; \ 131 oss << MSG; \ 132 throw XQUERY_EXCEPTION( LOCALNAME, ERROR_PARAMS( oss.str() ) ); \ 133 } while (0) 134 135 } // namespace zorba 136 137 #endif /* ZORBA_XQUERY_DIAGNOSTICS_H */ 138 /* vim:set et sw=2 ts=2: */ 139