w_base.cpp

00001 /* -*- mode:C++; c-basic-offset:4 -*-
00002      Shore-MT -- Multi-threaded port of the SHORE storage manager
00003    
00004                        Copyright (c) 2007-2009
00005       Data Intensive Applications and Systems Labaratory (DIAS)
00006                Ecole Polytechnique Federale de Lausanne
00007    
00008                          All Rights Reserved.
00009    
00010    Permission to use, copy, modify and distribute this software and
00011    its documentation is hereby granted, provided that both the
00012    copyright notice and this permission notice appear in all copies of
00013    the software, derivative works or modified versions, and any
00014    portions thereof, and that both notices appear in supporting
00015    documentation.
00016    
00017    This code is distributed in the hope that it will be useful, but
00018    WITHOUT ANY WARRANTY; without even the implied warranty of
00019    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS
00020    DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
00021    RESULTING FROM THE USE OF THIS SOFTWARE.
00022 */
00023 
00024 /*<std-header orig-src='shore'>
00025 
00026  $Id: w_base.cpp,v 1.55 2010/05/26 01:20:23 nhall Exp $
00027 
00028 SHORE -- Scalable Heterogeneous Object REpository
00029 
00030 Copyright (c) 1994-99 Computer Sciences Department, University of
00031                       Wisconsin -- Madison
00032 All Rights Reserved.
00033 
00034 Permission to use, copy, modify and distribute this software and its
00035 documentation is hereby granted, provided that both the copyright
00036 notice and this permission notice appear in all copies of the
00037 software, derivative works or modified versions, and any portions
00038 thereof, and that both notices appear in supporting documentation.
00039 
00040 THE AUTHORS AND THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY
00041 OF WISCONSIN - MADISON ALLOW FREE USE OF THIS SOFTWARE IN ITS
00042 "AS IS" CONDITION, AND THEY DISCLAIM ANY LIABILITY OF ANY KIND
00043 FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
00044 
00045 This software was developed with support by the Advanced Research
00046 Project Agency, ARPA order number 018 (formerly 8230), monitored by
00047 the U.S. Army Research Laboratory under contract DAAB07-91-C-Q518.
00048 Further funding for this work was provided by DARPA through
00049 Rome Research Laboratory Contract No. F30602-97-2-0247.
00050 
00051 */
00052 
00053 #include "w_defines.h"
00054 
00055 /*  -- do not edit anything above this line --   </std-header>*/
00056 
00057 #define W_SOURCE
00058 
00059 #ifdef __GNUG__
00060 #pragma implementation "w_base.h"
00061 #endif
00062 
00063 #include <w_base.h>
00064 #include <sstream>
00065 
00066 /*--------------------------------------------------------------*
00067  *  constants for w_base_t                                      *
00068  *--------------------------------------------------------------*/
00069 const w_base_t::int1_t    w_base_t::int1_max  = 0x7f;
00070 const w_base_t::int1_t    w_base_t::int1_min  = (const w_base_t::int1_t) 0x80u;
00071 const w_base_t::uint1_t   w_base_t::uint1_max = 0xff;
00072 const w_base_t::uint1_t   w_base_t::uint1_min = 0x0;
00073 const w_base_t::int2_t    w_base_t::int2_max  = 0x7fff;
00074 const w_base_t::int2_t    w_base_t::int2_min  = (const w_base_t::int2_t) 0x8000u;
00075 const w_base_t::uint2_t   w_base_t::uint2_max = 0xffff;
00076 const w_base_t::uint2_t   w_base_t::uint2_min = 0x0;
00077 const w_base_t::int4_t    w_base_t::int4_max  = 0x7fffffff;
00078 const w_base_t::int4_t    w_base_t::int4_min  = 0x80000000;
00079 const w_base_t::uint4_t   w_base_t::uint4_max = 0xffffffff;
00080 const w_base_t::uint4_t   w_base_t::uint4_min = 0x0;
00081 
00082 #    define LONGLONGCONSTANT(i) i##LL
00083 #    define ULONGLONGCONSTANT(i) i##ULL
00084 
00085 #ifdef ARCH_LP64
00086 
00087 const w_base_t::uint8_t   w_base_t::uint8_max =
00088                 ULONGLONGCONSTANT(0xffffffffffffffff);
00089 const w_base_t::uint8_t   w_base_t::uint8_min =
00090                 ULONGLONGCONSTANT(0x0);
00091 const w_base_t::int8_t   w_base_t::int8_max =
00092                 LONGLONGCONSTANT(0x7fffffffffffffff);
00093 const w_base_t::int8_t   w_base_t::int8_min =
00094                 LONGLONGCONSTANT(0x8000000000000000);
00095 #else
00096 
00097 const w_base_t::uint8_t   w_base_t::uint8_max =
00098                 ULONGLONGCONSTANT(0xffffffff);
00099 const w_base_t::uint8_t   w_base_t::uint8_min =
00100                 ULONGLONGCONSTANT(0x0);
00101 const w_base_t::int8_t   w_base_t::int8_max =
00102                 LONGLONGCONSTANT(0x7fffffff);
00103 const w_base_t::int8_t   w_base_t::int8_min =
00104                 LONGLONGCONSTANT(0x80000000);
00105 #endif
00106 
00107 ostream&
00108 operator<<(ostream& o, const w_base_t&)
00109 {
00110     w_base_t::assert_failed("w_base::operator<<() called", __FILE__, __LINE__);
00111     return o;
00112 }
00113 
00114 void
00115 w_base_t::assert_failed(
00116     const char*        desc,
00117     const char*        file,
00118     uint4_t        line)
00119 {
00120     stringstream os;
00121     /* make the error look something like an RC in the meantime. */
00122     os << "assertion failure: " << desc << endl
00123         << "1. error in "
00124         << file << ':' << line
00125         << " Assertion failed" << endl
00126         << "\tcalled from:" << endl
00127         << "\t0) " << file << ':' << line
00128         << endl << ends;
00129     fprintf(stderr, "%s", os.str().c_str());
00130     abort();
00131 }
00132 
00133 
00134 typedef ios::fmtflags  fmtflags;
00135 
00136 #include <w_strstream.h>
00137 
00138 /* name is local to this file */
00139 static w_base_t::uint8_t    
00140 __strtou8(        
00141     const char *str,
00142     char **endptr,
00143     int     base,
00144     bool  is_signed
00145 )
00146 {
00147 #if defined(ARCH_LP64)
00148     return is_signed? strtol(str, endptr, base): strtoul(str, endptr, base);
00149 #else
00150     return is_signed? strtoll(str, endptr, base): strtoull(str, endptr, base);
00151 #endif
00152 }
00153 
00154 w_base_t::int8_t    
00155 w_base_t::strtoi8(
00156     const char *str,
00157     char **endptr,
00158     int     base
00159 )
00160 {
00161     w_base_t::int8_t    i8;
00162     w_base_t::int8_t    u8 =
00163         __strtou8(str, endptr, base, true);
00164     i8 = w_base_t::int8_t(u8);
00165     return i8;
00166 }
00167 
00168 w_base_t::uint8_t    
00169 w_base_t::strtou8(
00170     const char *str,
00171     char **endptr,
00172     int     base
00173 )
00174 {
00175     return __strtou8(str, endptr, base, false);
00176 }
00177 
00178 #if defined(SOLARIS2)
00179 #include <ieeefp.h>
00180 #else
00181 #include <cmath>
00182 #endif
00183 
00184 bool
00185 w_base_t::is_finite(const f8_t x)
00186 {
00187     bool value = false;
00188     value = finite(x);
00189     return value;
00190 }
00191 
00192 bool
00193 w_base_t::is_infinite(const f8_t x)
00194 {
00195     bool value = false;
00196 #if defined(SOLARIS2)
00197     value = !finite(x) && !isnand(x);
00198 #elif defined(MacOSX) && W_GCC_THIS_VER >= W_GCC_VER(3,0)
00199     value = !finite(x) && !__isnand(x);
00200 #else
00201     value = !finite(x) && !isnan(x);
00202 #endif
00203     return value;
00204 }
00205 
00206 bool
00207 w_base_t::is_nan(const f8_t x)
00208 {
00209     bool value = false;
00210 #if defined(SOLARIS2)
00211     value = isnand(x);
00212 #elif defined(MacOSX) && W_GCC_THIS_VER >= W_GCC_VER(3,0)
00213     value = __isnand(x);
00214 #else
00215     value = isnan(x);
00216 #endif
00217     return value;
00218 }
00219 
00220 bool
00221 w_base_t::is_infinite_or_nan(const f8_t x)
00222 {
00223     bool value = false;
00224     value = !finite(x);
00225     return value;
00226 }
00227 
00228 
00229 void    w_base_t::abort()
00230 {
00231     cout.flush();
00232     cerr.flush();
00233     ::abort();
00234 }
00235 
00236 
00237 /* Provide our own pure_virtual() so we can generate abort's if
00238    a virtual function is abused.  Name choice is somewhat
00239    hacky, since it is system and compiler dependent. */
00240 
00241 #ifdef __GNUG__
00242 #define    PURE_VIRTUAL    extern "C" void __pure_virtual()
00243 #else
00244 #define    PURE_VIRTUAL    void pure_virtual()
00245 #endif
00246 
00247 PURE_VIRTUAL
00248 {
00249     /* Just in case the iostreams generate another error ... */
00250     static    bool    called = false;
00251     if (!called)
00252         cerr << "** Pure virtual function called" << endl;
00253     called = true;
00254 
00255     w_base_t::abort();
00256     /*NOTREACHED*/
00257 }
00258 
00259 
00260 #include <netinet/in.h>
00261 w_base_t::uint2_t w_base_t::w_ntohs(w_base_t::uint2_t net)
00262 {
00263     return ntohs(net);
00264 }
00265 
00266 w_base_t::uint2_t w_base_t::w_htons(w_base_t::uint2_t host)
00267 {
00268     return htons(host);
00269 }
00270 
00271 w_base_t::uint4_t w_base_t::w_ntohl(w_base_t::uint4_t net)
00272 {
00273     return ntohl(net);
00274 }
00275 
00276 w_base_t::uint4_t w_base_t::w_htonl(w_base_t::uint4_t host)
00277 {
00278     return htonl(host);
00279 }

Generated on Wed Jul 7 17:22:32 2010 for Shore Storage Manager by  doxygen 1.4.7