Generated on Mon May 10 06:46:41 2010 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: 2009-01-20 23:44:27 +0100 (Tue, 20 Jan 2009) $ by $Author: schulte $
00013  *     $Revision: 8082 $
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       s << "#(" << cardMin << ")";
00073     } else {
00074       printBound(s,lb);
00075       s << "..";
00076       printBound(s,ub);
00077       if (cardMin==cardMax) {
00078         s << "#(" << cardMin << ")";
00079       } else {
00080         s << "#(" << cardMin << "," << cardMax << ")";
00081       }
00082     }
00083   }
00084 
00085   template<class Char, class Traits>
00086   std::basic_ostream<Char,Traits>&
00087   operator <<(std::basic_ostream<Char,Traits>& os, const SetView& x) {
00088     std::basic_ostringstream<Char,Traits> s;
00089     s.copyfmt(os); s.width(0);
00090     LubRanges<SetView> ub(x);
00091     GlbRanges<SetView> lb(x);
00092     print(s, x.assigned(), lb, ub, x.cardMin(), x.cardMax()) ;
00093     return os << s.str();
00094   }
00095 
00096   template<class Char, class Traits>
00097   inline std::basic_ostream<Char,Traits>&
00098   operator <<(std::basic_ostream<Char,Traits>& os, const EmptyView&) {
00099     return os << "{}#0";
00100   }
00101 
00102   template<class Char, class Traits>
00103   std::basic_ostream<Char,Traits>&
00104   operator <<(std::basic_ostream<Char,Traits>& os, const UniverseView&) {
00105     std::basic_ostringstream<Char,Traits> s;
00106     s.copyfmt(os); s.width(0);
00107     s << "{" << Gecode::Set::Limits::min << ".."
00108       << Gecode::Set::Limits::max << "}#("
00109       << Gecode::Set::Limits::card << ")";
00110     return os << s.str();
00111   }
00112 
00113   template<class Char, class Traits>
00114   std::basic_ostream<Char,Traits>&
00115   operator <<(std::basic_ostream<Char,Traits>& os, const ConstantView& x) {
00116     std::basic_ostringstream<Char,Traits> s;
00117     s.copyfmt(os); s.width(0);
00118     LubRanges<ConstantView> ub(x);
00119     printBound(s, ub);
00120     s << "#(" << x.cardMin() << ")";
00121     return os << s.str();
00122   }
00123 
00124   template<class Char, class Traits>
00125   std::basic_ostream<Char,Traits>&
00126   operator <<(std::basic_ostream<Char,Traits>& os, const SingletonView& x) {
00127     std::basic_ostringstream<Char,Traits> s;
00128     s.copyfmt(os); s.width(0);
00129     if (x.assigned()) {
00130       s << "{" << x.glbMin() << "}#(1)";
00131     } else {
00132       LubRanges<SingletonView> ub(x);
00133       s << "{}..";
00134       printBound(s, ub);
00135       s << "#(1)";
00136     }
00137     return os << s.str();
00138   }
00139 
00140 }}
00141 
00142 // STATISTICS: set-var