Generated on Tue Apr 18 10:22:04 2017 for Gecode by doxygen 1.6.3

brancher-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  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2017
00008  *
00009  *  Last modified:
00010  *     $Date: 2017-04-01 20:27:10 +0200 (Sat, 01 Apr 2017) $ by $Author: schulte $
00011  *     $Revision: 15623 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 #include <functional>
00039 
00040 namespace Gecode {
00041 
00043   template<class Var, class Val>
00044   using VarValPrint = std::function<void(const Space& home, const Brancher& b,
00045                                          unsigned int a,
00046                                          Var x, int i, const Val& m,
00047                                          std::ostream& o)>;
00048  
00050   template<class View, class Val>
00051   class BrancherPrint {
00052   public:
00054     typedef typename View::VarType Var;
00055   protected:
00056     SharedData<VarValPrint<Var,Val>> p;
00057   public:
00059     BrancherPrint(VarValPrint<Var,Val> vvp);
00061     BrancherPrint(Space& home, bool shared, BrancherPrint& bp);
00063     operator bool(void) const;
00065     void operator ()(const Space& home, const Brancher& b,
00066                      unsigned int a,
00067                      View x, int i, const Val& m,
00068                      std::ostream& o) const;
00070     bool notice(void) const;
00072     void dispose(Space& home);
00073   };
00074 
00076   template<class View, class Val>
00077   class BrancherNoPrint {
00078   public:
00080     typedef typename View::VarType Var;
00081   public:
00083     BrancherNoPrint(VarValPrint<Var,Val> vvp);
00085     BrancherNoPrint(Space& home, bool shared, BrancherNoPrint& bp);
00087     operator bool(void) const;
00089     void operator ()(const Space& home, const Brancher& b,
00090                      unsigned int a,
00091                      View x, int i, const Val& m,
00092                      std::ostream& o) const;
00094     bool notice(void) const;
00096     void dispose(Space& home);
00097   };
00098 
00099 
00100 
00101   template<class View, class Val>
00102   forceinline
00103   BrancherPrint<View,Val>::BrancherPrint(VarValPrint<Var,Val> vvp) : p(vvp) {
00104     if (!vvp)
00105       throw Gecode::InvalidFunction("BrancherPrint::BrancherPrint");
00106   }
00107   
00108   template<class View, class Val>
00109   forceinline
00110   BrancherPrint<View,Val>::BrancherPrint(Space& home, bool shared,
00111                                          BrancherPrint<View,Val>& bp) {
00112     p.update(home,shared,bp.p);
00113   }
00114 
00115   template<class View, class Val>
00116   forceinline
00117   BrancherPrint<View,Val>::operator bool(void) const {
00118     return true;
00119   }
00120 
00121   template<class View, class Val>
00122   forceinline void
00123   BrancherPrint<View,Val>::operator ()(const Space& home, const Brancher& b,
00124                                        unsigned int a,
00125                                        View x, int i, const Val& m,
00126                                        std::ostream& o) const {
00127     GECODE_VALID_FUNCTION(p());
00128     Var xv(x.varimp());
00129     p()(home,b,a,xv,i,m,o);
00130   }
00131 
00132   template<class View, class Val>
00133   forceinline bool
00134   BrancherPrint<View,Val>::notice(void) const {
00135     return true;
00136   }
00137 
00138   template<class View, class Val>
00139   forceinline void
00140   BrancherPrint<View,Val>::dispose(Space&) {
00141     p.~SharedData<VarValPrint<Var,Val>>();
00142   }
00143 
00144 
00145   template<class View, class Val>
00146   forceinline
00147   BrancherNoPrint<View,Val>::BrancherNoPrint(VarValPrint<Var,Val> vvp) {
00148     assert(!vvp);
00149   }
00150   
00151   template<class View, class Val>
00152   forceinline
00153   BrancherNoPrint<View,Val>::BrancherNoPrint(Space&, bool,
00154                                              BrancherNoPrint<View,Val>&) {}
00155 
00156   template<class View, class Val>
00157   forceinline
00158   BrancherNoPrint<View,Val>::operator bool(void) const {
00159     return false;
00160   }
00161 
00162   template<class View, class Val>
00163   forceinline void
00164   BrancherNoPrint<View,Val>::operator ()(const Space&, const Brancher&,
00165                                          unsigned int,
00166                                          View, int, const Val&,
00167                                          std::ostream&) const {}
00168   template<class View, class Val>
00169   forceinline bool
00170   BrancherNoPrint<View,Val>::notice(void) const {
00171     return false;
00172   }
00173 
00174   template<class View, class Val>
00175   forceinline void
00176   BrancherNoPrint<View,Val>::dispose(Space&) {}
00177 
00178 }
00179 
00180 // STATISTICS: kernel-branch