Generated on Fri Oct 19 11:24:58 2018 for Gecode by doxygen 1.6.3

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