Generated on Sat Feb 7 2015 02:01:17 for Gecode by doxygen 1.8.9.1
print.hpp
Go to the documentation of this file.
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  * Last modified:
10  * $Date: 2013-03-07 02:18:29 +0100 (Thu, 07 Mar 2013) $ by $Author: mears $
11  * $Revision: 13455 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 #include <sstream>
39 
40 namespace Gecode { namespace Int {
41 
42  template<class Char, class Traits, class View>
43  std::basic_ostream<Char,Traits>&
44  print_view(std::basic_ostream<Char,Traits>& os, const View& x) {
45  std::basic_ostringstream<Char,Traits> s;
46  s.copyfmt(os); s.width(0);
47  if (x.assigned()) {
48  s << x.val();
49  } else if (x.range()) {
50  s << '[' << x.min() << ".." << x.max() << ']';
51  } else {
52  s << '{';
54  while (true) {
55  if (r.min() == r.max()) {
56  s << r.min();
57  } else {
58  s << r.min() << ".." << r.max();
59  }
60  ++r;
61  if (!r()) break;
62  s << ',';
63  }
64  s << '}';
65  }
66  return os << s.str();
67  }
68 
69  template<class Char, class Traits, class Val, class UnsVal>
70  std::basic_ostream<Char,Traits>&
71  print_scale(std::basic_ostream<Char,Traits>& os,
72  const ScaleView<Val,UnsVal>& x) {
73  std::basic_ostringstream<Char,Traits> s;
74  s.copyfmt(os); s.width(0);
75  if (x.assigned()) {
76  s << x.val();
77  } else {
78  s << '{';
80  while (true) {
81  if (r.min() == r.max()) {
82  s << r.min();
83  } else {
84  s << r.min() << ".." << r.max();
85  }
86  ++r;
87  if (!r()) break;
88  s << ',';
89  }
90  s << '}';
91  }
92  return os << s.str();
93  }
94 
95  template<class Char, class Traits>
96  inline std::basic_ostream<Char,Traits>&
97  operator <<(std::basic_ostream<Char,Traits>& os, const IntView& x) {
98  return print_view(os,x);
99  }
100  template<class Char, class Traits>
101  inline std::basic_ostream<Char,Traits>&
102  operator <<(std::basic_ostream<Char,Traits>& os, const MinusView& x) {
103  return print_view(os,x);
104  }
105  template<class Char, class Traits>
106  inline std::basic_ostream<Char,Traits>&
107  operator <<(std::basic_ostream<Char,Traits>& os, const OffsetView& x) {
108  return print_view(os,x);
109  }
110  template<class Char, class Traits, class View>
111  inline std::basic_ostream<Char,Traits>&
112  operator <<(std::basic_ostream<Char,Traits>& os,
113  const CachedView<View>& x) {
114  return print_view(os,x);
115  }
116 
117  template<class Char, class Traits>
118  inline std::basic_ostream<Char,Traits>&
119  operator <<(std::basic_ostream<Char,Traits>& os, const IntScaleView& x) {
120  return print_scale<Char,Traits,int,unsigned int>(os,x);
121  }
122  template<class Char, class Traits>
123  inline std::basic_ostream<Char,Traits>&
124  operator <<(std::basic_ostream<Char,Traits>& os, const LLongScaleView& x) {
125  return print_scale<Char,Traits,long long int,unsigned long long int>(os,x);
126  }
127 
128  template<class Char, class Traits>
129  inline std::basic_ostream<Char,Traits>&
130  operator <<(std::basic_ostream<Char,Traits>& os, const ConstIntView& x) {
131  return os << x.val();
132  }
133  template<class Char, class Traits>
134  inline std::basic_ostream<Char,Traits>&
135  operator <<(std::basic_ostream<Char,Traits>& os, const ZeroIntView&) {
136  return os << 0;
137  }
138 
139 
140  template<class Char, class Traits>
141  std::basic_ostream<Char,Traits>&
142  operator <<(std::basic_ostream<Char,Traits>& os, const BoolView& x) {
143  if (x.one())
144  return os << 1;
145  if (x.zero())
146  return os << 0;
147  return os << "[0..1]";
148  }
149  template<class Char, class Traits>
150  std::basic_ostream<Char,Traits>&
151  operator <<(std::basic_ostream<Char,Traits>& os, const NegBoolView& x) {
152  if (x.one())
153  return os << 0;
154  if (x.zero())
155  return os << 1;
156  return os << "[0..1]";
157  }
158 
159 }}
160 
161 // STATISTICS: int-var
162 
Scale integer view (template)
Definition: view.hpp:671
bool assigned(void) const
Test whether view is assigned.
Negated Boolean view.
Definition: view.hpp:1503
std::basic_ostream< Char, Traits > & print_scale(std::basic_ostream< Char, Traits > &os, const ScaleView< Val, UnsVal > &x)
Definition: print.hpp:71
Range iterator for integer views.
Definition: view.hpp:54
int min(void) const
Return smallest value of range.
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
Offset integer view.
Definition: view.hpp:422
Zero integer view.
Definition: view.hpp:959
Constant integer view.
Definition: view.hpp:804
Integer view for integer variables.
Definition: view.hpp:129
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
std::basic_ostream< Char, Traits > & print_view(std::basic_ostream< Char, Traits > &os, const View &x)
Definition: print.hpp:44
Minus integer view.
Definition: view.hpp:276
Cached integer view.
Definition: view.hpp:1107
Val val(void) const
Return assigned value (only if assigned)
Definition: scale.hpp:85
int max(void) const
Return largest value of range.
Gecode toplevel namespace
Boolean view for Boolean variables.
Definition: view.hpp:1315