Generated on Mon Aug 25 11:35:34 2008 for Gecode by doxygen 1.5.6

print.cc

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2003
00008  *
00009  *  Last modified:
00010  *     $Date: 2007-08-09 15:30:21 +0200 (Thu, 09 Aug 2007) $ by $Author: tack $
00011  *     $Revision: 4790 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 // STATISTICS: int-var
00133