Generated on Sat May 25 2013 18:00:39 for Gecode by doxygen 1.8.3.1
brancher-val-sel-commit.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main author:
4  * Christian Schulte <schulte@gecode.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2012
8  *
9  * Last modified:
10  * $Date: 2012-10-30 07:46:12 +0100 (Tue, 30 Oct 2012) $ by $Author: tack $
11  * $Revision: 13166 $
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 namespace Gecode {
39 
46 
47  template<class _View, class _Val>
49  public:
51  typedef _View View;
53  typedef _Val Val;
54  public:
56  ValSelCommitBase(Space& home, const ValBranch& vb);
58  ValSelCommitBase(Space& home, bool shared,
61  virtual Val val(const Space& home, View x, int i) = 0;
63  virtual ModEvent commit(Space& home, unsigned int a, View x, int i, Val n) = 0;
65  virtual ValSelCommitBase<View,Val>* copy(Space& home, bool shared) = 0;
67  virtual bool notice(void) const = 0;
69  virtual void dispose(Space& home) = 0;
71 
72 
73  static void* operator new(size_t s, Space& home);
75  static void operator delete(void* p, Space& home);
77  static void operator delete(void* p);
79  };
80 
82  template<class ValSel, class ValCommit>
83  class ValSelCommit
84  : public ValSelCommitBase<typename ValSel::View,typename ValSel::Val> {
85  protected:
86  typedef typename ValSelCommitBase<typename ValSel::View,
87  typename ValSel::Val>::Val Val;
88  typedef typename ValSelCommitBase<typename ValSel::View,
94  public:
96  ValSelCommit(Space& home, const ValBranch& vb);
98  ValSelCommit(Space& home, bool shared,
101  virtual Val val(const Space& home, View x, int i);
103  virtual ModEvent commit(Space& home, unsigned int a, View x, int i, Val n);
105  virtual ValSelCommit<ValSel,ValCommit>* copy(Space& home, bool shared);
107  virtual bool notice(void) const;
109  virtual void dispose(Space& home);
110  };
112 
113 
114  template<class View, class Val>
117  template<class View, class Val>
121 
122  template<class View, class Val>
123  forceinline void
125  template<class View, class Val>
126  forceinline void
128  template<class View, class Val>
129  forceinline void*
131  return home.ralloc(s);
132  }
133 
134 
135 
136 
137  template<class ValSel, class ValCommit>
140  const ValBranch& vb)
141  : ValSelCommitBase<View,Val>(home,vb), s(home,vb), c(home,vb) {}
142 
143  template<class ValSel, class ValCommit>
147  : ValSelCommitBase<View,Val>(home,shared,vsc),
148  s(home,shared,vsc.s), c(home,shared,vsc.c) {}
149 
150  template<class ValSel, class ValCommit>
153  return s.val(home,x,i);
154  }
155 
156  template<class ValSel, class ValCommit>
157  ModEvent
159  View x, int i, Val n) {
160  return c.commit(home,a,x,i,n);
161  }
162 
163  template<class ValSel, class ValCommit>
166  return new (home) ValSelCommit<ValSel,ValCommit>(home,shared,*this);
167  }
168 
169  template<class ValSel, class ValCommit>
170  bool
172  return s.notice() || c.notice();
173  }
174 
175  template<class ValSel, class ValCommit>
176  void
178  s.dispose(home);
179  c.dispose(home);
180  }
181 
182 }
183 
184 // STATISTICS: kernel-branch