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:     20th September 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 
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      4
00083 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_CHARACTER_REVISION   1
00084 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_CHARACTER_EDIT       22
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(char value);
00154 
00155 private:
00156     explicit character(int); // Prevents implicit conversion from an integer
00157 
00158 public:
00160     pan_char_t const*   data() const;
00162     pan_char_t const*   c_str() const;
00164     size_t              length() const;
00165 
00166 private:
00167     pan_char_t  m_value[2];
00168 
00169 private:
00170 #if !defined(STLSOFT_COMPILER_IS_GCC)
00171     character(class_type const&);
00172 #endif /* compiler */
00173     class_type& operator =(class_type const&);
00174 };
00175 
00176 /* /////////////////////////////////////////////////////////////////////////
00177  * String Access Shims
00178  */
00179 
00180 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00181 
00182 # if !defined(PANTHEIOS_NO_NAMESPACE)
00183 namespace shims
00184 {
00185 # endif /* !PANTHEIOS_NO_NAMESPACE */
00186 
00188 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00189 inline wchar_t const* c_str_data_w(character const& r)
00190 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00191 inline char const* c_str_data_a(character const& r)
00192 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00193 {
00194     return r.data();
00195 }
00197 inline pan_char_t const* c_str_data(character const& r)
00198 {
00199     return r.data();
00200 }
00201 
00203 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00204 inline size_t c_str_len_w(character const& r)
00205 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00206 inline size_t c_str_len_a(character const& r)
00207 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00208 {
00209     return r.length();
00210 }
00212 inline size_t c_str_len(character const& r)
00213 {
00214     return r.length();
00215 }
00216 
00218 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00219 inline wchar_t const* c_str_ptr_a(character const& r)
00220 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00221 inline char const* c_str_ptr_a(character const& r)
00222 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00223 {
00224     return r.c_str();
00225 }
00227 inline pan_char_t const* c_str_ptr(character const& r)
00228 {
00229     return r.c_str();
00230 }
00231 
00232 # if !defined(PANTHEIOS_NO_NAMESPACE)
00233 } /* namespace shims */
00234 
00235 #  if defined(STLSOFT_COMPILER_IS_GCC)
00236     /* GCC does not seem to correctly handle the phases of
00237      * processing of C++ templates, so we need to 'use' the
00238      * shims into the same namespace as the inserter class
00239      * in order that ADL can suffice instead.
00240      */
00241 #   ifdef PANTHEIOS_USE_WIDE_STRINGS
00242     using ::pantheios::shims::c_str_data_w;
00243     using ::pantheios::shims::c_str_len_w;
00244     using ::pantheios::shims::c_str_ptr_w;
00245 #   else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00246     using ::pantheios::shims::c_str_data_a;
00247     using ::pantheios::shims::c_str_len_a;
00248     using ::pantheios::shims::c_str_ptr_a;
00249 #   endif /* PANTHEIOS_USE_WIDE_STRINGS */
00250     using ::pantheios::shims::c_str_data;
00251     using ::pantheios::shims::c_str_len;
00252     using ::pantheios::shims::c_str_ptr;
00253 #  endif /* compiler */
00254 
00255 # endif /* !PANTHEIOS_NO_NAMESPACE */
00256 
00257 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
00258 
00259 /* /////////////////////////////////////////////////////////////////////////
00260  * Implementation
00261  */
00262 
00263 inline /* explicit */ character::character(char value)
00264 {
00265     m_value[0]  =   value;
00266     m_value[1]  =   '\0';
00267 }
00268 
00269 inline pan_char_t const* character::data() const
00270 {
00271     return m_value;
00272 }
00273 
00274 inline pan_char_t const* character::c_str() const
00275 {
00276     return m_value;
00277 }
00278 
00279 inline size_t character::length() const
00280 {
00281     return 1;
00282 }
00283 
00284 /* /////////////////////////////////////////////////////////////////////////
00285  * Namespace
00286  */
00287 
00288 #if !defined(PANTHEIOS_NO_NAMESPACE)
00289 } /* namespace pantheios */
00290 
00291 namespace stlsoft
00292 {
00293     // 'Export' the string access shims into the STLSoft namespace
00294     //
00295     // c_str_ptr(_a) is not necessary for version 1.0 of Pantheios, but it's
00296     // defined and exported in order to allow for the case where someone
00297     // may find a legitimate use for the conversion classes additional to
00298     // the type-tunneling of the Pantheios API.
00299 
00300 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00301     using ::pantheios::shims::c_str_data_w;
00302     using ::pantheios::shims::c_str_len_w;
00303     using ::pantheios::shims::c_str_ptr_w;
00304 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00305     using ::pantheios::shims::c_str_data_a;
00306     using ::pantheios::shims::c_str_len_a;
00307     using ::pantheios::shims::c_str_ptr_a;
00308 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00309     using ::pantheios::shims::c_str_data;
00310     using ::pantheios::shims::c_str_len;
00311     using ::pantheios::shims::c_str_ptr;
00312 }
00313 
00314 #endif /* !PANTHEIOS_NO_NAMESPACE */
00315 
00316 /* /////////////////////////////////////////////////////////////////////////
00317  * Inclusion
00318  */
00319 
00320 #ifdef STLSOFT_PPF_pragma_once_SUPPORT
00321 # pragma once
00322 #endif /* STLSOFT_PPF_pragma_once_SUPPORT */
00323 
00324 /* ////////////////////////////////////////////////////////////////////// */
00325 
00326 #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_CHARACTER */
00327 
00328 /* ///////////////////////////// end of file //////////////////////////// */

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