1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  *  Main authors:
4  *     Christian Schulte <schulte@gecode.org>
5  *     Guido Tack <tack@gecode.org>
6  *
7  *  Copyright:
8  *     Christian Schulte, 2004
9  *     Guido Tack, 2004
10  *
11  *  This file is part of Gecode, the generic constraint
12  *  development environment:
13  *     http://www.gecode.org
14  *
15  *  Permission is hereby granted, free of charge, to any person obtaining
16  *  a copy of this software and associated documentation files (the
17  *  "Software"), to deal in the Software without restriction, including
18  *  without limitation the rights to use, copy, modify, merge, publish,
19  *  distribute, sublicense, and/or sell copies of the Software, and to
20  *  permit persons to whom the Software is furnished to do so, subject to
21  *  the following conditions:
22  *
23  *  The above copyright notice and this permission notice shall be
24  *  included in all copies or substantial portions of the Software.
25  *
26  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33  *
34  */
35 
36 #ifndef GECODE_INT_IDX_VIEW_HH
37 #define GECODE_INT_IDX_VIEW_HH
38 
39 #include <gecode/int.hh>
40 
41 namespace Gecode { namespace Int {
42 
43   /**
44    * \brief Class for pair of index and view
45    *
46    */
47   template<class View>
48   class IdxView {
49   public:
50     /// The index
51     int idx;
52     /// Thhe view
53     View view;
54     /// Allocate memory for \a n index-view pairs
55     static IdxView* allocate(Space& home, int n);
56   };
57 
58   /// Class to map VarArg type to view
59   template<class View>
60   class ViewToVarArg {};
61 
62   /**
63    * \brief An array of IdxView pairs
64    *
65    */
66   template<class View>
67   class IdxViewArray {
68   private:
69     /// The actual array
70     IdxView<View>* xs;
71     /// The size of the array
72     int n;
73   public:
74     /// Default constructor
75     IdxViewArray(void);
76     /// Copy constructor
77     IdxViewArray(const IdxViewArray<View>&);
78     /// Construct an IdxViewArray from \a x
79     IdxViewArray(Space& home, const typename ViewToVarArg<View>::argtype& x);
80     /// Construct an IdxViewArray of size \a n
81     IdxViewArray(Space& home, int n);
82 
83     /// Return the current size
84     int size(void) const;
85     /// Set the size to \a n
86     void size(int n);
87 
88     /// Access element \a n
89     IdxView<View>& operator [](int n);
90     /// Access element \a n
91     const IdxView<View>& operator [](int) const;
92 
93     /**
94      * Subscribe propagator \a p with propagation condition \a pc
95      * to all elements of the array.
96      */
97     void subscribe(Space& home, Propagator& p, PropCond pc, bool process=true);
98     /**
99      * Cancel subscription of propagator \a p with propagation condition \a pc
100      * for all elements of the array.
101      */
102     void cancel(Space& home, Propagator& p, PropCond pc);
103     /// Schedule propagator \a p
104     void reschedule(Space& home, Propagator& p, PropCond pc);
105 
106     /// Cloning
107     void update(Space& home, IdxViewArray<View>& x);
108   };
109 
110   /**
111    * \brief Print array elements enclosed in curly brackets
112    * \relates IdxViewArray
113    */
114   template<class Char, class Traits, class View>
115   std::basic_ostream<Char,Traits>&
116   operator <<(std::basic_ostream<Char,Traits>& os,
117               const IdxViewArray<View>& x);
118 
119 }}
120 
121 #include <gecode/int/idx-view.hpp>
122 
123 #endif
124 
125 
126 // STATISTICS: int-prop
127 
128