diff --git a/components/nif/niffile.cpp b/components/nif/niffile.cpp index b33f0c051..118a58299 100644 --- a/components/nif/niffile.cpp +++ b/components/nif/niffile.cpp @@ -16,105 +16,96 @@ NIFFile::NIFFile(Files::IStreamPtr stream, const std::string &name) NIFFile::~NIFFile() { - for (std::vector::iterator it = records.begin() ; it != records.end(); ++it) - { - delete *it; - } + for (Record* record : records) + delete record; } template static Record* construct() { return new NodeType; } struct RecordFactoryEntry { - typedef Record* (*create_t) (); + using create_t = Record* (*)(); create_t mCreate; RecordType mType; }; -///Helper function for adding records to the factory map -static std::pair makeEntry(std::string recName, Record* (*create_t) (), RecordType type) -{ - RecordFactoryEntry anEntry = {create_t,type}; - return std::make_pair(recName, anEntry); -} - ///These are all the record types we know how to read. static std::map makeFactory() { - std::map newFactory; - newFactory.insert(makeEntry("NiNode", &construct , RC_NiNode )); - newFactory.insert(makeEntry("NiSwitchNode", &construct , RC_NiSwitchNode )); - newFactory.insert(makeEntry("NiLODNode", &construct , RC_NiLODNode )); - newFactory.insert(makeEntry("AvoidNode", &construct , RC_AvoidNode )); - newFactory.insert(makeEntry("NiCollisionSwitch", &construct , RC_NiCollisionSwitch )); - newFactory.insert(makeEntry("NiBSParticleNode", &construct , RC_NiBSParticleNode )); - newFactory.insert(makeEntry("NiBSAnimationNode", &construct , RC_NiBSAnimationNode )); - newFactory.insert(makeEntry("NiBillboardNode", &construct , RC_NiBillboardNode )); - newFactory.insert(makeEntry("NiTriShape", &construct , RC_NiTriShape )); - newFactory.insert(makeEntry("NiTriStrips", &construct , RC_NiTriStrips )); - newFactory.insert(makeEntry("NiLines", &construct , RC_NiLines )); - newFactory.insert(makeEntry("NiRotatingParticles", &construct , RC_NiRotatingParticles )); - newFactory.insert(makeEntry("NiAutoNormalParticles", &construct , RC_NiAutoNormalParticles )); - newFactory.insert(makeEntry("NiCamera", &construct , RC_NiCamera )); - newFactory.insert(makeEntry("RootCollisionNode", &construct , RC_RootCollisionNode )); - newFactory.insert(makeEntry("NiTexturingProperty", &construct , RC_NiTexturingProperty )); - newFactory.insert(makeEntry("NiFogProperty", &construct , RC_NiFogProperty )); - newFactory.insert(makeEntry("NiMaterialProperty", &construct , RC_NiMaterialProperty )); - newFactory.insert(makeEntry("NiZBufferProperty", &construct , RC_NiZBufferProperty )); - newFactory.insert(makeEntry("NiAlphaProperty", &construct , RC_NiAlphaProperty )); - newFactory.insert(makeEntry("NiVertexColorProperty", &construct , RC_NiVertexColorProperty )); - newFactory.insert(makeEntry("NiShadeProperty", &construct , RC_NiShadeProperty )); - newFactory.insert(makeEntry("NiDitherProperty", &construct , RC_NiDitherProperty )); - newFactory.insert(makeEntry("NiWireframeProperty", &construct , RC_NiWireframeProperty )); - newFactory.insert(makeEntry("NiSpecularProperty", &construct , RC_NiSpecularProperty )); - newFactory.insert(makeEntry("NiStencilProperty", &construct , RC_NiStencilProperty )); - newFactory.insert(makeEntry("NiVisController", &construct , RC_NiVisController )); - newFactory.insert(makeEntry("NiGeomMorpherController", &construct , RC_NiGeomMorpherController )); - newFactory.insert(makeEntry("NiKeyframeController", &construct , RC_NiKeyframeController )); - newFactory.insert(makeEntry("NiAlphaController", &construct , RC_NiAlphaController )); - newFactory.insert(makeEntry("NiRollController", &construct , RC_NiRollController )); - newFactory.insert(makeEntry("NiUVController", &construct , RC_NiUVController )); - newFactory.insert(makeEntry("NiPathController", &construct , RC_NiPathController )); - newFactory.insert(makeEntry("NiMaterialColorController", &construct , RC_NiMaterialColorController )); - newFactory.insert(makeEntry("NiBSPArrayController", &construct , RC_NiBSPArrayController )); - newFactory.insert(makeEntry("NiParticleSystemController", &construct , RC_NiParticleSystemController )); - newFactory.insert(makeEntry("NiFlipController", &construct , RC_NiFlipController )); - newFactory.insert(makeEntry("NiAmbientLight", &construct , RC_NiLight )); - newFactory.insert(makeEntry("NiDirectionalLight", &construct , RC_NiLight )); - newFactory.insert(makeEntry("NiPointLight", &construct , RC_NiLight )); - newFactory.insert(makeEntry("NiSpotLight", &construct , RC_NiLight )); - newFactory.insert(makeEntry("NiTextureEffect", &construct , RC_NiTextureEffect )); - newFactory.insert(makeEntry("NiVertWeightsExtraData", &construct , RC_NiVertWeightsExtraData )); - newFactory.insert(makeEntry("NiTextKeyExtraData", &construct , RC_NiTextKeyExtraData )); - newFactory.insert(makeEntry("NiStringExtraData", &construct , RC_NiStringExtraData )); - newFactory.insert(makeEntry("NiGravity", &construct , RC_NiGravity )); - newFactory.insert(makeEntry("NiPlanarCollider", &construct , RC_NiPlanarCollider )); - newFactory.insert(makeEntry("NiSphericalCollider", &construct , RC_NiSphericalCollider )); - newFactory.insert(makeEntry("NiParticleGrowFade", &construct , RC_NiParticleGrowFade )); - newFactory.insert(makeEntry("NiParticleColorModifier", &construct , RC_NiParticleColorModifier )); - newFactory.insert(makeEntry("NiParticleRotation", &construct , RC_NiParticleRotation )); - newFactory.insert(makeEntry("NiFloatData", &construct , RC_NiFloatData )); - newFactory.insert(makeEntry("NiTriShapeData", &construct , RC_NiTriShapeData )); - newFactory.insert(makeEntry("NiTriStripsData", &construct , RC_NiTriStripsData )); - newFactory.insert(makeEntry("NiLinesData", &construct , RC_NiLinesData )); - newFactory.insert(makeEntry("NiVisData", &construct , RC_NiVisData )); - newFactory.insert(makeEntry("NiColorData", &construct , RC_NiColorData )); - newFactory.insert(makeEntry("NiPixelData", &construct , RC_NiPixelData )); - newFactory.insert(makeEntry("NiMorphData", &construct , RC_NiMorphData )); - newFactory.insert(makeEntry("NiKeyframeData", &construct , RC_NiKeyframeData )); - newFactory.insert(makeEntry("NiSkinData", &construct , RC_NiSkinData )); - newFactory.insert(makeEntry("NiUVData", &construct , RC_NiUVData )); - newFactory.insert(makeEntry("NiPosData", &construct , RC_NiPosData )); - newFactory.insert(makeEntry("NiRotatingParticlesData", &construct , RC_NiRotatingParticlesData )); - newFactory.insert(makeEntry("NiAutoNormalParticlesData", &construct , RC_NiAutoNormalParticlesData )); - newFactory.insert(makeEntry("NiSequenceStreamHelper", &construct , RC_NiSequenceStreamHelper )); - newFactory.insert(makeEntry("NiSourceTexture", &construct , RC_NiSourceTexture )); - newFactory.insert(makeEntry("NiSkinInstance", &construct , RC_NiSkinInstance )); - newFactory.insert(makeEntry("NiLookAtController", &construct , RC_NiLookAtController )); - newFactory.insert(makeEntry("NiPalette", &construct , RC_NiPalette )); - return newFactory; + std::map factory; + factory["NiNode"] = {&construct , RC_NiNode }; + factory["NiSwitchNode"] = {&construct , RC_NiSwitchNode }; + factory["NiLODNode"] = {&construct , RC_NiLODNode }; + factory["AvoidNode"] = {&construct , RC_AvoidNode }; + factory["NiCollisionSwitch"] = {&construct , RC_NiCollisionSwitch }; + factory["NiBSParticleNode"] = {&construct , RC_NiBSParticleNode }; + factory["NiBSAnimationNode"] = {&construct , RC_NiBSAnimationNode }; + factory["NiBillboardNode"] = {&construct , RC_NiBillboardNode }; + factory["NiTriShape"] = {&construct , RC_NiTriShape }; + factory["NiTriStrips"] = {&construct , RC_NiTriStrips }; + factory["NiLines"] = {&construct , RC_NiLines }; + factory["NiRotatingParticles"] = {&construct , RC_NiRotatingParticles }; + factory["NiAutoNormalParticles"] = {&construct , RC_NiAutoNormalParticles }; + factory["NiCamera"] = {&construct , RC_NiCamera }; + factory["RootCollisionNode"] = {&construct , RC_RootCollisionNode }; + factory["NiTexturingProperty"] = {&construct , RC_NiTexturingProperty }; + factory["NiFogProperty"] = {&construct , RC_NiFogProperty }; + factory["NiMaterialProperty"] = {&construct , RC_NiMaterialProperty }; + factory["NiZBufferProperty"] = {&construct , RC_NiZBufferProperty }; + factory["NiAlphaProperty"] = {&construct , RC_NiAlphaProperty }; + factory["NiVertexColorProperty"] = {&construct , RC_NiVertexColorProperty }; + factory["NiShadeProperty"] = {&construct , RC_NiShadeProperty }; + factory["NiDitherProperty"] = {&construct , RC_NiDitherProperty }; + factory["NiWireframeProperty"] = {&construct , RC_NiWireframeProperty }; + factory["NiSpecularProperty"] = {&construct , RC_NiSpecularProperty }; + factory["NiStencilProperty"] = {&construct , RC_NiStencilProperty }; + factory["NiVisController"] = {&construct , RC_NiVisController }; + factory["NiGeomMorpherController"] = {&construct , RC_NiGeomMorpherController }; + factory["NiKeyframeController"] = {&construct , RC_NiKeyframeController }; + factory["NiAlphaController"] = {&construct , RC_NiAlphaController }; + factory["NiRollController"] = {&construct , RC_NiRollController }; + factory["NiUVController"] = {&construct , RC_NiUVController }; + factory["NiPathController"] = {&construct , RC_NiPathController }; + factory["NiMaterialColorController"] = {&construct , RC_NiMaterialColorController }; + factory["NiBSPArrayController"] = {&construct , RC_NiBSPArrayController }; + factory["NiParticleSystemController"] = {&construct , RC_NiParticleSystemController }; + factory["NiFlipController"] = {&construct , RC_NiFlipController }; + factory["NiAmbientLight"] = {&construct , RC_NiLight }; + factory["NiDirectionalLight"] = {&construct , RC_NiLight }; + factory["NiPointLight"] = {&construct , RC_NiLight }; + factory["NiSpotLight"] = {&construct , RC_NiLight }; + factory["NiTextureEffect"] = {&construct , RC_NiTextureEffect }; + factory["NiVertWeightsExtraData"] = {&construct , RC_NiVertWeightsExtraData }; + factory["NiTextKeyExtraData"] = {&construct , RC_NiTextKeyExtraData }; + factory["NiStringExtraData"] = {&construct , RC_NiStringExtraData }; + factory["NiGravity"] = {&construct , RC_NiGravity }; + factory["NiPlanarCollider"] = {&construct , RC_NiPlanarCollider }; + factory["NiSphericalCollider"] = {&construct , RC_NiSphericalCollider }; + factory["NiParticleGrowFade"] = {&construct , RC_NiParticleGrowFade }; + factory["NiParticleColorModifier"] = {&construct , RC_NiParticleColorModifier }; + factory["NiParticleRotation"] = {&construct , RC_NiParticleRotation }; + factory["NiFloatData"] = {&construct , RC_NiFloatData }; + factory["NiTriShapeData"] = {&construct , RC_NiTriShapeData }; + factory["NiTriStripsData"] = {&construct , RC_NiTriStripsData }; + factory["NiLinesData"] = {&construct , RC_NiLinesData }; + factory["NiVisData"] = {&construct , RC_NiVisData }; + factory["NiColorData"] = {&construct , RC_NiColorData }; + factory["NiPixelData"] = {&construct , RC_NiPixelData }; + factory["NiMorphData"] = {&construct , RC_NiMorphData }; + factory["NiKeyframeData"] = {&construct , RC_NiKeyframeData }; + factory["NiSkinData"] = {&construct , RC_NiSkinData }; + factory["NiUVData"] = {&construct , RC_NiUVData }; + factory["NiPosData"] = {&construct , RC_NiPosData }; + factory["NiRotatingParticlesData"] = {&construct , RC_NiRotatingParticlesData }; + factory["NiAutoNormalParticlesData"] = {&construct , RC_NiAutoNormalParticlesData }; + factory["NiSequenceStreamHelper"] = {&construct , RC_NiSequenceStreamHelper }; + factory["NiSourceTexture"] = {&construct , RC_NiSourceTexture }; + factory["NiSkinInstance"] = {&construct , RC_NiSkinInstance }; + factory["NiLookAtController"] = {&construct , RC_NiLookAtController }; + factory["NiPalette"] = {&construct , RC_NiPalette }; + return factory; } @@ -149,7 +140,7 @@ void NIFFile::parse(Files::IStreamPtr stream) if(ver != NIFStream::generateVersion(4,0,0,0) && ver != VER_MW) fail("Unsupported NIF version: " + printVersion(ver)); // Number of records - size_t recNum = nif.getInt(); + size_t recNum = nif.getUInt(); records.resize(recNum); for(size_t i = 0;i < recNum;i++) @@ -201,8 +192,8 @@ void NIFFile::parse(Files::IStreamPtr stream) } // Once parsing is done, do post-processing. - for(size_t i=0; ipost(this); + for (Record* record : records) + record->post(this); } void NIFFile::setUseSkinning(bool skinning)