this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Christian Schulte <schulte@gecode.org> 5 * 6 * Copyright: 7 * Christian Schulte, 2009 8 * 9 * This file is part of Gecode, the generic constraint 10 * development environment: 11 * http://www.gecode.org 12 * 13 * Permission is hereby granted, free of charge, to any person obtaining 14 * a copy of this software and associated documentation files (the 15 * "Software"), to deal in the Software without restriction, including 16 * without limitation the rights to use, copy, modify, merge, publish, 17 * distribute, sublicense, and/or sell copies of the Software, and to 18 * permit persons to whom the Software is furnished to do so, subject to 19 * the following conditions: 20 * 21 * The above copyright notice and this permission notice shall be 22 * included in all copies or substantial portions of the Software. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 * 32 */ 33 34namespace Gecode { namespace Int { 35 36 /* 37 * Task array 38 */ 39 40 template<class Task> 41 forceinline 42 TaskArray<Task>::TaskArray(void) 43 : n(0), t(nullptr) {} 44 template<class Task> 45 forceinline 46 TaskArray<Task>::TaskArray(Space& home, int n0) 47 : n(n0), t(home.alloc<Task>(n)) { 48 assert(n > 0); 49 } 50 template<class Task> 51 forceinline 52 TaskArray<Task>::TaskArray(const TaskArray<Task>& a) 53 : n(a.n), t(a.t) {} 54 template<class Task> 55 forceinline const TaskArray<Task>& 56 TaskArray<Task>::operator =(const TaskArray<Task>& a) { 57 n=a.n; t=a.t; 58 return *this; 59 } 60 61 template<class Task> 62 forceinline int 63 TaskArray<Task>::size(void) const { 64 return n; 65 } 66 template<class Task> 67 forceinline void 68 TaskArray<Task>::size(int n0) { 69 n = n0; 70 } 71 72 template<class Task> 73 forceinline Task& 74 TaskArray<Task>::operator [](int i) { 75 assert((i >= 0) && (i < n)); 76 return t[i]; 77 } 78 template<class Task> 79 forceinline const Task& 80 TaskArray<Task>::operator [](int i) const { 81 assert((i >= 0) && (i < n)); 82 return t[i]; 83 } 84 85 template<class Task> 86 forceinline void 87 TaskArray<Task>::subscribe(Space& home, Propagator& p, PropCond pc) { 88 for (int i=0; i<n; i++) 89 t[i].subscribe(home,p,pc); 90 } 91 92 template<class Task> 93 forceinline void 94 TaskArray<Task>::cancel(Space& home, Propagator& p, PropCond pc) { 95 for (int i=0; i<n; i++) 96 t[i].cancel(home,p,pc); 97 } 98 99 template<class Task> 100 forceinline void 101 TaskArray<Task>::reschedule(Space& home, Propagator& p, PropCond pc) { 102 for (int i=0; i<n; i++) 103 t[i].reschedule(home,p,pc); 104 } 105 106 template<class Task> 107 forceinline void 108 TaskArray<Task>::update(Space& home, TaskArray& a) { 109 n=a.n; t=home.alloc<Task>(n); 110 for (int i=0; i<n; i++) 111 t[i].update(home,a.t[i]); 112 } 113 114 115 template<class Char, class Traits, class Task> 116 std::basic_ostream<Char,Traits>& 117 operator <<(std::basic_ostream<Char,Traits>& os, 118 const TaskArray<Task>& t) { 119 std::basic_ostringstream<Char,Traits> s; 120 s.copyfmt(os); s.width(0); 121 s << '{'; 122 if (t.size() > 0) { 123 s << t[0]; 124 for (int i=1; i<t.size(); i++) 125 s << ", " << t[i]; 126 } 127 s << '}'; 128 return os << s.str(); 129 } 130 131 132 /* 133 * Task view array 134 */ 135 template<class TaskView> 136 forceinline 137 TaskViewArray<TaskView>::TaskViewArray(TaskArray<Task>& t0) 138 : t(t0) {} 139 140 template<class TaskView> 141 forceinline int 142 TaskViewArray<TaskView>::size(void) const { 143 return t.size(); 144 } 145 146 template<class TaskView> 147 forceinline void 148 TaskViewArray<TaskView>::size(int n) { 149 t.size(n); 150 } 151 152 template<class TaskView> 153 forceinline TaskView& 154 TaskViewArray<TaskView>::operator [](int i) { 155 return static_cast<TaskView&>(t[i]); 156 } 157 template<class TaskView> 158 forceinline const TaskView& 159 TaskViewArray<TaskView>::operator [](int i) const { 160 return static_cast<const TaskView&>(t[i]); 161 } 162 163 template<class Char, class Traits, class TaskView> 164 std::basic_ostream<Char,Traits>& 165 operator <<(std::basic_ostream<Char,Traits>& os, 166 const TaskViewArray<TaskView>& t) { 167 std::basic_ostringstream<Char,Traits> s; 168 s.copyfmt(os); s.width(0); 169 s << '{'; 170 if (t.size() > 0) { 171 s << t[0]; 172 for (int i=1; i<t.size(); i++) 173 s << ", " << t[i]; 174 } 175 s << '}'; 176 return os << s.str(); 177 } 178 179 180}} 181 182// STATISTICS: int-other