policies.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* Boost interval/policies.hpp template implementation file
  2. *
  3. * Copyright 2003 Guillaume Melquiond
  4. *
  5. * Distributed under the Boost Software License, Version 1.0.
  6. * (See accompanying file LICENSE_1_0.txt or
  7. * copy at http://www.boost.org/LICENSE_1_0.txt)
  8. */
  9. #ifndef BOOST_NUMERIC_INTERVAL_POLICIES_HPP
  10. #define BOOST_NUMERIC_INTERVAL_POLICIES_HPP
  11. #include <boost/numeric/interval/interval.hpp>
  12. namespace boost {
  13. namespace numeric {
  14. namespace interval_lib {
  15. /*
  16. * policies class
  17. */
  18. template<class Rounding, class Checking>
  19. struct policies
  20. {
  21. typedef Rounding rounding;
  22. typedef Checking checking;
  23. };
  24. /*
  25. * policies switching classes
  26. */
  27. template<class OldInterval, class NewRounding>
  28. class change_rounding
  29. {
  30. typedef typename OldInterval::base_type T;
  31. typedef typename OldInterval::traits_type p;
  32. typedef typename p::checking checking;
  33. public:
  34. typedef interval<T, policies<NewRounding, checking> > type;
  35. };
  36. template<class OldInterval, class NewChecking>
  37. class change_checking
  38. {
  39. typedef typename OldInterval::base_type T;
  40. typedef typename OldInterval::traits_type p;
  41. typedef typename p::rounding rounding;
  42. public:
  43. typedef interval<T, policies<rounding, NewChecking> > type;
  44. };
  45. /*
  46. * Protect / unprotect: control whether the rounding mode is set/reset
  47. * at each operation, rather than once and for all.
  48. */
  49. template<class OldInterval>
  50. class unprotect
  51. {
  52. typedef typename OldInterval::base_type T;
  53. typedef typename OldInterval::traits_type p;
  54. typedef typename p::rounding r;
  55. typedef typename r::unprotected_rounding newRounding;
  56. public:
  57. typedef typename change_rounding<OldInterval, newRounding>::type type;
  58. };
  59. } // namespace interval_lib
  60. } // namespace numeric
  61. } // namespace boost
  62. #endif // BOOST_NUMERIC_INTERVAL_POLICIES_HPP