var-map.icc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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