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

pantheios/inserters/exception.hpp

Go to the documentation of this file.
00001 /* /////////////////////////////////////////////////////////////////////////
00002  * File:        pantheios/inserters/exception.hpp
00003  *
00004  * Purpose:     String inserter for std::exception-derived types.
00005  *
00006  * Created:     22nd March 2010
00007  * Updated:     26th November 2010
00008  *
00009  * Home:        http://www.pantheios.org/
00010  *
00011  * Copyright (c) 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 name(s) of Matthew Wilson and Synesis Software nor the
00024  *   names of any contributors may be used to endorse or promote products
00025  *   derived 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 PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_EXCEPTION
00048 #define PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_EXCEPTION
00049 
00050 /* /////////////////////////////////////////////////////////////////////////
00051  * Version information
00052  */
00053 
00054 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00055 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_EXCEPTION_MAJOR      1
00056 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_EXCEPTION_MINOR      0
00057 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_EXCEPTION_REVISION   1
00058 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_EXCEPTION_EDIT       2
00059 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
00060 
00061 /* /////////////////////////////////////////////////////////////////////////
00062  * Includes
00063  */
00064 
00065 #ifndef PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS
00066 # include <pantheios/pantheios.h>
00067 #endif /* !PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS */
00068 
00069 #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_STRING_H_FWD
00070 # include <stlsoft/shims/access/string/fwd.h>
00071 #endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_STRING_H_FWD */
00072 
00073 #include <exception>
00074 
00075 /* /////////////////////////////////////////////////////////////////////////
00076  * Namespace
00077  */
00078 
00079 #if !defined(PANTHEIOS_NO_NAMESPACE)
00080 namespace pantheios
00081 {
00082 #endif /* !PANTHEIOS_NO_NAMESPACE */
00083 
00084 /* /////////////////////////////////////////////////////////////////////////
00085  * Typedefs
00086  */
00087 
00088 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00089 
00090 # if !defined(PANTHEIOS_NO_NAMESPACE)
00091 namespace inserters
00092 {
00093 # endif /* !PANTHEIOS_NO_NAMESPACE */
00094 
00095 class exception_inserter
00096 {
00097 public:
00098     typedef exception_inserter  class_type;
00099 
00100 public:
00101     explicit exception_inserter(std::exception const& x);
00102 private:
00103 #if !defined(STLSOFT_COMPILER_IS_GCC)
00104 //    exception_inserter(class_type const&);
00105 #endif /* compiler */
00106     class_type& operator =(class_type const&);
00107 
00108 public:
00109     pan_char_t const*   c_str() const;
00110     pan_char_t const*   data() const;
00111     size_t              length() const;
00112 
00113 private:
00114     void construct_() const;
00115     void construct_();
00116 
00117 private:
00118     pan_char_t*             m_value;
00119     size_t                  m_len;
00120     std::exception const&   m_x;
00121 };
00122 
00123 # if !defined(PANTHEIOS_NO_NAMESPACE)
00124 } /* namespace inserters */
00125 # endif /* !PANTHEIOS_NO_NAMESPACE */
00126 
00127 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
00128 
00129 /* /////////////////////////////////////////////////////////////////////////
00130  * Typedefs
00131  */
00132 
00137 #ifdef PANTHEIOS_USE_WIDE_STRINGS
00138 
00139 inline
00140 #  if !defined(PANTHEIOS_NO_NAMESPACE)
00141 inserters::
00142 #  endif /* !PANTHEIOS_NO_NAMESPACE */
00143 exception_inserter exception(
00144     std::exception const& x
00145 )
00146 {
00147     return 
00148 #  if !defined(PANTHEIOS_NO_NAMESPACE)
00149       inserters::
00150 #  endif /* !PANTHEIOS_NO_NAMESPACE */
00151         exception_inserter(x);
00152 }
00153 
00154 #else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00155 
00156 inline std::exception const& exception(
00157     std::exception const& x
00158 )
00159 {
00160     return x;
00161 }
00162 
00163 #endif /* PANTHEIOS_USE_WIDE_STRINGS */
00164 
00165 /* /////////////////////////////////////////////////////////////////////////
00166  * String Access Shims
00167  */
00168 
00169 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00170 
00171 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00172 
00173 #  if !defined(PANTHEIOS_NO_NAMESPACE)
00174 namespace shims
00175 {
00176     using inserters::exception_inserter;
00177 #  endif /* !PANTHEIOS_NO_NAMESPACE */
00178 
00180 inline wchar_t const* c_str_data_w(exception_inserter const& i)
00181 {
00182     return i.data();
00183 }
00185 inline pan_char_t const* c_str_data(exception_inserter const& i)
00186 {
00187     return i.data();
00188 }
00189 
00191 inline size_t c_str_len_w(exception_inserter const& i)
00192 {
00193     return i.length();
00194 }
00196 inline size_t c_str_len(exception_inserter const& i)
00197 {
00198     return i.length();
00199 }
00200 
00202 inline wchar_t const* c_str_ptr_w(exception_inserter const& i)
00203 {
00204     return i.c_str();
00205 }
00207 inline pan_char_t const* c_str_ptr(exception_inserter const& i)
00208 {
00209     return i.c_str();
00210 }
00211 
00212 #  if !defined(PANTHEIOS_NO_NAMESPACE)
00213 } /* namespace shims */
00214 
00215 #   if defined(STLSOFT_COMPILER_IS_GCC)
00216     /* GCC does not seem to correctly handle the phases of
00217      * processing of C++ templates, so we need to 'use' the
00218      * shims into the same namespace as the inserter class
00219      * in order that ADL can suffice instead.
00220      */
00221     using ::pantheios::shims::c_str_data_w;
00222     using ::pantheios::shims::c_str_len_w;
00223     using ::pantheios::shims::c_str_ptr_w;
00224     using ::pantheios::shims::c_str_data;
00225     using ::pantheios::shims::c_str_len;
00226     using ::pantheios::shims::c_str_ptr;
00227 #   endif /* compiler */
00228 
00229 #  endif /* !PANTHEIOS_NO_NAMESPACE */
00230 
00231 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00232 
00233 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
00234 
00235 /* /////////////////////////////////////////////////////////////////////////
00236  * Namespace
00237  */
00238 
00239 #if !defined(PANTHEIOS_NO_NAMESPACE)
00240 } /* namespace pantheios */
00241 
00242 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00243 
00244 namespace stlsoft
00245 {
00246     // 'Export' the string access shims into the STLSoft namespace
00247     //
00248     // c_str_ptr(_w) is not necessary for version 1.0 of Pantheios, but it's
00249     // defined and exported in order to allow for the case where someone
00250     // may find a legitimate use for the conversion classes additional to
00251     // the type-tunneling of the Pantheios API.
00252 
00253     using ::pantheios::shims::c_str_data_w;
00254     using ::pantheios::shims::c_str_len_w;
00255     using ::pantheios::shims::c_str_ptr_w;
00256     using ::pantheios::shims::c_str_data;
00257     using ::pantheios::shims::c_str_len;
00258     using ::pantheios::shims::c_str_ptr;
00259 }
00260 
00261 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00262 
00263 #endif /* !PANTHEIOS_NO_NAMESPACE */
00264 
00265 /* /////////////////////////////////////////////////////////////////////////
00266  * Inclusion
00267  */
00268 
00269 #ifdef STLSOFT_PPF_pragma_once_SUPPORT
00270 # pragma once
00271 #endif /* STLSOFT_PPF_pragma_once_SUPPORT */
00272 
00273 /* ////////////////////////////////////////////////////////////////////// */
00274 
00275 #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_EXCEPTION */
00276 
00277 /* ///////////////////////////// end of file //////////////////////////// */

pantheios Library documentation © Matthew Wilson & Synesis Software, 2006-2011 SourceForge.net Logo