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