2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
|
|
|
Copyright (c) 2011-2013 Bolero MURAKAMI
|
|
|
|
https://github.com/bolero-MURAKAMI/Sprout
|
|
|
|
|
|
|
|
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)
|
|
|
|
=============================================================================*/
|
2012-08-28 16:16:12 +00:00
|
|
|
#ifndef SPROUT_RATIONAL_IO_HPP
|
|
|
|
#define SPROUT_RATIONAL_IO_HPP
|
|
|
|
|
|
|
|
#include <ios>
|
|
|
|
#include <iostream>
|
|
|
|
#include <sprout/config.hpp>
|
|
|
|
#include <sprout/rational/rational.hpp>
|
|
|
|
#include <sprout/detail/io/ios_state.hpp>
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
//
|
|
|
|
// operator>>
|
|
|
|
// operator<<
|
|
|
|
//
|
|
|
|
template<typename Elem, typename Traits, typename IntType>
|
2013-11-02 09:28:18 +00:00
|
|
|
inline SPROUT_NON_CONSTEXPR std::basic_istream<Elem, Traits>&
|
2012-08-28 16:16:12 +00:00
|
|
|
operator>>(std::basic_istream<Elem, Traits>& lhs, sprout::rational<IntType>& rhs) {
|
|
|
|
IntType n = IntType(0);
|
|
|
|
IntType d = IntType(1);
|
|
|
|
Elem c = 0;
|
|
|
|
sprout::detail::io::ios_flags_saver saver(lhs);
|
|
|
|
lhs >> n;
|
|
|
|
c = lhs.get();
|
|
|
|
if (c != Elem('/')) {
|
|
|
|
lhs.clear(std::istream::badbit);
|
|
|
|
}
|
|
|
|
lhs >> std::noskipws;
|
|
|
|
lhs >> d;
|
|
|
|
if (lhs) {
|
|
|
|
rhs.assign(n, d);
|
|
|
|
}
|
|
|
|
return lhs;
|
|
|
|
}
|
|
|
|
template<typename Elem, typename Traits, typename IntType>
|
2013-11-02 09:28:18 +00:00
|
|
|
inline SPROUT_NON_CONSTEXPR std::basic_ostream<Elem, Traits>&
|
2012-08-28 16:16:12 +00:00
|
|
|
operator<<(std::basic_ostream<Elem, Traits>& lhs, sprout::rational<IntType> const& rhs) {
|
|
|
|
return lhs << rhs.numerator() << Elem('/') << rhs.denominator();
|
|
|
|
}
|
2013-03-22 05:24:19 +00:00
|
|
|
} // namespace sprout
|
2012-08-28 16:16:12 +00:00
|
|
|
|
2012-09-21 06:43:30 +00:00
|
|
|
#endif // SPROUT_RATIONAL_IO_HPP
|