print.cc
Go to the documentation of this file.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 "gecode/int.hh"
00039
00040 namespace Gecode { namespace Int {
00041
00042 template <class View>
00043 inline static std::ostream&
00044 print_view(std::ostream& os, const View& x) {
00045 if (x.assigned()) {
00046 return os << x.val();
00047 } else if (x.range()) {
00048 return os << '[' << x.min() << ".." << x.max() << ']';
00049 } else {
00050 os << '{';
00051 ViewRanges<View> r(x);
00052 while (true) {
00053 if (r.min() == r.max()) {
00054 os << r.min();
00055 } else {
00056 os << r.min() << ".." << r.max();
00057 }
00058 ++r;
00059 if (!r()) break;
00060 os << ',';
00061 }
00062 return os << '}';
00063 }
00064 }
00065
00066 template <class Val, class UnsVal>
00067 std::ostream&
00068 print_scale(std::ostream& os, const ScaleView<Val,UnsVal>& x) {
00069 if (x.assigned()) {
00070 return os << x.val();
00071 } else {
00072 os << '{';
00073 ViewRanges<ScaleView<Val,UnsVal> > r(x);
00074 while (true) {
00075 if (r.min() == r.max()) {
00076 os << r.min();
00077 } else {
00078 os << r.min() << ".." << r.max();
00079 }
00080 ++r;
00081 if (!r()) break;
00082 os << ',';
00083 }
00084 return os << '}';
00085 }
00086 }
00087
00088 }}
00089
00090 std::ostream&
00091 operator<<(std::ostream& os, const Gecode::Int::IntView& x) {
00092 return Gecode::Int::print_view(os,x);
00093 }
00094 std::ostream&
00095 operator<<(std::ostream& os, const Gecode::Int::BoolView& x) {
00096 return Gecode::Int::print_view(os,x);
00097 }
00098 std::ostream&
00099 operator<<(std::ostream& os, const Gecode::Int::MinusView& x) {
00100 return Gecode::Int::print_view(os,x);
00101 }
00102 std::ostream&
00103 operator<<(std::ostream& os, const Gecode::Int::OffsetView& x) {
00104 return Gecode::Int::print_view(os,x);
00105 }
00106 std::ostream&
00107 operator<<(std::ostream& os, const Gecode::Int::IntScaleView& x) {
00108 return Gecode::Int::print_scale<int,unsigned int>(os,x);
00109 }
00110 std::ostream&
00111 operator<<(std::ostream& os, const Gecode::Int::DoubleScaleView& x) {
00112 return Gecode::Int::print_scale<double,double>(os,x);
00113 }
00114 std::ostream&
00115 operator<<(std::ostream& os, const Gecode::Int::ConstIntView& x) {
00116 return os << x.val();
00117 }
00118 std::ostream&
00119 operator<<(std::ostream& os, const Gecode::Int::ZeroIntView&) {
00120 return os << 0;
00121 }
00122 std::ostream&
00123 operator<<(std::ostream& os, const Gecode::Int::NegBoolView& x) {
00124 if (x.one())
00125 return os << 1;
00126 if (x.zero())
00127 return os << 0;
00128 return os << "[0..1]";
00129 }
00130
00131
00132
00133