include/pantheios/inserters/b64.hpp

Go to the documentation of this file.
00001 /* /////////////////////////////////////////////////////////////////////////
00002  * File:        pantheios/inserters/b64.hpp
00003  *
00004  * Purpose:     String inserters for fundamental types
00005  *
00006  * Created:     31st July 2006
00007  * Updated:     1st September 2006
00008  *
00009  * Author:      Matthew Wilson
00010  *
00011  * Home:        http://www.pantheios.org/
00012  *
00013  * Copyright:   Matthew Wilson, 2006.
00014  *
00015  * Redistribution and use in source and binary forms, with or without
00016  * modification, are permitted provided that the following conditions are met:
00017  *
00018  * - Redistributions of source code must retain the above copyright notice, this
00019  *   list of conditions and the following disclaimer.
00020  * - Redistributions in binary form must reproduce the above copyright notice,
00021  *   this list of conditions and the following disclaimer in the documentation
00022  *   and/or other materials provided with the distribution.
00023  * - Neither the names of Matthew Wilson and Synesis Software nor the names of
00024  *   any contributors may be used to endorse or promote products derived from
00025  *   this software without specific prior written permission.
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00028  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00030  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00031  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00032  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00033  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00034  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00035  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00036  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00037  * 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    0
00059 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_B64_REVISION 1
00060 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_B64_EDIT     1
00061 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
00062 
00063 /* /////////////////////////////////////////////////////////////////////////
00064  * Includes
00065  */
00066 
00067 #include <pantheios/pantheios.hpp>
00068 #include <pantheios/inserters/fmt.hpp>
00069 
00070 #include <b64/b64.h>    // If your compiler can't see this, you may be
00071                         // missing the b64 library. Download from
00072                         //  http://www.synesis.com.au/software/b64.html
00073 
00074 
00075 #include <stlsoft/shims/access/string/fwd.h>
00076 
00077 #include <stdio.h>
00078 
00079 /* /////////////////////////////////////////////////////////////////////////
00080  * Namespace
00081  */
00082 
00083 // Must have namespace alias, in case PANTHEIOS_NO_NAMESPACE is defined
00084 namespace b64_api = ::b64;
00085 
00086 #if !defined(PANTHEIOS_NO_NAMESPACE)
00087 namespace pantheios
00088 {
00089 
00090 #endif /* !PANTHEIOS_NO_NAMESPACE */
00091 
00092 /* /////////////////////////////////////////////////////////////////////////
00093  * Inserter classes
00094  */
00095 
00152 class b64
00153 {
00156 public:
00157     typedef b64             class_type;
00158     typedef b64_api::B64_RC B64_RC;
00160 
00163 public:
00164     b64(    void const  *pv
00165         ,   size_t      cb);
00166 
00167     b64(    void const  *pv
00168         ,   size_t      cb
00169         ,   unsigned    flags);
00170 
00171     b64(    void const  *pv
00172         ,   size_t      cb
00173         ,   unsigned    flags
00174         ,   int         lineLen
00175         ,   B64_RC      *rc = NULL);
00176 
00177     ~b64() stlsoft_throw_0();
00179 
00182 public:
00184     char const  *data() const;
00186     char const  *c_str() const;
00188     size_t      length() const;
00190 
00193 private:
00194     void construct_() const;
00195     void construct_();
00197 
00200 private:
00201     char const  *m_value;
00202     size_t      m_len;
00203     void const  *m_pv;
00204     size_t      m_cb;
00205     unsigned    m_flags;
00206     int         m_lineLen;
00207     B64_RC      *m_rc;
00209 
00212 private:
00213 #if !defined(STLSOFT_COMPILER_IS_GCC)
00214     b64(class_type const &);
00215 #endif /* compiler */
00216     class_type &operator =(class_type const &);
00218 };
00219 
00220 /* /////////////////////////////////////////////////////////////////////////
00221  * String Access Shims
00222  */
00223 
00224 inline char const *c_str_data_a(b64 const &i)
00225 {
00226     return i.data();
00227 }
00228 inline char const *c_str_data(b64 const &i)
00229 {
00230     return i.data();
00231 }
00232 
00233 inline size_t c_str_len_a(b64 const &i)
00234 {
00235     return i.length();
00236 }
00237 inline size_t c_str_len(b64 const &i)
00238 {
00239     return i.length();
00240 }
00241 
00242 inline char const *c_str_ptr_a(b64 const &i)
00243 {
00244     return i.c_str();
00245 }
00246 inline char const *c_str_ptr(b64 const &i)
00247 {
00248     return i.c_str();
00249 }
00250 
00251 /* /////////////////////////////////////////////////////////////////////////
00252  * Namespace
00253  */
00254 
00255 #if !defined(PANTHEIOS_NO_NAMESPACE)
00256 } /* namespace pantheios */
00257 
00258 namespace stlsoft
00259 {
00260     // 'Export' the string access shims into the STLSoft namespace
00261     //
00262     // c_str_ptr(_a) is not necessary for version 1.0 of Pantheios, but it's
00263     // defined and exported in order to allow for the case where someone
00264     // may find a legitimate use for the conversion classes additional to
00265     // the type-tunnelling of the Panthieos API.
00266 
00267     using ::pantheios::c_str_data_a;
00268     using ::pantheios::c_str_data;
00269 
00270     using ::pantheios::c_str_len;
00271     using ::pantheios::c_str_len_a;
00272 
00273     using ::pantheios::c_str_ptr_a;
00274     using ::pantheios::c_str_ptr;
00275 }
00276 
00277 #endif /* !PANTHEIOS_NO_NAMESPACE */
00278 
00279 /* /////////////////////////////////////////////////////////////////////////
00280  * Inclusion
00281  */
00282 
00283 #ifdef STLSOFT_CF_PRAGMA_ONCE_SUPPORT
00284 # pragma once
00285 #endif /* STLSOFT_CF_PRAGMA_ONCE_SUPPORT */
00286 
00287 /* ////////////////////////////////////////////////////////////////////// */
00288 
00289 #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_B64 */
00290 
00291 /* ////////////////////////////////////////////////////////////////////// */

pantheios Library documentation © Matthew Wilson, 2006 SourceForge.net Logo