Generated on Wed Nov 1 15:04:41 2006 for Gecode by doxygen 1.4.5

print.cc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Christian Schulte <schulte@gecode.org>
00004  *
00005  *  Copyright:
00006  *     Christian Schulte, 2003
00007  *
00008  *  Last modified:
00009  *     $Date: 2006-04-11 15:58:37 +0200 (Tue, 11 Apr 2006) $ by $Author: tack $
00010  *     $Revision: 3188 $
00011  *
00012  *  This file is part of Gecode, the generic constraint
00013  *  development environment:
00014  *     http://www.gecode.org
00015  *
00016  *  See the file "LICENSE" for information on usage and
00017  *  redistribution of this file, and for a
00018  *     DISCLAIMER OF ALL WARRANTIES.
00019  *
00020  */
00021 
00022 #include "gecode/int.hh"
00023 
00024 namespace Gecode { namespace Int {
00025 
00026   template <class View>
00027   inline static std::ostream&
00028   print_view(std::ostream& os, const View& x) {
00029     if (x.assigned()) {
00030       return os << x.val();
00031     } else if (x.range()) {
00032       return os << '[' << x.min() << ".." << x.max() << ']';
00033     } else {
00034       os << '{';
00035       ViewRanges<View> r(x);
00036       while (true) {
00037         if (r.min() == r.max()) {
00038           os << r.min();
00039         } else {
00040           os << r.min() << ".." << r.max();
00041         }
00042         ++r;
00043         if (!r()) break;
00044         os << ',';
00045       }
00046       return os << '}';
00047     }
00048   }
00049 
00050   template <class Val, class UnsVal>
00051   std::ostream&
00052   print_scale(std::ostream& os, const ScaleView<Val,UnsVal>& x) {
00053     if (x.assigned()) {
00054       return os << x.val();
00055     } else {
00056       os << '{';
00057       ViewRanges<ScaleView<Val,UnsVal> > r(x);
00058       while (true) {
00059         if (r.min() == r.max()) {
00060           os << r.min();
00061         } else {
00062           os << r.min() << ".." << r.max();
00063         }
00064         ++r;
00065         if (!r()) break;
00066         os << ',';
00067       }
00068       return os << '}';
00069     }
00070   }
00071 
00072 }}
00073 
00074 std::ostream&
00075 operator<<(std::ostream& os, const Gecode::Int::IntView& x) {
00076   return Gecode::Int::print_view(os,x);
00077 }
00078 std::ostream&
00079 operator<<(std::ostream& os, const Gecode::Int::MinusView& x) {
00080   return Gecode::Int::print_view(os,x);
00081 }
00082 std::ostream&
00083 operator<<(std::ostream& os, const Gecode::Int::OffsetView& x) {
00084   return Gecode::Int::print_view(os,x);
00085 }
00086 std::ostream&
00087 operator<<(std::ostream& os, const Gecode::Int::IntScaleView& x) {
00088   return Gecode::Int::print_scale<int,unsigned int>(os,x);
00089 }
00090 std::ostream&
00091 operator<<(std::ostream& os, const Gecode::Int::DoubleScaleView& x) {
00092   return Gecode::Int::print_scale<double,double>(os,x);
00093 }
00094 std::ostream&
00095 operator<<(std::ostream& os, const Gecode::Int::ConstIntView& x) {
00096   return os << x.val();
00097 }
00098 std::ostream&
00099 operator<<(std::ostream& os, const Gecode::Int::NegBoolView& x) {
00100   if (x.one())
00101     return os << 1;
00102   if (x.zero())
00103     return os << 0;
00104   return os << "[0..1]";
00105 }
00106 
00107 
00108 // STATISTICS: int-var
00109