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 template<class Char, class Traits, class View>
00111 inline std::basic_ostream<Char,Traits>&
00112 operator <<(std::basic_ostream<Char,Traits>& os,
00113 const CachedView<View>& x) {
00114 return print_view(os,x);
00115 }
00116
00117 template<class Char, class Traits>
00118 inline std::basic_ostream<Char,Traits>&
00119 operator <<(std::basic_ostream<Char,Traits>& os, const IntScaleView& x) {
00120 return print_scale<Char,Traits,int,unsigned int>(os,x);
00121 }
00122 template<class Char, class Traits>
00123 inline std::basic_ostream<Char,Traits>&
00124 operator <<(std::basic_ostream<Char,Traits>& os, const DoubleScaleView& x) {
00125 return print_scale<Char,Traits,double,double>(os,x);
00126 }
00127
00128 template<class Char, class Traits>
00129 inline std::basic_ostream<Char,Traits>&
00130 operator <<(std::basic_ostream<Char,Traits>& os, const ConstIntView& x) {
00131 return os << x.val();
00132 }
00133 template<class Char, class Traits>
00134 inline std::basic_ostream<Char,Traits>&
00135 operator <<(std::basic_ostream<Char,Traits>& os, const ZeroIntView&) {
00136 return os << 0;
00137 }
00138
00139
00140 template<class Char, class Traits>
00141 std::basic_ostream<Char,Traits>&
00142 operator <<(std::basic_ostream<Char,Traits>& os, const BoolView& x) {
00143 if (x.one())
00144 return os << 1;
00145 if (x.zero())
00146 return os << 0;
00147 return os << "[0..1]";
00148 }
00149 template<class Char, class Traits>
00150 std::basic_ostream<Char,Traits>&
00151 operator <<(std::basic_ostream<Char,Traits>& os, const NegBoolView& x) {
00152 if (x.one())
00153 return os << 0;
00154 if (x.zero())
00155 return os << 1;
00156 return os << "[0..1]";
00157 }
00158
00159 }}
00160
00161
00162