comparison framework/SVFileReader.h @ 685:7540733f5480 by-id

Overhaul SV file reader etc
author Chris Cannam
date Thu, 04 Jul 2019 14:31:22 +0100
parents 26a0cb8335e3
children 610fa108fbcc
comparison
equal deleted inserted replaced
684:5e9b1956b609 685:7540733f5480
23 23
24 #include <map> 24 #include <map>
25 25
26 class Pane; 26 class Pane;
27 class Model; 27 class Model;
28 class Path;
28 class Document; 29 class Document;
29 class PlayParameters; 30 class PlayParameters;
30 31
31 class SVFileReaderPaneCallback 32 class SVFileReaderPaneCallback
32 { 33 {
180 181
181 // For loading a single layer onto an existing pane 182 // For loading a single layer onto an existing pane
182 void setCurrentPane(Pane *pane) { m_currentPane = pane; } 183 void setCurrentPane(Pane *pane) { m_currentPane = pane; }
183 184
184 bool startElement(const QString &namespaceURI, 185 bool startElement(const QString &namespaceURI,
185 const QString &localName, 186 const QString &localName,
186 const QString &qName, 187 const QString &qName,
187 const QXmlAttributes& atts) override; 188 const QXmlAttributes& atts) override;
188 189
189 bool characters(const QString &) override; 190 bool characters(const QString &) override;
190 191
191 bool endElement(const QString &namespaceURI, 192 bool endElement(const QString &namespaceURI,
192 const QString &localName, 193 const QString &localName,
193 const QString &qName) override; 194 const QString &qName) override;
194 195
195 bool error(const QXmlParseException &exception) override; 196 bool error(const QXmlParseException &exception) override;
196 bool fatalError(const QXmlParseException &exception) override; 197 bool fatalError(const QXmlParseException &exception) override;
197 198
198 enum FileType 199 enum FileType
231 bool readMeasurement(const QXmlAttributes &); 232 bool readMeasurement(const QXmlAttributes &);
232 233
233 void makeAggregateModels(); 234 void makeAggregateModels();
234 void addUnaddedModels(); 235 void addUnaddedModels();
235 236
236 bool haveModel(int id) { 237 // We use the term "pending" of things that have been referred to
237 return (m_models.find(id) != m_models.end()) && m_models[id]; 238 // but not yet constructed because their definitions are
239 // incomplete. They are just referred to with an ExportId. Models
240 // that have been constructed are always added straight away to
241 // ById and are referred to with a ModelId (everywhere where
242 // previously we would have used a Model *). m_models maps from
243 // ExportId (as read from the file) to complete Models, or to a
244 // ModelId of None for any model that could not be constructed for
245 // some reason.
246
247 typedef XmlExportable::ExportId ExportId;
248
249 bool haveModel(ExportId id) {
250 return (m_models.find(id) != m_models.end()) && !m_models[id].isNone();
238 } 251 }
239 252
240 struct PendingAggregateRec { 253 struct PendingAggregateRec {
241 QString name; 254 QString name;
242 sv_samplerate_t sampleRate; 255 sv_samplerate_t sampleRate;
243 std::vector<int> components; 256 std::vector<ExportId> components;
244 }; 257 };
245 258
246 Document *m_document; 259 Document *m_document;
247 SVFileReaderPaneCallback &m_paneCallback; 260 SVFileReaderPaneCallback &m_paneCallback;
248 QString m_location; 261 QString m_location;
249 Pane *m_currentPane; 262 Pane *m_currentPane;
250 std::map<int, Layer *> m_layers; 263 std::map<ExportId, Layer *> m_layers;
251 std::map<int, Model *> m_models; 264 std::map<ExportId, ModelId> m_models;
252 std::set<Model *> m_addedModels; 265 std::map<ExportId, Path *> m_paths;
253 std::map<int, PendingAggregateRec> m_pendingAggregates; 266 std::set<ModelId> m_addedModels; // i.e. added to Document, not just ById
254 std::map<int, int> m_awaitingDatasets; // map dataset id -> model id 267 std::map<ExportId, PendingAggregateRec> m_pendingAggregates;
268
269 // A model element often contains a dataset id, and the dataset
270 // then follows it. When the model is read, an entry in this map
271 // is added, mapping from the dataset's export id (the actual
272 // dataset has not been read yet) back to the export id of the
273 // object that needs it. We map to export id rather than model id,
274 // because the object might be a path rather than a model.
275 std::map<ExportId, ExportId> m_awaitingDatasets;
276
277 // And then this is the model or path that a dataset element is
278 // currently being read into, i.e. the value looked up from
279 // m_awaitingDatasets at the point where the dataset is found.
280 ExportId m_currentDataset;
281
255 Layer *m_currentLayer; 282 Layer *m_currentLayer;
256 Model *m_currentDataset; 283 ModelId m_currentDerivedModel;
257 Model *m_currentDerivedModel; 284 ExportId m_pendingDerivedModel;
258 int m_currentDerivedModelId;
259 PlayParameters *m_currentPlayParameters; 285 PlayParameters *m_currentPlayParameters;
260 Transform m_currentTransform; 286 Transform m_currentTransform;
261 Model *m_currentTransformSource; 287 ModelId m_currentTransformSource;
262 int m_currentTransformChannel; 288 int m_currentTransformChannel;
263 bool m_currentTransformIsNewStyle; 289 bool m_currentTransformIsNewStyle;
264 QString m_datasetSeparator; 290 QString m_datasetSeparator;
265 bool m_inRow; 291 bool m_inRow;
266 bool m_inLayer; 292 bool m_inLayer;