fail_count.ipp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/beast
  8. //
  9. #ifndef BOOST_BEAST_TEST_IMPL_FAIL_COUNT_IPP
  10. #define BOOST_BEAST_TEST_IMPL_FAIL_COUNT_IPP
  11. #include <boost/beast/core/error.hpp>
  12. #include <boost/beast/experimental/test/error.hpp>
  13. #include <boost/throw_exception.hpp>
  14. namespace boost {
  15. namespace beast {
  16. namespace test {
  17. inline
  18. fail_count::
  19. fail_count(
  20. std::size_t n,
  21. error_code ev)
  22. : n_(n)
  23. , ec_(ev)
  24. {
  25. }
  26. inline
  27. void
  28. fail_count::
  29. fail()
  30. {
  31. if(i_ < n_)
  32. ++i_;
  33. if(i_ == n_)
  34. BOOST_THROW_EXCEPTION(system_error{ec_});
  35. }
  36. inline
  37. bool
  38. fail_count::
  39. fail(error_code& ec)
  40. {
  41. if(i_ < n_)
  42. ++i_;
  43. if(i_ == n_)
  44. {
  45. ec = ec_;
  46. return true;
  47. }
  48. ec.assign(0, ec.category());
  49. return false;
  50. }
  51. } // test
  52. } // beast
  53. } // boost
  54. #endif