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 2012
00008  *
00009  * Home:        http://www.pantheios.org/
00010  *
00011  * Copyright (c) 2005-2012, 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     29
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 #endif /* !PANTHEIOS_NO_NAMESPACE */
00086 
00087 /* /////////////////////////////////////////////////////////////////////////
00088  * Inserter classes
00089  */
00090 
00111 class pointer
00112 {
00113 public:
00115     typedef pointer     class_type;
00116 
00117 public:
00131     pointer(void const volatile* pv, int widthAndFormat);
00132 
00140     pointer(void const volatile* pv, int minWidth, int format);
00141 
00142 public:
00144     pan_char_t const*   data() const;
00146     pan_char_t const*   c_str() const;
00148     size_t              length() const;
00149 
00150 private:
00151     void construct_() const;
00152     void construct_();
00153 
00154     static int validate_width_(int minWidth);
00155 
00156 private:
00157     void const volatile*    m_value;
00158     size_t                  m_len;
00159     const int               m_minWidth;
00160     const int               m_format;
00161     pan_char_t              m_sz[23];
00162 
00163 private:
00164 #if !defined(STLSOFT_COMPILER_IS_GCC)
00165     pointer(class_type const&);
00166 #endif /* compiler */
00167     class_type& operator =(class_type const&);
00168 };
00169 
00170 /* /////////////////////////////////////////////////////////////////////////
00171  * String Access Shims
00172  */
00173 
00174 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00175 
00176 # if !defined(PANTHEIOS_NO_NAMESPACE)
00177 namespace shims
00178 {
00179 # endif /* !PANTHEIOS_NO_NAMESPACE */
00180 
00182 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00183 inline wchar_t const* c_str_data_w(pointer const& p)
00184 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00185 inline char const* c_str_data_a(pointer const& p)
00186 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00187 {
00188     return p.data();
00189 }
00191 inline pan_char_t const* c_str_data(pointer const& p)
00192 {
00193     return p.data();
00194 }
00195 
00197 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00198 inline size_t c_str_len_w(pointer const& p)
00199 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00200 inline size_t c_str_len_a(pointer const& p)
00201 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00202 {
00203     return p.length();
00204 }
00206 inline size_t c_str_len(pointer const& p)
00207 {
00208     return p.length();
00209 }
00210 
00212 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00213 inline wchar_t const* c_str_ptr_w(pointer const& p)
00214 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00215 inline char const* c_str_ptr_a(pointer const& p)
00216 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00217 {
00218     return p.c_str();
00219 }
00221 inline pan_char_t const* c_str_ptr(pointer const& p)
00222 {
00223     return p.c_str();
00224 }
00225 
00226 # if !defined(PANTHEIOS_NO_NAMESPACE)
00227 } /* namespace shims */
00228 
00229 #  if defined(STLSOFT_COMPILER_IS_GCC)
00230     /* GCC does not seem to correctly handle the phases of
00231      * processing of C++ templates, so we need to 'use' the
00232      * shims into the same namespace as the inserter class
00233      * in order that ADL can suffice instead.
00234      */
00235 #   ifdef PANTHEIOS_USE_WIDE_STRINGS
00236     using ::pantheios::shims::c_str_data_w;
00237     using ::pantheios::shims::c_str_len_w;
00238     using ::pantheios::shims::c_str_ptr_w;
00239 #   else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00240     using ::pantheios::shims::c_str_data_a;
00241     using ::pantheios::shims::c_str_len_a;
00242     using ::pantheios::shims::c_str_ptr_a;
00243 #   endif /* PANTHEIOS_USE_WIDE_STRINGS */
00244     using ::pantheios::shims::c_str_data;
00245     using ::pantheios::shims::c_str_len;
00246     using ::pantheios::shims::c_str_ptr;
00247 #  endif /* compiler */
00248 
00249 # endif /* !PANTHEIOS_NO_NAMESPACE */
00250 
00251 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
00252 
00253 /* /////////////////////////////////////////////////////////////////////////
00254  * Namespace
00255  */
00256 
00257 #if !defined(PANTHEIOS_NO_NAMESPACE)
00258 } /* namespace pantheios */
00259 
00260 namespace stlsoft
00261 {
00262     // 'Export' the string access shims into the STLSoft namespace
00263     //
00264     // c_str_ptr(_a) is not necessary for version 1.0 of Pantheios, but it's
00265     // defined and exported in order to allow for the case where someone
00266     // may find a legitimate use for the conversion classes additional to
00267     // the type-tunneling of the Pantheios API.
00268 
00269 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00270     using ::pantheios::shims::c_str_data_w;
00271     using ::pantheios::shims::c_str_len_w;
00272     using ::pantheios::shims::c_str_ptr_w;
00273 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00274     using ::pantheios::shims::c_str_data_a;
00275     using ::pantheios::shims::c_str_len_a;
00276     using ::pantheios::shims::c_str_ptr_a;
00277 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00278     using ::pantheios::shims::c_str_data;
00279     using ::pantheios::shims::c_str_len;
00280     using ::pantheios::shims::c_str_ptr;
00281 }
00282 
00283 #endif /* !PANTHEIOS_NO_NAMESPACE */
00284 
00285 /* /////////////////////////////////////////////////////////////////////////
00286  * Inclusion
00287  */
00288 
00289 #ifdef STLSOFT_PPF_pragma_once_SUPPORT
00290 # pragma once
00291 #endif /* STLSOFT_PPF_pragma_once_SUPPORT */
00292 
00293 /* ////////////////////////////////////////////////////////////////////// */
00294 
00295 #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_POINTER */
00296 
00297 /* ///////////////////////////// end of file //////////////////////////// */

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