Generated on Thu Mar 22 10:39:33 2012 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: 2011-05-25 16:56:41 +0200 (Wed, 25 May 2011) $ by $Author: schulte $
00011  *     $Revision: 12022 $
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   inline 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   inline 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>::update(Space& home, bool share, TaskArray& a) {
00106     n=a.n; t=home.alloc<Task>(n);
00107     for (int i=n; i--; )
00108       t[i].update(home,share,a.t[i]);
00109   }
00110 
00111 
00112   template<class Char, class Traits, class Task>
00113   std::basic_ostream<Char,Traits>&
00114   operator <<(std::basic_ostream<Char,Traits>& os, 
00115               const TaskArray<Task>& t) {
00116     std::basic_ostringstream<Char,Traits> s;
00117     s.copyfmt(os); s.width(0);
00118     s << '{';
00119     if (t.size() > 0) {
00120       s << t[0];
00121       for (int i=1; i<t.size(); i++)
00122         s << ", " << t[i];
00123     }
00124     s << '}';
00125     return os << s.str();
00126   }
00127 
00128 
00129   /*
00130    * Task view array
00131    */
00132   template<class TaskView>
00133   forceinline
00134   TaskViewArray<TaskView>::TaskViewArray(TaskArray<Task>& t0)
00135     : t(t0) {}
00136 
00137   template<class TaskView>
00138   forceinline int 
00139   TaskViewArray<TaskView>::size(void) const {
00140     return t.size();
00141   }
00142 
00143   template<class TaskView>
00144   forceinline void
00145   TaskViewArray<TaskView>::size(int n) {
00146     t.size(n);
00147   }
00148 
00149   template<class TaskView>
00150   forceinline TaskView&
00151   TaskViewArray<TaskView>::operator [](int i) {
00152     return static_cast<TaskView&>(t[i]);
00153   }
00154   template<class TaskView>
00155   forceinline const TaskView&
00156   TaskViewArray<TaskView>::operator [](int i) const {
00157     return static_cast<const TaskView&>(t[i]);
00158   }
00159 
00160   template<class Char, class Traits, class TaskView>
00161   std::basic_ostream<Char,Traits>&
00162   operator <<(std::basic_ostream<Char,Traits>& os, 
00163               const TaskViewArray<TaskView>& t) {
00164     std::basic_ostringstream<Char,Traits> s;
00165     s.copyfmt(os); s.width(0);
00166     s << '{';
00167     if (t.size() > 0) {
00168       s << t[0];
00169       for (int i=1; i<t.size(); i++)
00170         s << ", " << t[i];
00171     }
00172     s << '}';
00173     return os << s.str();
00174   }
00175 
00176 
00177 }}
00178 
00179 // STATISTICS: int-other