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

pantheios/inserters/boolean.hpp

Go to the documentation of this file.
00001 /* /////////////////////////////////////////////////////////////////////////
00002  * File:        pantheios/inserters/boolean.hpp
00003  *
00004  * Purpose:     String inserter for booleans.
00005  *
00006  * Created:     3rd August 2008
00007  * Updated:     5th May 2010
00008  *
00009  * Home:        http://www.pantheios.org/
00010  *
00011  * Copyright (c) 2008-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 names of Matthew Wilson and Synesis Software nor the names
00024  *   of any contributors may be used to endorse or promote products derived
00025  *   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 
00047 #ifndef PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_BOOLEAN
00048 #define PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_BOOLEAN
00049 
00050 /* /////////////////////////////////////////////////////////////////////////
00051  * Version information
00052  */
00053 
00054 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00055 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_BOOLEAN_MAJOR    1
00056 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_BOOLEAN_MINOR    3
00057 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_BOOLEAN_REVISION 2
00058 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_BOOLEAN_EDIT     15
00059 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
00060 
00061 /* /////////////////////////////////////////////////////////////////////////
00062  * Includes
00063  */
00064 
00065 #ifndef PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS
00066 # include <pantheios/pantheios.h>
00067 #endif /* !PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS */
00068 
00069 #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_STRING_H_FWD
00070 # include <stlsoft/shims/access/string/fwd.h>
00071 #endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_STRING_H_FWD */
00072 
00073 /* /////////////////////////////////////////////////////////////////////////
00074  * Namespace
00075  */
00076 
00077 #if !defined(PANTHEIOS_NO_NAMESPACE)
00078 namespace pantheios
00079 {
00080 #else /* ? !PANTHEIOS_NO_NAMESPACE */
00081 # if defined(__RPCNDR_H__)
00082 #  error pantheios::boolean may not be used with Windows when namespace is suspended. If you are including pantheios/inserters.hpp, try including only those specific inserter files that you need
00083 # endif /* rpcndr.h */
00084 #endif /* !PANTHEIOS_NO_NAMESPACE */
00085 
00086 /* /////////////////////////////////////////////////////////////////////////
00087  * Classes
00088  */
00089 
00112 class boolean
00113 {
00116 public:
00117     typedef boolean     class_type;
00119 
00122 public:
00126     explicit boolean(bool value)
00127         : m_value(value)
00128     {}
00129 private:
00130     class_type& operator =(class_type const&);
00132 
00135 public:
00136     static void set_value_strings(pan_char_t const* falseName, pan_char_t const* trueName) /* throw(std::bad_alloc) */;
00138 
00141 public:
00143     pan_char_t const* data() const
00144     {
00145         return get_slice_(m_value)->ptr;
00146     }
00148     pan_char_t const* c_str() const
00149     {
00150         return get_slice_(m_value)->ptr;
00151     }
00153     size_t      length() const
00154     {
00155         return get_slice_(m_value)->len;
00156     }
00158 
00161 private:
00162     static pan_slice_t const* get_slice_(bool value);
00164 
00167 private:
00168     const bool m_value;
00170 };
00171 
00172 /* /////////////////////////////////////////////////////////////////////////
00173  * Implementation
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 
00187 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00188 
00189 inline wchar_t const* c_str_data_w(boolean const& b)
00190 {
00191     return b.data();
00192 }
00193 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00194 
00195 inline char const* c_str_data_a(boolean const& b)
00196 {
00197     return b.data();
00198 }
00199 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00200 
00201 inline pan_char_t const* c_str_data(boolean const& b)
00202 {
00203     return b.data();
00204 }
00205 
00206 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00207 
00208 inline size_t c_str_len_w(boolean const& b)
00209 {
00210     return b.length();
00211 }
00212 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00213 
00214 inline size_t c_str_len_a(boolean const& b)
00215 {
00216     return b.length();
00217 }
00218 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00219 
00220 inline size_t c_str_len(boolean const& b)
00221 {
00222     return b.length();
00223 }
00224 
00225 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00226 
00227 inline wchar_t const* c_str_ptr_w(boolean const& b)
00228 {
00229     return b.c_str();
00230 }
00231 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00232 
00233 inline char const* c_str_ptr_a(boolean const& b)
00234 {
00235     return b.c_str();
00236 }
00237 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00238 
00239 inline pan_char_t const* c_str_ptr(boolean const& b)
00240 {
00241     return b.c_str();
00242 }
00243 
00244 # if !defined(PANTHEIOS_NO_NAMESPACE)
00245 } /* namespace shims */
00246 
00247 #  if defined(STLSOFT_COMPILER_IS_GCC)
00248     /* GCC does not seem to correctly handle the phases of
00249      * processing of C++ templates, so we need to 'use' the
00250      * shims into the same namespace as the inserter class
00251      * in order that ADL can suffice instead.
00252      */
00253 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00254     using ::pantheios::shims::c_str_data_w;
00255     using ::pantheios::shims::c_str_len_w;
00256     using ::pantheios::shims::c_str_ptr_w;
00257 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00258     using ::pantheios::shims::c_str_data_a;
00259     using ::pantheios::shims::c_str_len_a;
00260     using ::pantheios::shims::c_str_ptr_a;
00261 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00262     using ::pantheios::shims::c_str_data;
00263     using ::pantheios::shims::c_str_len;
00264     using ::pantheios::shims::c_str_ptr;
00265 #  endif /* compiler */
00266 
00267 # endif /* !PANTHEIOS_NO_NAMESPACE */
00268 
00269 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
00270 
00271 /* /////////////////////////////////////////////////////////////////////////
00272  * Namespace
00273  */
00274 
00275 #if !defined(PANTHEIOS_NO_NAMESPACE)
00276 } /* namespace pantheios */
00277 
00278 namespace stlsoft
00279 {
00280     // 'Export' the string access shims into the STLSoft namespace
00281     //
00282     // c_str_ptr(_a) is not necessary for version 1.0 of Pantheios, but it's
00283     // defined and exported in order to allow for the case where someone
00284     // may find a legitimate use for the conversion classes additional to
00285     // the type-tunneling of the Pantheios API.
00286 
00287 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00288     using ::pantheios::shims::c_str_data_w;
00289     using ::pantheios::shims::c_str_len_w;
00290     using ::pantheios::shims::c_str_ptr_w;
00291 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00292     using ::pantheios::shims::c_str_data_a;
00293     using ::pantheios::shims::c_str_len_a;
00294     using ::pantheios::shims::c_str_ptr_a;
00295 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00296 
00297     using ::pantheios::shims::c_str_data;
00298     using ::pantheios::shims::c_str_len;
00299     using ::pantheios::shims::c_str_ptr;
00300 }
00301 
00302 #endif /* !PANTHEIOS_NO_NAMESPACE */
00303 
00304 /* /////////////////////////////////////////////////////////////////////////
00305  * Inclusion
00306  */
00307 
00308 #ifdef STLSOFT_PPF_pragma_once_SUPPORT
00309 # pragma once
00310 #endif /* STLSOFT_PPF_pragma_once_SUPPORT */
00311 
00312 /* ////////////////////////////////////////////////////////////////////// */
00313 
00314 #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_BOOLEAN */
00315 
00316 /* ///////////////////////////// end of file //////////////////////////// */

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