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: 2010-06-07 14:18:14 +0200 (Mon, 07 Jun 2010) $ by $Author: tack $ 00013 * $Revision: 11048 $ 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 Iter::Ranges::IsRangeIter<I>(); 00049 s << '{'; 00050 while (r()) { 00051 if (r.min() == r.max()) { 00052 s << r.min(); 00053 } else if (r.min()+1 == r.max()) { 00054 s << r.min() << "," << r.max(); 00055 } else { 00056 s << r.min() << ".." << r.max(); 00057 } 00058 ++r; 00059 if (!r()) break; 00060 s << ','; 00061 } 00062 s << '}'; 00063 } 00064 00066 template<class Char, class Traits, class IL, class IU> 00067 void 00068 print(std::basic_ostream<Char,Traits>& s, bool assigned, IL& lb, IU& ub, 00069 unsigned int cardMin, unsigned int cardMax) { 00070 if (assigned) { 00071 printBound(s, ub); 00072 } else { 00073 printBound(s,lb); 00074 s << ".."; 00075 printBound(s,ub); 00076 if (cardMin==cardMax) { 00077 s << "#(" << cardMin << ")"; 00078 } else { 00079 s << "#(" << cardMin << "," << cardMax << ")"; 00080 } 00081 } 00082 } 00083 00084 template<class Char, class Traits> 00085 std::basic_ostream<Char,Traits>& 00086 operator <<(std::basic_ostream<Char,Traits>& os, const SetView& x) { 00087 std::basic_ostringstream<Char,Traits> s; 00088 s.copyfmt(os); s.width(0); 00089 LubRanges<SetView> ub(x); 00090 GlbRanges<SetView> lb(x); 00091 print(s, x.assigned(), lb, ub, x.cardMin(), x.cardMax()) ; 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 EmptyView&) { 00098 return os << "{}#0"; 00099 } 00100 00101 template<class Char, class Traits> 00102 std::basic_ostream<Char,Traits>& 00103 operator <<(std::basic_ostream<Char,Traits>& os, const UniverseView&) { 00104 std::basic_ostringstream<Char,Traits> s; 00105 s.copyfmt(os); s.width(0); 00106 s << "{" << Gecode::Set::Limits::min << ".." 00107 << Gecode::Set::Limits::max << "}#(" 00108 << Gecode::Set::Limits::card << ")"; 00109 return os << s.str(); 00110 } 00111 00112 template<class Char, class Traits> 00113 std::basic_ostream<Char,Traits>& 00114 operator <<(std::basic_ostream<Char,Traits>& os, const ConstSetView& x) { 00115 std::basic_ostringstream<Char,Traits> s; 00116 s.copyfmt(os); s.width(0); 00117 LubRanges<ConstSetView> ub(x); 00118 printBound(s, ub); 00119 s << "#(" << x.cardMin() << ")"; 00120 return os << s.str(); 00121 } 00122 00123 template<class Char, class Traits> 00124 std::basic_ostream<Char,Traits>& 00125 operator <<(std::basic_ostream<Char,Traits>& os, const SingletonView& x) { 00126 std::basic_ostringstream<Char,Traits> s; 00127 s.copyfmt(os); s.width(0); 00128 if (x.assigned()) { 00129 s << "{" << x.glbMin() << "}#(1)"; 00130 } else { 00131 LubRanges<SingletonView> ub(x); 00132 s << "{}.."; 00133 printBound(s, ub); 00134 s << "#(1)"; 00135 } 00136 return os << s.str(); 00137 } 00138 00139 }} 00140 00141 // STATISTICS: set-var