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 #include <sstream>
00037
00038 namespace Gecode { namespace Set {
00039
00041 template<class Char, class Traits, class I>
00042 void
00043 printBound(std::basic_ostream<Char,Traits>& s, I& r) {
00044 s << '{';
00045 while (r()) {
00046 if (r.min() == r.max()) {
00047 s << r.min();
00048 } else if (r.min()+1 == r.max()) {
00049 s << r.min() << "," << r.max();
00050 } else {
00051 s << r.min() << ".." << r.max();
00052 }
00053 ++r;
00054 if (!r()) break;
00055 s << ',';
00056 }
00057 s << '}';
00058 }
00059
00061 template<class Char, class Traits, class IL, class IU>
00062 void
00063 print(std::basic_ostream<Char,Traits>& s, bool assigned, IL& lb, IU& ub,
00064 unsigned int cardMin, unsigned int cardMax) {
00065 if (assigned) {
00066 printBound(s, ub);
00067 } else {
00068 printBound(s,lb);
00069 s << "..";
00070 printBound(s,ub);
00071 if (cardMin==cardMax) {
00072 s << "#(" << cardMin << ")";
00073 } else {
00074 s << "#(" << cardMin << "," << cardMax << ")";
00075 }
00076 }
00077 }
00078
00079 template<class Char, class Traits>
00080 std::basic_ostream<Char,Traits>&
00081 operator <<(std::basic_ostream<Char,Traits>& os, const SetView& x) {
00082 std::basic_ostringstream<Char,Traits> s;
00083 s.copyfmt(os); s.width(0);
00084 LubRanges<SetView> ub(x);
00085 GlbRanges<SetView> lb(x);
00086 print(s, x.assigned(), lb, ub, x.cardMin(), x.cardMax()) ;
00087 return os << s.str();
00088 }
00089
00090 template<class Char, class Traits>
00091 inline std::basic_ostream<Char,Traits>&
00092 operator <<(std::basic_ostream<Char,Traits>& os, const EmptyView&) {
00093 return os << "{}#0";
00094 }
00095
00096 template<class Char, class Traits>
00097 std::basic_ostream<Char,Traits>&
00098 operator <<(std::basic_ostream<Char,Traits>& os, const UniverseView&) {
00099 std::basic_ostringstream<Char,Traits> s;
00100 s.copyfmt(os); s.width(0);
00101 s << "{" << Gecode::Set::Limits::min << ".."
00102 << Gecode::Set::Limits::max << "}#("
00103 << Gecode::Set::Limits::card << ")";
00104 return os << s.str();
00105 }
00106
00107 template<class Char, class Traits>
00108 std::basic_ostream<Char,Traits>&
00109 operator <<(std::basic_ostream<Char,Traits>& os, const ConstSetView& x) {
00110 std::basic_ostringstream<Char,Traits> s;
00111 s.copyfmt(os); s.width(0);
00112 LubRanges<ConstSetView> ub(x);
00113 printBound(s, ub);
00114 s << "#(" << x.cardMin() << ")";
00115 return os << s.str();
00116 }
00117
00118 template<class Char, class Traits>
00119 std::basic_ostream<Char,Traits>&
00120 operator <<(std::basic_ostream<Char,Traits>& os, const SingletonView& x) {
00121 std::basic_ostringstream<Char,Traits> s;
00122 s.copyfmt(os); s.width(0);
00123 if (x.assigned()) {
00124 s << "{" << x.glbMin() << "}#(1)";
00125 } else {
00126 LubRanges<SingletonView> ub(x);
00127 s << "{}..";
00128 printBound(s, ub);
00129 s << "#(1)";
00130 }
00131 return os << s.str();
00132 }
00133
00134 }}
00135
00136