<commit_before>// This file is part of BlueSky
// 
// BlueSky is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
// 
// BlueSky 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 BlueSky; if not, see <http://www.gnu.org/licenses/>.

#ifndef BS_SERIALIZE_TEXT_MMP1RZ0U
#define BS_SERIALIZE_TEXT_MMP1RZ0U

#include <boost/serialization/serialization.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <sstream>

namespace blue_sky {

/*-----------------------------------------------------------------
 * helper functions that serialize any BS type to/from str
 *----------------------------------------------------------------*/

template< class T >
BS_API_PLUGIN std::string serialize_to_str(smart_ptr< T, true >& t) {
	std::ostringstream os;
	boost::archive::text_oarchive ar(os);
	ar << t;
	return os.str();
}

template< class T >
BS_API_PLUGIN smart_ptr< T, true > serialize_from_str(const std::string& src) {
	std::istringstream is(src);
	boost::archive::text_iarchive ar(is);
	smart_ptr< T, true > t;
	ar >> t;
	return t;
}

template< class T >
BS_API_PLUGIN smart_ptr< T, true > copy_via_serialize(smart_ptr< T, true > src) {
	return serialize_from_str< T >(serialize_to_str< T >(src));
}<commit_msg>SRZ: ensure archive is destroyed before stream is closed<commit_after>// This file is part of BlueSky
// 
// BlueSky is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
// 
// BlueSky 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 BlueSky; if not, see <http://www.gnu.org/licenses/>.

#ifndef BS_SERIALIZE_TEXT_MMP1RZ0U
#define BS_SERIALIZE_TEXT_MMP1RZ0U

#include <boost/serialization/serialization.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <sstream>

namespace blue_sky {

/*-----------------------------------------------------------------
 * helper functions that serialize any BS type to/from str
 *----------------------------------------------------------------*/

template< class T >
BS_API_PLUGIN std::string serialize_to_str(smart_ptr< T, true >& t) {
	std::ostringstream os;
	// ensure archive is destroyed before stream is closed
	{
		boost::archive::text_oarchive ar(os);
		ar << t;
	}
	return os.str();
}

template< class T >
BS_API_PLUGIN smart_ptr< T, true > serialize_from_str(const std::string& src) {
	std::istringstream is(src);
	smart_ptr< T, true > t;
	// ensure archive is destroyed before stream is closed
	{
		boost::archive::text_iarchive ar(is);
		ar >> t;
	}
	return t;
}

template< class T >
BS_API_PLUGIN smart_ptr< T, true > copy_via_serialize(smart_ptr< T, true > src) {
	return serialize_from_str< T >(serialize_to_str< T >(src));
}
{'fraction_non_alphanumeric': 0.16708368084514874, 'fraction_numerical': 0.0027800945232137894, 'mean_word_length': 3.074745186862967, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3498936', 'n_tokens_mistral': 1099, 'n_tokens_neox': 1077, 'n_words': 390}