00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00027 #include <semantics_delta.h>
00028 #include <add_algo>
00029
00030 semantics_delta::semantics_delta(
00031 const std::vector<unsigned int>& __i, const std::vector<uint32_t>& __b)
00032 : delta_base("change semantics"), indices(__i), new_f_sem(__b)
00033 { std::pair_sort(indices.begin(), indices.end(), new_f_sem.begin(),
00034 new_f_sem.end()); }
00035
00036 bool semantics_delta::search(unsigned int _i,
00037 std::vector<unsigned int>::iterator& _xs)
00038 {
00039 _xs = std::lower_bound(indices.begin(), indices.end(), _i);
00040 return _xs != indices.end() && *_xs == _i;
00041 }
00042
00043 void semantics_delta::set(const std::vector<unsigned int>& _i,
00044 const std::vector<semantics>& _s)
00045 {
00046 std::vector<unsigned int>::const_iterator _xi, _ei(_i.end());
00047 std::vector<semantics>::const_iterator _xs, _es(_s.end());
00048 for(_xi = _i.begin(), _xs = _s.begin(); _xi != _ei && _xs != _es;
00049 ++_xi, ++_xs)
00050 set(*_xi, *_xs);
00051 }
00052
00053 void semantics_delta::set(const std::vector<unsigned int>& _i,
00054 const std::vector<uint32_t>& _s)
00055 {
00056 indices = _i;
00057 new_f_sem = _s;
00058 std::pair_sort(indices.begin(), indices.end(),
00059 new_f_sem.begin(), new_f_sem.end());
00060 }
00061
00062 void semantics_delta::set_convex(const std::vector<unsigned int>& _i,
00063 const std::vector<convex_e>& _s)
00064 {
00065 std::vector<unsigned int>::const_iterator _xi, _ei(_i.end());
00066 std::vector<convex_e>::const_iterator _xs, _es(_s.end());
00067 for(_xi = _i.begin(), _xs = _s.begin(); _xi != _ei && _xs != _es;
00068 ++_xi, ++_xs)
00069 set_convex(*_xi, *_xs);
00070 }
00071
00072 void semantics_delta::set_activity(const std::vector<unsigned int>& _i,
00073 const std::vector<activity_descr>& _s)
00074 {
00075 std::vector<unsigned int>::const_iterator _xi, _ei(_i.end());
00076 std::vector<activity_descr>::const_iterator _xs, _es(_s.end());
00077 for(_xi = _i.begin(), _xs = _s.begin(); _xi != _ei && _xs != _es;
00078 ++_xi, ++_xs)
00079 set_activity(*_xi, *_xs);
00080 }
00081
00082 void semantics_delta::set_separable(
00083 const std::vector<unsigned int>& _i,
00084 const std::vector<tristate>& _s)
00085 {
00086 std::vector<unsigned int>::const_iterator _xi, _ei(_i.end());
00087 std::vector<tristate>::const_iterator _xs, _es(_s.end());
00088 for(_xi = _i.begin(), _xs = _s.begin(); _xi != _ei && _xs != _es;
00089 ++_xi, ++_xs)
00090 set_separable(*_xi, *_xs);
00091 }
00092
00093 void semantics_delta::set_integer(
00094 const std::vector<unsigned int>& _i,
00095 const std::vector<bool>& _s)
00096 {
00097 std::vector<unsigned int>::const_iterator _xi, _ei(_i.end());
00098 std::vector<bool>::const_iterator _xs, _es(_s.end());
00099 for(_xi = _i.begin(), _xs = _s.begin(); _xi != _ei && _xs != _es;
00100 ++_xi, ++_xs)
00101 set_integer(*_xi, *_xs);
00102 }
00103
00104 void semantics_delta::set_hard(const std::vector<unsigned int>& _i,
00105 const std::vector<bool>& _s)
00106 {
00107 std::vector<unsigned int>::const_iterator _xi, _ei(_i.end());
00108 std::vector<bool>::const_iterator _xs, _es(_s.end());
00109 for(_xi = _i.begin(), _xs = _s.begin(); _xi != _ei && _xs != _es;
00110 ++_xi, ++_xs)
00111 set_hard(*_xi, *_xs);
00112 }
00113
00114 void semantics_delta::set_type(const std::vector<unsigned int>& _i,
00115 const std::vector<type_annotation>& _s)
00116 {
00117 std::vector<unsigned int>::const_iterator _xi, _ei(_i.end());
00118 std::vector<type_annotation>::const_iterator _xs, _es(_s.end());
00119 for(_xi = _i.begin(), _xs = _s.begin(); _xi != _ei && _xs != _es;
00120 ++_xi, ++_xs)
00121 set_type(*_xi, *_xs);
00122 }
00123
00124 void semantics_delta::set(unsigned int _i, const semantics& s)
00125 {
00126 std::vector<unsigned int>::iterator _xs;
00127 if(search(_i, _xs))
00128 new_f_sem[_xs - indices.begin()] = encode(s);
00129 else
00130 {
00131 new_f_sem.insert(new_f_sem.begin() + (_xs - indices.begin()), encode(s));
00132 indices.insert(_xs, _i);
00133 }
00134 }
00135
00136 void semantics_delta::set_convex(unsigned int _i, const convex_e& c)
00137 {
00138 std::vector<unsigned int>::iterator _xs;
00139 if(search(_i, _xs))
00140 new_f_sem[_xs - indices.begin()] =
00141 encode_convex(new_f_sem[_xs - indices.begin()], c);
00142 else
00143 {
00144 new_f_sem.insert(new_f_sem.begin() + (_xs - indices.begin()),
00145 encode_convex(0, c));
00146 indices.insert(_xs, _i);
00147 }
00148 }
00149
00150 void semantics_delta::set_activity(unsigned int _i, const activity_descr& a)
00151 {
00152 std::vector<unsigned int>::iterator _xs;
00153 if(search(_i, _xs))
00154 new_f_sem[_xs - indices.begin()] =
00155 encode_activity(new_f_sem[_xs - indices.begin()], a);
00156 else
00157 {
00158 new_f_sem.insert(new_f_sem.begin() + (_xs - indices.begin()),
00159 encode_activity(0, a));
00160 indices.insert(_xs, _i);
00161 }
00162 }
00163
00164 void semantics_delta::set_separable(unsigned int _i,
00165 const tristate& t)
00166 {
00167 std::vector<unsigned int>::iterator _xs;
00168 if(search(_i, _xs))
00169 new_f_sem[_xs - indices.begin()] =
00170 encode_separable(new_f_sem[_xs - indices.begin()], t);
00171 else
00172 {
00173 new_f_sem.insert(new_f_sem.begin() + (_xs - indices.begin()),
00174 encode_separable(0, t));
00175 indices.insert(_xs, _i);
00176 }
00177 }
00178
00179 void semantics_delta::set_integer(unsigned int _i, bool b)
00180 {
00181 std::vector<unsigned int>::iterator _xs;
00182 if(search(_i, _xs))
00183 new_f_sem[_xs - indices.begin()] =
00184 encode_integer(new_f_sem[_xs - indices.begin()], b);
00185 else
00186 {
00187 new_f_sem.insert(new_f_sem.begin() + (_xs - indices.begin()),
00188 encode_integer(0, b));
00189 indices.insert(_xs, _i);
00190 }
00191 }
00192
00193 void semantics_delta::set_hard(unsigned int _i, bool b)
00194 {
00195 std::vector<unsigned int>::iterator _xs;
00196 if(search(_i, _xs))
00197 new_f_sem[_xs - indices.begin()] =
00198 encode_hard(new_f_sem[_xs - indices.begin()], b);
00199 else
00200 {
00201 new_f_sem.insert(new_f_sem.begin() + (_xs - indices.begin()),
00202 encode_hard(0, b));
00203 indices.insert(_xs, _i);
00204 }
00205 }
00206
00207 void semantics_delta::set_type(unsigned int _i,
00208 const type_annotation& a)
00209 {
00210 std::vector<unsigned int>::iterator _xs;
00211 if(search(_i, _xs))
00212 new_f_sem[_xs - indices.begin()] =
00213 encode_type(new_f_sem[_xs - indices.begin()], a);
00214 else
00215 {
00216 new_f_sem.insert(new_f_sem.begin() + (_xs - indices.begin()),
00217 encode_type(0, a));
00218 indices.insert(_xs, _i);
00219 }
00220 }
00221
00222 bool semantics_delta::apply(work_node& _x, undelta_base*& _u) const
00223 {
00224 std::vector<uint32_t> _vs;
00225 model* __mod = _x.get_model_ptr();
00226 std::vector<uint32_t>::const_iterator _xs, _es(new_f_sem.end());
00227
00228 if(indices.empty())
00229 {
00230 unsigned int n(__mod->number_of_nodes()), i;
00231 _vs.reserve(n);
00232 for(i = 0, _xs = new_f_sem.begin(); i < n && _xs != _es; ++i, ++_xs)
00233 {
00234 _vs.push_back(encode(__mod->node(i)->sem));
00235 decode(*_xs, __mod->node(i)->sem);
00236 }
00237 }
00238 else
00239 {
00240 std::vector<unsigned int>::const_iterator _c;
00241 _vs.reserve(new_f_sem.size());
00242 for(_c = indices.begin(), _xs = new_f_sem.begin(); _xs != _es; ++_c, ++_xs)
00243 {
00244 _vs.push_back(encode(__mod->node(*_c)->sem));
00245 decode(*_xs, __mod->node(*_c)->sem);
00246 }
00247 }
00248 _u = (undelta_base *) new semantics_undelta(indices, _vs);
00249 return true;
00250 }
00251
00252 bool semantics_undelta::unapply(work_node& _x) const
00253 {
00254 model* __mod = _x.get_model_ptr();
00255 std::vector<uint32_t>::const_iterator _xs, _es(old_f_sem.end());
00256
00257 if(indices.empty())
00258 {
00259 unsigned int n(__mod->number_of_nodes()), i;
00260 for(i = 0, _xs = old_f_sem.begin(); i < n && _xs != _es; ++i, ++_xs)
00261 ((semantics_delta*)this)->decode(*_xs, __mod->node(i)->sem);
00262 }
00263 else
00264 {
00265 std::vector<unsigned int>::const_iterator _c;
00266 for(_c = indices.begin(), _xs = old_f_sem.begin(); _xs != _es; ++_c, ++_xs)
00267 ((semantics_delta*)this)->decode(*_xs, __mod->node(*_c)->sem);
00268 }
00269 return true;
00270 }
00271