Synesis Software STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ...

fastformat/exceptions.hpp

Go to the documentation of this file.
00001 /* /////////////////////////////////////////////////////////////////////////
00002  * File:        fastformat/exceptions.hpp
00003  *
00004  * Purpose:     FastFormat API exception classes.
00005  *
00006  * Created:     23rd October 2008
00007  * Updated:     30th April 2010
00008  *
00009  * Home:        http://www.fastformat.org/
00010  *
00011  * Copyright (c) 2008-2010, Matthew Wilson and Synesis Software
00012  * All rights reserved.
00013  *
00014  * Redistribution and use in source and binary forms, with or without
00015  * modification, are permitted provided that the following conditions are
00016  * met:
00017  *
00018  * - Redistributions of source code must retain the above copyright notice,
00019  *   this list of conditions and the following disclaimer.
00020  * - Redistributions in binary form must reproduce the above copyright
00021  *   notice, this list of conditions and the following disclaimer in the
00022  *   documentation and/or other materials provided with the distribution.
00023  * - Neither the names of Matthew Wilson and Synesis Software nor the names
00024  *   of any contributors may be used to endorse or promote products derived
00025  *   from this software without specific prior written permission.
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00028  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
00029  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00030  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
00031  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00032  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00033  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00034  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00035  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00036  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00037  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038  *
00039  * ////////////////////////////////////////////////////////////////////// */
00040 
00041 
00047 #ifndef FASTFORMAT_INCL_FASTFORMAT_HPP_EXCEPTIONS
00048 #define FASTFORMAT_INCL_FASTFORMAT_HPP_EXCEPTIONS
00049 
00050 /* /////////////////////////////////////////////////////////////////////////
00051  * Version information
00052  */
00053 
00054 #ifndef FASTFORMAT_DOCUMENTATION_SKIP_SECTION
00055 # define FASTFORMAT_VER_FASTFORMAT_HPP_EXCEPTIONS_MAJOR     1
00056 # define FASTFORMAT_VER_FASTFORMAT_HPP_EXCEPTIONS_MINOR     1
00057 # define FASTFORMAT_VER_FASTFORMAT_HPP_EXCEPTIONS_REVISION  2
00058 # define FASTFORMAT_VER_FASTFORMAT_HPP_EXCEPTIONS_EDIT      8
00059 #endif /* !FASTFORMAT_DOCUMENTATION_SKIP_SECTION */
00060 
00061 /* /////////////////////////////////////////////////////////////////////////
00062  * Language
00063  */
00064 
00065 #ifndef __cplusplus
00066 # error This file can only be included in C++ compilation units
00067 #endif /* !__cplusplus */
00068 
00069 /* /////////////////////////////////////////////////////////////////////////
00070  * Includes
00071  */
00072 
00073 #include <fastformat/fastformat.h>
00074 #include <fastformat/quality/contract.h>
00075 #include <fastformat/quality/cover.h>
00076 
00077 #include <stlsoft/stlsoft.h>
00078 
00079 #include <exception>
00080 #include <stdexcept>
00081 #include <string>
00082 
00083 /* /////////////////////////////////////////////////////////////////////////
00084  * Namespace
00085  */
00086 
00087 #if !defined(FASTFORMAT_NO_NAMESPACE)
00088 namespace fastformat
00089 {
00090 #endif /* !FASTFORMAT_NO_NAMESPACE */
00091 
00092 /* /////////////////////////////////////////////////////////////////////////
00093  * Classes
00094  */
00095 
00102 class fastformat_exception
00103     : public std::runtime_error
00104 {
00105 public: // Member Types
00107     typedef std::runtime_error              parent_class_type;
00109     typedef fastformat_exception            class_type;
00111     typedef std::string                     multibyte_string_type;
00113     typedef std::basic_string<ff_char_t>    string_type;
00114 
00115 public: // Construction
00120     explicit fastformat_exception(char const* message)
00121         : parent_class_type(validate_message_(message))
00122     {
00123         FASTFORMAT_COVER_MARK_ENTRY();
00124     }
00125     virtual ~fastformat_exception() stlsoft_throw_0() = 0;
00126 
00127 private:
00129     class_type& operator =(class_type const&);
00130 
00131 protected: // Implementation
00132 #ifndef FASTFORMAT_DOCUMENTATION_SKIP_SECTION
00133     static ff_char_t const* validate_format_(ff_char_t const* format)
00134     {
00135         FASTFORMAT_CONTRACT_ENFORCE_PRECONDITION_PARAMS_APPL_LAYER(NULL != format, "format parameter may not be null");
00136 
00137         FASTFORMAT_COVER_MARK_ENTRY();
00138 
00139         return format;
00140     }
00141     static ff_char_t const* validate_format_(ff_char_t const* format, size_t cchFormat)
00142     {
00143         FASTFORMAT_CONTRACT_ENFORCE_PRECONDITION_PARAMS_APPL_LAYER((NULL != format || 0 == cchFormat), "format string pointer may not be null unless length is zero");
00144         STLSOFT_SUPPRESS_UNUSED(cchFormat);
00145 
00146         FASTFORMAT_COVER_MARK_ENTRY();
00147 
00148         return format;
00149     }
00150     static char const* validate_message_(char const* message)
00151     {
00152         FASTFORMAT_CONTRACT_ENFORCE_PRECONDITION_PARAMS_APPL_LAYER(NULL != message, "message parameter may not be null");
00153 
00154         FASTFORMAT_COVER_MARK_ENTRY();
00155 
00156         return message;
00157     }
00158 #endif /* !FASTFORMAT_DOCUMENTATION_SKIP_SECTION */
00159 };
00160 
00165     class format_parsing_exception
00166         : public fastformat_exception
00167     {
00168     public: // Member Types
00170         typedef fastformat_exception                        parent_class_type;
00172         typedef format_parsing_exception                    class_type;
00174         typedef parent_class_type::multibyte_string_type    message_string_type;
00176         typedef parent_class_type::string_type              string_type;
00177 
00178     public: // Construction
00185         format_parsing_exception(char const* message, ff_parse_code_t code, ff_char_t const* format)
00186             : parent_class_type(validate_message_(message))
00187             , code(code)
00188             , format(validate_format_(format))
00189         {
00190             FASTFORMAT_COVER_MARK_ENTRY();
00191         }
00199         format_parsing_exception(char const* message, ff_parse_code_t code, ff_char_t const* format, size_t cchFormat)
00200             : parent_class_type(validate_message_(message))
00201             , code(code)
00202             , format(validate_format_(format, cchFormat), cchFormat)
00203         {
00204             FASTFORMAT_COVER_MARK_ENTRY();
00205         }
00206         virtual ~format_parsing_exception() stlsoft_throw_0() = 0;
00207     private:
00209         class_type& operator =(class_type const&);
00210 
00211     public: // Attributes
00213         const ff_parse_code_t   code;
00215         const string_type       format;
00216     };
00217 
00220         class illformed_format_exception
00221             : public format_parsing_exception
00222         {
00223         public: // Member Types
00225             typedef format_parsing_exception        parent_class_type;
00227             typedef illformed_format_exception      class_type;
00229             typedef parent_class_type::string_type  string_type;
00230 
00231         public: // Construction
00238             illformed_format_exception(char const* message, ff_parse_code_t code, ff_char_t const* format)
00239                 : parent_class_type(message, code, format)
00240             {
00241                 FASTFORMAT_COVER_MARK_ENTRY();
00242             }
00250             illformed_format_exception(char const* message, ff_parse_code_t code, ff_char_t const* format, size_t cchFormat)
00251                 : parent_class_type(message, code, format, cchFormat)
00252             {
00253                 FASTFORMAT_COVER_MARK_ENTRY();
00254             }
00255         private:
00257             class_type& operator =(class_type const&);
00258         };
00259 
00270     class mismatched_replacements_exception
00271         : public fastformat_exception
00272     {
00273     public: // Member Types
00275         typedef fastformat_exception                parent_class_type;
00277         typedef mismatched_replacements_exception   class_type;
00279         typedef parent_class_type::string_type      string_type;
00280 
00281     public: // Construction
00289         explicit mismatched_replacements_exception(char const* message, ff_replacement_code_t code, int numberOfReplacements, int firstMismatchedReplacementIndex)
00290             : parent_class_type(validate_message_(message))
00291             , code(code)
00292             , numberOfReplacements(numberOfReplacements)
00293             , firstMismatchedReplacementIndex(firstMismatchedReplacementIndex)
00294         {
00295             FASTFORMAT_COVER_MARK_ENTRY();
00296         }
00297         virtual ~mismatched_replacements_exception() stlsoft_throw_0() = 0;
00298     private:
00300         class_type& operator =(class_type const&);
00301 
00302     public: // Attributes
00304         const ff_replacement_code_t     code;
00306         const int                       numberOfReplacements;
00308         const int                       firstMismatchedReplacementIndex;
00309     };
00310 
00317         class missing_argument_exception
00318             : public mismatched_replacements_exception
00319         {
00320         public: // Member Types
00322             typedef mismatched_replacements_exception   parent_class_type;
00324             typedef missing_argument_exception          class_type;
00326             typedef parent_class_type::string_type      string_type;
00327 
00328         public: // Construction
00336             missing_argument_exception(char const* message, ff_replacement_code_t code, int numberOfReplacements, int firstMismatchedReplacementIndex)
00337                 : parent_class_type(validate_message_(message), code, numberOfReplacements, firstMismatchedReplacementIndex)
00338             {
00339                 FASTFORMAT_COVER_MARK_ENTRY();
00340             }
00341         private:
00343             class_type& operator =(class_type const&);
00344         };
00345 
00355         class unreferenced_argument_exception
00356             : public mismatched_replacements_exception
00357         {
00358         public: // Member Types
00360             typedef mismatched_replacements_exception   parent_class_type;
00362             typedef unreferenced_argument_exception     class_type;
00364             typedef parent_class_type::string_type      string_type;
00365 
00366         public: // Construction
00374             unreferenced_argument_exception(char const* message, ff_replacement_code_t code, int numberOfReplacements, int firstMismatchedReplacementIndex)
00375                 : parent_class_type(validate_message_(message), code, numberOfReplacements, firstMismatchedReplacementIndex)
00376             {
00377                 FASTFORMAT_COVER_MARK_ENTRY();
00378             }
00379         private:
00381             class_type& operator =(class_type const&);
00382         };
00383 
00394     class bundle_exception
00395         : public fastformat_exception
00396     {
00397     public: // Member Types
00399         typedef fastformat_exception                parent_class_type;
00401         typedef bundle_exception                    class_type;
00403         typedef parent_class_type::string_type      string_type;
00404 
00405     public: // Construction
00410         explicit bundle_exception(char const* message)
00411             : parent_class_type(validate_message_(message))
00412         {
00413             FASTFORMAT_COVER_MARK_ENTRY();
00414         }
00415         virtual ~bundle_exception() stlsoft_throw_0() = 0;
00416     private:
00418         class_type& operator =(class_type const&);
00419     };
00420 
00421 /* /////////////////////////////////////////////////////////////////////////
00422  * Implementation
00423  */
00424 
00425 #ifndef FASTFORMAT_DOCUMENTATION_SKIP_SECTION
00426 
00427 inline /* virtual */ fastformat_exception::~fastformat_exception() stlsoft_throw_0() /* = 0 */
00428 {}
00429 
00430 inline /* virtual */ format_parsing_exception::~format_parsing_exception() stlsoft_throw_0() /* = 0 */
00431 {}
00432 
00433 inline /* virtual */ mismatched_replacements_exception::~mismatched_replacements_exception() stlsoft_throw_0() /* = 0 */
00434 {}
00435 
00436 inline /* virtual */ bundle_exception::~bundle_exception() stlsoft_throw_0() /* = 0 */
00437 {}
00438 
00439 #endif /* !FASTFORMAT_DOCUMENTATION_SKIP_SECTION */
00440 
00441 /* /////////////////////////////////////////////////////////////////////////
00442  * Namespace
00443  */
00444 
00445 #if !defined(FASTFORMAT_NO_NAMESPACE)
00446 } /* namespace fastformat */
00447 #endif /* !FASTFORMAT_NO_NAMESPACE */
00448 
00449 /* /////////////////////////////////////////////////////////////////////////
00450  * Inclusion
00451  */
00452 
00453 #ifdef STLSOFT_PPF_pragma_once_SUPPORT
00454 # pragma once
00455 #endif /* STLSOFT_PPF_pragma_once_SUPPORT */
00456 
00457 /* ////////////////////////////////////////////////////////////////////// */
00458 
00459 #endif /* FASTFORMAT_INCL_FASTFORMAT_HPP_EXCEPTIONS */
00460 
00461 /* ///////////////////////////// end of file //////////////////////////// */

FastFormat Library documentation © Matthew Wilson, 2006-2009 SourceForge.net Logo