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