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