comparison framework/Document.cpp @ 636:e2715204feaa fix-static-analysis

Use nullptr throughout
author Chris Cannam
date Mon, 26 Nov 2018 14:34:06 +0000
parents 4612d44ae753
children 3168deb50199 e19c609a7bec
comparison
equal deleted inserted replaced
635:26a0cb8335e3 636:e2715204feaa
47 //#define DEBUG_DOCUMENT 1 47 //#define DEBUG_DOCUMENT 1
48 48
49 //!!! still need to handle command history, documentRestored/documentModified 49 //!!! still need to handle command history, documentRestored/documentModified
50 50
51 Document::Document() : 51 Document::Document() :
52 m_mainModel(0), 52 m_mainModel(nullptr),
53 m_autoAlignment(false), 53 m_autoAlignment(false),
54 m_align(new Align()), 54 m_align(new Align()),
55 m_isIncomplete(false) 55 m_isIncomplete(false)
56 { 56 {
57 connect(this, 57 connect(this,
113 if (m_mainModel) { 113 if (m_mainModel) {
114 m_mainModel->aboutToDelete(); 114 m_mainModel->aboutToDelete();
115 emit modelAboutToBeDeleted(m_mainModel); 115 emit modelAboutToBeDeleted(m_mainModel);
116 } 116 }
117 117
118 emit mainModelChanged(0); 118 emit mainModelChanged(nullptr);
119 delete m_mainModel; 119 delete m_mainModel;
120 } 120 }
121 121
122 Layer * 122 Layer *
123 Document::createLayer(LayerFactory::LayerType type) 123 Document::createLayer(LayerFactory::LayerType type)
124 { 124 {
125 Layer *newLayer = LayerFactory::getInstance()->createLayer(type); 125 Layer *newLayer = LayerFactory::getInstance()->createLayer(type);
126 if (!newLayer) return 0; 126 if (!newLayer) return nullptr;
127 127
128 newLayer->setObjectName(getUniqueLayerName(newLayer->objectName())); 128 newLayer->setObjectName(getUniqueLayerName(newLayer->objectName()));
129 129
130 m_layers.insert(newLayer); 130 m_layers.insert(newLayer);
131 131
141 141
142 Layer * 142 Layer *
143 Document::createMainModelLayer(LayerFactory::LayerType type) 143 Document::createMainModelLayer(LayerFactory::LayerType type)
144 { 144 {
145 Layer *newLayer = createLayer(type); 145 Layer *newLayer = createLayer(type);
146 if (!newLayer) return 0; 146 if (!newLayer) return nullptr;
147 setModel(newLayer, m_mainModel); 147 setModel(newLayer, m_mainModel);
148 return newLayer; 148 return newLayer;
149 } 149 }
150 150
151 Layer * 151 Layer *
154 LayerFactory::LayerTypeSet types = 154 LayerFactory::LayerTypeSet types =
155 LayerFactory::getInstance()->getValidLayerTypes(model); 155 LayerFactory::getInstance()->getValidLayerTypes(model);
156 156
157 if (types.empty()) { 157 if (types.empty()) {
158 cerr << "WARNING: Document::importLayer: no valid display layer for model" << endl; 158 cerr << "WARNING: Document::importLayer: no valid display layer for model" << endl;
159 return 0; 159 return nullptr;
160 } 160 }
161 161
162 //!!! for now, just use the first suitable layer type 162 //!!! for now, just use the first suitable layer type
163 LayerFactory::LayerType type = *types.begin(); 163 LayerFactory::LayerType type = *types.begin();
164 164
165 Layer *newLayer = LayerFactory::getInstance()->createLayer(type); 165 Layer *newLayer = LayerFactory::getInstance()->createLayer(type);
166 if (!newLayer) return 0; 166 if (!newLayer) return nullptr;
167 167
168 newLayer->setObjectName(getUniqueLayerName(newLayer->objectName())); 168 newLayer->setObjectName(getUniqueLayerName(newLayer->objectName()));
169 169
170 addImportedModel(model); 170 addImportedModel(model);
171 setModel(newLayer, model); 171 setModel(newLayer, model);
185 } 185 }
186 186
187 Layer * 187 Layer *
188 Document::createEmptyLayer(LayerFactory::LayerType type) 188 Document::createEmptyLayer(LayerFactory::LayerType type)
189 { 189 {
190 if (!m_mainModel) return 0; 190 if (!m_mainModel) return nullptr;
191 191
192 Model *newModel = 192 Model *newModel =
193 LayerFactory::getInstance()->createEmptyModel(type, m_mainModel); 193 LayerFactory::getInstance()->createEmptyModel(type, m_mainModel);
194 if (!newModel) return 0; 194 if (!newModel) return nullptr;
195 195
196 Layer *newLayer = createLayer(type); 196 Layer *newLayer = createLayer(type);
197 if (!newLayer) { 197 if (!newLayer) {
198 delete newModel; 198 delete newModel;
199 return 0; 199 return nullptr;
200 } 200 }
201 201
202 addImportedModel(newModel); 202 addImportedModel(newModel);
203 setModel(newLayer, newModel); 203 setModel(newLayer, newModel);
204 204
208 Layer * 208 Layer *
209 Document::createDerivedLayer(LayerFactory::LayerType type, 209 Document::createDerivedLayer(LayerFactory::LayerType type,
210 TransformId transform) 210 TransformId transform)
211 { 211 {
212 Layer *newLayer = createLayer(type); 212 Layer *newLayer = createLayer(type);
213 if (!newLayer) return 0; 213 if (!newLayer) return nullptr;
214 214
215 newLayer->setObjectName(getUniqueLayerName 215 newLayer->setObjectName(getUniqueLayerName
216 (TransformFactory::getInstance()-> 216 (TransformFactory::getInstance()->
217 getTransformFriendlyName(transform))); 217 getTransformFriendlyName(transform)));
218 218
224 const ModelTransformer::Input &input) 224 const ModelTransformer::Input &input)
225 { 225 {
226 Transforms transforms; 226 Transforms transforms;
227 transforms.push_back(transform); 227 transforms.push_back(transform);
228 vector<Layer *> layers = createDerivedLayers(transforms, input); 228 vector<Layer *> layers = createDerivedLayers(transforms, input);
229 if (layers.empty()) return 0; 229 if (layers.empty()) return nullptr;
230 else return layers[0]; 230 else return layers[0];
231 } 231 }
232 232
233 vector<Layer *> 233 vector<Layer *>
234 Document::createDerivedLayers(const Transforms &transforms, 234 Document::createDerivedLayers(const Transforms &transforms,
235 const ModelTransformer::Input &input) 235 const ModelTransformer::Input &input)
236 { 236 {
237 QString message; 237 QString message;
238 vector<Model *> newModels = addDerivedModels(transforms, input, message, 0); 238 vector<Model *> newModels = addDerivedModels(transforms, input, message, nullptr);
239 239
240 if (newModels.empty()) { 240 if (newModels.empty()) {
241 //!!! This identifier may be wrong! 241 //!!! This identifier may be wrong!
242 emit modelGenerationFailed(transforms[0].getIdentifier(), message); 242 emit modelGenerationFailed(transforms[0].getIdentifier(), message);
243 return vector<Layer *>(); 243 return vector<Layer *>();
638 << endl; 638 << endl;
639 return; 639 return;
640 } 640 }
641 641
642 ModelRecord rec; 642 ModelRecord rec;
643 rec.source = 0; 643 rec.source = nullptr;
644 rec.channel = 0; 644 rec.channel = 0;
645 rec.refcount = 0; 645 rec.refcount = 0;
646 rec.additional = false; 646 rec.additional = false;
647 647
648 m_models[model] = rec; 648 m_models[model] = rec;
674 << endl; 674 << endl;
675 return; 675 return;
676 } 676 }
677 677
678 ModelRecord rec; 678 ModelRecord rec;
679 rec.source = 0; 679 rec.source = nullptr;
680 rec.channel = 0; 680 rec.channel = 0;
681 rec.refcount = 0; 681 rec.refcount = 0;
682 rec.additional = true; 682 rec.additional = true;
683 683
684 m_models[model] = rec; 684 m_models[model] = rec;
730 } 730 }
731 } 731 }
732 732
733 Transforms tt; 733 Transforms tt;
734 tt.push_back(transform); 734 tt.push_back(transform);
735 vector<Model *> mm = addDerivedModels(tt, input, message, 0); 735 vector<Model *> mm = addDerivedModels(tt, input, message, nullptr);
736 if (mm.empty()) return 0; 736 if (mm.empty()) return nullptr;
737 else return mm[0]; 737 else return mm[0];
738 } 738 }
739 739
740 vector<Model *> 740 vector<Model *>
741 Document::addDerivedModels(const Transforms &transforms, 741 Document::addDerivedModels(const Transforms &transforms,
781 } 781 }
782 782
783 void 783 void
784 Document::releaseModel(Model *model) // Will _not_ release main model! 784 Document::releaseModel(Model *model) // Will _not_ release main model!
785 { 785 {
786 if (model == 0) { 786 if (model == nullptr) {
787 return; 787 return;
788 } 788 }
789 789
790 if (model == m_mainModel) { 790 if (model == m_mainModel) {
791 return; 791 return;
816 int sourceCount = 0; 816 int sourceCount = 0;
817 817
818 for (ModelMap::iterator i = m_models.begin(); i != m_models.end(); ++i) { 818 for (ModelMap::iterator i = m_models.begin(); i != m_models.end(); ++i) {
819 if (i->second.source == model) { 819 if (i->second.source == model) {
820 ++sourceCount; 820 ++sourceCount;
821 i->second.source = 0; 821 i->second.source = nullptr;
822 } 822 }
823 } 823 }
824 824
825 if (sourceCount > 0) { 825 if (sourceCount > 0) {
826 SVDEBUG << "Document::releaseModel: Deleting model " 826 SVDEBUG << "Document::releaseModel: Deleting model "
1099 // The reference has an empty alignment to itself. This makes 1099 // The reference has an empty alignment to itself. This makes
1100 // it possible to distinguish between the reference and any 1100 // it possible to distinguish between the reference and any
1101 // unaligned model just by looking at the model itself, 1101 // unaligned model just by looking at the model itself,
1102 // without also knowing what the main model is 1102 // without also knowing what the main model is
1103 SVDEBUG << "Document::alignModel(" << model << "): is main model, setting appropriately" << endl; 1103 SVDEBUG << "Document::alignModel(" << model << "): is main model, setting appropriately" << endl;
1104 rm->setAlignment(new AlignmentModel(model, model, 0, 0)); 1104 rm->setAlignment(new AlignmentModel(model, model, nullptr, nullptr));
1105 return; 1105 return;
1106 } 1106 }
1107 1107
1108 if (!m_align->alignModel(m_mainModel, rm)) { 1108 if (!m_align->alignModel(m_mainModel, rm)) {
1109 cerr << "Alignment failed: " << m_align->getError() << endl; 1109 cerr << "Alignment failed: " << m_align->getError() << endl;