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(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