Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/chrono/io/duration_put.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 |
---|---|
11 #ifndef BOOST_CHRONO_IO_DURATION_PUT_HPP | 11 #ifndef BOOST_CHRONO_IO_DURATION_PUT_HPP |
12 #define BOOST_CHRONO_IO_DURATION_PUT_HPP | 12 #define BOOST_CHRONO_IO_DURATION_PUT_HPP |
13 | 13 |
14 #include <boost/chrono/config.hpp> | 14 #include <boost/chrono/config.hpp> |
15 #include <boost/chrono/io/duration_units.hpp> | 15 #include <boost/chrono/io/duration_units.hpp> |
16 #include <boost/chrono/process_cpu_clocks.hpp> | |
16 #include <boost/assert.hpp> | 17 #include <boost/assert.hpp> |
17 #include <locale> | 18 #include <locale> |
18 | 19 |
19 namespace boost | 20 namespace boost |
20 { | 21 { |
21 namespace chrono | 22 namespace chrono |
22 { | 23 { |
23 | 24 |
25 namespace detail | |
26 { | |
27 template <class T> | |
28 struct propagate { | |
29 typedef T type; | |
30 }; | |
31 template <> | |
32 struct propagate<boost::int_least32_t> { | |
33 typedef boost::int_least64_t type; | |
34 }; | |
35 } | |
24 /** | 36 /** |
25 * @tparam ChatT a character type | 37 * @tparam ChatT a character type |
26 * @tparam OutputIterator a model of @c OutputIterator | 38 * @tparam OutputIterator a model of @c OutputIterator |
27 * | 39 * |
28 * The @c duration_put facet provides facilities for formatted output of duration values. | 40 * The @c duration_put facet provides facilities for formatted output of duration values. |
88 * | 100 * |
89 * @Returns An iterator pointing immediately after the last character produced. | 101 * @Returns An iterator pointing immediately after the last character produced. |
90 */ | 102 */ |
91 template <typename Rep, typename Period> | 103 template <typename Rep, typename Period> |
92 iter_type put(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d, const CharT* pattern, | 104 iter_type put(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d, const CharT* pattern, |
93 const CharT* pat_end) const | 105 const CharT* pat_end, const char_type* val = 0) const |
94 { | 106 { |
95 if (std::has_facet<duration_units<CharT> >(ios.getloc())) | 107 if (std::has_facet<duration_units<CharT> >(ios.getloc())) |
96 { | 108 { |
97 duration_units<CharT> const&facet = std::use_facet<duration_units<CharT> >( | 109 duration_units<CharT> const&facet = std::use_facet<duration_units<CharT> >( |
98 ios.getloc()); | 110 ios.getloc()); |
99 return put(facet, s, ios, fill, d, pattern, pat_end); | 111 return put(facet, s, ios, fill, d, pattern, pat_end, val); |
100 } | 112 } |
101 else | 113 else |
102 { | 114 { |
103 duration_units_default<CharT> facet; | 115 duration_units_default<CharT> facet; |
104 return put(facet, s, ios, fill, d, pattern, pat_end); | 116 return put(facet, s, ios, fill, d, pattern, pat_end, val); |
105 } | 117 } |
106 } | 118 } |
107 | 119 |
108 template <typename Rep, typename Period> | 120 template <typename Rep, typename Period> |
109 iter_type put(duration_units<CharT> const& units_facet, iter_type s, std::ios_base& ios, char_type fill, | 121 iter_type put(duration_units<CharT> const& units_facet, iter_type s, std::ios_base& ios, char_type fill, |
110 duration<Rep, Period> const& d, const CharT* pattern, const CharT* pat_end) const | 122 duration<Rep, Period> const& d, const CharT* pattern, const CharT* pat_end, const char_type* val = 0) const |
111 { | 123 { |
112 | 124 |
113 const std::ctype<char_type>& ct = std::use_facet<std::ctype<char_type> >(ios.getloc()); | 125 const std::ctype<char_type>& ct = std::use_facet<std::ctype<char_type> >(ios.getloc()); |
114 for (; pattern != pat_end; ++pattern) | 126 for (; pattern != pat_end; ++pattern) |
115 { | 127 { |
123 char fmt = ct.narrow(*pattern, 0); | 135 char fmt = ct.narrow(*pattern, 0); |
124 switch (fmt) | 136 switch (fmt) |
125 { | 137 { |
126 case 'v': | 138 case 'v': |
127 { | 139 { |
128 s = put_value(s, ios, fill, d); | 140 s = put_value(s, ios, fill, d, val); |
129 break; | 141 break; |
130 } | 142 } |
131 case 'u': | 143 case 'u': |
132 { | 144 { |
133 s = put_unit(units_facet, s, ios, fill, d); | 145 s = put_unit(units_facet, s, ios, fill, d); |
156 * return put(s, ios, d, str.data(), str.data() + str.size()); | 168 * return put(s, ios, d, str.data(), str.data() + str.size()); |
157 * @endcode | 169 * @endcode |
158 * @Returns An iterator pointing immediately after the last character produced. | 170 * @Returns An iterator pointing immediately after the last character produced. |
159 */ | 171 */ |
160 template <typename Rep, typename Period> | 172 template <typename Rep, typename Period> |
161 iter_type put(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d) const | 173 iter_type put(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d, const char_type* val = 0) const |
162 { | 174 { |
163 if (std::has_facet<duration_units<CharT> >(ios.getloc())) | 175 if (std::has_facet<duration_units<CharT> >(ios.getloc())) |
164 { | 176 { |
165 duration_units<CharT> const&facet = std::use_facet<duration_units<CharT> >( | 177 duration_units<CharT> const&facet = std::use_facet<duration_units<CharT> >( |
166 ios.getloc()); | 178 ios.getloc()); |
167 std::basic_string<CharT> str = facet.get_pattern(); | 179 std::basic_string<CharT> str = facet.get_pattern(); |
168 return put(facet, s, ios, fill, d, str.data(), str.data() + str.size()); | 180 return put(facet, s, ios, fill, d, str.data(), str.data() + str.size(), val); |
169 } | 181 } |
170 else | 182 else |
171 { | 183 { |
172 duration_units_default<CharT> facet; | 184 duration_units_default<CharT> facet; |
173 std::basic_string<CharT> str = facet.get_pattern(); | 185 std::basic_string<CharT> str = facet.get_pattern(); |
174 return put(facet, s, ios, fill, d, str.data(), str.data() + str.size()); | 186 |
187 return put(facet, s, ios, fill, d, str.data(), str.data() + str.size(), val); | |
175 } | 188 } |
176 } | 189 } |
177 | 190 |
178 /** | 191 /** |
179 * | 192 * |
183 * @param d the duration | 196 * @param d the duration |
184 * @Effects As if s=std::use_facet<std::num_put<CharT, iter_type> >(ios.getloc()).put(s, ios, fill, static_cast<long int> (d.count())). | 197 * @Effects As if s=std::use_facet<std::num_put<CharT, iter_type> >(ios.getloc()).put(s, ios, fill, static_cast<long int> (d.count())). |
185 * @Returns s, iterator pointing immediately after the last character produced. | 198 * @Returns s, iterator pointing immediately after the last character produced. |
186 */ | 199 */ |
187 template <typename Rep, typename Period> | 200 template <typename Rep, typename Period> |
188 iter_type put_value(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d) const | 201 iter_type put_value(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d, const char_type* val = 0) const |
189 { | 202 { |
203 if (val) | |
204 { | |
205 while (*val) { | |
206 *s = *val; | |
207 s++; val++; | |
208 } | |
209 return s; | |
210 } | |
190 return std::use_facet<std::num_put<CharT, iter_type> >(ios.getloc()).put(s, ios, fill, | 211 return std::use_facet<std::num_put<CharT, iter_type> >(ios.getloc()).put(s, ios, fill, |
191 static_cast<long int> (d.count())); | 212 static_cast<typename detail::propagate<Rep>::type> (d.count())); |
213 } | |
214 | |
215 template <typename Rep, typename Period> | |
216 iter_type put_value(iter_type s, std::ios_base& ios, char_type fill, duration<process_times<Rep>, Period> const& d, const char_type* = 0) const | |
217 { | |
218 *s++ = CharT('{'); | |
219 s = put_value(s, ios, fill, process_real_cpu_clock::duration(d.count().real)); | |
220 *s++ = CharT(';'); | |
221 s = put_value(s, ios, fill, process_user_cpu_clock::duration(d.count().user)); | |
222 *s++ = CharT(';'); | |
223 s = put_value(s, ios, fill, process_system_cpu_clock::duration(d.count().system)); | |
224 *s++ = CharT('}'); | |
225 return s; | |
192 } | 226 } |
193 | 227 |
194 /** | 228 /** |
195 * | 229 * |
196 * @param s an output stream iterator | 230 * @param s an output stream iterator |
238 string_type str = facet.get_n_d_unit(get_duration_style(ios), d); | 272 string_type str = facet.get_n_d_unit(get_duration_style(ios), d); |
239 s=std::copy(str.begin(), str.end(), s); | 273 s=std::copy(str.begin(), str.end(), s); |
240 } | 274 } |
241 return s; | 275 return s; |
242 } | 276 } |
277 template <typename Rep, typename Period> | |
278 iter_type put_unit(duration_units<CharT> const& facet, iter_type s, std::ios_base& ios, char_type fill, | |
279 duration<process_times<Rep>, Period> const& d) const | |
280 { | |
281 duration<Rep,Period> real(d.count().real); | |
282 if (facet.template is_named_unit<Period>()) { | |
283 string_type str = facet.get_unit(get_duration_style(ios), real); | |
284 s=std::copy(str.begin(), str.end(), s); | |
285 } else { | |
286 *s++ = CharT('['); | |
287 std::use_facet<std::num_put<CharT, iter_type> >(ios.getloc()).put(s, ios, fill, Period::num); | |
288 *s++ = CharT('/'); | |
289 std::use_facet<std::num_put<CharT, iter_type> >(ios.getloc()).put(s, ios, fill, Period::den); | |
290 *s++ = CharT(']'); | |
291 string_type str = facet.get_n_d_unit(get_duration_style(ios), real); | |
292 s=std::copy(str.begin(), str.end(), s); | |
293 } | |
294 return s; | |
295 } | |
243 | 296 |
244 /** | 297 /** |
245 * Unique identifier for this type of facet. | 298 * Unique identifier for this type of facet. |
246 */ | 299 */ |
247 static std::locale::id id; | 300 static std::locale::id id; |