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