/** example for serialization -*- c++ -*- *************************** * - begin : 2007-01-02 * - copyright : (C) 2007 by Gunter Winkler * - email : guwi17@gmx.de * * Distributed under the Boost Software License, Version 1.0. (See * accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) ********************************************************************/ #include #include #include #include #include #include #include #include #include template std::basic_ostream &operator << (std::basic_ostream &os, const V &v) { os << '[' << v .size () << "]("; if (v .size () > 0) os << v [0]; for (size_t i = 1; i < v .size (); ++ i) os << ',' << v [i]; os << ')'; return os; } namespace boost { namespace serialization { template void serialize(Archive & ar, std::complex & x, const unsigned int /* version */) { ar & x.real(); ar & x.imag(); } } // namespace serialization } // namespace boost template bool test_archive(const size_t size, const char* fname = "ua.txt") { CONTAINER x((size)); for (size_t i=0; i bool test_archive(const size_t size1, const size_t size2, const char* fname = "ua.txt") { CONTAINER x(size1,size2); for (size_t i=0; i 1) size = ::atoi (argv [1]); std::cout << "size " << size << std::endl; using namespace boost::numeric::ublas; std::cout << ( test_archive< unbounded_array >(size) ) << std::endl; std::cout << ( test_archive< bounded_array >(40) ) << std::endl; std::cout << ( test_archive< vector >(size) ) << std::endl; std::cout << ( test_archive< vector > >(size, "uc.txt") ) << std::endl; std::cout << ( test_archive< vector >(size) ) << std::endl; std::cout << ( test_archive< bounded_vector >(5, "ub.txt") ) << std::endl; std::cout << ( test_archive< c_vector >(5, "ud.txt") ) << std::endl; std::cout << ( test_archive< matrix >(size, size, "m1.txt") ) << std::endl; std::cout << ( test_archive< bounded_matrix >(5, 3, "m2.txt") ) << std::endl; std::cout << ( test_archive< vector_of_vector >(size, size, "m3.txt") ) << std::endl; std::cout << ( test_archive< c_matrix >(5, 3, "m4.txt") ) << std::endl; return EXIT_SUCCESS; } /* compile: $ LANG=C g++ -g -Wall -I $HOME/include -o ex_serial ex_serial.cpp -L $HOME/lib -l boost_serialization generated output: $ ./ex_serial size 10 1 1 1 1 1 1 1 1 1 1 1 $ cat u?.txt m?.txt 22 serialization::archive 4 0 0 0 0 10 0 1 2 3 4 5 6 7 8 9 22 serialization::archive 4 0 0 0 0 5 0 1 2 3 4 22 serialization::archive 4 0 0 0 0 10 0 0 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 22 serialization::archive 4 0 0 5 5 0 1 2 3 4 22 serialization::archive 4 0 0 10 10 0 0 100 0 1 2 3 4 5 6 7 8 9 100 101 102 103 104 105 106 107 108 109 200 201 202 203 204 205 206 207 208 209 300 301 302 303 304 305 306 307 308 309 400 401 402 403 404 405 406 407 408 409 500 501 502 503 504 505 506 507 508 509 600 601 602 603 604 605 606 607 608 609 700 701 702 703 704 705 706 707 708 709 800 801 802 803 804 805 806 807 808 809 900 901 902 903 904 905 906 907 908 909 22 serialization::archive 4 0 0 5 3 0 0 15 0 1 2 100 101 102 200 201 202 300 301 302 400 401 402 22 serialization::archive 4 0 0 10 10 0 0 11 0 0 10 0 1 2 3 4 5 6 7 8 9 10 100 101 102 103 104 105 106 107 108 109 10 200 201 202 203 204 205 206 207 208 209 10 300 301 302 303 304 305 306 307 308 309 10 400 401 402 403 404 405 406 407 408 409 10 500 501 502 503 504 505 506 507 508 509 10 600 601 602 603 604 605 606 607 608 609 10 700 701 702 703 704 705 706 707 708 709 10 800 801 802 803 804 805 806 807 808 809 10 900 901 902 903 904 905 906 907 908 909 0 22 serialization::archive 4 0 0 5 3 3 0 1 2 3 100 101 102 3 200 201 202 3 300 301 302 3 400 401 402 */