Generated on Sat Oct 20 2018 12:43:45 for Gecode by doxygen 1.8.13
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, 2017
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 <functional>
35 
36 namespace Gecode {
37 
39  template<class Var, class Val>
40  using VarValPrint = std::function<void(const Space& home, const Brancher& b,
41  unsigned int a,
42  Var x, int i, const Val& m,
43  std::ostream& o)>;
44 
46  template<class View, class Val>
47  class BrancherPrint {
48  public:
50  typedef typename View::VarType Var;
51  protected:
53  public:
59  operator bool(void) const;
61  void operator ()(const Space& home, const Brancher& b,
62  unsigned int a,
63  View x, int i, const Val& m,
64  std::ostream& o) const;
66  bool notice(void) const;
68  void dispose(Space& home);
69  };
70 
72  template<class View, class Val>
74  public:
76  typedef typename View::VarType Var;
77  public:
83  operator bool(void) const;
85  void operator ()(const Space& home, const Brancher& b,
86  unsigned int a,
87  View x, int i, const Val& m,
88  std::ostream& o) const;
90  bool notice(void) const;
92  void dispose(Space& home);
93  };
94 
95 
96 
97  template<class View, class Val>
100  if (!vvp)
101  throw Gecode::InvalidFunction("BrancherPrint::BrancherPrint");
102  }
103 
104  template<class View, class Val>
107  : p(bp.p) {
108  }
109 
110  template<class View, class Val>
113  return true;
114  }
115 
116  template<class View, class Val>
117  forceinline void
119  unsigned int a,
120  View x, int i, const Val& m,
121  std::ostream& o) const {
123  Var xv(x.varimp());
124  p()(home,b,a,xv,i,m,o);
125  }
126 
127  template<class View, class Val>
128  forceinline bool
130  return true;
131  }
132 
133  template<class View, class Val>
134  forceinline void
137  }
138 
139 
140  template<class View, class Val>
143  assert(!vvp);
144  (void) vvp;
145  }
146 
147  template<class View, class Val>
150 
151  template<class View, class Val>
154  return false;
155  }
156 
157  template<class View, class Val>
158  forceinline void
160  unsigned int,
161  View, int, const Val&,
162  std::ostream&) const {}
163  template<class View, class Val>
164  forceinline bool
166  return false;
167  }
168 
169  template<class View, class Val>
170  forceinline void
172 
173 }
174 
175 // STATISTICS: kernel-branch
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition: print.hpp:165
std::function< void(const Space &home, const Brancher &b, unsigned int a, Var x, int i, const Val &m, std::ostream &o)> VarValPrint
Function type for printing variable and value selection.
Definition: print.hpp:43
View::VarType Var
The corresponding variable type.
Definition: print.hpp:76
#define forceinline
Definition: config.hpp:185
Computation spaces.
Definition: core.hpp:1701
Class storing a print function.
Definition: print.hpp:47
Class without print function.
Definition: print.hpp:73
SharedData< VarValPrint< Var, Val > > p
Definition: print.hpp:52
BrancherPrint(VarValPrint< Var, Val > vvp)
Initialize.
Definition: print.hpp:99
Base-class for branchers.
Definition: core.hpp:1401
Gecode::IntArgs i({1, 2, 3, 4})
~SharedData(void)
Destructors.
void dispose(Space &home)
Delete.
Definition: print.hpp:135
struct Gecode::@593::NNF::@62::@63 b
For binary nodes (and, or, eqv)
BrancherNoPrint(VarValPrint< Var, Val > vvp)
Initialize.
Definition: print.hpp:142
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition: print.hpp:129
void operator()(const Space &home, const Brancher &b, unsigned int a, View x, int i, const Val &m, std::ostream &o) const
Invoke print function.
Definition: print.hpp:118
Exception: invalid function
Definition: exception.hpp:114
#define GECODE_VALID_FUNCTION(f)
Assert that a function is valid.
Definition: macros.hpp:94
void dispose(Space &home)
Delete.
Definition: print.hpp:171
Class for sharing data between spaces.
Definition: shared-data.hpp:38
Post propagator for SetVar x
Definition: set.hh:767
Gecode toplevel namespace
void operator()(const Space &home, const Brancher &b, unsigned int a, View x, int i, const Val &m, std::ostream &o) const
Invoke print function.
Definition: print.hpp:159
struct Gecode::@593::NNF::@62::@64 a
For atomic nodes.
View::VarType Var
The corresponding variable type.
Definition: print.hpp:50