Generated on Tue Apr 18 10:22:07 2017 for Gecode by doxygen 1.6.3

shared-data.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, 2017
00008  *
00009  *  Last modified:
00010  *     $Date: 2017-02-10 02:39:13 +0100 (Fri, 10 Feb 2017) $ by $Author: schulte $
00011  *     $Revision: 15401 $
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 {
00039 
00041   template<class Data>
00042   class SharedData : public SharedHandle {
00043   protected:
00045     class SDO : public SharedHandle::Object {
00046     public:
00048       const Data d;
00050       SDO(const Data& d0);
00052       SDO(const SDO& sdo);
00054       virtual Object* copy(void) const;
00056       virtual ~SDO(void);
00057     };
00058   public:
00060     SharedData(const Data& d);
00062     SharedData(void);
00064     SharedData(const SharedData& sd);
00066     SharedData& operator =(const SharedData& sd);
00068     const Data& operator ()(void) const;
00070     void update(Space& home, bool share, SharedHandle& sh);
00072     ~SharedData(void);
00073   };
00074 
00075 
00076   template<class Data>
00077   forceinline
00078   SharedData<Data>::SDO::SDO(const Data& d0)
00079     : d(d0) {}
00080 
00081   template<class Data>
00082   forceinline
00083   SharedData<Data>::SDO::SDO(const SDO& sdo)
00084     : d(sdo.d) {}
00085 
00086   template<class Data>
00087   forceinline SharedHandle::Object*
00088   SharedData<Data>::SDO::copy(void) const {
00089     return new SDO(*this);
00090   }
00091 
00092   template<class Data>
00093   forceinline
00094   SharedData<Data>::SDO::~SDO(void) {}
00095 
00096 
00097   template<class Data>
00098   forceinline
00099   SharedData<Data>::SharedData(const Data& d) 
00100     : SharedHandle(new SDO(d)) {}
00101 
00102   template<class Data>
00103   forceinline
00104   SharedData<Data>::SharedData(void) {}
00105 
00106   template<class Data>
00107   forceinline
00108   SharedData<Data>::SharedData(const SharedData<Data>& sd)
00109     : SharedHandle(sd) {}
00110 
00111   template<class Data>
00112   forceinline SharedData<Data>&
00113   SharedData<Data>::operator =(const SharedData<Data>& sd) {
00114     return static_cast<SharedData&>(SharedHandle::operator =(sd));
00115   }
00116 
00117   template<class Data>
00118   forceinline const Data&
00119   SharedData<Data>::operator ()(void) const {
00120     return static_cast<SDO*>(object())->d;
00121   }
00122 
00123   template<class Data>
00124   forceinline void
00125   SharedData<Data>::update(Space& home, bool share, SharedHandle& sh) {
00126     SharedHandle::update(home,share,sh);
00127   }
00128 
00129   template<class Data>
00130   forceinline
00131   SharedData<Data>::~SharedData(void) {}
00132 
00133 }
00134 
00135 // STATISTICS: kernel-other