Changeset 36441 for trunk/psModules/src/objects/pmModelClass.c
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/bills_branches/bills_201312 (added) merged: 36383,36386,36388-36396,36406-36407,36409-36412,36415-36420,36422-36427,36433,36436-36439
- Property svn:mergeinfo changed
-
trunk/psModules
- Property svn:mergeinfo changed
/branches/bills_branches/bills_201312/psModules (added) merged: 36389,36412,36422-36424
- Property svn:mergeinfo changed
-
trunk/psModules/src/objects/pmModelClass.c
r34259 r36441 66 66 67 67 static pmModelClass *models = NULL; 68 static psVector *modelClassLookupTable = NULL; // translation between model types in header and here 68 69 static int Nmodels = 0; 69 70 … … 135 136 models = NULL; 136 137 Nmodels = 0; 138 psFree(modelClassLookupTable); 139 modelClassLookupTable = NULL; 137 140 return; 138 141 } … … 193 196 } 194 197 198 199 bool pmModelClassWriteHeader(psMetadata *header) 200 { 201 psMetadataAddS32(header, PS_LIST_TAIL, "MTNUM", PS_META_REPLACE, "number of model types", Nmodels); 202 for (int i = 0; i < Nmodels; i++) { 203 char modelNameKey[16]; 204 char modelValKey[16]; 205 sprintf(modelNameKey, "MTNAM%02d", i); 206 sprintf(modelValKey, "MTVAL%02d", i); 207 psMetadataAddStr(header, PS_LIST_TAIL, modelNameKey, PS_META_REPLACE, "", models[i].name); 208 psMetadataAddS32(header, PS_LIST_TAIL, modelValKey, PS_META_REPLACE, "", i); 209 } 210 211 return true; 212 } 213 214 bool pmModelClassReadHeader(psMetadata *header) { 215 psFree(modelClassLookupTable); 216 217 bool status; 218 int numHeaderModels = psMetadataLookupS32(&status, header, "MTNUM"); 219 if (!status) { 220 return false; 221 } 222 223 psVector *inputTypes = psVectorAlloc(numHeaderModels, PS_TYPE_S32); 224 psVector *localTypes = psVectorAlloc(numHeaderModels, PS_TYPE_S32); 225 int max_val = -1; 226 for (int i = 0; i < numHeaderModels; i++) { 227 char modelNameKey[16]; 228 char modelValKey[16]; 229 sprintf(modelNameKey, "MTNAM%02d", i); 230 sprintf(modelValKey, "MTVAL%02d", i); 231 psString thisName = psMetadataLookupStr(&status, header, modelNameKey); 232 int thisVal = psMetadataLookupS32(&status, header, modelValKey); 233 if (thisVal > max_val) { 234 max_val = thisVal; 235 } 236 inputTypes->data.S32[i] = thisVal; 237 localTypes->data.S32[i] = pmModelClassGetType(thisName); 238 } 239 if (max_val < 0) { 240 psFree(inputTypes); 241 psFree(localTypes); 242 return false; 243 } 244 245 modelClassLookupTable = psVectorAlloc(max_val + 1, PS_TYPE_S32); 246 psVectorInit(modelClassLookupTable, -1); 247 248 for (int i = 0; i < numHeaderModels; i++) { 249 int thisVal = inputTypes->data.S32[i]; 250 int localVal = localTypes->data.S32[i]; 251 modelClassLookupTable->data.S32[thisVal] = localVal; 252 } 253 psFree(inputTypes); 254 psFree(localTypes); 255 256 return true; 257 } 258 259 pmModelType pmModelClassGetLocalType(pmModelType inputType) { 260 pmModelType localType = -1; 261 262 if (modelClassLookupTable) { 263 if (inputType >= 0 && inputType < modelClassLookupTable->n) { 264 localType = modelClassLookupTable->data.S32[inputType]; 265 } 266 } else { 267 // no lookup table defined 268 // for backwards compatability if inputType refers to a defined model, return it 269 if (inputType >= 0 && pmModelClassGetName(inputType)) { 270 localType = inputType; 271 } 272 } 273 274 return localType; 275 }
Note:
See TracChangeset
for help on using the changeset viewer.
