heavy_objects.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #ifndef BOOST_FLYWEIGHT_TEST_HEAVY_OBJECTS_HPP
  11. #define BOOST_FLYWEIGHT_TEST_HEAVY_OBJECTS_HPP
  12. #if defined(_MSC_VER)
  13. #pragma once
  14. #endif
  15. #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
  16. #include <boost/noncopyable.hpp>
  17. #include <iosfwd>
  18. #include <string>
  19. struct texture
  20. {
  21. texture(const std::string& str_=""):str(str_){}
  22. friend bool operator==(
  23. const texture& x,const texture& y){return x.str==y.str;}
  24. friend bool operator< (
  25. const texture& x,const texture& y){return x.str< y.str;}
  26. friend bool operator!=(
  27. const texture& x,const texture& y){return x.str!=y.str;}
  28. friend bool operator> (
  29. const texture& x,const texture& y){return x.str> y.str;}
  30. friend bool operator>=(
  31. const texture& x,const texture& y){return x.str>=y.str;}
  32. friend bool operator<=(
  33. const texture& x,const texture& y){return x.str<=y.str;}
  34. friend std::ostream& operator<<(std::ostream& os,const texture& x)
  35. {
  36. return os<<x.str;
  37. }
  38. friend std::istream& operator>>(std::istream& is,texture& x)
  39. {
  40. return is>>x.str;
  41. }
  42. std::string str;
  43. };
  44. struct from_texture_to_string
  45. {
  46. const std::string& operator()(const texture& x)const{return x.str;}
  47. };
  48. struct factorization:private boost::noncopyable
  49. {
  50. factorization(int n_=0):n(n_){}
  51. friend bool operator==(
  52. const factorization& x,const factorization& y){return x.n==y.n;}
  53. friend bool operator< (
  54. const factorization& x,const factorization& y){return x.n< y.n;}
  55. friend bool operator!=(
  56. const factorization& x,const factorization& y){return x.n!=y.n;}
  57. friend bool operator> (
  58. const factorization& x,const factorization& y){return x.n> y.n;}
  59. friend bool operator>=(
  60. const factorization& x,const factorization& y){return x.n>=y.n;}
  61. friend bool operator<=(
  62. const factorization& x,const factorization& y){return x.n<=y.n;}
  63. friend std::ostream& operator<<(std::ostream& os,const factorization& x)
  64. {
  65. return os<<x.n;
  66. }
  67. friend std::istream& operator>>(std::istream& is,factorization& x)
  68. {
  69. return is>>x.n;
  70. }
  71. int n;
  72. };
  73. #if !defined(BOOST_NO_EXCEPTIONS)
  74. struct throwing_value_exception{};
  75. struct throwing_value
  76. {
  77. throwing_value():n(0){}
  78. throwing_value(const throwing_value&){throw throwing_value_exception();}
  79. throwing_value(int){throw throwing_value_exception();}
  80. int n;
  81. };
  82. struct from_throwing_value_to_int
  83. {
  84. const int& operator()(const throwing_value& x)const{return x.n;}
  85. };
  86. #endif
  87. #endif