[729] | 1 | #include "paramtrans.h"
|
---|
| 2 | #include <frams/util/extvalue.h>
|
---|
| 3 |
|
---|
| 4 | void TwoWayMap::printList(const SListTempl<int>& L)
|
---|
| 5 | {
|
---|
| 6 | for (int i=0;i<L.size();i++)
|
---|
| 7 | {
|
---|
| 8 | int x=L(i);
|
---|
| 9 | if (x>=0) printf("%d",x);
|
---|
| 10 | else printf("x");
|
---|
| 11 | }
|
---|
| 12 | }
|
---|
| 13 |
|
---|
| 14 | void TwoWayMap::print()
|
---|
| 15 | {
|
---|
| 16 | printList(map);
|
---|
| 17 | printf("/");
|
---|
| 18 | printList(invmap);
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | void TwoWayMap::reset(int size)
|
---|
| 22 | {
|
---|
| 23 | map.clear(); invmap.clear();
|
---|
| 24 | for (int i=0;i<size;i++)
|
---|
| 25 | {
|
---|
| 26 | map.set(i,i);
|
---|
| 27 | invmap.set(i,i);
|
---|
| 28 | }
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | /** @return -2 = out of bounds */
|
---|
| 32 | int TwoWayMap::get(int pos)
|
---|
| 33 | {
|
---|
| 34 | if ((pos<0)||(pos>=map.size())) return -2;
|
---|
| 35 | return map(pos);
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | /** @return -2 = out of bounds */
|
---|
| 39 | int TwoWayMap::invget(int pos)
|
---|
| 40 | {
|
---|
| 41 | if ((pos<0)||(pos>=invmap.size())) return -2;
|
---|
| 42 | return invmap(pos);
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | void TwoWayMap::insert(int i)
|
---|
| 46 | {// map/invmap: 01234/01234 add(1) -> 0-1234/02345
|
---|
| 47 | // 1--40-2/406-3 add(1) -> 1---40-2/507-4
|
---|
| 48 | map.insert(i,-1);
|
---|
| 49 | for (int p=i+1;p<map.size();p++)
|
---|
| 50 | {
|
---|
| 51 | int x=map(p);
|
---|
| 52 | if (x>=0)
|
---|
| 53 | invmap.set(x,p);
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | void TwoWayMap::remove(int i)
|
---|
| 58 | {
|
---|
| 59 | // map/invmap: 01234/01234 rem(1) -> 0234/0-123
|
---|
| 60 | // 1--40-2/406-3 rem(1) -> 1-40-2/305-2
|
---|
| 61 | int x=map(i);
|
---|
| 62 | if (x>=0) invmap.set(x,-1);
|
---|
| 63 | map.remove(i);
|
---|
| 64 | for (int p=i;p<map.size();p++)
|
---|
| 65 | {
|
---|
| 66 | int x=map(p);
|
---|
| 67 | if (x>=0)
|
---|
| 68 | invmap.set(x,p);
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | ///////////////////////////
|
---|
| 73 |
|
---|
| 74 | ParamTransaction::ParamTransaction(MutableParamInterface &mpi)
|
---|
| 75 | :par(mpi)
|
---|
| 76 | {
|
---|
| 77 | panode=par.onadd.add(STATRICKCALLBACK(this,&ParamTransaction::onPropAdd,0));
|
---|
| 78 | pdnode=par.ondelete.add(STATRICKCALLBACK(this,&ParamTransaction::onPropDelete,0));
|
---|
| 79 | pcnode=par.onchange.add(STATRICKCALLBACK(this,&ParamTransaction::onPropChange,0));
|
---|
| 80 | ganode=par.ongroupadd.add(STATRICKCALLBACK(this,&ParamTransaction::onGroupAdd,0));
|
---|
| 81 | gdnode=par.ongroupdelete.add(STATRICKCALLBACK(this,&ParamTransaction::onGroupDelete,0));
|
---|
| 82 | gcnode=par.ongroupchange.add(STATRICKCALLBACK(this,&ParamTransaction::onGroupChange,0));
|
---|
| 83 | reset();
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | ParamTransaction::~ParamTransaction()
|
---|
| 87 | {
|
---|
| 88 | par.onadd.removeNode(panode);
|
---|
| 89 | par.ondelete.removeNode(pdnode);
|
---|
| 90 | par.onchange.removeNode(pcnode);
|
---|
| 91 | par.ongroupadd.removeNode(ganode);
|
---|
| 92 | par.ongroupdelete.removeNode(gdnode);
|
---|
| 93 | par.ongroupchange.removeNode(gcnode);
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | void ParamTransaction::reset()
|
---|
| 97 | {
|
---|
| 98 | resetMaps();
|
---|
| 99 | changed=false;
|
---|
| 100 | grchanged=false;
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | void ParamTransaction::onPropAdd(void* data,intptr_t i)
|
---|
| 104 | {
|
---|
| 105 | propmap.insert((int)i);
|
---|
| 106 | changed=true;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | void ParamTransaction::onPropDelete(void* data,intptr_t i)
|
---|
| 110 | {
|
---|
| 111 | propmap.remove((int)i);
|
---|
| 112 | changed=true;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | void ParamTransaction::onGroupAdd(void* data,intptr_t i)
|
---|
| 116 | {
|
---|
| 117 | groupmap.insert((int)i);
|
---|
| 118 | grchanged=true;
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | void ParamTransaction::onGroupDelete(void* data,intptr_t i)
|
---|
| 122 | {
|
---|
| 123 | groupmap.remove((int)i);
|
---|
| 124 | grchanged=true;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | void ParamTransaction::onPropChange(void* data,intptr_t i)
|
---|
| 128 | {
|
---|
| 129 | changed=true;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | void ParamTransaction::onGroupChange(void* data,intptr_t i)
|
---|
| 133 | {
|
---|
| 134 | grchanged=true;
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | void ParamTransaction::resetMaps()
|
---|
| 138 | {
|
---|
| 139 | propmap.reset(par.getPropCount());
|
---|
| 140 | groupmap.reset(par.getGroupCount());
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | int ParamTransaction::propertyPosition(int prop)
|
---|
| 144 | {return propmap.invget(prop);}
|
---|
| 145 |
|
---|
| 146 | int ParamTransaction::groupPosition(int group)
|
---|
| 147 | {return groupmap.invget(group);}
|
---|
| 148 |
|
---|
| 149 | const char * ParamTransaction::id(int i)
|
---|
| 150 | {
|
---|
| 151 | i=propertyPosition(i);
|
---|
| 152 | if (i==-2) return 0;
|
---|
| 153 | if (i>=0) return par.id(i); else return "?";
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | const char * ParamTransaction::name(int i)
|
---|
| 157 | {
|
---|
| 158 | i=propertyPosition(i);
|
---|
| 159 | if (i==-2) return 0;
|
---|
| 160 | if (i>=0) return par.name(i); else return "?";
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | const char * ParamTransaction::type(int i)
|
---|
| 164 | {
|
---|
| 165 | i=propertyPosition(i);
|
---|
| 166 | if (i==-2) return 0;
|
---|
| 167 | if (i>=0) return par.type(i); else return "?";
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | const char * ParamTransaction::help(int i)
|
---|
| 171 | {
|
---|
| 172 | i=propertyPosition(i);
|
---|
| 173 | return (i>=0)?par.help(i):0;
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | int ParamTransaction::flags(int i)
|
---|
| 177 | {
|
---|
| 178 | i=propertyPosition(i);
|
---|
| 179 | return (i>=0)?par.flags(i):0;
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | int ParamTransaction::group(int i)
|
---|
| 183 | {
|
---|
| 184 | i=propertyPosition(i);
|
---|
| 185 | return (i>=0)?par.group(i):0;
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | const char * ParamTransaction::grname(int i)
|
---|
| 189 | {
|
---|
| 190 | i=groupPosition(i);
|
---|
| 191 | if (i==-2) return 0;
|
---|
| 192 | return (i>=0)?par.grname(i):"?";
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | int ParamTransaction::grmember(int g, int i)
|
---|
| 196 | {
|
---|
| 197 | g=groupPosition(g);
|
---|
| 198 | if (g<0) return -9999;
|
---|
| 199 | for(int p=0;p<getPropCount();p++)
|
---|
| 200 | if (group(p)==g)
|
---|
| 201 | if (!i--)
|
---|
| 202 | return p;
|
---|
| 203 | return -9999;
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | void ParamTransaction::call(int i, ExtValue *a, ExtValue *b)
|
---|
| 207 | {
|
---|
| 208 | i=propertyPosition(i);
|
---|
| 209 | if (i>=0) par.call(i,a,b);
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | SString ParamTransaction::getString(int i)
|
---|
| 213 | {
|
---|
| 214 | i=propertyPosition(i);
|
---|
| 215 | return (i>=0)?par.getString(i):SString();
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | paInt ParamTransaction::getInt(int i)
|
---|
| 219 | {
|
---|
| 220 | i=propertyPosition(i);
|
---|
| 221 | return (i>=0)?par.getInt(i):0;
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 | double ParamTransaction::getDouble(int i)
|
---|
| 225 | {
|
---|
| 226 | i=propertyPosition(i);
|
---|
| 227 | return (i>=0)?par.getDouble(i):0;
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 | ExtObject ParamTransaction::getObject(int i)
|
---|
| 231 | {
|
---|
| 232 | i=propertyPosition(i);
|
---|
| 233 | return (i>=0)?par.getObject(i):ExtObject();
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 | ExtValue ParamTransaction::getExtValue(int i)
|
---|
| 237 | {
|
---|
| 238 | i=propertyPosition(i);
|
---|
| 239 | return (i>=0)?par.getExtValue(i):ExtValue();
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 | int ParamTransaction::setInt(int i, paInt v)
|
---|
| 243 | {
|
---|
| 244 | i=propertyPosition(i);
|
---|
| 245 | return (i>=0)?par.setInt(i,v):PSET_NOPROPERTY;
|
---|
| 246 | }
|
---|
| 247 |
|
---|
| 248 | int ParamTransaction::setDouble(int i, double v)
|
---|
| 249 | {
|
---|
| 250 | i=propertyPosition(i);
|
---|
| 251 | return (i>=0)?par.setDouble(i,v):PSET_NOPROPERTY;
|
---|
| 252 | }
|
---|
| 253 |
|
---|
| 254 | int ParamTransaction::setString(int i, const SString &v)
|
---|
| 255 | {
|
---|
| 256 | i=propertyPosition(i);
|
---|
| 257 | return (i>=0)?par.setString(i,v):PSET_NOPROPERTY;
|
---|
| 258 | }
|
---|
| 259 |
|
---|
| 260 | int ParamTransaction::setObject(int i, const ExtObject &v)
|
---|
| 261 | {
|
---|
| 262 | i=propertyPosition(i);
|
---|
| 263 | return (i>=0)?par.setObject(i,v):PSET_NOPROPERTY;
|
---|
| 264 | }
|
---|
| 265 |
|
---|
| 266 | int ParamTransaction::setExtValue(int i, const ExtValue &v)
|
---|
| 267 | {
|
---|
| 268 | i=propertyPosition(i);
|
---|
| 269 | return (i>=0)?par.setExtValue(i,v):PSET_NOPROPERTY;
|
---|
| 270 | }
|
---|