Generated on Mon Aug 25 11:35:40 2008 for Gecode by doxygen 1.5.6

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-07-11 09:39:08 +0200 (Fri, 11 Jul 2008) $ by $Author: tack $
00011  *     $Revision: 7297 $
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(const Space* home, const Var& v, const Support::Symbol& n,
00135         bool registerOnly = false);
00137     template <class Var> void
00138     putArray(const Space* home, const VarArgArray<Var>& v,
00139              const Support::Symbol& n, bool registerOnly = false);
00141     template <class Var> void
00142     putArray(const Space* home, const VarArray<Var>& v,
00143              const Support::Symbol& n,
00144              bool registerOnly = false);
00145 
00147 
00148   };
00149   
00160   class GECODE_KERNEL_EXPORT VarMapIter {
00161   private:
00163     VarMap* m;
00165     int i;
00166   public:
00168     VarMapIter(VarMap& m);
00170     bool operator()(void) const;
00172     VarSpec& spec(void) const;
00174     VarImpBase* varImpBase(void) const;
00176     Var var(void) const;
00178     void operator++(void);
00179   };
00180 
00181   template <> void
00182   inline
00183   VarMap::put(const Space* home, const Reflection::Var& x,
00184               const Support::Symbol& n, bool registerOnly) {
00185     if (! (n == ""))
00186       name(x.varImpBase(), n);
00187     if (!registerOnly) {
00188       Reflection::Arg* a = x.spec(home, *this);
00189       delete a;
00190     }
00191   }
00192 
00193   template <class V> void
00194   VarMap::put(const Space* home, const V& x, const Support::Symbol& n,
00195               bool registerOnly) {
00196     typename VarViewTraits<V>::View v(x);
00197     if (! (n == ""))
00198       name(v.var(), n);
00199     if (!registerOnly) {
00200       Reflection::Arg* a = v.spec(home, *this);
00201       delete a;
00202     }
00203   }
00204 
00205   template <class Var> void
00206   VarMap::putArray(const Space* home, const VarArgArray<Var>& x,
00207                    const Support::Symbol& n, bool registerOnly) {
00208     for (int i=0; i<x.size(); i++) {
00209       std::stringstream s;
00210       s << i;
00211       Support::Symbol nn = n.copy();
00212       nn += Support::Symbol(s.str().c_str(), true);
00213       put(home, x[i], nn, registerOnly);
00214     }
00215   }
00216   template <class Var> void
00217   VarMap::putArray(const Space* home, const VarArray<Var>& x,
00218                    const Support::Symbol& n, bool registerOnly) {
00219     for (int i=0; i<x.size(); i++) {
00220       std::stringstream s;
00221       s << i;
00222       Support::Symbol nn = n.copy();
00223       nn += Support::Symbol(s.str().c_str(), true);
00224       put(home, x[i], nn, registerOnly);
00225     }
00226   }
00227 
00228 }}
00229 
00230 // STATISTICS: kernel-other