demo_dll_a.ipp 7.6 KB

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