ximol/error.hpp

Go to the documentation of this file.
00001 /*****************************************************************************\
00002  *                                                                           *
00003  * library XiMoL                                                             *
00004  * Copyright (C) 2002, 2003, 2004 Florent Tournois                           *
00005  *                                                                           *
00006  * This library is free software; you can redistribute it and/or             *
00007  * modify it under the terms of the GNU Lesser General Public                *
00008  * License as published by the Free Software Foundation; either              *
00009  * version 2.1 of the License, or (at your option) any later version.        *
00010  *                                                                           *
00011  * This library is distributed in the hope that it will be useful,           *
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00014  * Lesser General Public License for more details.                           *
00015  *                                                                           *
00016  * You should have received a copy of the GNU Lesser General Public          *
00017  * License along with this library; if not, write to the Free Software       *
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA   *
00019  *                                                                           *
00020 \*****************************************************************************/
00021 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00022 /** \file 
00023         \brief Define the main error class.
00024         @ingroup exceptions
00025 
00026         \author Tournois Florent
00027         \version 1.0
00028 
00029     $Id: error.hpp,v 1.15 2004/03/04 18:45:29 tournois Exp $
00030     $Log: error.hpp,v $
00031     Revision 1.15  2004/03/04 18:45:29  tournois
00032     Compatibility with gcc.
00033 
00034     Revision 1.14  2004/03/03 22:05:30  tournois
00035     Add a short roadmap.
00036     Add BOOST_NO_STD_WSTRING for gcc.
00037 
00038     Revision 1.13  2004/02/22 10:27:32  tournois
00039     Add some doc.
00040 
00041     Revision 1.12  2004/02/22 09:54:19  tournois
00042     Change years on the copyright.
00043 
00044     Revision 1.11  2004/01/29 20:52:35  tournois
00045     doc and tutorial.
00046 
00047     Revision 1.10  2004/01/27 21:49:51  tournois
00048     Add docs and tutorial.
00049 
00050     Revision 1.9  2003/11/16 13:25:25  tournois
00051     Change the error to use wide string.
00052     Change the translation to use wide string.
00053 
00054     Revision 1.8  2003/11/16 11:03:23  tournois
00055     no message
00056 
00057     Revision 1.7  2003/11/15 19:06:39  tournois
00058     no message
00059 
00060     Revision 1.6  2003/11/02 19:23:01  tournois
00061     Go to the boost coding standard.
00062     Change all name to lower case.
00063 
00064     Revision 1.5  2003/10/25 13:53:39  hfp
00065     review and separation
00066 
00067     Revision 1.4  2003/10/08 10:20:06  hfp
00068     Enum openmode is already qualified by class-scope (implicit).
00069 
00070     Revision 1.3  2003/09/24 08:28:17  tournois
00071     Create the namespace Encoders, Parser, Xml
00072     Change the library organization.
00073     add VC7.1 project for this organization.
00074 
00075   */
00076 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00077 #ifndef _XIMOL_ERROR_H_
00078 #define _XIMOL_ERROR_H_
00079 
00080 #include <ximol/namespace_defs.hpp>
00081 #include <ximol/export_defs.hpp>
00082 #include <ximol/typedefs.hpp>
00083 #include <exception>
00084 #include <sstream>
00085 
00086 //-----------------------------------------------------------------------------
00087 /** Macro to throw the error.
00088   * @ingroup exceptions
00089   * This macro create the exception, and you could put to
00090   *     some additional information.
00091   *     
00092   *      \code
00093   *      XIMOL_THROW << L"error description" 
00094   *                  << XIMOL_AS_ERROR;
00095   *      \endcode
00096   *
00097   *     @see error
00098   *     @see XIMOL_AS_ERROR 
00099   */
00100 //-----------------------------------------------------------------------------
00101 #define XIMOL_THROW { XIMOL_NAMESPACE_PATH::error err; err 
00102 
00103 //-----------------------------------------------------------------------------
00104 /** Macro to precise the location.
00105   * @ingroup exceptions
00106   * This macro return a string with the position in the code.
00107   *
00108   */
00109 //-----------------------------------------------------------------------------
00110 #define XIMOL_HERE (::std::ostringstream()<<"(file "<<__FILE__<<",line "<<__LINE__<<")").str() 
00111 
00112 //-----------------------------------------------------------------------------
00113 /** Macro to throw the error.
00114   * @ingroup exceptions
00115   *  This macro throw effectively the exception.
00116   *
00117   *      \code
00118   *      XIMOL_THROW << L"error description" 
00119   *                  << XIMOL_AS_ERROR;
00120   *      \endcode
00121   *
00122   *      @see error
00123   *      @see XIMOL_AS_ERROR 
00124   */
00125 //-----------------------------------------------------------------------------
00126 #define XIMOL_AS_ERROR  ""; throw err; };
00127 
00128 
00129 XIMOL_BEGIN_NAMESPACE
00130 
00131 //=============================================================================
00132 /** An implementation of a simple error.
00133  *  @ingroup exceptions
00134  *  this class is streamable and have two intersting function
00135  *  \code
00136  *        const char* what() const throw();
00137  *    const ::std::wstring & message() const throw();
00138  *  \endcode
00139  */
00140 //=============================================================================
00141 class XIMOL_EXPORT error 
00142         : public ::std::wostringstream
00143         , public ::std::exception
00144 {
00145 public: // nested types
00146         typedef ::std::wostringstream stream_type;
00147         typedef ::std::wstring        string_type;
00148    
00149 public: // constructor(s) & destructor
00150 
00151     ///@name constructor(s) & destructor
00152     //@{
00153         error();
00154         explicit error(const string_type& str);
00155         error(const error& err);
00156         ~error() throw();
00157     //@}
00158             
00159 public: // methods
00160         /// The most important function (return the error message).
00161         const char* what() const throw();
00162 
00163     /// Get the error message.
00164     const string_type & message() const throw();
00165 
00166 private:
00167     mutable ::std::string buffer_;
00168     mutable string_type wbuffer_;
00169 }; // end of the class error
00170 
00171 XIMOL_END_NAMESPACE
00172 
00173 #endif // #ifndef _XIMOL_ERROR_H_


Donate to the XiMoL project SourceForge.net Logo If you have any questions about XiMoL, you could write to tournois@users.sourceforge.net.