00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <sstream>
00039
00040 namespace Gecode { namespace Int {
00041
00042 template<class Char, class Traits, class View>
00043 std::basic_ostream<Char,Traits>&
00044 print_view(std::basic_ostream<Char,Traits>& os, const View& x) {
00045 std::basic_ostringstream<Char,Traits> s;
00046 s.copyfmt(os); s.width(0);
00047 if (x.assigned()) {
00048 s << x.val();
00049 } else if (x.range()) {
00050 s << '[' << x.min() << ".." << x.max() << ']';
00051 } else {
00052 s << '{';
00053 ViewRanges<View> r(x);
00054 while (true) {
00055 if (r.min() == r.max()) {
00056 s << r.min();
00057 } else {
00058 s << r.min() << ".." << r.max();
00059 }
00060 ++r;
00061 if (!r()) break;
00062 s << ',';
00063 }
00064 s << '}';
00065 }
00066 return os << s.str();
00067 }
00068
00069 template<class Char, class Traits, class Val, class UnsVal>
00070 std::basic_ostream<Char,Traits>&
00071 print_scale(std::basic_ostream<Char,Traits>& os,
00072 const ScaleView<Val,UnsVal>& x) {
00073 std::basic_ostringstream<Char,Traits> s;
00074 s.copyfmt(os); s.width(0);
00075 if (x.assigned()) {
00076 s << x.val();
00077 } else {
00078 s << '{';
00079 ViewRanges<ScaleView<Val,UnsVal> > r(x);
00080 while (true) {
00081 if (r.min() == r.max()) {
00082 s << r.min();
00083 } else {
00084 s << r.min() << ".." << r.max();
00085 }
00086 ++r;
00087 if (!r()) break;
00088 s << ',';
00089 }
00090 s << '}';
00091 }
00092 return os << s.str();
00093 }
00094
00095 template<class Char, class Traits>
00096 inline std::basic_ostream<Char,Traits>&
00097 operator <<(std::basic_ostream<Char,Traits>& os, const IntView& x) {
00098 return print_view(os,x);
00099 }
00100 template<class Char, class Traits>
00101 inline std::basic_ostream<Char,Traits>&
00102 operator <<(std::basic_ostream<Char,Traits>& os, const MinusView& x) {
00103 return print_view(os,x);
00104 }
00105 template<class Char, class Traits>
00106 inline std::basic_ostream<Char,Traits>&
00107 operator <<(std::basic_ostream<Char,Traits>& os, const OffsetView& x) {
00108 return print_view(os,x);
00109 }
00110
00111 template<class Char, class Traits>
00112 inline std::basic_ostream<Char,Traits>&
00113 operator <<(std::basic_ostream<Char,Traits>& os, const IntScaleView& x) {
00114 return print_scale<int,unsigned int>(os,x);
00115 }
00116 template<class Char, class Traits>
00117 inline std::basic_ostream<Char,Traits>&
00118 operator <<(std::basic_ostream<Char,Traits>& os, const DoubleScaleView& x) {
00119 return print_scale<double,double>(os,x);
00120 }
00121
00122 template<class Char, class Traits>
00123 inline std::basic_ostream<Char,Traits>&
00124 operator <<(std::basic_ostream<Char,Traits>& os, const ConstIntView& x) {
00125 return os << x.val();
00126 }
00127 template<class Char, class Traits>
00128 inline std::basic_ostream<Char,Traits>&
00129 operator <<(std::basic_ostream<Char,Traits>& os, const ZeroIntView& x) {
00130 return os << 0;
00131 }
00132
00133
00134 template<class Char, class Traits>
00135 std::basic_ostream<Char,Traits>&
00136 operator <<(std::basic_ostream<Char,Traits>& os, const BoolView& x) {
00137 if (x.one())
00138 return os << 1;
00139 if (x.zero())
00140 return os << 0;
00141 return os << "[0..1]";
00142 }
00143 template<class Char, class Traits>
00144 std::basic_ostream<Char,Traits>&
00145 operator <<(std::basic_ostream<Char,Traits>& os, const NegBoolView& x) {
00146 if (x.one())
00147 return os << 0;
00148 if (x.zero())
00149 return os << 1;
00150 return os << "[0..1]";
00151 }
00152
00153 }}
00154
00155
00156