Generated on Thu Mar 22 10:39:41 2012 for Gecode by doxygen 1.6.3

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: 2011-09-28 14:14:32 +0200 (Wed, 28 Sep 2011) $ by $Author: tack $
00011  *     $Revision: 12417 $
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   template<class Char, class Traits, class View>
00111   inline std::basic_ostream<Char,Traits>&
00112   operator <<(std::basic_ostream<Char,Traits>& os,
00113               const CachedView<View>& x) {
00114     return print_view(os,x);
00115   }
00116 
00117   template<class Char, class Traits>
00118   inline std::basic_ostream<Char,Traits>&
00119   operator <<(std::basic_ostream<Char,Traits>& os, const IntScaleView& x) {
00120     return print_scale<Char,Traits,int,unsigned int>(os,x);
00121   }
00122   template<class Char, class Traits>
00123   inline std::basic_ostream<Char,Traits>&
00124   operator <<(std::basic_ostream<Char,Traits>& os, const DoubleScaleView& x) {
00125     return print_scale<Char,Traits,double,double>(os,x);
00126   }
00127 
00128   template<class Char, class Traits>
00129   inline std::basic_ostream<Char,Traits>&
00130   operator <<(std::basic_ostream<Char,Traits>& os, const ConstIntView& x) {
00131     return os << x.val();
00132   }
00133   template<class Char, class Traits>
00134   inline std::basic_ostream<Char,Traits>&
00135   operator <<(std::basic_ostream<Char,Traits>& os, const ZeroIntView&) {
00136     return os << 0;
00137   }
00138 
00139 
00140   template<class Char, class Traits>
00141   std::basic_ostream<Char,Traits>&
00142   operator <<(std::basic_ostream<Char,Traits>& os, const BoolView& x) {
00143     if (x.one())
00144       return os << 1;
00145     if (x.zero())
00146       return os << 0;
00147     return os << "[0..1]";
00148   }
00149   template<class Char, class Traits>
00150   std::basic_ostream<Char,Traits>&
00151   operator <<(std::basic_ostream<Char,Traits>& os, const NegBoolView& x) {
00152     if (x.one())
00153       return os << 0;
00154     if (x.zero())
00155       return os << 1;
00156     return os << "[0..1]";
00157   }
00158 
00159 }}
00160 
00161 // STATISTICS: int-var
00162