comparison framework/Document.h @ 661:a2bf5e6c54ce single-point

Retain models in registration order, to assist in getting stable file format in load/save
author Chris Cannam
date Tue, 02 Apr 2019 14:32:24 +0100
parents 163573a73ebe
children 351b1302064e
comparison
equal deleted inserted replaced
660:85ada073d2db 661:a2bf5e6c54ce
368 368
369 // This does not use ModelTransformer::Input, because it would 369 // This does not use ModelTransformer::Input, because it would
370 // be confusing to have Input objects hanging around with NULL 370 // be confusing to have Input objects hanging around with NULL
371 // models in them. 371 // models in them.
372 372
373 Model *model;
373 const Model *source; 374 const Model *source;
374 int channel; 375 int channel;
375 Transform transform; 376 Transform transform;
376 bool additional; 377 bool additional;
377 378
378 // Count of the number of layers using this model. 379 // Count of the number of layers using this model.
379 int refcount; 380 int refcount;
380 }; 381 };
381 382
382 typedef std::map<Model *, ModelRecord> ModelMap; 383 // This used to be a map<Model *, ModelRecord>, but a vector
383 ModelMap m_models; 384 // ensures that models are consistently recorded in order of
385 // creation rather than at the whim of heap allocation, and that's
386 // useful for automated testing. We don't expect ever to have so
387 // many models that there is any significant overhead there.
388 typedef std::vector<ModelRecord> ModelList;
389 ModelList m_models;
390
391 ModelList::iterator findModelInList(Model *m) {
392 for (ModelList::iterator i = m_models.begin();
393 i != m_models.end(); ++i) {
394 if (i->model == m) {
395 return i;
396 }
397 }
398 return m_models.end();
399 }
400
401 void deleteModelFromList(Model *m) {
402 ModelList keep;
403 bool found = false;
404 for (const ModelRecord &rec: m_models) {
405 if (rec.model == m) {
406 found = true;
407 m->aboutToDelete();
408 emit modelAboutToBeDeleted(m);
409 } else {
410 keep.push_back(rec);
411 }
412 }
413 m_models = keep;
414 if (found) {
415 delete m;
416 }
417 }
384 418
385 /** 419 /**
386 * Add an extra derived model (returned at the end of processing a 420 * Add an extra derived model (returned at the end of processing a
387 * transform). 421 * transform).
388 */ 422 */