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

pantheios/inserters/blob.hpp

Go to the documentation of this file.
00001 /* /////////////////////////////////////////////////////////////////////////
00002  * File:        pantheios/inserters/blob.hpp
00003  *
00004  * Purpose:     String inserter for binary regions.
00005  *
00006  * Created:     21st June 2005
00007  * Updated:     22nd March 2010
00008  *
00009  * Home:        http://www.pantheios.org/
00010  *
00011  * Copyright (c) 2005-2010, Matthew Wilson and Synesis Software
00012  * Copyright (c) 1999-2005, Synesis Software and Matthew Wilson
00013  * All rights reserved.
00014  *
00015  * Redistribution and use in source and binary forms, with or without
00016  * modification, are permitted provided that the following conditions are
00017  * met:
00018  *
00019  * - Redistributions of source code must retain the above copyright notice,
00020  *   this list of conditions and the following disclaimer.
00021  * - Redistributions in binary form must reproduce the above copyright
00022  *   notice, this list of conditions and the following disclaimer in the
00023  *   documentation and/or other materials provided with the distribution.
00024  * - Neither the name(s) of Matthew Wilson and Synesis Software nor the
00025  *   names of any contributors may be used to endorse or promote products
00026  *   derived from this software without specific prior written permission.
00027  *
00028  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00029  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
00030  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00031  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
00032  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00033  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00034  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00035  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00036  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00037  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00038  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039  *
00040  * ////////////////////////////////////////////////////////////////////// */
00041 
00042 
00049 #ifndef PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_BLOB
00050 #define PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_BLOB
00051 
00052 /* /////////////////////////////////////////////////////////////////////////
00053  * Version information
00054  */
00055 
00056 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00057 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_BLOB_MAJOR       2
00058 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_BLOB_MINOR       4
00059 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_BLOB_REVISION    4
00060 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_BLOB_EDIT        27
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 #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_STRING_H_FWD
00075 # include <stlsoft/shims/access/string/fwd.h>
00076 #endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_STRING_H_FWD */
00077 
00078 #ifndef PANTHEIOS_INCL_H_STDIO
00079 # define PANTHEIOS_INCL_H_STDIO
00080 # include <stdio.h>
00081 #endif /* !PANTHEIOS_INCL_H_STDIO */
00082 
00083 /* /////////////////////////////////////////////////////////////////////////
00084  * Namespace
00085  */
00086 
00087 #if !defined(PANTHEIOS_NO_NAMESPACE)
00088 namespace pantheios
00089 {
00090 
00091 #endif /* !PANTHEIOS_NO_NAMESPACE */
00092 
00093 /* /////////////////////////////////////////////////////////////////////////
00094  * Inserter classes
00095  */
00096 
00153 class blob
00154 {
00157 public:
00158     typedef blob    class_type;
00160 
00163 public:
00169     blob(   void const* pv
00170         ,   size_t      cb);
00171 
00181     blob(   void const*         pv
00182         ,   size_t              cb
00183         ,   unsigned            bytesPerGroup
00184         ,   pan_char_t const*   groupSeparator);
00185 
00198     blob(   void const*         pv
00199         ,   size_t              cb
00200         ,   unsigned            bytesPerGroup
00201         ,   pan_char_t const*   groupSeparator
00202         ,   int                 groupsPerLine
00203         ,   pan_char_t const*   lineSeparator  =   PANTHEIOS_LITERAL_STRING("\n")
00204     );
00205 
00207     ~blob() stlsoft_throw_0();
00209 
00212 public:
00214     pan_char_t const*   data() const;
00216     pan_char_t const*   c_str() const;
00218     size_t              length() const;
00220 
00223 private:
00224     void construct_() const;
00225     void construct_();
00227 
00230 private:
00231     pan_char_t const*   m_value;
00232     size_t              m_len;
00233     void const* const   m_pv;
00234     size_t              m_cb;
00235     unsigned            m_byteGrouping;
00236     pan_char_t const*   m_groupSeparator;
00237     int                 m_groupsPerLine;
00238     pan_char_t const*   m_lineSeparator;
00240 
00243 private:
00244 #if !defined(STLSOFT_COMPILER_IS_GCC)
00245     blob(class_type const&);
00246 #endif /* compiler */
00247     class_type& operator =(class_type const&);
00249 };
00250 
00251 /* /////////////////////////////////////////////////////////////////////////
00252  * String Access Shims
00253  */
00254 
00255 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00256 
00257 # if !defined(PANTHEIOS_NO_NAMESPACE)
00258 namespace shims
00259 {
00260 # endif /* !PANTHEIOS_NO_NAMESPACE */
00261 
00263 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00264 inline wchar_t const* c_str_data_w(blob const& b)
00265 {
00266     return b.data();
00267 }
00268 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00269 inline char const* c_str_data_a(blob const& b)
00270 {
00271     return b.data();
00272 }
00273 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00274 
00275 inline pan_char_t const* c_str_data(blob const& b)
00276 {
00277     return b.data();
00278 }
00279 
00281 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00282 inline size_t c_str_len_w(blob const& b)
00283 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00284 inline size_t c_str_len_a(blob const& b)
00285 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00286 {
00287     return b.length();
00288 }
00290 inline size_t c_str_len(blob const& b)
00291 {
00292     return b.length();
00293 }
00294 
00296 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00297 inline wchar_t const* c_str_ptr_w(blob const& b)
00298 {
00299     return b.c_str();
00300 }
00301 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00302 inline char const* c_str_ptr_a(blob const& b)
00303 {
00304     return b.c_str();
00305 }
00306 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00307 
00308 inline pan_char_t const* c_str_ptr(blob const& b)
00309 {
00310     return b.c_str();
00311 }
00312 
00313 # if !defined(PANTHEIOS_NO_NAMESPACE)
00314 } /* namespace shims */
00315 
00316 #  if defined(STLSOFT_COMPILER_IS_GCC)
00317     /* GCC does not seem to correctly handle the phases of
00318      * processing of C++ templates, so we need to 'use' the
00319      * shims into the same namespace as the inserter class
00320      * in order that ADL can suffice instead.
00321      */
00322 #   ifdef PANTHEIOS_USE_WIDE_STRINGS
00323     using ::pantheios::shims::c_str_data_w;
00324     using ::pantheios::shims::c_str_len_w;
00325     using ::pantheios::shims::c_str_ptr_w;
00326 #   else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00327     using ::pantheios::shims::c_str_data_a;
00328     using ::pantheios::shims::c_str_len_a;
00329     using ::pantheios::shims::c_str_ptr_a;
00330 #   endif /* PANTHEIOS_USE_WIDE_STRINGS */
00331     using ::pantheios::shims::c_str_data;
00332     using ::pantheios::shims::c_str_len;
00333     using ::pantheios::shims::c_str_ptr;
00334 #  endif /* compiler */
00335 
00336 # endif /* !PANTHEIOS_NO_NAMESPACE */
00337 
00338 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
00339 
00340 /* /////////////////////////////////////////////////////////////////////////
00341  * Namespace
00342  */
00343 
00344 #if !defined(PANTHEIOS_NO_NAMESPACE)
00345 } /* namespace pantheios */
00346 
00347 namespace stlsoft
00348 {
00349     // 'Export' the string access shims into the STLSoft namespace
00350     //
00351     // c_str_ptr(_a) is not necessary for version 1.0 of Pantheios, but it's
00352     // defined and exported in order to allow for the case where someone
00353     // may find a legitimate use for the conversion classes additional to
00354     // the type-tunneling of the Pantheios API.
00355 
00356 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00357     using ::pantheios::shims::c_str_data_w;
00358     using ::pantheios::shims::c_str_len_w;
00359     using ::pantheios::shims::c_str_ptr_w;
00360 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00361     using ::pantheios::shims::c_str_data_a;
00362     using ::pantheios::shims::c_str_len_a;
00363     using ::pantheios::shims::c_str_ptr_a;
00364 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00365     using ::pantheios::shims::c_str_data;
00366     using ::pantheios::shims::c_str_len;
00367     using ::pantheios::shims::c_str_ptr;
00368 }
00369 
00370 #endif /* !PANTHEIOS_NO_NAMESPACE */
00371 
00372 /* /////////////////////////////////////////////////////////////////////////
00373  * Inclusion
00374  */
00375 
00376 #ifdef STLSOFT_PPF_pragma_once_SUPPORT
00377 # pragma once
00378 #endif /* STLSOFT_PPF_pragma_once_SUPPORT */
00379 
00380 /* ////////////////////////////////////////////////////////////////////// */
00381 
00382 #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_BLOB */
00383 
00384 /* ///////////////////////////// end of file //////////////////////////// */

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