comparison DEPENDENCIES/generic/include/boost/chrono/io/duration_io.hpp @ 101:c530137014c0

Update Boost headers (1.58.0)
author Chris Cannam
date Mon, 07 Sep 2015 11:12:49 +0100
parents 2665513ce2d3
children
comparison
equal deleted inserted replaced
100:793467b5e61c 101:c530137014c0
16 #include <boost/chrono/io/ios_base_state.hpp> 16 #include <boost/chrono/io/ios_base_state.hpp>
17 #include <boost/chrono/io/duration_put.hpp> 17 #include <boost/chrono/io/duration_put.hpp>
18 #include <boost/chrono/io/duration_get.hpp> 18 #include <boost/chrono/io/duration_get.hpp>
19 #include <boost/chrono/io/utility/manip_base.hpp> 19 #include <boost/chrono/io/utility/manip_base.hpp>
20 #include <boost/detail/no_exceptions_support.hpp> 20 #include <boost/detail/no_exceptions_support.hpp>
21 #include <boost/type_traits/is_integral.hpp>
22 #include <boost/type_traits/is_floating_point.hpp>
21 #include <locale> 23 #include <locale>
22 #include <iostream> 24 #include <iostream>
25 #include <sstream>
23 26
24 namespace boost 27 namespace boost
25 { 28 {
26 namespace chrono 29 namespace chrono
27 { 30 {
69 * Explicit construction from an i/o stream. 72 * Explicit construction from an i/o stream.
70 * 73 *
71 * Store a reference to the i/o stream and the value of the associated @c duration_style. 74 * Store a reference to the i/o stream and the value of the associated @c duration_style.
72 */ 75 */
73 explicit duration_style_io_saver(state_type &s) : 76 explicit duration_style_io_saver(state_type &s) :
74 s_save_(s) 77 s_save_(s), a_save_(get_duration_style(s))
75 { 78 {
76 a_save_ = get_duration_style(s_save_);
77 } 79 }
78 80
79 /** 81 /**
80 * Construction from an i/o stream and a @c duration_style to restore. 82 * Construction from an i/o stream and a @c duration_style to restore.
81 * 83 *
82 * Stores a reference to the i/o stream and the value @c duration_style to restore given as parameter. 84 * Stores a reference to the i/o stream and the value @c new_value @c duration_style to set.
83 */ 85 */
84 duration_style_io_saver(state_type &s, aspect_type new_value) : 86 duration_style_io_saver(state_type &s, aspect_type new_value) :
85 s_save_(s), a_save_(new_value) 87 s_save_(s), a_save_(get_duration_style(s))
86 { 88 {
89 set_duration_style(s, new_value);
87 } 90 }
88 91
89 /** 92 /**
90 * Destructor. 93 * Destructor.
91 * 94 *
108 duration_style_io_saver& operator=(duration_style_io_saver const& rhs) ; 111 duration_style_io_saver& operator=(duration_style_io_saver const& rhs) ;
109 112
110 state_type& s_save_; 113 state_type& s_save_;
111 aspect_type a_save_; 114 aspect_type a_save_;
112 }; 115 };
116
117 template <class Rep>
118 struct duration_put_enabled
119 : integral_constant<bool,
120 is_integral<Rep>::value || is_floating_point<Rep>::value
121 >
122 {};
123
113 124
114 /** 125 /**
115 * duration stream inserter 126 * duration stream inserter
116 * @param os the output stream 127 * @param os the output stream
117 * @param d to value to insert 128 * @param d to value to insert
118 * @return @c os 129 * @return @c os
119 */ 130 */
131
120 template <class CharT, class Traits, class Rep, class Period> 132 template <class CharT, class Traits, class Rep, class Period>
121 std::basic_ostream<CharT, Traits>& 133 typename boost::enable_if_c< ! duration_put_enabled<Rep>::value, std::basic_ostream<CharT, Traits>& >::type
134 operator<<(std::basic_ostream<CharT, Traits>& os, const duration<Rep, Period>& d)
135 {
136 std::basic_ostringstream<CharT, Traits> ostr;
137 ostr << d.count();
138 duration<int, Period> dd(0);
139 bool failed = false;
140 BOOST_TRY
141 {
142 std::ios_base::iostate err = std::ios_base::goodbit;
143 BOOST_TRY
144 {
145 typename std::basic_ostream<CharT, Traits>::sentry opfx(os);
146 if (bool(opfx))
147 {
148 if (!std::has_facet<duration_put<CharT> >(os.getloc()))
149 {
150 if (duration_put<CharT> ().put(os, os, os.fill(), dd, ostr.str().c_str()) .failed())
151 {
152 err = std::ios_base::badbit;
153 }
154 }
155 else if (std::use_facet<duration_put<CharT> >(os.getloc()) .put(os, os, os.fill(), dd, ostr.str().c_str()) .failed())
156 {
157 err = std::ios_base::badbit;
158 }
159 os.width(0);
160 }
161 }
162 BOOST_CATCH(...)
163 {
164 bool flag = false;
165 BOOST_TRY
166 {
167 os.setstate(std::ios_base::failbit);
168 }
169 BOOST_CATCH (std::ios_base::failure )
170 {
171 flag = true;
172 }
173 BOOST_CATCH_END
174 if (flag) throw;
175 }
176 BOOST_CATCH_END
177 if (err) os.setstate(err);
178 return os;
179 }
180 BOOST_CATCH(...)
181 {
182 failed = true;
183 }
184 BOOST_CATCH_END
185 if (failed) os.setstate(std::ios_base::failbit | std::ios_base::badbit);
186 return os;
187
188 }
189
190 template <class CharT, class Traits, class Rep, class Period>
191 typename boost::enable_if_c< duration_put_enabled<Rep>::value, std::basic_ostream<CharT, Traits>& >::type
122 operator<<(std::basic_ostream<CharT, Traits>& os, const duration<Rep, Period>& d) 192 operator<<(std::basic_ostream<CharT, Traits>& os, const duration<Rep, Period>& d)
123 { 193 {
124 bool failed = false; 194 bool failed = false;
125 BOOST_TRY 195 BOOST_TRY
126 { 196 {