comparison base/XmlExportable.cpp @ 1677:f97d64b8674f single-point

Make XmlExportables store their export IDs and always obtain a new one, avoiding reuse when an object is allocated at the same heap location as a previous one. This makes the ID system stable enough to be used in the export tests.
author Chris Cannam
date Thu, 28 Mar 2019 11:55:02 +0000
parents 48e9f538e6e9
children e4f31f506116
comparison
equal deleted inserted replaced
1676:3b51df7695a4 1677:f97d64b8674f
66 66
67 return "#" + r + g + b; 67 return "#" + r + g + b;
68 } 68 }
69 69
70 int 70 int
71 XmlExportable::getObjectExportId(const void * object) 71 XmlExportable::getExportId() const
72 { 72 {
73 static QMutex mutex; 73 if (m_exportId == -1) {
74 QMutexLocker locker(&mutex); 74 static QMutex mutex;
75 75 static int lastId = 0;
76 static std::map<const void *, int> idMap; 76 QMutexLocker locker(&mutex);
77 static int maxId = 0; 77 if (m_exportId == -1) {
78 78 m_exportId = ++lastId;
79 if (idMap.find(object) == idMap.end()) { 79 }
80 idMap[object] = maxId++;
81 } 80 }
82 81 return m_exportId;
83 return idMap[object];
84 } 82 }
85 83
86 84