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

pantheios/inserters/character.hpp

Go to the documentation of this file.
00001 /* /////////////////////////////////////////////////////////////////////////
00002  * File:        pantheios/inserters/character.hpp
00003  *
00004  * Purpose:     String inserters for fundamental types
00005  *
00006  * Created:     21st June 2005
00007  * Updated:     31st July 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 
00073 #ifndef PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_CHARACTER
00074 #define PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_CHARACTER
00075 
00076 /* /////////////////////////////////////////////////////////////////////////
00077  * Version information
00078  */
00079 
00080 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00081 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_CHARACTER_MAJOR      1
00082 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_CHARACTER_MINOR      5
00083 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_CHARACTER_REVISION   2
00084 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_CHARACTER_EDIT       24
00085 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
00086 
00087 /* /////////////////////////////////////////////////////////////////////////
00088  * Includes
00089  */
00090 
00091 #ifndef PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS
00092 # include <pantheios/pantheios.h>
00093 #endif /* !PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS */
00094 #ifndef PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_FMT
00095 # include <pantheios/inserters/fmt.hpp>
00096 #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_FMT */
00097 
00098 #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_STRING_H_FWD
00099 # include <stlsoft/shims/access/string/fwd.h>
00100 #endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_STRING_H_FWD */
00101 
00102 /* /////////////////////////////////////////////////////////////////////////
00103  * Namespace
00104  */
00105 
00106 #if !defined(PANTHEIOS_NO_NAMESPACE)
00107 namespace pantheios
00108 {
00109 
00110 #endif /* !PANTHEIOS_NO_NAMESPACE */
00111 
00112 /* /////////////////////////////////////////////////////////////////////////
00113  * Inserter classes
00114  */
00115 
00145 class character
00146 {
00147 public:
00149     typedef character   class_type;
00150 
00151 public:
00153     explicit character(pan_char_t value);
00154 
00155 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00156 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00157     explicit character(char value);
00158 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00159 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
00160 
00161 private:
00162     explicit character(int); // Prevents implicit conversion from an integer
00163 
00164 public:
00166     pan_char_t const*   data() const;
00168     pan_char_t const*   c_str() const;
00170     size_t              length() const;
00171 
00172 private:
00173     pan_char_t  m_value[2];
00174 
00175 private:
00176 #if !defined(STLSOFT_COMPILER_IS_GCC)
00177     character(class_type const&);
00178 #endif /* compiler */
00179     class_type& operator =(class_type const&);
00180 };
00181 
00182 /* /////////////////////////////////////////////////////////////////////////
00183  * String Access Shims
00184  */
00185 
00186 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00187 
00188 # if !defined(PANTHEIOS_NO_NAMESPACE)
00189 namespace shims
00190 {
00191 # endif /* !PANTHEIOS_NO_NAMESPACE */
00192 
00194 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00195 inline wchar_t const* c_str_data_w(character const& r)
00196 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00197 inline char const* c_str_data_a(character const& r)
00198 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00199 {
00200     return r.data();
00201 }
00203 inline pan_char_t const* c_str_data(character const& r)
00204 {
00205     return r.data();
00206 }
00207 
00209 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00210 inline size_t c_str_len_w(character const& r)
00211 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00212 inline size_t c_str_len_a(character const& r)
00213 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00214 {
00215     return r.length();
00216 }
00218 inline size_t c_str_len(character const& r)
00219 {
00220     return r.length();
00221 }
00222 
00224 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00225 inline wchar_t const* c_str_ptr_a(character const& r)
00226 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00227 inline char const* c_str_ptr_a(character const& r)
00228 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00229 {
00230     return r.c_str();
00231 }
00233 inline pan_char_t const* c_str_ptr(character const& r)
00234 {
00235     return r.c_str();
00236 }
00237 
00238 # if !defined(PANTHEIOS_NO_NAMESPACE)
00239 } /* namespace shims */
00240 
00241 #  if defined(STLSOFT_COMPILER_IS_GCC)
00242     /* GCC does not seem to correctly handle the phases of
00243      * processing of C++ templates, so we need to 'use' the
00244      * shims into the same namespace as the inserter class
00245      * in order that ADL can suffice instead.
00246      */
00247 #   ifdef PANTHEIOS_USE_WIDE_STRINGS
00248     using ::pantheios::shims::c_str_data_w;
00249     using ::pantheios::shims::c_str_len_w;
00250     using ::pantheios::shims::c_str_ptr_w;
00251 #   else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00252     using ::pantheios::shims::c_str_data_a;
00253     using ::pantheios::shims::c_str_len_a;
00254     using ::pantheios::shims::c_str_ptr_a;
00255 #   endif /* PANTHEIOS_USE_WIDE_STRINGS */
00256     using ::pantheios::shims::c_str_data;
00257     using ::pantheios::shims::c_str_len;
00258     using ::pantheios::shims::c_str_ptr;
00259 #  endif /* compiler */
00260 
00261 # endif /* !PANTHEIOS_NO_NAMESPACE */
00262 
00263 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
00264 
00265 /* /////////////////////////////////////////////////////////////////////////
00266  * Implementation
00267  */
00268 
00269 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00270 
00271 inline /* explicit */ character::character(pan_char_t value)
00272 {
00273     m_value[0]  =   value;
00274     m_value[1]  =   '\0';
00275 }
00276 
00277 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00278 inline /* explicit */ character::character(char value)
00279 {
00280     m_value[0]  =   value;
00281     m_value[1]  =   '\0';
00282 }
00283 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00284 
00285 inline pan_char_t const* character::data() const
00286 {
00287     return m_value;
00288 }
00289 
00290 inline pan_char_t const* character::c_str() const
00291 {
00292     return m_value;
00293 }
00294 
00295 inline size_t character::length() const
00296 {
00297     return 1;
00298 }
00299 
00300 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
00301 
00302 /* /////////////////////////////////////////////////////////////////////////
00303  * Namespace
00304  */
00305 
00306 #if !defined(PANTHEIOS_NO_NAMESPACE)
00307 } /* namespace pantheios */
00308 
00309 namespace stlsoft
00310 {
00311     // 'Export' the string access shims into the STLSoft namespace
00312     //
00313     // c_str_ptr(_a) is not necessary for version 1.0 of Pantheios, but it's
00314     // defined and exported in order to allow for the case where someone
00315     // may find a legitimate use for the conversion classes additional to
00316     // the type-tunneling of the Pantheios API.
00317 
00318 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00319     using ::pantheios::shims::c_str_data_w;
00320     using ::pantheios::shims::c_str_len_w;
00321     using ::pantheios::shims::c_str_ptr_w;
00322 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00323     using ::pantheios::shims::c_str_data_a;
00324     using ::pantheios::shims::c_str_len_a;
00325     using ::pantheios::shims::c_str_ptr_a;
00326 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00327     using ::pantheios::shims::c_str_data;
00328     using ::pantheios::shims::c_str_len;
00329     using ::pantheios::shims::c_str_ptr;
00330 }
00331 
00332 #endif /* !PANTHEIOS_NO_NAMESPACE */
00333 
00334 /* /////////////////////////////////////////////////////////////////////////
00335  * Inclusion
00336  */
00337 
00338 #ifdef STLSOFT_PPF_pragma_once_SUPPORT
00339 # pragma once
00340 #endif /* STLSOFT_PPF_pragma_once_SUPPORT */
00341 
00342 /* ////////////////////////////////////////////////////////////////////// */
00343 
00344 #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_CHARACTER */
00345 
00346 /* ///////////////////////////// end of file //////////////////////////// */

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