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