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

pantheios/inserters/b64.hpp

Go to the documentation of this file.
00001 /* /////////////////////////////////////////////////////////////////////////
00002  * File:        pantheios/inserters/b64.hpp
00003  *
00004  * Purpose:     String inserter for binary regions in Base-64.
00005  *
00006  * Created:     31st July 2006
00007  * Updated:     23rd July 2010
00008  *
00009  * Home:        http://www.pantheios.org/
00010  *
00011  * Copyright (c) 2006-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 
00049 #ifndef PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_B64
00050 #define PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_B64
00051 
00052 /* /////////////////////////////////////////////////////////////////////////
00053  * Version information
00054  */
00055 
00056 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00057 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_B64_MAJOR    1
00058 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_B64_MINOR    4
00059 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_B64_REVISION 3
00060 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_B64_EDIT     23
00061 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
00062 
00063 /* /////////////////////////////////////////////////////////////////////////
00064  * Includes
00065  */
00066 
00067 #ifndef PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS
00068 # include <pantheios/pantheios.h>
00069 #endif /* !PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS */
00070 #ifndef PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_FMT
00071 # include <pantheios/inserters/fmt.hpp>
00072 #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_FMT */
00073 
00074 
00075 /* b64 Header Files */
00076 #ifdef PANTHEIOS_NO_NAMESPACE
00077 
00078  /* If the pantheios namespace is suppressed, the pantheios::b64 type will
00079   * be placed into the global namespace. This will clash with the b64
00080   * namespace.
00081   *
00082   * To obviate this problem, we define the b64 namespace to b64_api via the
00083   * b64 custom namespace preprocessor symbol B64_CUSTOM_NAMESPACE.
00084   *
00085   * To be able to do this requires v1.3.1 (or later) of b64, so that is
00086   * asserted also.
00087   */
00088 
00089 # ifdef B64_INCL_B64_H_B64
00090 #  error Cannot include b64/b64.h before pantheios/inserters/b64.hpp
00091 # endif /* B64_INCL_B64_H_B64 */
00092 
00093 # define B64_CUSTOM_NAMESPACE      b64_api
00094 
00095 #endif /* PANTHEIOS_NO_NAMESPACE */
00096 
00097 #include <b64/b64.h>    // If your compiler can't see this, you may be
00098                         // missing the b64 library. Download from
00099                         // http://www.synesis.com.au/software/b64.html
00100 
00101 
00102 
00103 #ifdef PANTHEIOS_NO_NAMESPACE
00104 
00105 # if !defined(B64_VER) || \
00106      B64_VER < 0x010301ff
00107 #  error Version 1.3.1 (or later) of b64 is required
00108 # endif /* B64_VER */
00109 
00110 #else /* ? PANTHEIOS_NO_NAMESPACE */
00111 
00112  /* If we're not customising the b64 namespace, then we use a namespace
00113   * alias to get b64_api, which we need in order to disambiguate
00114   * pantheios::b64 with the pantheios namespace.
00115   */
00116 
00117 namespace b64_api = ::b64;
00118 
00119 #endif /* PANTHEIOS_NO_NAMESPACE */
00120 
00121 
00122 /* STLSoft Header Files */
00123 #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_STRING_H_FWD
00124 # include <stlsoft/shims/access/string/fwd.h>
00125 #endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_STRING_H_FWD */
00126 
00127 /* Standard C Header Files */
00128 #ifndef PANTHEIOS_INCL_H_STDIO
00129 # define PANTHEIOS_INCL_H_STDIO
00130 # include <stdio.h>
00131 #endif /* !PANTHEIOS_INCL_H_STDIO */
00132 
00133 /* /////////////////////////////////////////////////////////////////////////
00134  * Namespace
00135  */
00136 
00137 #if !defined(PANTHEIOS_NO_NAMESPACE)
00138 namespace pantheios
00139 {
00140 
00141 #endif /* !PANTHEIOS_NO_NAMESPACE */
00142 
00143 /* /////////////////////////////////////////////////////////////////////////
00144  * Inserter classes
00145  */
00146 
00203 class b64
00204 {
00207 public:
00208     typedef b64             class_type;
00209     typedef b64_api::B64_RC B64_RC;
00211 
00214 public:
00215     b64(    void const* pv
00216         ,   size_t      cb);
00217 
00218     b64(    void const* pv
00219         ,   size_t      cb
00220         ,   unsigned    flags);
00221 
00222     b64(    void const* pv
00223         ,   size_t      cb
00224         ,   unsigned    flags
00225         ,   int         lineLen
00226         ,   B64_RC*     rc = NULL);
00227 
00228     ~b64() stlsoft_throw_0();
00230 
00233 public:
00235     pan_char_t const*   data() const;
00237     pan_char_t const*   c_str() const;
00239     size_t              length() const;
00241 
00244 private:
00245     void construct_() const;
00246     void construct_();
00248 
00251 private:
00252     pan_char_t const*   m_value;
00253     size_t              m_len;
00254     void const*         m_pv;
00255     size_t              m_cb;
00256     unsigned            m_flags;
00257     int                 m_lineLen;
00258     B64_RC*             m_rc;
00260 
00263 private:
00264 #if !defined(STLSOFT_COMPILER_IS_GCC)
00265     b64(class_type const&);
00266 #endif /* compiler */
00267     class_type& operator =(class_type const&);
00269 };
00270 
00271 /* /////////////////////////////////////////////////////////////////////////
00272  * String Access Shims
00273  */
00274 
00275 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00276 
00277 # if !defined(PANTHEIOS_NO_NAMESPACE)
00278 namespace shims
00279 {
00280 # endif /* !PANTHEIOS_NO_NAMESPACE */
00281 
00283 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00284 inline wchar_t const* c_str_data_w(b64 const& i)
00285 {
00286     return i.data();
00287 }
00288 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00289 inline char const* c_str_data_a(b64 const& i)
00290 {
00291     return i.data();
00292 }
00293 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00294 
00295 inline pan_char_t const* c_str_data(b64 const& i)
00296 {
00297     return i.data();
00298 }
00299 
00301 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00302 inline size_t c_str_len_w(b64 const& i)
00303 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00304 inline size_t c_str_len_a(b64 const& i)
00305 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00306 {
00307     return i.length();
00308 }
00310 inline size_t c_str_len(b64 const& i)
00311 {
00312     return i.length();
00313 }
00314 
00316 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00317 inline wchar_t const* c_str_ptr_w(b64 const& i)
00318 {
00319     return i.c_str();
00320 }
00321 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00322 inline char const* c_str_ptr_a(b64 const& i)
00323 {
00324     return i.c_str();
00325 }
00326 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00327 
00328 inline pan_char_t const* c_str_ptr(b64 const& i)
00329 {
00330     return i.c_str();
00331 }
00332 
00333 # if !defined(PANTHEIOS_NO_NAMESPACE)
00334 } /* namespace shims */
00335 
00336 #  if defined(STLSOFT_COMPILER_IS_GCC)
00337     /* GCC does not seem to correctly handle the phases of
00338      * processing of C++ templates, so we need to 'use' the
00339      * shims into the same namespace as the inserter class
00340      * in order that ADL can suffice instead.
00341      */
00342 #   ifdef PANTHEIOS_USE_WIDE_STRINGS
00343     using ::pantheios::shims::c_str_data_w;
00344     using ::pantheios::shims::c_str_len_w;
00345     using ::pantheios::shims::c_str_ptr_w;
00346 #   else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00347     using ::pantheios::shims::c_str_data_a;
00348     using ::pantheios::shims::c_str_len_a;
00349     using ::pantheios::shims::c_str_ptr_a;
00350 #   endif /* PANTHEIOS_USE_WIDE_STRINGS */
00351     using ::pantheios::shims::c_str_data;
00352     using ::pantheios::shims::c_str_len;
00353     using ::pantheios::shims::c_str_ptr;
00354 #  endif /* compiler */
00355 
00356 # endif /* !PANTHEIOS_NO_NAMESPACE */
00357 
00358 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
00359 
00360 /* /////////////////////////////////////////////////////////////////////////
00361  * Namespace
00362  */
00363 
00364 #if !defined(PANTHEIOS_NO_NAMESPACE)
00365 } /* namespace pantheios */
00366 
00367 namespace stlsoft
00368 {
00369     // 'Export' the string access shims into the STLSoft namespace
00370     //
00371     // c_str_ptr(_a) is not necessary for version 1.0 of Pantheios, but it's
00372     // defined and exported in order to allow for the case where someone
00373     // may find a legitimate use for the conversion classes additional to
00374     // the type-tunneling of the Pantheios API.
00375 
00376 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00377     using ::pantheios::shims::c_str_data_w;
00378     using ::pantheios::shims::c_str_len_w;
00379     using ::pantheios::shims::c_str_ptr_w;
00380 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00381     using ::pantheios::shims::c_str_data_a;
00382     using ::pantheios::shims::c_str_len_a;
00383     using ::pantheios::shims::c_str_ptr_a;
00384 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00385     using ::pantheios::shims::c_str_data;
00386     using ::pantheios::shims::c_str_len;
00387     using ::pantheios::shims::c_str_ptr;
00388 }
00389 
00390 #endif /* !PANTHEIOS_NO_NAMESPACE */
00391 
00392 /* /////////////////////////////////////////////////////////////////////////
00393  * Inclusion
00394  */
00395 
00396 #ifdef STLSOFT_PPF_pragma_once_SUPPORT
00397 # pragma once
00398 #endif /* STLSOFT_PPF_pragma_once_SUPPORT */
00399 
00400 /* ////////////////////////////////////////////////////////////////////// */
00401 
00402 #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_B64 */
00403 
00404 /* ///////////////////////////// end of file //////////////////////////// */

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