this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Christian Schulte <schulte@gecode.org> 5 * 6 * Copyright: 7 * Christian Schulte, 2003 8 * 9 * This file is part of Gecode, the generic constraint 10 * development environment: 11 * http://www.gecode.org 12 * 13 * Permission is hereby granted, free of charge, to any person obtaining 14 * a copy of this software and associated documentation files (the 15 * "Software"), to deal in the Software without restriction, including 16 * without limitation the rights to use, copy, modify, merge, publish, 17 * distribute, sublicense, and/or sell copies of the Software, and to 18 * permit persons to whom the Software is furnished to do so, subject to 19 * the following conditions: 20 * 21 * The above copyright notice and this permission notice shall be 22 * included in all copies or substantial portions of the Software. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 * 32 */ 33 34#include <sstream> 35 36namespace Gecode { namespace Int { 37 38 template<class Char, class Traits, class View> 39 std::basic_ostream<Char,Traits>& 40 print_view(std::basic_ostream<Char,Traits>& os, const View& x) { 41 std::basic_ostringstream<Char,Traits> s; 42 s.copyfmt(os); s.width(0); 43 if (x.assigned()) { 44 s << x.val(); 45 } else if (x.range()) { 46 s << '[' << x.min() << ".." << x.max() << ']'; 47 } else { 48 s << '{'; 49 ViewRanges<View> r(x); 50 while (true) { 51 if (r.min() == r.max()) { 52 s << r.min(); 53 } else { 54 s << r.min() << ".." << r.max(); 55 } 56 ++r; 57 if (!r()) break; 58 s << ','; 59 } 60 s << '}'; 61 } 62 return os << s.str(); 63 } 64 65 template<class Char, class Traits, class Val, class UnsVal> 66 std::basic_ostream<Char,Traits>& 67 print_scale(std::basic_ostream<Char,Traits>& os, 68 const ScaleView<Val,UnsVal>& x) { 69 std::basic_ostringstream<Char,Traits> s; 70 s.copyfmt(os); s.width(0); 71 if (x.assigned()) { 72 s << x.val(); 73 } else { 74 s << '{'; 75 ViewRanges<ScaleView<Val,UnsVal> > r(x); 76 while (true) { 77 if (r.min() == r.max()) { 78 s << r.min(); 79 } else { 80 s << r.min() << ".." << r.max(); 81 } 82 ++r; 83 if (!r()) break; 84 s << ','; 85 } 86 s << '}'; 87 } 88 return os << s.str(); 89 } 90 91 template<class Char, class Traits> 92 inline std::basic_ostream<Char,Traits>& 93 operator <<(std::basic_ostream<Char,Traits>& os, const IntView& x) { 94 return print_view(os,x); 95 } 96 template<class Char, class Traits> 97 inline std::basic_ostream<Char,Traits>& 98 operator <<(std::basic_ostream<Char,Traits>& os, const MinusView& x) { 99 return print_view(os,x); 100 } 101 template<class Char, class Traits> 102 inline std::basic_ostream<Char,Traits>& 103 operator <<(std::basic_ostream<Char,Traits>& os, const OffsetView& x) { 104 return print_view(os,x); 105 } 106 template<class Char, class Traits, class View> 107 inline std::basic_ostream<Char,Traits>& 108 operator <<(std::basic_ostream<Char,Traits>& os, 109 const CachedView<View>& x) { 110 return print_view(os,x); 111 } 112 113 template<class Char, class Traits> 114 inline std::basic_ostream<Char,Traits>& 115 operator <<(std::basic_ostream<Char,Traits>& os, const IntScaleView& x) { 116 return print_scale<Char,Traits,int,unsigned int>(os,x); 117 } 118 template<class Char, class Traits> 119 inline std::basic_ostream<Char,Traits>& 120 operator <<(std::basic_ostream<Char,Traits>& os, const LLongScaleView& x) { 121 return print_scale<Char,Traits,long long int,unsigned long long int>(os,x); 122 } 123 124 template<class Char, class Traits> 125 inline std::basic_ostream<Char,Traits>& 126 operator <<(std::basic_ostream<Char,Traits>& os, const ConstIntView& x) { 127 return os << x.val(); 128 } 129 template<class Char, class Traits> 130 inline std::basic_ostream<Char,Traits>& 131 operator <<(std::basic_ostream<Char,Traits>& os, const ZeroIntView&) { 132 return os << 0; 133 } 134 135 136 template<class Char, class Traits> 137 std::basic_ostream<Char,Traits>& 138 operator <<(std::basic_ostream<Char,Traits>& os, const BoolView& x) { 139 if (x.one()) 140 return os << 1; 141 if (x.zero()) 142 return os << 0; 143 return os << "[0..1]"; 144 } 145 template<class Char, class Traits> 146 std::basic_ostream<Char,Traits>& 147 operator <<(std::basic_ostream<Char,Traits>& os, const NegBoolView& x) { 148 if (x.one()) 149 return os << 0; 150 if (x.zero()) 151 return os << 1; 152 return os << "[0..1]"; 153 } 154 155}} 156 157// STATISTICS: int-var 158