8#ifdef ADOBE_STD_SERIALIZATION
12#ifndef ADOBE_MANIP_HPP
13#define ADOBE_MANIP_HPP
32class manipulator_base {
34 manipulator_base() : error_m(std::ios_base::goodbit) {}
37 template <
typename StreamType>
38 std::ios_base::iostate handle_error(StreamType& strm)
const {
39 std::ios_base::iostate err(error_m);
45 catch (std::bad_alloc&) {
48 std::ios_base::iostate exception_mask(strm.exceptions());
50 if (exception_mask & std::ios_base::failbit &&
51 !(exception_mask & std::ios_base::badbit))
53 else if (exception_mask & std::ios_base::badbit) {
56 }
catch (std::ios_base::failure&) {
63 std::ios_base::iostate exception_mask(strm.exceptions());
65 if ((exception_mask & std::ios_base::badbit) && (err & std::ios_base::badbit))
67 else if (exception_mask & std::ios_base::failbit) {
70 }
catch (std::ios_base::failure&) {
79 void set_fail()
const { error_m |= std::ios_base::failbit; }
80 void set_bad()
const { error_m |= std::ios_base::badbit; }
82 mutable std::ios_base::iostate error_m;
87template <
typename ArgumentType,
class charT,
class traits>
88class basic_omanipulator :
public manipulator_base {
90 typedef ArgumentType argument_type;
91 typedef std::basic_ostream<charT, traits> stream_type;
92 typedef stream_type& (*manip_func)(stream_type&,
const ArgumentType&);
94 basic_omanipulator(manip_func pf,
const argument_type& arg) : pf_m(pf), arg_m(arg) {}
96 void do_manip(stream_type& strm)
const {
97 if (error_m != std::ios_base::goodbit)
98 strm.setstate(error_m);
100 std::ios_base::iostate err(error_m);
102 (*pf_m)(strm, arg_m);
104 err = handle_error(strm);
121template <
typename ArgumentType1,
typename ArgumentType2,
class charT,
class traits>
122class basic_omanipulator2 :
public manipulator_base {
124 typedef ArgumentType1 argument_type_1;
125 typedef ArgumentType2 argument_type_2;
126 typedef std::basic_ostream<charT, traits> stream_type;
127 typedef stream_type& (*manip_func)(stream_type&,
const ArgumentType1&,
const ArgumentType2&);
129 basic_omanipulator2(manip_func pf,
const ArgumentType1& arg1,
const ArgumentType2& arg2)
130 : pf_m(pf), arg1_m(arg1), arg2_m(arg2) {}
132 void do_manip(stream_type& strm)
const {
133 if (error_m != std::ios_base::goodbit)
134 strm.setstate(error_m);
136 std::ios_base::iostate err(error_m);
138 (*pf_m)(strm, arg1_m, arg2_m);
140 err = handle_error(strm);
152 argument_type_1 arg1_m;
153 argument_type_2 arg2_m;
158template <
class ArgumentType,
class charT,
class traits>
159std::basic_ostream<charT, traits>&
160operator<<(std::basic_ostream<charT, traits>& os,
161 const adobe::basic_omanipulator<ArgumentType, charT, traits>& manip) {
170template <
class ArgumentType1,
class ArgumentType2,
class charT,
class traits>
171std::basic_ostream<charT, traits>&
172operator<<(std::basic_ostream<charT, traits>& os,
173 const adobe::basic_omanipulator2<ArgumentType1, ArgumentType2, charT, traits>& manip) {
182template <
class charT,
class traits>
183class basic_bounded_width :
public basic_omanipulator<unsigned int, charT, traits> {
184 typedef basic_omanipulator<unsigned int, charT, traits> inherited_t;
187 typedef typename inherited_t::stream_type stream_type;
188 typedef typename inherited_t::argument_type argument_type;
190 basic_bounded_width(argument_type min, argument_type max)
191 : basic_omanipulator<argument_type, charT, traits>(basic_bounded_width::fct,
min),
194 inherited_t& operator()(argument_type i) {
195 inherited_t::arg_m = std::min(max_m, std::max(i, min_m));
200 static stream_type& fct(stream_type& strm,
const argument_type& i) {
209typedef basic_bounded_width<char, std::char_traits<char>> bounded_width;
210typedef basic_bounded_width<wchar_t, std::char_traits<wchar_t>> wbounded_width;
const T & max(const T &a, const T &b, R r)
minmax implementation
const T & min(const T &a, const T &b, R r)
minmax implementation
std::ostream & operator<<(std::ostream &s, const extents_t &x)