Generated on Tue Jul 18 2017 18:41:42 for Gecode by doxygen 1.8.13
shared-data.hpp
Go to the documentation of this file.
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, 2017
8  *
9  * Last modified:
10  * $Date: 2017-02-10 02:39:13 +0100 (Fri, 10 Feb 2017) $ by $Author: schulte $
11  * $Revision: 15401 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 namespace Gecode {
39 
41  template<class Data>
42  class SharedData : public SharedHandle {
43  protected:
45  class SDO : public SharedHandle::Object {
46  public:
48  const Data d;
50  SDO(const Data& d0);
52  SDO(const SDO& sdo);
54  virtual Object* copy(void) const;
56  virtual ~SDO(void);
57  };
58  public:
60  SharedData(const Data& d);
62  SharedData(void);
64  SharedData(const SharedData& sd);
66  SharedData& operator =(const SharedData& sd);
68  const Data& operator ()(void) const;
70  void update(Space& home, bool share, SharedHandle& sh);
72  ~SharedData(void);
73  };
74 
75 
76  template<class Data>
79  : d(d0) {}
80 
81  template<class Data>
84  : d(sdo.d) {}
85 
86  template<class Data>
89  return new SDO(*this);
90  }
91 
92  template<class Data>
95 
96 
97  template<class Data>
100  : SharedHandle(new SDO(d)) {}
101 
102  template<class Data>
105 
106  template<class Data>
109  : SharedHandle(sd) {}
110 
111  template<class Data>
114  return static_cast<SharedData&>(SharedHandle::operator =(sd));
115  }
116 
117  template<class Data>
118  forceinline const Data&
120  return static_cast<SDO*>(object())->d;
121  }
122 
123  template<class Data>
124  forceinline void
125  SharedData<Data>::update(Space& home, bool share, SharedHandle& sh) {
126  SharedHandle::update(home,share,sh);
127  }
128 
129  template<class Data>
132 
133 }
134 
135 // STATISTICS: kernel-other
void update(Space &home, bool share, SharedHandle &sh)
Update during cloning.
The shared handle.
Definition: core.hpp:79
virtual Object * copy(void) const
Create new non-shared copy.
Definition: shared-data.hpp:88
SharedData(void)
Create as uninitialized.
SDO(const Data &d0)
Initialization.
Definition: shared-data.hpp:78
const Data & operator()(void) const
Provide access to data.
Computation spaces.
Definition: core.hpp:1748
SharedData & operator=(const SharedData &sd)
Assignment operator.
Gecode::IntSet d(v, 7)
const Data d
Data to be shared.
Definition: shared-data.hpp:48
~SharedData(void)
Destructors.
virtual ~SDO(void)
Destructor.
Definition: shared-data.hpp:94
The object storing the actual data.
Definition: shared-data.hpp:45
Class for sharing data between spaces.
Definition: shared-data.hpp:42
#define forceinline
Definition: config.hpp:173
The shared object.
Definition: core.hpp:88
Gecode toplevel namespace