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
00028 #ifndef _SEMANTICS_DELTA_H_
00029 #define _SEMANTICS_DELTA_H_
00030
00031 #include <api_delta.h>
00032
00033 namespace coco {
00034
00036
00041 class semantics_undelta : public undelta_base
00042 {
00043 private:
00047 std::vector<unsigned int> indices;
00051 std::vector<uint32_t> old_f_sem;
00052
00053 public:
00055 semantics_undelta(const std::vector<unsigned int>& __i,
00056 const std::vector<uint32_t>& __s) : undelta_base(),
00057 indices(__i),
00058 old_f_sem(__s) {}
00059
00061 semantics_undelta(const std::vector<unsigned int>& __i) : undelta_base(),
00062 indices(__i),
00063 old_f_sem() {}
00065 semantics_undelta(const semantics_undelta& __d) : undelta_base(__d),
00066 indices(__d.indices),
00067 old_f_sem(__d.old_f_sem)
00068 {
00069 #if DEBUG_DELTA
00070 std::cerr << "Called semantics_undelta copy constructor" << std::endl;
00071 #endif
00072 }
00073
00075 semantics_undelta* new_copy() const { return new semantics_undelta(*this); }
00077 void destroy_copy(undelta_base* __d) const { delete (semantics_undelta*)__d; }
00078
00080 bool unapply(work_node& _x, const delta_id& _did) const;
00081
00082 friend class semantics_delta;
00083 };
00084
00086
00091 class semantics_delta : public delta_base
00092 {
00093 private:
00096 std::vector<unsigned int> indices;
00123 std::vector<uint32_t> new_f_sem;
00124
00125 private:
00130 bool search(unsigned int _i, std::vector<unsigned int>::iterator& _xs);
00131
00137 uint32_t ebool(uint32_t e, bool b, int idx) const
00138
00139
00140 { uint32_t bi = idx == 0 ? 1 : (idx == 1 ? 3 : 9);
00141 uint32_t s = e % (bi*3);
00142 if(idx != 0) s -= e % bi;
00143 return e - s + (b ? 2*bi : bi);
00144 }
00146 uint32_t etristate(const tristate& t) const
00147 { return t == t_true ? 1 : (t == t_false ? 3 : 2); }
00149 uint32_t econvex_e(const convex_e& c) const
00150 { return (c == c_concave ? 3 : (uint32_t) c.i()) | (c.t() << 16); }
00152 uint32_t etype_annotation(const type_annotation& a) const
00153 { return (uint32_t) a; }
00155 uint32_t eactivity_descr(const activity_descr& a) const
00156 { return (uint32_t) a; }
00157
00163 void dbool(uint32_t c, bool &b, int idx) const
00164
00165
00166 { uint32_t bi = idx == 0 ? 1 : (idx == 1 ? 3 : 9);
00167 uint32_t s = c % (bi*3);
00168 if(idx != 0) s -= c % bi;
00169 if(s)
00170 b = (s != bi);
00171 }
00173 void dtristate(uint32_t c, tristate& t) const
00174 { if(c == 3) t = t_false; else if(c != 0) t = (tristate) c; }
00176 void dconvex_e(uint32_t c, convex_e& ce) const
00177 { uint16_t t = c >> 16;
00178 ce = t; c = c&0xffff;
00179 if(c == 3) ce = c_concave; else if(c != 0) ce = (convex_info) c; }
00181 void dtype_annotation(uint32_t c, type_annotation& a) const
00182 { a = (type_annotation) c; }
00184 void dactivity_descr(uint32_t c, activity_descr& a) const
00185 { if(c) a = (activity_descr) c; }
00186
00187 public:
00190 uint32_t encode_convex(uint32_t e, const convex_e& c) const
00191 { return (e & ~7) | econvex_e(c) | (1<<2); }
00194 uint32_t encode_activity(uint32_t e, const activity_descr& a) const
00195 { return (e & ~(7 << 3)) | (eactivity_descr(a)<<3); }
00198 uint32_t encode_is_at_either_bound(uint32_t e, bool b) const
00199 { return (e & ~(31 << 6)) | (ebool((e>>6)&31, b, 0)<<6); }
00202 uint32_t encode_integer(uint32_t e, bool b) const
00203 { return (e & ~(31 << 6)) | (ebool((e>>6)&31, b, 1)<<6); }
00206 uint32_t encode_hard(uint32_t e, bool b) const
00207 { return (e & ~(31 << 6)) | (ebool((e>>6)&31, b, 2)<<6); }
00210 uint32_t encode_separable(uint32_t e, const tristate& t) const
00211 { return (e & ~(3 << 11)) | (etristate(t)<<11); }
00214 uint32_t encode_type(uint32_t e, const type_annotation& a) const
00215 { return (e & ~(3 << 13)) | (etype_annotation(a)<<13) | (1<<15); }
00217 uint32_t encode(const semantics& s) const
00218 { uint32_t e(0);
00219 e = encode_convex(e, s.property_flags.c_info);
00220 e = encode_activity(e, s.property_flags.act);
00221 e = encode_separable(e, s.property_flags.separable);
00222 e = encode_is_at_either_bound(e, s.property_flags.is_at_either_bound);
00223 e = encode_integer(e, s.annotation_flags.integer);
00224 e = encode_type(e, s.annotation_flags.type);
00225 e = encode_hard(e, s.annotation_flags.hard);
00226 return e;
00227 }
00228
00231 void decode_convex(uint32_t e, convex_e& c) const
00232 { if(e & (1<<2)) dconvex_e(e & 0xffff0003, c); }
00235 void decode_activity(uint32_t e, activity_descr& a) const
00236 { dactivity_descr((e>>3) & 7, a); }
00239 void decode_is_at_either_bound(uint32_t e, bool& b) const
00240 { dbool((e>>6) & 31, b, 0); }
00243 void decode_integer(uint32_t e, bool& b) const
00244 { dbool((e>>6) & 31, b, 1); }
00247 void decode_hard(uint32_t e, bool& b) const
00248 { dbool((e>>6) & 31, b, 2); }
00251 void decode_separable(uint32_t e, tristate& t) const
00252 { dtristate((e>>11) & 3, t); }
00255 void decode_type(uint32_t e, type_annotation& a) const
00256 { if(e & (1<<15)) dtype_annotation((e>>13) & 3, a); }
00259 void decode(uint32_t e, semantics& s) const
00260 {
00261 decode_convex(e, s.property_flags.c_info);
00262 decode_activity(e, s.property_flags.act);
00263 decode_separable(e, s.property_flags.separable);
00264 decode_is_at_either_bound(e, s.property_flags.is_at_either_bound);
00265 decode_integer(e, s.annotation_flags.integer);
00266 decode_type(e, s.annotation_flags.type);
00267 decode_hard(e, s.annotation_flags.hard);
00268 }
00269
00270 public:
00272 semantics_delta() : delta_base("change semantics"), indices(), new_f_sem() {}
00275 semantics_delta(const std::vector<unsigned int>& __i,
00276 const std::vector<uint32_t>& __b);
00277
00280 semantics_delta(unsigned int __i, uint32_t __b)
00281 : delta_base("change semantics"), indices(1,__i),
00282 new_f_sem(1,__b) {}
00283
00285 semantics_delta(const semantics_delta& __d)
00286 : delta_base(__d), indices(__d.indices),
00287 new_f_sem(__d.new_f_sem)
00288 {
00289 #if DEBUG_DELTA
00290 std::cerr << "Called semantics_delta copy constructor" << std::endl;
00291 #endif
00292 }
00293
00295 semantics_delta* new_copy() const { return new semantics_delta(*this); }
00297 void destroy_copy(delta_base* __d) const { delete (semantics_delta*)__d; }
00298
00301 void set(const std::vector<unsigned int>& _i,
00302 const std::vector<uint32_t>& _s);
00303
00307 void set(const std::vector<unsigned int>& _i,
00308 const std::vector<semantics>& _s);
00311 void set(unsigned int _i, const semantics& _s);
00316 void set_convex(const std::vector<unsigned int>& _i,
00317 const std::vector<convex_e>& c);
00321 void set_convex(unsigned int _i, const convex_e& c);
00326 void set_activity(const std::vector<unsigned int>& _i,
00327 const std::vector<activity_descr>& a);
00332 void set_activity(unsigned int _i, const activity_descr& a);
00337 void set_separable(const std::vector<unsigned int>& _i,
00338 const std::vector<tristate>& t);
00343 void set_separable(unsigned int _i, const tristate& t);
00348 void set_is_at_either_bound(const std::vector<unsigned int>& _i,
00349 const std::vector<bool>& b);
00354 void set_is_at_either_bound(unsigned int _i, bool b);
00359 void set_integer(const std::vector<unsigned int>& _i,
00360 const std::vector<bool>& b);
00365 void set_integer(unsigned int _i, bool b);
00370 void set_hard(const std::vector<unsigned int>& _i,
00371 const std::vector<bool>& b);
00376 void set_hard(unsigned int _i, bool b);
00381 void set_type(const std::vector<unsigned int>& _i,
00382 const std::vector<type_annotation>& a);
00387 void set_type(unsigned int _i, const type_annotation& a);
00388
00391 bool apply(work_node& _x, undelta_base*& _u, const delta_id& _did) const;
00392
00394 bool operator==(const delta_base& _c) const
00395 { return _c.get_action() == get_action() &&
00396 this->operator==(*(semantics_delta*)&_c); }
00397 bool operator!=(const delta_base& _c) const
00398 { return _c.get_action() != get_action() ||
00399 this->operator!=(*(semantics_delta*)&_c); }
00400
00402 bool operator==(const semantics_delta& _c) const
00403 { return this == &_c
00404 || (indices == _c.indices && new_f_sem == _c.new_f_sem); }
00405 bool operator!=(const semantics_delta& _c) const
00406 { return this != &_c
00407 && (indices != _c.indices || new_f_sem != _c.new_f_sem); }
00408
00409 friend class semantics_undelta;
00410 };
00411
00412 }
00413
00414 #endif