00001 /* ///////////////////////////////////////////////////////////////////////// 00002 * File: pantheios/inserters/real.hpp 00003 * 00004 * Purpose: String inserters for fundamental types 00005 * 00006 * Created: 21st June 2005 00007 * Updated: 1st September 2006 00008 * 00009 * Author: Matthew Wilson 00010 * 00011 * Home: http://www.pantheios.org/ 00012 * 00013 * Copyright: Matthew Wilson and Synesis Software Pty Ltd, 1999-2005. 00014 * Matthew Wilson, 2005-2006. 00015 * 00016 * Redistribution and use in source and binary forms, with or without 00017 * modification, are permitted provided that the following conditions are met: 00018 * 00019 * - Redistributions of source code must retain the above copyright notice, this 00020 * list of conditions and the following disclaimer. 00021 * - Redistributions in binary form must reproduce the above copyright notice, 00022 * this list of conditions and the following disclaimer in the documentation 00023 * and/or other materials provided with the distribution. 00024 * - Neither the names of Matthew Wilson and Synesis Software nor the names of 00025 * any contributors may be used to endorse or promote products derived from 00026 * this software without specific prior written permission. 00027 * 00028 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00029 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00030 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00031 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00032 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00033 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00034 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00035 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00036 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00037 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00038 * POSSIBILITY OF SUCH DAMAGE. 00039 * 00040 * ////////////////////////////////////////////////////////////////////// */ 00041 00042 00049 #ifndef PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_REAL 00050 #define PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_REAL 00051 00052 /* ///////////////////////////////////////////////////////////////////////// 00053 * Version information 00054 */ 00055 00056 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION 00057 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_REAL_MAJOR 2 00058 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_REAL_MINOR 0 00059 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_REAL_REVISION 8 00060 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_REAL_EDIT 8 00061 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */ 00062 00063 /* ///////////////////////////////////////////////////////////////////////// 00064 * Includes 00065 */ 00066 00067 #include <pantheios/pantheios.hpp> 00068 #include <pantheios/inserters/fmt.hpp> 00069 00070 #include <stlsoft/shims/access/string/fwd.h> 00071 00072 /* ///////////////////////////////////////////////////////////////////////// 00073 * Namespace 00074 */ 00075 00076 #if !defined(PANTHEIOS_NO_NAMESPACE) 00077 namespace pantheios 00078 { 00079 00080 #endif /* !PANTHEIOS_NO_NAMESPACE */ 00081 00082 /* ///////////////////////////////////////////////////////////////////////// 00083 * Inserter classes 00084 */ 00085 00113 class real 00114 { 00115 public: 00116 typedef real class_type; 00117 00118 public: 00120 explicit real(float value, int widthAndFormat = 0); 00122 explicit real(double value, int widthAndFormat = 0); 00124 explicit real(long double value, int widthAndFormat = 0); 00125 00126 private: 00127 explicit real(int); // Prevents implicit conversion from an integer 00128 00129 public: 00131 char const *data() const; 00133 char const *c_str() const; 00135 size_t length() const; 00136 00137 private: 00138 void construct_() const; 00139 void construct_(); 00140 00141 private: 00142 enum RealSize 00143 { 00144 typeIsFloat = -1 00145 , typeIsDouble = -2 00146 , typeIsLongDouble = -3 00147 }; 00148 00149 union u 00150 { 00151 float fValue; 00152 double dValue; 00153 long double ldValue; 00154 }; 00155 00156 u m_value; // The value, copied for lazy conversion 00157 size_t m_len; // Length, and marker for type: 1 == float; 2 == double; 3 == long double 00158 char m_sz[256]; // Marker for converted, if m_sz[0] == '\0' 00159 const int m_widthAndFormat; 00160 00161 private: 00162 #if !defined(STLSOFT_COMPILER_IS_GCC) 00163 real(class_type const &); 00164 #endif /* compiler */ 00165 class_type &operator =(class_type const &); 00166 }; 00167 00168 /* ///////////////////////////////////////////////////////////////////////// 00169 * String Access Shims 00170 */ 00171 00172 inline char const *c_str_data_a(real const &r) 00173 { 00174 return r.data(); 00175 } 00176 inline char const *c_str_data(real const &r) 00177 { 00178 return r.data(); 00179 } 00180 00181 inline size_t c_str_len_a(real const &r) 00182 { 00183 return r.length(); 00184 } 00185 inline size_t c_str_len(real const &r) 00186 { 00187 return r.length(); 00188 } 00189 00190 inline char const *c_str_ptr_a(real const &r) 00191 { 00192 return r.c_str(); 00193 } 00194 inline char const *c_str_ptr(real const &r) 00195 { 00196 return r.c_str(); 00197 } 00198 00199 /* ///////////////////////////////////////////////////////////////////////// 00200 * Namespace 00201 */ 00202 00203 #if !defined(PANTHEIOS_NO_NAMESPACE) 00204 } /* namespace pantheios */ 00205 00206 namespace stlsoft 00207 { 00208 // 'Export' the string access shims into the STLSoft namespace 00209 // 00210 // c_str_ptr(_a) is not necessary for version 1.0 of Pantheios, but it's 00211 // defined and exported in order to allow for the case where someone 00212 // may find a legitimate use for the conversion classes additional to 00213 // the type-tunnelling of the Panthieos API. 00214 00215 using ::pantheios::c_str_data_a; 00216 using ::pantheios::c_str_data; 00217 00218 using ::pantheios::c_str_len; 00219 using ::pantheios::c_str_len_a; 00220 00221 using ::pantheios::c_str_ptr_a; 00222 using ::pantheios::c_str_ptr; 00223 } 00224 00225 #endif /* !PANTHEIOS_NO_NAMESPACE */ 00226 00227 /* ///////////////////////////////////////////////////////////////////////// 00228 * Inclusion 00229 */ 00230 00231 #ifdef STLSOFT_CF_PRAGMA_ONCE_SUPPORT 00232 # pragma once 00233 #endif /* STLSOFT_CF_PRAGMA_ONCE_SUPPORT */ 00234 00235 /* ////////////////////////////////////////////////////////////////////// */ 00236 00237 #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_REAL */ 00238 00239 /* ////////////////////////////////////////////////////////////////////// */
|
|
pantheios Library documentation © Matthew Wilson, 2006 |
|