Generated on Sun Feb 17 15:24:11 2019 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  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 #include <sstream>
00035 
00036 namespace Gecode { namespace Int {
00037 
00038   template<class Char, class Traits, class View>
00039   std::basic_ostream<Char,Traits>&
00040   print_view(std::basic_ostream<Char,Traits>& os, const View& x) {
00041     std::basic_ostringstream<Char,Traits> s;
00042     s.copyfmt(os); s.width(0);
00043     if (x.assigned()) {
00044       s << x.val();
00045     } else if (x.range()) {
00046       s << '[' << x.min() << ".." << x.max() << ']';
00047     } else {
00048       s << '{';
00049       ViewRanges<View> r(x);
00050       while (true) {
00051         if (r.min() == r.max()) {
00052           s << r.min();
00053         } else {
00054           s << r.min() << ".." << r.max();
00055         }
00056         ++r;
00057         if (!r()) break;
00058         s << ',';
00059       }
00060       s << '}';
00061     }
00062     return os << s.str();
00063   }
00064 
00065   template<class Char, class Traits, class Val, class UnsVal>
00066   std::basic_ostream<Char,Traits>&
00067   print_scale(std::basic_ostream<Char,Traits>& os,
00068               const ScaleView<Val,UnsVal>& x) {
00069     std::basic_ostringstream<Char,Traits> s;
00070     s.copyfmt(os); s.width(0);
00071     if (x.assigned()) {
00072       s << x.val();
00073     } else {
00074       s << '{';
00075       ViewRanges<ScaleView<Val,UnsVal> > r(x);
00076       while (true) {
00077         if (r.min() == r.max()) {
00078           s << r.min();
00079         } else {
00080           s << r.min() << ".." << r.max();
00081         }
00082         ++r;
00083         if (!r()) break;
00084         s << ',';
00085       }
00086       s << '}';
00087     }
00088     return os << s.str();
00089   }
00090 
00091   template<class Char, class Traits>
00092   inline std::basic_ostream<Char,Traits>&
00093   operator <<(std::basic_ostream<Char,Traits>& os, const IntView& x) {
00094     return print_view(os,x);
00095   }
00096   template<class Char, class Traits>
00097   inline std::basic_ostream<Char,Traits>&
00098   operator <<(std::basic_ostream<Char,Traits>& os, const MinusView& x) {
00099     return print_view(os,x);
00100   }
00101   template<class Char, class Traits>
00102   inline std::basic_ostream<Char,Traits>&
00103   operator <<(std::basic_ostream<Char,Traits>& os, const OffsetView& x) {
00104     return print_view(os,x);
00105   }
00106   template<class Char, class Traits, class View>
00107   inline std::basic_ostream<Char,Traits>&
00108   operator <<(std::basic_ostream<Char,Traits>& os,
00109               const CachedView<View>& x) {
00110     return print_view(os,x);
00111   }
00112 
00113   template<class Char, class Traits>
00114   inline std::basic_ostream<Char,Traits>&
00115   operator <<(std::basic_ostream<Char,Traits>& os, const IntScaleView& x) {
00116     return print_scale<Char,Traits,int,unsigned int>(os,x);
00117   }
00118   template<class Char, class Traits>
00119   inline std::basic_ostream<Char,Traits>&
00120   operator <<(std::basic_ostream<Char,Traits>& os, const LLongScaleView& x) {
00121     return print_scale<Char,Traits,long long int,unsigned long long int>(os,x);
00122   }
00123 
00124   template<class Char, class Traits>
00125   inline std::basic_ostream<Char,Traits>&
00126   operator <<(std::basic_ostream<Char,Traits>& os, const ConstIntView& x) {
00127     return os << x.val();
00128   }
00129   template<class Char, class Traits>
00130   inline std::basic_ostream<Char,Traits>&
00131   operator <<(std::basic_ostream<Char,Traits>& os, const ZeroIntView&) {
00132     return os << 0;
00133   }
00134 
00135 
00136   template<class Char, class Traits>
00137   std::basic_ostream<Char,Traits>&
00138   operator <<(std::basic_ostream<Char,Traits>& os, const BoolView& x) {
00139     if (x.one())
00140       return os << 1;
00141     if (x.zero())
00142       return os << 0;
00143     return os << "[0..1]";
00144   }
00145   template<class Char, class Traits>
00146   std::basic_ostream<Char,Traits>&
00147   operator <<(std::basic_ostream<Char,Traits>& os, const NegBoolView& x) {
00148     if (x.one())
00149       return os << 0;
00150     if (x.zero())
00151       return os << 1;
00152     return os << "[0..1]";
00153   }
00154 
00155 }}
00156 
00157 // STATISTICS: int-var
00158