From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- .../flyweight/test/test_serialization_template.hpp | 128 +++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 src/boost/libs/flyweight/test/test_serialization_template.hpp (limited to 'src/boost/libs/flyweight/test/test_serialization_template.hpp') diff --git a/src/boost/libs/flyweight/test/test_serialization_template.hpp b/src/boost/libs/flyweight/test/test_serialization_template.hpp new file mode 100644 index 00000000..76770818 --- /dev/null +++ b/src/boost/libs/flyweight/test/test_serialization_template.hpp @@ -0,0 +1,128 @@ +/* Boost.Flyweight test template for serialization capabilities. + * + * Copyright 2006-2014 Joaquin M Lopez Munoz. + * 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) + * + * See http://www.boost.org/libs/flyweight for library home page. + */ + +#ifndef BOOST_FLYWEIGHT_TEST_SERIALIZATION_TEMPLATE_HPP +#define BOOST_FLYWEIGHT_TEST_SERIALIZATION_TEMPLATE_HPP + +#if defined(_MSC_VER)&&(_MSC_VER>=1200) +#pragma once +#endif + +#include /* keep it first to prevent nasty warns in MSVC */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "heavy_objects.hpp" + +#define LENGTHOF(array) (sizeof(array)/sizeof((array)[0])) + +struct tracked_string +{ + typedef tracked_string type; + + tracked_string(){} + tracked_string(const char* str_):str(str_){} + + const std::string& get()const{return str;} + + friend bool operator==(const type& x,const type& y){return x.str==y.str;} + friend bool operator< (const type& x,const type& y){return x.str< y.str;} + friend bool operator!=(const type& x,const type& y){return x.str!=y.str;} + friend bool operator> (const type& x,const type& y){return x.str> y.str;} + friend bool operator>=(const type& x,const type& y){return x.str>=y.str;} + friend bool operator<=(const type& x,const type& y){return x.str<=y.str;} + +private: + friend class boost::serialization::access; + + template + void serialize(Archive& ar,const unsigned int){ar&str;} + + std::string str; +}; + +#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) +namespace boost{ +#endif + +inline std::size_t hash_value(const tracked_string& x) +{ + boost::hash h; + return h(x.get()); +} + +#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) +} /* namespace boost */ +#endif + +template +void test_serialization_template( + ForwardIterator first,ForwardIterator last + BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Flyweight)) +{ + std::vector v1; + while(first!=last)v1.push_back(Flyweight(*first++)); + std::ostringstream oss; + { + const std::vector& crv1=v1; + boost::archive::text_oarchive oa(oss); + oa< v2; + { + std::istringstream iss(oss.str()); + boost::archive::text_iarchive ia(iss); + ia>>v2; + } + + BOOST_TEST(v1==v2); +} + +template +void test_serialization_template( + BOOST_EXPLICIT_TEMPLATE_TYPE(FlyweightSpecifier)) +{ + typedef typename boost::mpl::apply1< + FlyweightSpecifier,std::string + >::type string_flyweight; + + typedef typename boost::mpl::apply1< + FlyweightSpecifier,tracked_string + >::type tracked_string_flyweight; + + typedef typename boost::mpl::apply1< + FlyweightSpecifier, + boost::flyweights::key_value + >::type texture_flyweight; + + const char* words[]={"hello","boost","flyweight","boost","bye","c++","c++"}; + test_serialization_template( + &words[0],&words[0]+LENGTHOF(words)); + test_serialization_template( + &words[0],&words[0]+LENGTHOF(words)); + + const char* textures[]={ + "wood","grass","sand","granite","terracotta","wood","sand","grass"}; + test_serialization_template( + &textures[0],&textures[0]+LENGTHOF(textures)); +} + +#undef LENGTHOF + +#endif -- cgit v1.2.3