1 /* Classes for Boost.Flyweight key-value tests. 2 * 3 * Copyright 2006-2014 Joaquin M Lopez Munoz. 4 * Distributed under the Boost Software License, Version 1.0. 5 * (See accompanying file LICENSE_1_0.txt or copy at 6 * http://www.boost.org/LICENSE_1_0.txt) 7 * 8 * See http://www.boost.org/libs/flyweight for library home page. 9 */ 10 11 #ifndef BOOST_FLYWEIGHT_TEST_HEAVY_OBJECTS_HPP 12 #define BOOST_FLYWEIGHT_TEST_HEAVY_OBJECTS_HPP 13 14 #if defined(_MSC_VER) 15 #pragma once 16 #endif 17 18 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */ 19 #include <boost/noncopyable.hpp> 20 #include <iosfwd> 21 #include <string> 22 23 struct texture 24 { texturetexture25 texture(const std::string& str_=""):str(str_){} 26 operator ==(const texture & x,const texture & y)27 friend bool operator==( 28 const texture& x,const texture& y){return x.str==y.str;} operator <(const texture & x,const texture & y)29 friend bool operator< ( 30 const texture& x,const texture& y){return x.str< y.str;} operator !=(const texture & x,const texture & y)31 friend bool operator!=( 32 const texture& x,const texture& y){return x.str!=y.str;} operator >(const texture & x,const texture & y)33 friend bool operator> ( 34 const texture& x,const texture& y){return x.str> y.str;} operator >=(const texture & x,const texture & y)35 friend bool operator>=( 36 const texture& x,const texture& y){return x.str>=y.str;} operator <=(const texture & x,const texture & y)37 friend bool operator<=( 38 const texture& x,const texture& y){return x.str<=y.str;} 39 operator <<(std::ostream & os,const texture & x)40 friend std::ostream& operator<<(std::ostream& os,const texture& x) 41 { 42 return os<<x.str; 43 } 44 operator >>(std::istream & is,texture & x)45 friend std::istream& operator>>(std::istream& is,texture& x) 46 { 47 return is>>x.str; 48 } 49 50 std::string str; 51 }; 52 53 struct from_texture_to_string 54 { operator ()from_texture_to_string55 const std::string& operator()(const texture& x)const{return x.str;} 56 }; 57 58 struct factorization:private boost::noncopyable 59 { factorizationfactorization60 factorization(int n_=0):n(n_){} 61 operator ==(const factorization & x,const factorization & y)62 friend bool operator==( 63 const factorization& x,const factorization& y){return x.n==y.n;} operator <(const factorization & x,const factorization & y)64 friend bool operator< ( 65 const factorization& x,const factorization& y){return x.n< y.n;} operator !=(const factorization & x,const factorization & y)66 friend bool operator!=( 67 const factorization& x,const factorization& y){return x.n!=y.n;} operator >(const factorization & x,const factorization & y)68 friend bool operator> ( 69 const factorization& x,const factorization& y){return x.n> y.n;} operator >=(const factorization & x,const factorization & y)70 friend bool operator>=( 71 const factorization& x,const factorization& y){return x.n>=y.n;} operator <=(const factorization & x,const factorization & y)72 friend bool operator<=( 73 const factorization& x,const factorization& y){return x.n<=y.n;} 74 operator <<(std::ostream & os,const factorization & x)75 friend std::ostream& operator<<(std::ostream& os,const factorization& x) 76 { 77 return os<<x.n; 78 } 79 operator >>(std::istream & is,factorization & x)80 friend std::istream& operator>>(std::istream& is,factorization& x) 81 { 82 return is>>x.n; 83 } 84 85 int n; 86 }; 87 88 #if !defined(BOOST_NO_EXCEPTIONS) 89 struct throwing_value_exception{}; 90 91 struct throwing_value 92 { throwing_valuethrowing_value93 throwing_value():n(0){} throwing_valuethrowing_value94 throwing_value(const throwing_value&){throw throwing_value_exception();} throwing_valuethrowing_value95 throwing_value(int){throw throwing_value_exception();} 96 97 int n; 98 }; 99 100 struct from_throwing_value_to_int 101 { operator ()from_throwing_value_to_int102 const int& operator()(const throwing_value& x)const{return x.n;} 103 }; 104 #endif 105 106 #endif 107