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:     18th June 2012
00008  *
00009  * Home:        http://www.pantheios.org/
00010  *
00011  * Copyright (c) 2008-2012, 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 3
00058 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_BOOLEAN_EDIT     17
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     virtual
00163     pan_slice_t const* get_slice_(bool value) const
00164     {
00165         return get_slice_(0, value);
00166     }
00167 protected:
00168     static pan_slice_t const* get_slice_(
00169         int     index
00170     ,   bool    value
00171     );
00173 
00176 protected:
00177     const bool m_value;
00179 };
00180 
00181 /* /////////////////////////////////////////////////////////////////////////
00182  * Implementation
00183  */
00184 
00185 /* /////////////////////////////////////////////////////////////////////////
00186  * String Access Shims
00187  */
00188 
00189 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00190 
00191 # if !defined(PANTHEIOS_NO_NAMESPACE)
00192 namespace shims
00193 {
00194 # endif /* !PANTHEIOS_NO_NAMESPACE */
00195 
00196 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00197 
00198 inline wchar_t const* c_str_data_w(boolean const& b)
00199 {
00200     return b.data();
00201 }
00202 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00203 
00204 inline char const* c_str_data_a(boolean const& b)
00205 {
00206     return b.data();
00207 }
00208 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00209 
00210 inline pan_char_t const* c_str_data(boolean const& b)
00211 {
00212     return b.data();
00213 }
00214 
00215 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00216 
00217 inline size_t c_str_len_w(boolean const& b)
00218 {
00219     return b.length();
00220 }
00221 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00222 
00223 inline size_t c_str_len_a(boolean const& b)
00224 {
00225     return b.length();
00226 }
00227 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00228 
00229 inline size_t c_str_len(boolean const& b)
00230 {
00231     return b.length();
00232 }
00233 
00234 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00235 
00236 inline wchar_t const* c_str_ptr_w(boolean const& b)
00237 {
00238     return b.c_str();
00239 }
00240 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00241 
00242 inline char const* c_str_ptr_a(boolean const& b)
00243 {
00244     return b.c_str();
00245 }
00246 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00247 
00248 inline pan_char_t const* c_str_ptr(boolean const& b)
00249 {
00250     return b.c_str();
00251 }
00252 
00253 # if !defined(PANTHEIOS_NO_NAMESPACE)
00254 } /* namespace shims */
00255 
00256 #  if defined(STLSOFT_COMPILER_IS_GCC)
00257     /* GCC does not seem to correctly handle the phases of
00258      * processing of C++ templates, so we need to 'use' the
00259      * shims into the same namespace as the inserter class
00260      * in order that ADL can suffice instead.
00261      */
00262 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00263     using ::pantheios::shims::c_str_data_w;
00264     using ::pantheios::shims::c_str_len_w;
00265     using ::pantheios::shims::c_str_ptr_w;
00266 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00267     using ::pantheios::shims::c_str_data_a;
00268     using ::pantheios::shims::c_str_len_a;
00269     using ::pantheios::shims::c_str_ptr_a;
00270 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00271     using ::pantheios::shims::c_str_data;
00272     using ::pantheios::shims::c_str_len;
00273     using ::pantheios::shims::c_str_ptr;
00274 #  endif /* compiler */
00275 
00276 # endif /* !PANTHEIOS_NO_NAMESPACE */
00277 
00278 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
00279 
00280 /* /////////////////////////////////////////////////////////////////////////
00281  * Namespace
00282  */
00283 
00284 #if !defined(PANTHEIOS_NO_NAMESPACE)
00285 } /* namespace pantheios */
00286 
00287 namespace stlsoft
00288 {
00289     // 'Export' the string access shims into the STLSoft namespace
00290     //
00291     // c_str_ptr(_a) is not necessary for version 1.0 of Pantheios, but it's
00292     // defined and exported in order to allow for the case where someone
00293     // may find a legitimate use for the conversion classes additional to
00294     // the type-tunneling of the Pantheios API.
00295 
00296 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00297     using ::pantheios::shims::c_str_data_w;
00298     using ::pantheios::shims::c_str_len_w;
00299     using ::pantheios::shims::c_str_ptr_w;
00300 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00301     using ::pantheios::shims::c_str_data_a;
00302     using ::pantheios::shims::c_str_len_a;
00303     using ::pantheios::shims::c_str_ptr_a;
00304 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00305 
00306     using ::pantheios::shims::c_str_data;
00307     using ::pantheios::shims::c_str_len;
00308     using ::pantheios::shims::c_str_ptr;
00309 }
00310 
00311 #endif /* !PANTHEIOS_NO_NAMESPACE */
00312 
00313 /* /////////////////////////////////////////////////////////////////////////
00314  * Inclusion
00315  */
00316 
00317 #ifdef STLSOFT_PPF_pragma_once_SUPPORT
00318 # pragma once
00319 #endif /* STLSOFT_PPF_pragma_once_SUPPORT */
00320 
00321 /* ////////////////////////////////////////////////////////////////////// */
00322 
00323 #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_BOOLEAN */
00324 
00325 /* ///////////////////////////// end of file //////////////////////////// */

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