Generated on Wed Mar 19 07:30:01 2008 for Gecode by doxygen 1.5.5

var-map.icc

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Guido Tack <tack@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Guido Tack, 2007
00008  *
00009  *  Last modified:
00010  *     $Date: 2008-01-28 12:40:59 +0100 (Mon, 28 Jan 2008) $ by $Author: tack $
00011  *     $Revision: 5988 $
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 #include <sstream>
00039 
00040 namespace Gecode { namespace Reflection {
00041   
00042   class VarMapIter;
00043 
00064   class GECODE_KERNEL_EXPORT VarMap {
00065     friend class VarMapIter;
00066   private:
00067     class VarMapObj;
00068     VarMapObj* vo;
00069     
00070   public:
00072     VarMap(void);
00074     VarMap(const VarMap&);
00076     VarMap& operator=(const VarMap&);
00078     GECODE_MSC_VIRTUAL ~VarMap(void);
00079     
00081     int size(void) const;
00082     
00084     int index(const VarImpBase* x) const;
00086     int index(const Support::Symbol& n) const;
00087 
00089     bool nameIsKnown(const Support::Symbol& n) const;
00090 
00092     bool hasName(const VarImpBase* x) const;
00094     bool hasName(int i) const;
00095 
00097     Support::Symbol name(const VarImpBase* x) const;
00099     Support::Symbol name(int i) const;
00100 
00102     VarImpBase* varImpBase(const Support::Symbol& n) const;
00104     VarImpBase* varImpBase(int i) const;
00106     Var var(const Support::Symbol& n) const;
00108     Var var(int i) const;
00109 
00111     VarSpec& spec(const VarImpBase* x) const;
00113     VarSpec& spec(int i) const;
00115     VarSpec& spec(const Support::Symbol& n) const;
00116 
00118     void name(VarImpBase* x, const Support::Symbol& n);
00119 
00121     int put(const VarImpBase* x, VarSpec* vs);
00122 
00124     void putMasterObject(void* obj);
00126     int getSharedIndex(void* obj) const;
00128     void* getSharedObject(int i) const;
00129 
00131 
00132 
00133     template <class Var> void
00134     put(Space* home, const Var& v, const Support::Symbol& n,
00135         bool registerOnly = false);
00137     template <class Var> void
00138     putArray(Space* home, const VarArgArray<Var>& v,
00139              const Support::Symbol& n, bool registerOnly = false);
00141     template <class Var> void
00142     putArray(Space* home, const VarArray<Var>& v, const Support::Symbol& n,
00143              bool registerOnly = false);
00144 
00146 
00147   };
00148   
00159   class GECODE_KERNEL_EXPORT VarMapIter {
00160   private:
00162     VarMap* m;
00164     int i;
00165   public:
00167     VarMapIter(VarMap& m);
00169     bool operator()(void) const;
00171     VarSpec& spec(void) const;
00173     VarImpBase* varImpBase(void) const;
00175     Var var(void) const;
00177     void operator++(void);
00178   };
00179 
00180   template <> void
00181   inline
00182   VarMap::put(Space* home, const Reflection::Var& x,
00183               const Support::Symbol& n, bool registerOnly) {
00184     name(x.var<VarImpBase>(), n);
00185     if (!registerOnly) {
00186       Reflection::Arg* a = x.spec(home, *this);
00187       delete a;
00188     }
00189   }
00190 
00191   template <class V> void
00192   VarMap::put(Space* home, const V& x, const Support::Symbol& n,
00193               bool registerOnly) {
00194     typename VarViewTraits<V>::View v(x);
00195     name(v.var(), n);
00196     if (!registerOnly) {
00197       Reflection::Arg* a = v.spec(home, *this);
00198       delete a;
00199     }
00200   }
00201 
00202   template <class Var> void
00203   VarMap::putArray(Space* home, const VarArgArray<Var>& x,
00204                    const Support::Symbol& n, bool registerOnly) {
00205     for (int i=0; i<x.size(); i++) {
00206       std::stringstream s;
00207       s << i;
00208       Support::Symbol nn = n.copy();
00209       nn += Support::Symbol(s.str().c_str(), true);
00210       put(home, x[i], nn, registerOnly);
00211     }
00212   }
00213   template <class Var> void
00214   VarMap::putArray(Space* home, const VarArray<Var>& x,
00215                    const Support::Symbol& n, bool registerOnly) {
00216     for (int i=0; i<x.size(); i++) {
00217       std::stringstream s;
00218       s << i;
00219       Support::Symbol nn = n.copy();
00220       nn += Support::Symbol(s.str().c_str(), true);
00221       put(home, x[i], nn, registerOnly);
00222     }
00223   }
00224 
00225 }}
00226 
00227 // STATISTICS: kernel-other