Generated on Tue Apr 18 10:21:34 2017 for Gecode by doxygen 1.6.3

array.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, 2009
00008  *
00009  *  Last modified:
00010  *     $Date: 2016-06-29 17:28:17 +0200 (Wed, 29 Jun 2016) $ by $Author: schulte $
00011  *     $Revision: 15137 $
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 namespace Gecode { namespace Int {
00039 
00040   /*
00041    * Task array
00042    */
00043 
00044   template<class Task>
00045   forceinline
00046   TaskArray<Task>::TaskArray(void)
00047     : n(0), t(NULL) {}
00048   template<class Task>
00049   forceinline
00050   TaskArray<Task>::TaskArray(Space& home, int n0)
00051     : n(n0), t(home.alloc<Task>(n)) {
00052     assert(n > 0);
00053   }
00054   template<class Task>
00055   forceinline
00056   TaskArray<Task>::TaskArray(const TaskArray<Task>& a)
00057     : n(a.n), t(a.t) {}
00058   template<class Task>
00059   forceinline const TaskArray<Task>&
00060   TaskArray<Task>::operator =(const TaskArray<Task>& a) {
00061     n=a.n; t=a.t;
00062     return *this;
00063   }
00064 
00065   template<class Task>
00066   forceinline int
00067   TaskArray<Task>::size(void) const {
00068     return n;
00069   }
00070   template<class Task>
00071   forceinline void
00072   TaskArray<Task>::size(int n0) {
00073     n = n0;
00074   }
00075 
00076   template<class Task>
00077   forceinline Task&
00078   TaskArray<Task>::operator [](int i) {
00079     assert((i >= 0) && (i < n));
00080     return t[i];
00081   }
00082   template<class Task>
00083   forceinline const Task&
00084   TaskArray<Task>::operator [](int i) const {
00085     assert((i >= 0) && (i < n));
00086     return t[i];
00087   }
00088 
00089   template<class Task>
00090   forceinline void
00091   TaskArray<Task>::subscribe(Space& home, Propagator& p, PropCond pc) {
00092     for (int i=n; i--; )
00093       t[i].subscribe(home,p,pc);
00094   }
00095 
00096   template<class Task>
00097   forceinline void
00098   TaskArray<Task>::cancel(Space& home, Propagator& p, PropCond pc) {
00099     for (int i=n; i--; )
00100       t[i].cancel(home,p,pc);
00101   }
00102 
00103   template<class Task>
00104   forceinline void
00105   TaskArray<Task>::reschedule(Space& home, Propagator& p, PropCond pc) {
00106     for (int i=n; i--; )
00107       t[i].reschedule(home,p,pc);
00108   }
00109 
00110   template<class Task>
00111   forceinline void
00112   TaskArray<Task>::update(Space& home, bool share, TaskArray& a) {
00113     n=a.n; t=home.alloc<Task>(n);
00114     for (int i=n; i--; )
00115       t[i].update(home,share,a.t[i]);
00116   }
00117 
00118 
00119   template<class Char, class Traits, class Task>
00120   std::basic_ostream<Char,Traits>&
00121   operator <<(std::basic_ostream<Char,Traits>& os,
00122               const TaskArray<Task>& t) {
00123     std::basic_ostringstream<Char,Traits> s;
00124     s.copyfmt(os); s.width(0);
00125     s << '{';
00126     if (t.size() > 0) {
00127       s << t[0];
00128       for (int i=1; i<t.size(); i++)
00129         s << ", " << t[i];
00130     }
00131     s << '}';
00132     return os << s.str();
00133   }
00134 
00135 
00136   /*
00137    * Task view array
00138    */
00139   template<class TaskView>
00140   forceinline
00141   TaskViewArray<TaskView>::TaskViewArray(TaskArray<Task>& t0)
00142     : t(t0) {}
00143 
00144   template<class TaskView>
00145   forceinline int
00146   TaskViewArray<TaskView>::size(void) const {
00147     return t.size();
00148   }
00149 
00150   template<class TaskView>
00151   forceinline void
00152   TaskViewArray<TaskView>::size(int n) {
00153     t.size(n);
00154   }
00155 
00156   template<class TaskView>
00157   forceinline TaskView&
00158   TaskViewArray<TaskView>::operator [](int i) {
00159     return static_cast<TaskView&>(t[i]);
00160   }
00161   template<class TaskView>
00162   forceinline const TaskView&
00163   TaskViewArray<TaskView>::operator [](int i) const {
00164     return static_cast<const TaskView&>(t[i]);
00165   }
00166 
00167   template<class Char, class Traits, class TaskView>
00168   std::basic_ostream<Char,Traits>&
00169   operator <<(std::basic_ostream<Char,Traits>& os,
00170               const TaskViewArray<TaskView>& t) {
00171     std::basic_ostringstream<Char,Traits> s;
00172     s.copyfmt(os); s.width(0);
00173     s << '{';
00174     if (t.size() > 0) {
00175       s << t[0];
00176       for (int i=1; i<t.size(); i++)
00177         s << ", " << t[i];
00178     }
00179     s << '}';
00180     return os << s.str();
00181   }
00182 
00183 
00184 }}
00185 
00186 // STATISTICS: int-other