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

pantheios/inserters/pointer.hpp

Go to the documentation of this file.
00001 /* /////////////////////////////////////////////////////////////////////////
00002  * File:        pantheios/inserters/pointer.hpp
00003  *
00004  * Purpose:     String inserters for fundamental types
00005  *
00006  * Created:     21st June 2005
00007  * Updated:     14th February 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_POINTER
00050 #define PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_POINTER
00051 
00052 /* /////////////////////////////////////////////////////////////////////////
00053  * Version information
00054  */
00055 
00056 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00057 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_POINTER_MAJOR    2
00058 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_POINTER_MINOR    4
00059 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_POINTER_REVISION 4
00060 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_POINTER_EDIT     28
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 /* /////////////////////////////////////////////////////////////////////////
00079  * Namespace
00080  */
00081 
00082 #if !defined(PANTHEIOS_NO_NAMESPACE)
00083 namespace pantheios
00084 {
00085 
00086 #endif /* !PANTHEIOS_NO_NAMESPACE */
00087 
00088 /* /////////////////////////////////////////////////////////////////////////
00089  * Inserter classes
00090  */
00091 
00112 class pointer
00113 {
00114 public:
00116     typedef pointer     class_type;
00117 
00118 public:
00130     pointer(void const volatile* pv, int widthAndFormat);
00131 
00139     pointer(void const volatile* pv, int minWidth, int format);
00140 
00141 public:
00143     pan_char_t const*   data() const;
00145     pan_char_t const*   c_str() const;
00147     size_t              length() const;
00148 
00149 private:
00150     void construct_() const;
00151     void construct_();
00152 
00153     static int validate_width_(int minWidth);
00154 
00155 private:
00156     void const volatile*    m_value;
00157     size_t                  m_len;
00158     const int               m_minWidth;
00159     const int               m_format;
00160     pan_char_t              m_sz[23];
00161 
00162 private:
00163 #if !defined(STLSOFT_COMPILER_IS_GCC)
00164     pointer(class_type const&);
00165 #endif /* compiler */
00166     class_type& operator =(class_type const&);
00167 };
00168 
00169 /* /////////////////////////////////////////////////////////////////////////
00170  * String Access Shims
00171  */
00172 
00173 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00174 
00175 # if !defined(PANTHEIOS_NO_NAMESPACE)
00176 namespace shims
00177 {
00178 # endif /* !PANTHEIOS_NO_NAMESPACE */
00179 
00181 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00182 inline wchar_t const* c_str_data_w(pointer const& p)
00183 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00184 inline char const* c_str_data_a(pointer const& p)
00185 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00186 {
00187     return p.data();
00188 }
00190 inline pan_char_t const* c_str_data(pointer const& p)
00191 {
00192     return p.data();
00193 }
00194 
00196 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00197 inline size_t c_str_len_w(pointer const& p)
00198 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00199 inline size_t c_str_len_a(pointer const& p)
00200 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00201 {
00202     return p.length();
00203 }
00205 inline size_t c_str_len(pointer const& p)
00206 {
00207     return p.length();
00208 }
00209 
00211 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00212 inline wchar_t const* c_str_ptr_w(pointer const& p)
00213 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00214 inline char const* c_str_ptr_a(pointer const& p)
00215 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00216 {
00217     return p.c_str();
00218 }
00220 inline pan_char_t const* c_str_ptr(pointer const& p)
00221 {
00222     return p.c_str();
00223 }
00224 
00225 # if !defined(PANTHEIOS_NO_NAMESPACE)
00226 } /* namespace shims */
00227 
00228 #  if defined(STLSOFT_COMPILER_IS_GCC)
00229     /* GCC does not seem to correctly handle the phases of
00230      * processing of C++ templates, so we need to 'use' the
00231      * shims into the same namespace as the inserter class
00232      * in order that ADL can suffice instead.
00233      */
00234 #   ifdef PANTHEIOS_USE_WIDE_STRINGS
00235     using ::pantheios::shims::c_str_data_w;
00236     using ::pantheios::shims::c_str_len_w;
00237     using ::pantheios::shims::c_str_ptr_w;
00238 #   else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00239     using ::pantheios::shims::c_str_data_a;
00240     using ::pantheios::shims::c_str_len_a;
00241     using ::pantheios::shims::c_str_ptr_a;
00242 #   endif /* PANTHEIOS_USE_WIDE_STRINGS */
00243     using ::pantheios::shims::c_str_data;
00244     using ::pantheios::shims::c_str_len;
00245     using ::pantheios::shims::c_str_ptr;
00246 #  endif /* compiler */
00247 
00248 # endif /* !PANTHEIOS_NO_NAMESPACE */
00249 
00250 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
00251 
00252 /* /////////////////////////////////////////////////////////////////////////
00253  * Namespace
00254  */
00255 
00256 #if !defined(PANTHEIOS_NO_NAMESPACE)
00257 } /* namespace pantheios */
00258 
00259 namespace stlsoft
00260 {
00261     // 'Export' the string access shims into the STLSoft namespace
00262     //
00263     // c_str_ptr(_a) is not necessary for version 1.0 of Pantheios, but it's
00264     // defined and exported in order to allow for the case where someone
00265     // may find a legitimate use for the conversion classes additional to
00266     // the type-tunneling of the Pantheios API.
00267 
00268 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00269     using ::pantheios::shims::c_str_data_w;
00270     using ::pantheios::shims::c_str_len_w;
00271     using ::pantheios::shims::c_str_ptr_w;
00272 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00273     using ::pantheios::shims::c_str_data_a;
00274     using ::pantheios::shims::c_str_len_a;
00275     using ::pantheios::shims::c_str_ptr_a;
00276 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00277     using ::pantheios::shims::c_str_data;
00278     using ::pantheios::shims::c_str_len;
00279     using ::pantheios::shims::c_str_ptr;
00280 }
00281 
00282 #endif /* !PANTHEIOS_NO_NAMESPACE */
00283 
00284 /* /////////////////////////////////////////////////////////////////////////
00285  * Inclusion
00286  */
00287 
00288 #ifdef STLSOFT_PPF_pragma_once_SUPPORT
00289 # pragma once
00290 #endif /* STLSOFT_PPF_pragma_once_SUPPORT */
00291 
00292 /* ////////////////////////////////////////////////////////////////////// */
00293 
00294 #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_POINTER */
00295 
00296 /* ///////////////////////////// end of file //////////////////////////// */

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