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

pantheios/inserters/slice.hpp

Go to the documentation of this file.
00001 /* /////////////////////////////////////////////////////////////////////////
00002  * File:        pantheios/inserters/slice.hpp
00003  *
00004  * Purpose:     String inserter for slices of strings.
00005  *
00006  * Created:     13th February 2010
00007  * Updated:     27th December 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 
00048 #ifndef PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_PAD
00049 #define PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_PAD
00050 
00051 /* /////////////////////////////////////////////////////////////////////////
00052  * Version information
00053  */
00054 
00055 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00056 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_PAD_MAJOR    1
00057 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_PAD_MINOR    0
00058 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_PAD_REVISION 3
00059 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_PAD_EDIT     5
00060 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
00061 
00062 /* /////////////////////////////////////////////////////////////////////////
00063  * Includes
00064  */
00065 
00066 #ifndef PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS
00067 # include <pantheios/pantheios.h>
00068 #endif /* !PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS */
00069 
00070 #include <stlsoft/memory/auto_buffer.hpp>
00071 #include <stlsoft/shims/access/string.hpp>
00072 
00073 /* /////////////////////////////////////////////////////////////////////////
00074  * Namespace
00075  */
00076 
00077 #if !defined(PANTHEIOS_NO_NAMESPACE)
00078 namespace pantheios
00079 {
00080 #endif /* !PANTHEIOS_NO_NAMESPACE */
00081 
00082 /* /////////////////////////////////////////////////////////////////////////
00083  * Classes
00084  */
00085 
00086 #ifdef PANTHEIOS_CF_NAMESPACE_SUPPORT
00087 //namespace inserters
00088 //{
00089 #endif /* PANTHEIOS_CF_NAMESPACE_SUPPORT */
00090 
00094 class slice_inserter
00095 {
00098 public:
00099     typedef slice_inserter                          class_type;
00100 private:
00101     typedef stlsoft::auto_buffer<pan_char_t, 256>   buffer_type_;
00103 
00106 public:
00107     slice_inserter(
00108         pan_char_t const*   str
00109     ,   size_t              len
00110     ,   pan_char_t const*   strName
00111     ,   pan_char_t const*   lenName
00112     ,   pan_char_t const*   equals
00113     ,   pan_char_t const*   separator
00114     );
00115 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00116     slice_inserter(class_type const& rhs);
00117 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
00119 
00122 public:
00124     pan_char_t const*   data() const;
00126     pan_char_t const*   c_str() const;
00128     size_t              length() const;
00130 
00133 private:
00134     void construct_() const;
00135     void construct_();
00137 
00140 private:
00141     pan_char_t const*   m_str;
00142     size_t              m_len;
00143     pan_char_t const*   m_strName;
00144     pan_char_t const*   m_lenName;
00145     pan_char_t const*   m_equals;
00146     pan_char_t const*   m_separator;
00147     buffer_type_        m_buffer;
00149 
00152 private:
00153     class_type& operator =(class_type const&);
00155 };
00156 
00157 #ifdef PANTHEIOS_CF_NAMESPACE_SUPPORT
00158 //namespace inserters
00159 //{
00160 #endif /* PANTHEIOS_CF_NAMESPACE_SUPPORT */
00161 
00162 /* /////////////////////////////////////////////////////////////////////////
00163  * Inserter functions
00164  */
00165 
00172 inline pan_slice_t slice(
00173     pan_char_t const*   str
00174 ,   size_t              len
00175 )
00176 {
00177     return pan_slice_t(str, len);
00178 }
00179 
00186 inline slice_inserter slice(
00187     pan_char_t const*   str
00188 ,   size_t              len
00189 ,   pan_char_t const*   strName
00190 )
00191 {
00192     return slice_inserter(str, len, strName, NULL, NULL, NULL);
00193 }
00194 
00202 inline slice_inserter slice(
00203     pan_char_t const*   str
00204 ,   size_t              len
00205 ,   pan_char_t const*   strName
00206 ,   pan_char_t const*   lenName
00207 )
00208 {
00209     return slice_inserter(str, len, strName, lenName, NULL, NULL);
00210 }
00211 
00220 inline slice_inserter slice(
00221     pan_char_t const*   str
00222 ,   size_t              len
00223 ,   pan_char_t const*   strName
00224 ,   pan_char_t const*   lenName
00225 ,   pan_char_t const*   equals
00226 )
00227 {
00228     return slice_inserter(str, len, strName, lenName, equals, NULL);
00229 }
00230 
00240 inline slice_inserter slice(
00241     pan_char_t const*   str
00242 ,   size_t              len
00243 ,   pan_char_t const*   strName
00244 ,   pan_char_t const*   lenName
00245 ,   pan_char_t const*   equals
00246 ,   pan_char_t const*   separator
00247 )
00248 {
00249     return slice_inserter(str, len, strName, lenName, equals, separator);
00250 }
00251 
00252 /* /////////////////////////////////////////////////////////////////////////
00253  * String Access Shims
00254  */
00255 
00256 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00257 
00258 # if !defined(PANTHEIOS_NO_NAMESPACE)
00259 namespace shims
00260 {
00261 # endif /* !PANTHEIOS_NO_NAMESPACE */
00262 
00264 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00265 inline wchar_t const* c_str_data_w(slice_inserter const& i)
00266 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00267 inline char const* c_str_data_a(slice_inserter const& i)
00268 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00269 {
00270     return i.data();
00271 }
00273 inline pan_char_t const* c_str_data(slice_inserter const& i)
00274 {
00275     return i.data();
00276 }
00277 
00279 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00280 inline size_t c_str_len_w(slice_inserter const& i)
00281 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00282 inline size_t c_str_len_a(slice_inserter const& i)
00283 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00284 {
00285     return i.length();
00286 }
00288 inline size_t c_str_len(slice_inserter const& i)
00289 {
00290     return i.length();
00291 }
00292 
00294 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00295 inline wchar_t const* c_str_ptr_w(slice_inserter const& i)
00296 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00297 inline char const* c_str_ptr_a(slice_inserter const& i)
00298 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00299 {
00300     return i.c_str();
00301 }
00303 inline pan_char_t const* c_str_ptr(slice_inserter const& i)
00304 {
00305     return i.c_str();
00306 }
00307 
00308 # if !defined(PANTHEIOS_NO_NAMESPACE)
00309 } /* namespace shims */
00310 
00311 #  if defined(STLSOFT_COMPILER_IS_GCC)
00312     /* GCC does not seem to correctly handle the phases of
00313      * processing of C++ templates, so we need to 'use' the
00314      * shims into the same namespace as the inserter class
00315      * in order that ADL can suffice instead.
00316      */
00317 #   ifdef PANTHEIOS_USE_WIDE_STRINGS
00318     using ::pantheios::shims::c_str_data_w;
00319     using ::pantheios::shims::c_str_len_w;
00320     using ::pantheios::shims::c_str_ptr_w;
00321 #   else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00322     using ::pantheios::shims::c_str_data_a;
00323     using ::pantheios::shims::c_str_len_a;
00324     using ::pantheios::shims::c_str_ptr_a;
00325 #   endif /* PANTHEIOS_USE_WIDE_STRINGS */
00326     using ::pantheios::shims::c_str_data;
00327     using ::pantheios::shims::c_str_len;
00328     using ::pantheios::shims::c_str_ptr;
00329 #  endif /* compiler */
00330 
00331 # endif /* !PANTHEIOS_NO_NAMESPACE */
00332 
00333 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
00334 
00335 /* /////////////////////////////////////////////////////////////////////////
00336  * Namespace
00337  */
00338 
00339 #if !defined(PANTHEIOS_NO_NAMESPACE)
00340 } /* namespace pantheios */
00341 
00342 namespace stlsoft
00343 {
00344     // 'Export' the string access shims into the STLSoft namespace
00345     //
00346     // c_str_ptr(_a) is not necessary for version 1.0 of Pantheios, but it's
00347     // defined and exported in order to allow for the case where someone
00348     // may find a legitimate use for the conversion classes additional to
00349     // the type-tunneling of the Pantheios API.
00350 
00351 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00352     using ::pantheios::shims::c_str_data_w;
00353     using ::pantheios::shims::c_str_len_w;
00354     using ::pantheios::shims::c_str_ptr_w;
00355 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00356     using ::pantheios::shims::c_str_data_a;
00357     using ::pantheios::shims::c_str_len_a;
00358     using ::pantheios::shims::c_str_ptr_a;
00359 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00360     using ::pantheios::shims::c_str_data;
00361     using ::pantheios::shims::c_str_len;
00362     using ::pantheios::shims::c_str_ptr;
00363 }
00364 
00365 #endif /* !PANTHEIOS_NO_NAMESPACE */
00366 
00367 /* /////////////////////////////////////////////////////////////////////////
00368  * Inclusion
00369  */
00370 
00371 #ifdef STLSOFT_PPF_pragma_once_SUPPORT
00372 # pragma once
00373 #endif /* STLSOFT_PPF_pragma_once_SUPPORT */
00374 
00375 /* ////////////////////////////////////////////////////////////////////// */
00376 
00377 #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_PAD */
00378 
00379 /* ///////////////////////////// end of file //////////////////////////// */

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