| 1 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 |
| 2 | // A.cpp simple class test |
| 3 | |
| 4 | // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . |
| 5 | // Use, modification and distribution is subject to the Boost Software |
| 6 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
| 7 | // http://www.boost.org/LICENSE_1_0.txt) |
| 8 | |
| 9 | // See http://www.boost.org for updates, documentation, and revision history. |
| 10 | |
| 11 | #include <cassert> |
| 12 | #include <cstdlib> // rand() |
| 13 | #include <cstddef> // size_t |
| 14 | |
| 15 | |
| 16 | #include <boost/config.hpp> |
| 17 | #if BOOST_CXX_VERSION > 199711L // only include floating point if C++ version >= C++11 |
| 18 | #include <boost/math/special_functions/next.hpp> |
| 19 | #endif |
| 20 | #if defined(BOOST_NO_STDC_NAMESPACE) |
| 21 | namespace std{ |
| 22 | using ::rand; |
| 23 | using ::size_t; |
| 24 | } |
| 25 | #endif |
| 26 | |
| 27 | #include <boost/detail/workaround.hpp> |
| 28 | #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) |
| 29 | #include <boost/archive/dinkumware.hpp> |
| 30 | #endif |
| 31 | |
| 32 | #include "A.hpp" |
| 33 | |
| 34 | template<class S> |
| 35 | void randomize(S &x) |
| 36 | { |
| 37 | assert(0 == x.size()); |
| 38 | for(;;){ |
| 39 | unsigned int i = std::rand() % 27; |
| 40 | if(0 == i) |
| 41 | break; |
| 42 | x += static_cast<typename S::value_type>('a' - 1 + i); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | template<class T> |
| 47 | void accumulate(std::size_t & s, const T & t){ |
| 48 | const char * tptr = (const char *)(& t); |
| 49 | unsigned int count = sizeof(t); |
| 50 | while(count-- > 0){ |
| 51 | s += *tptr++; |
| 52 | } |
| 53 | } |
| 54 | A_DLL_DECL |
| 55 | A::operator std::size_t () const { |
| 56 | std::size_t retval = 0; |
| 57 | accumulate(s&: retval, t: b); |
| 58 | #ifndef BOOST_NO_INT64_T |
| 59 | accumulate(s&: retval, t: f); |
| 60 | accumulate(s&: retval, t: g); |
| 61 | #endif |
| 62 | accumulate(s&: retval, t: l); |
| 63 | accumulate(s&: retval, t: m); |
| 64 | accumulate(s&: retval, t: n); |
| 65 | accumulate(s&: retval, t: o); |
| 66 | accumulate(s&: retval, t: p); |
| 67 | accumulate(s&: retval, t: q); |
| 68 | #ifndef BOOST_NO_CWCHAR |
| 69 | accumulate(s&: retval, t: r); |
| 70 | #endif |
| 71 | accumulate(s&: retval, t: c); |
| 72 | accumulate(s&: retval, t: s); |
| 73 | accumulate(s&: retval, t); |
| 74 | accumulate(s&: retval, t: u); |
| 75 | accumulate(s&: retval, t: v); |
| 76 | return retval; |
| 77 | } |
| 78 | |
| 79 | #if defined(_MSC_VER) |
| 80 | #pragma warning(push) // Save warning settings. |
| 81 | #pragma warning(disable : 4244) // Disable possible loss of data warning |
| 82 | #endif |
| 83 | |
| 84 | A_DLL_DECL |
| 85 | A::A() : |
| 86 | b(true), |
| 87 | #ifndef BOOST_NO_INT64_T |
| 88 | f(static_cast<boost::int64_t>(std::rand()) * static_cast<boost::int64_t>(std::rand())), |
| 89 | g(static_cast<boost::uint64_t>(std::rand()) * static_cast<boost::uint64_t>(std::rand())), |
| 90 | #endif |
| 91 | l(static_cast<enum h>(std::rand() % 3)), |
| 92 | m(std::rand()), |
| 93 | n(std::rand()), |
| 94 | o(std::rand()), |
| 95 | p(std::rand()), |
| 96 | q(std::rand()), |
| 97 | #ifndef BOOST_NO_CWCHAR |
| 98 | r(std::rand()), |
| 99 | #endif |
| 100 | c(0xff & std::rand()), |
| 101 | s(0xff & std::rand()), |
| 102 | t(0xff & std::rand()), |
| 103 | u(std::rand()), |
| 104 | v(std::rand()), |
| 105 | w((float)std::rand()), |
| 106 | x((double)std::rand()) |
| 107 | { |
| 108 | randomize(x&: y); |
| 109 | #ifndef BOOST_NO_STD_WSTRING |
| 110 | randomize(x&: z); |
| 111 | #endif |
| 112 | } |
| 113 | |
| 114 | #if defined(_MSC_VER) |
| 115 | #pragma warning(pop) // Restore warnings to previous state. |
| 116 | #endif |
| 117 | |
| 118 | A_DLL_DECL bool |
| 119 | A::operator==(const A &rhs) const { |
| 120 | if(b != rhs.b) |
| 121 | return false; |
| 122 | if(l != rhs.l) |
| 123 | return false; |
| 124 | #ifndef BOOST_NO_INT64_T |
| 125 | if(f != rhs.f) |
| 126 | return false; |
| 127 | if(g != rhs.g) |
| 128 | return false; |
| 129 | #endif |
| 130 | if(m != rhs.m) |
| 131 | return false; |
| 132 | if(n != rhs.n) |
| 133 | return false; |
| 134 | if(o != rhs.o) |
| 135 | return false; |
| 136 | if(p != rhs.p) |
| 137 | return false; |
| 138 | if(q != rhs.q) |
| 139 | return false; |
| 140 | #ifndef BOOST_NO_CWCHAR |
| 141 | if(r != rhs.r) |
| 142 | return false; |
| 143 | #endif |
| 144 | if(c != rhs.c) |
| 145 | return false; |
| 146 | if(s != rhs.s) |
| 147 | return false; |
| 148 | if(t != rhs.t) |
| 149 | return false; |
| 150 | if(u != rhs.u) |
| 151 | return false; |
| 152 | if(v != rhs.v) |
| 153 | return false; |
| 154 | #if BOOST_CXX_VERSION > 199711L // only include floating point if C++ version >= C++11 |
| 155 | if(std::abs( x: boost::math::float_distance(a: w, b: rhs.w)) > 1) |
| 156 | return false; |
| 157 | if(std::abs( x: boost::math::float_distance(a: x, b: rhs.x)) > 1) |
| 158 | return false; |
| 159 | #endif |
| 160 | if(0 != y.compare(str: rhs.y)) |
| 161 | |
| 162 | return false; |
| 163 | #ifndef BOOST_NO_STD_WSTRING |
| 164 | if(0 != z.compare(str: rhs.z)) |
| 165 | return false; |
| 166 | #endif |
| 167 | return true; |
| 168 | } |
| 169 | |
| 170 | A_DLL_DECL bool |
| 171 | A::operator!=(const A &rhs) const { |
| 172 | return ! (*this == rhs); |
| 173 | } |
| 174 | |
| 175 | A_DLL_DECL bool |
| 176 | A::operator<(const A &rhs) const { |
| 177 | if(b != rhs.b) |
| 178 | return b < rhs.b; |
| 179 | #ifndef BOOST_NO_INT64_T |
| 180 | if(f != rhs.f) |
| 181 | return f < rhs.f; |
| 182 | if(g != rhs.g) |
| 183 | return g < rhs.g; |
| 184 | #endif |
| 185 | if(l != rhs.l ) |
| 186 | return l < rhs.l; |
| 187 | if(m != rhs.m ) |
| 188 | return m < rhs.m; |
| 189 | if(n != rhs.n ) |
| 190 | return n < rhs.n; |
| 191 | if(o != rhs.o ) |
| 192 | return o < rhs.o; |
| 193 | if(p != rhs.p ) |
| 194 | return p < rhs.p; |
| 195 | if(q != rhs.q ) |
| 196 | return q < rhs.q; |
| 197 | #ifndef BOOST_NO_CWCHAR |
| 198 | if(r != rhs.r ) |
| 199 | return r < rhs.r; |
| 200 | #endif |
| 201 | if(c != rhs.c ) |
| 202 | return c < rhs.c; |
| 203 | if(s != rhs.s ) |
| 204 | return s < rhs.s; |
| 205 | if(t != rhs.t ) |
| 206 | return t < rhs.t; |
| 207 | if(u != rhs.u ) |
| 208 | return u < rhs.u; |
| 209 | if(v != rhs.v ) |
| 210 | return v < rhs.v; |
| 211 | if(w != rhs.w ) |
| 212 | return w < rhs.w; |
| 213 | if(x != rhs.x ) |
| 214 | return x < rhs.x; |
| 215 | int i = y.compare(str: rhs.y); |
| 216 | if(i != 0 ) |
| 217 | return i < 0; |
| 218 | #ifndef BOOST_NO_STD_WSTRING |
| 219 | int j = z.compare(str: rhs.z); |
| 220 | if(j != 0 ) |
| 221 | return j < 0; |
| 222 | #endif |
| 223 | return false; |
| 224 | } |
| 225 | |