Generated on Thu Apr 11 13:59:01 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  *     Guido Tack <tack@gecode.org>
00005  *     Gabor Szokoli <szokoli@gecode.org>
00006  *
00007  *  Copyright:
00008  *     Guido Tack, 2004, 2005
00009  *     Gabor Szokoli, 2004
00010  *
00011  *  This file is part of Gecode, the generic constraint
00012  *  development environment:
00013  *     http://www.gecode.org
00014  *
00015  *  Permission is hereby granted, free of charge, to any person obtaining
00016  *  a copy of this software and associated documentation files (the
00017  *  "Software"), to deal in the Software without restriction, including
00018  *  without limitation the rights to use, copy, modify, merge, publish,
00019  *  distribute, sublicense, and/or sell copies of the Software, and to
00020  *  permit persons to whom the Software is furnished to do so, subject to
00021  *  the following conditions:
00022  *
00023  *  The above copyright notice and this permission notice shall be
00024  *  included in all copies or substantial portions of the Software.
00025  *
00026  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00027  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00028  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00029  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00030  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00031  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00032  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00033  *
00034  */
00035 
00036 #include <sstream>
00037 
00038 namespace Gecode { namespace Set {
00039 
00041   template<class Char, class Traits, class I>
00042   void
00043   printBound(std::basic_ostream<Char,Traits>& s, I& r) {
00044     s << '{';
00045     while (r()) {
00046       if (r.min() == r.max()) {
00047         s << r.min();
00048       } else if (r.min()+1 == r.max()) {
00049         s << r.min() << "," << r.max();
00050       } else {
00051         s << r.min() << ".." << r.max();
00052       }
00053       ++r;
00054       if (!r()) break;
00055       s << ',';
00056     }
00057     s << '}';
00058   }
00059 
00061   template<class Char, class Traits, class IL, class IU>
00062   void
00063   print(std::basic_ostream<Char,Traits>& s, bool assigned, IL& lb, IU& ub,
00064         unsigned int cardMin, unsigned int cardMax) {
00065     if (assigned) {
00066       printBound(s, ub);
00067     } else {
00068       printBound(s,lb);
00069       s << "..";
00070       printBound(s,ub);
00071       if (cardMin==cardMax) {
00072         s << "#(" << cardMin << ")";
00073       } else {
00074         s << "#(" << cardMin << "," << cardMax << ")";
00075       }
00076     }
00077   }
00078 
00079   template<class Char, class Traits>
00080   std::basic_ostream<Char,Traits>&
00081   operator <<(std::basic_ostream<Char,Traits>& os, const SetView& x) {
00082     std::basic_ostringstream<Char,Traits> s;
00083     s.copyfmt(os); s.width(0);
00084     LubRanges<SetView> ub(x);
00085     GlbRanges<SetView> lb(x);
00086     print(s, x.assigned(), lb, ub, x.cardMin(), x.cardMax()) ;
00087     return os << s.str();
00088   }
00089 
00090   template<class Char, class Traits>
00091   inline std::basic_ostream<Char,Traits>&
00092   operator <<(std::basic_ostream<Char,Traits>& os, const EmptyView&) {
00093     return os << "{}#0";
00094   }
00095 
00096   template<class Char, class Traits>
00097   std::basic_ostream<Char,Traits>&
00098   operator <<(std::basic_ostream<Char,Traits>& os, const UniverseView&) {
00099     std::basic_ostringstream<Char,Traits> s;
00100     s.copyfmt(os); s.width(0);
00101     s << "{" << Gecode::Set::Limits::min << ".."
00102       << Gecode::Set::Limits::max << "}#("
00103       << Gecode::Set::Limits::card << ")";
00104     return os << s.str();
00105   }
00106 
00107   template<class Char, class Traits>
00108   std::basic_ostream<Char,Traits>&
00109   operator <<(std::basic_ostream<Char,Traits>& os, const ConstSetView& x) {
00110     std::basic_ostringstream<Char,Traits> s;
00111     s.copyfmt(os); s.width(0);
00112     LubRanges<ConstSetView> ub(x);
00113     printBound(s, ub);
00114     s << "#(" << x.cardMin() << ")";
00115     return os << s.str();
00116   }
00117 
00118   template<class Char, class Traits>
00119   std::basic_ostream<Char,Traits>&
00120   operator <<(std::basic_ostream<Char,Traits>& os, const SingletonView& x) {
00121     std::basic_ostringstream<Char,Traits> s;
00122     s.copyfmt(os); s.width(0);
00123     if (x.assigned()) {
00124       s << "{" << x.glbMin() << "}#(1)";
00125     } else {
00126       LubRanges<SingletonView> ub(x);
00127       s << "{}..";
00128       printBound(s, ub);
00129       s << "#(1)";
00130     }
00131     return os << s.str();
00132   }
00133 
00134 }}
00135 
00136 // STATISTICS: set-var