/******************************************************************************* * * TRIQS: a Toolbox for Research in Interacting Quantum Systems * * Copyright (C) 2012 by M. Ferrero, O. Parcollet * * TRIQS is free software: you can redistribute it and/or modify it under the * terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * TRIQS. If not, see . * ******************************************************************************/ #ifndef TRIQS_SERIAL_H #define TRIQS_SERIAL_H #include #include //#include //#include #include #include #include #include #include #include #include #include #include namespace triqs { // serialize obj into an std::string template std::string serialize (T const & obj) { std::string serial_str; boost::iostreams::back_insert_device inserter(serial_str); boost::iostreams::stream > s(inserter); //boost::archive::binary_oarchive oa(s); boost::archive::text_oarchive oa(s); oa << obj; s.flush(); return serial_str; } template T deserialize (std::string const & serial_str) { T obj; // wrap buffer inside a stream and deserialize serial_str into obj boost::iostreams::basic_array_source device(serial_str.data(), serial_str.size()); boost::iostreams::stream > s(device); //boost::archive::binary_iarchive ia(s); boost::archive::text_iarchive ia(s); ia >> obj; return obj; } template void deserialize_into_view (std::string const & serial_str, T & x) { typename regular_type_if_exists_else_type::type obj; // wrap buffer inside a stream and deserialize serial_str into obj boost::iostreams::basic_array_source device(serial_str.data(), serial_str.size()); boost::iostreams::stream > s(device); boost::archive::text_iarchive ia(s); //boost::archive::binary_iarchive ia(s); ia >> obj; x= typename view_type_if_exists_else_type::type (obj); } } #endif