demo_dll_a.hpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. #ifndef BOOST_SERIALIZATION_TEST_A_HPP
  2. #define BOOST_SERIALIZATION_TEST_A_HPP
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER)
  5. # pragma once
  6. #endif
  7. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  8. // A.hpp simple class test
  9. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  10. // Use, modification and distribution is subject to the Boost Software
  11. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. // See http://www.boost.org for updates, documentation, and revision history.
  14. #include <cassert>
  15. #include <cstdlib> // for rand()
  16. #include <cmath> // for fabs()
  17. #include <cstddef> // size_t
  18. #include <boost/math/special_functions/next.hpp>
  19. #include <boost/config.hpp>
  20. #if defined(BOOST_NO_STDC_NAMESPACE)
  21. namespace std{
  22. using ::rand;
  23. using ::fabs;
  24. using ::size_t;
  25. }
  26. #endif
  27. //#include <boost/test/test_exec_monitor.hpp>
  28. #include <boost/limits.hpp>
  29. #include <boost/cstdint.hpp>
  30. #include <boost/detail/workaround.hpp>
  31. #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1)
  32. #include <boost/archive/dinkumware.hpp>
  33. #endif
  34. #include <boost/serialization/nvp.hpp>
  35. #include <boost/serialization/string.hpp>
  36. #include <boost/serialization/access.hpp>
  37. class A
  38. {
  39. private:
  40. friend class boost::serialization::access;
  41. // note: from an aesthetic perspective, I would much prefer to have this
  42. // defined out of line. Unfortunately, this trips a bug in the VC 6.0
  43. // compiler. So hold our nose and put it her to permit running of tests.
  44. template<class Archive>
  45. void serialize(
  46. Archive &ar,
  47. const unsigned int /* file_version */
  48. ){
  49. ar & BOOST_SERIALIZATION_NVP(b);
  50. #ifndef BOOST_NO_INT64_T
  51. ar & BOOST_SERIALIZATION_NVP(f);
  52. ar & BOOST_SERIALIZATION_NVP(g);
  53. #endif
  54. #if BOOST_WORKAROUND(__BORLANDC__, <= 0x551 )
  55. int i;
  56. if(BOOST_DEDUCED_TYPENAME Archive::is_saving::value){
  57. i = l;
  58. ar & BOOST_SERIALIZATION_NVP(i);
  59. }
  60. else{
  61. ar & BOOST_SERIALIZATION_NVP(i);
  62. l = i;
  63. }
  64. #else
  65. ar & BOOST_SERIALIZATION_NVP(l);
  66. #endif
  67. ar & BOOST_SERIALIZATION_NVP(m);
  68. ar & BOOST_SERIALIZATION_NVP(n);
  69. ar & BOOST_SERIALIZATION_NVP(o);
  70. ar & BOOST_SERIALIZATION_NVP(p);
  71. ar & BOOST_SERIALIZATION_NVP(q);
  72. #ifndef BOOST_NO_CWCHAR
  73. ar & BOOST_SERIALIZATION_NVP(r);
  74. #endif
  75. ar & BOOST_SERIALIZATION_NVP(c);
  76. ar & BOOST_SERIALIZATION_NVP(s);
  77. ar & BOOST_SERIALIZATION_NVP(t);
  78. ar & BOOST_SERIALIZATION_NVP(u);
  79. ar & BOOST_SERIALIZATION_NVP(v);
  80. ar & BOOST_SERIALIZATION_NVP(w);
  81. ar & BOOST_SERIALIZATION_NVP(x);
  82. ar & BOOST_SERIALIZATION_NVP(y);
  83. #ifndef BOOST_NO_STD_WSTRING
  84. ar & BOOST_SERIALIZATION_NVP(z);
  85. #endif
  86. }
  87. bool b;
  88. #ifndef BOOST_NO_INT64_T
  89. boost::int64_t f;
  90. boost::uint64_t g;
  91. #endif
  92. enum h {
  93. i = 0,
  94. j,
  95. k
  96. } l;
  97. std::size_t m;
  98. signed long n;
  99. unsigned long o;
  100. signed short p;
  101. unsigned short q;
  102. #ifndef BOOST_NO_CWCHAR
  103. wchar_t r;
  104. #endif
  105. char c;
  106. signed char s;
  107. unsigned char t;
  108. signed int u;
  109. unsigned int v;
  110. float w;
  111. double x;
  112. std::string y;
  113. #ifndef BOOST_NO_STD_WSTRING
  114. std::wstring z;
  115. #endif
  116. public:
  117. A();
  118. bool operator==(const A &rhs) const;
  119. bool operator!=(const A &rhs) const;
  120. bool operator<(const A &rhs) const; // used by less
  121. // hash function for class A
  122. operator std::size_t () const;
  123. friend std::ostream & operator<<(std::ostream & os, A const & a);
  124. friend std::istream & operator>>(std::istream & is, A & a);
  125. };
  126. //BOOST_TEST_DONT_PRINT_LOG_VALUE(A);
  127. template<class S>
  128. void randomize(S &x)
  129. {
  130. assert(0 == x.size());
  131. for(;;){
  132. unsigned int i = std::rand() % 27;
  133. if(0 == i)
  134. break;
  135. x += static_cast<BOOST_DEDUCED_TYPENAME S::value_type>('a' - 1 + i);
  136. }
  137. }
  138. template<class T>
  139. void accumulate(std::size_t & s, const T & t){
  140. const char * tptr = (const char *)(& t);
  141. unsigned int count = sizeof(t);
  142. while(count-- > 0){
  143. s += *tptr++;
  144. }
  145. }
  146. A::operator std::size_t () const {
  147. std::size_t retval = 0;
  148. accumulate(retval, b);
  149. #ifndef BOOST_NO_INT64_T
  150. accumulate(retval, f);
  151. accumulate(retval, g);
  152. #endif
  153. accumulate(retval, l);
  154. accumulate(retval, m);
  155. accumulate(retval, n);
  156. accumulate(retval, o);
  157. accumulate(retval, p);
  158. accumulate(retval, q);
  159. #ifndef BOOST_NO_CWCHAR
  160. accumulate(retval, r);
  161. #endif
  162. accumulate(retval, c);
  163. accumulate(retval, s);
  164. accumulate(retval, t);
  165. accumulate(retval, u);
  166. accumulate(retval, v);
  167. return retval;
  168. }
  169. inline A::A() :
  170. b(true),
  171. #ifndef BOOST_NO_INT64_T
  172. f(std::rand() * std::rand()),
  173. g(std::rand() * std::rand()),
  174. #endif
  175. l(static_cast<enum h>(std::rand() % 3)),
  176. m(std::rand()),
  177. n(std::rand()),
  178. o(std::rand()),
  179. p(std::rand()),
  180. q(std::rand()),
  181. #ifndef BOOST_NO_CWCHAR
  182. r(std::rand()),
  183. #endif
  184. c(std::rand()),
  185. s(std::rand()),
  186. t(std::rand()),
  187. u(std::rand()),
  188. v(std::rand()),
  189. w((float)std::rand()),
  190. x((double)std::rand())
  191. {
  192. randomize(y);
  193. #ifndef BOOST_NO_STD_WSTRING
  194. randomize(z);
  195. #endif
  196. }
  197. inline bool A::operator==(const A &rhs) const
  198. {
  199. if(b != rhs.b)
  200. return false;
  201. if(l != rhs.l)
  202. return false;
  203. #ifndef BOOST_NO_INT64_T
  204. if(f != rhs.f)
  205. return false;
  206. if(g != rhs.g)
  207. return false;
  208. #endif
  209. if(m != rhs.m)
  210. return false;
  211. if(n != rhs.n)
  212. return false;
  213. if(o != rhs.o)
  214. return false;
  215. if(p != rhs.p)
  216. return false;
  217. if(q != rhs.q)
  218. return false;
  219. #ifndef BOOST_NO_CWCHAR
  220. if(r != rhs.r)
  221. return false;
  222. #endif
  223. if(c != rhs.c)
  224. return false;
  225. if(s != rhs.s)
  226. return false;
  227. if(t != rhs.t)
  228. return false;
  229. if(u != rhs.u)
  230. return false;
  231. if(v != rhs.v)
  232. return false;
  233. if(std::abs( boost::math::float_distance(w, rhs.w)) > 1)
  234. return false;
  235. if(std::abs( boost::math::float_distance(x, rhs.x)) > 1)
  236. return false;
  237. if(0 != y.compare(rhs.y))
  238. return false;
  239. #ifndef BOOST_NO_STD_WSTRING
  240. if(0 != z.compare(rhs.z))
  241. return false;
  242. #endif
  243. return true;
  244. }
  245. inline bool A::operator!=(const A &rhs) const
  246. {
  247. return ! (*this == rhs);
  248. }
  249. inline bool A::operator<(const A &rhs) const
  250. {
  251. if(b != rhs.b)
  252. return b < rhs.b;
  253. #ifndef BOOST_NO_INT64_T
  254. if(f != rhs.f)
  255. return f < rhs.f;
  256. if(g != rhs.g)
  257. return g < rhs.g;
  258. #endif
  259. if(l != rhs.l )
  260. return l < rhs.l;
  261. if(m != rhs.m )
  262. return m < rhs.m;
  263. if(n != rhs.n )
  264. return n < rhs.n;
  265. if(o != rhs.o )
  266. return o < rhs.o;
  267. if(p != rhs.p )
  268. return p < rhs.p;
  269. if(q != rhs.q )
  270. return q < rhs.q;
  271. #ifndef BOOST_NO_CWCHAR
  272. if(r != rhs.r )
  273. return r < rhs.r;
  274. #endif
  275. if(c != rhs.c )
  276. return c < rhs.c;
  277. if(s != rhs.s )
  278. return s < rhs.s;
  279. if(t != rhs.t )
  280. return t < rhs.t;
  281. if(u != rhs.u )
  282. return u < rhs.u;
  283. if(v != rhs.v )
  284. return v < rhs.v;
  285. if(w != rhs.w )
  286. return w < rhs.w;
  287. if(x != rhs.x )
  288. return x < rhs.x;
  289. int i = y.compare(rhs.y);
  290. if(i != 0 )
  291. return i < 0;
  292. #ifndef BOOST_NO_STD_WSTRING
  293. int j = z.compare(rhs.z);
  294. if(j != 0 )
  295. return j < 0;
  296. #endif
  297. return false;
  298. }
  299. #endif // BOOST_SERIALIZATION_TEST_A_HPP