2017-07-20 08:01:46 -07:00
|
|
|
//
|
2017-02-06 20:07:03 -05:00
|
|
|
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
|
2017-07-20 08:01:46 -07:00
|
|
|
//
|
|
|
|
|
// 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)
|
|
|
|
|
//
|
|
|
|
|
|
2016-05-06 19:14:17 -04:00
|
|
|
#ifndef BEAST_UNIT_TEST_AMOUNT_HPP
|
|
|
|
|
#define BEAST_UNIT_TEST_AMOUNT_HPP
|
2017-07-20 08:01:46 -07:00
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
|
#include <ostream>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
namespace beast {
|
|
|
|
|
namespace unit_test {
|
|
|
|
|
|
|
|
|
|
/** Utility for producing nicely composed output of amounts with units. */
|
|
|
|
|
class amount
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
std::size_t n_;
|
|
|
|
|
std::string const& what_;
|
|
|
|
|
|
|
|
|
|
public:
|
2016-08-29 10:43:56 -04:00
|
|
|
amount(amount const&) = default;
|
|
|
|
|
amount& operator=(amount const&) = delete;
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2016-08-26 08:01:44 -04:00
|
|
|
template<class = void>
|
2016-08-29 10:43:56 -04:00
|
|
|
amount(std::size_t n, std::string const& what);
|
2017-07-20 08:01:46 -07:00
|
|
|
|
|
|
|
|
friend
|
|
|
|
|
std::ostream&
|
2016-08-29 10:43:56 -04:00
|
|
|
operator<<(std::ostream& s, amount const& t);
|
2017-07-20 08:01:46 -07:00
|
|
|
};
|
|
|
|
|
|
2016-08-26 08:01:44 -04:00
|
|
|
template<class>
|
2016-08-29 10:43:56 -04:00
|
|
|
amount::amount(std::size_t n, std::string const& what)
|
|
|
|
|
: n_(n)
|
|
|
|
|
, what_(what)
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
|
std::ostream&
|
2016-08-29 10:43:56 -04:00
|
|
|
operator<<(std::ostream& s, amount const& t)
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
2016-08-29 10:43:56 -04:00
|
|
|
s << t.n_ << " " << t.what_ <<((t.n_ != 1) ? "s" : "");
|
2017-07-20 08:01:46 -07:00
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // unit_test
|
|
|
|
|
} // beast
|
|
|
|
|
|
|
|
|
|
#endif
|