Use std::unique_ptr in ObjFileParser

pull/1666/head
Alexandre Avenel 2017-12-30 13:22:30 +01:00
parent 606fd6b1a1
commit ced6e8ce43
2 changed files with 7 additions and 10 deletions

View File

@ -60,7 +60,7 @@ const std::string ObjFileParser::DEFAULT_MATERIAL = AI_DEFAULT_MATERIAL_NAME;
ObjFileParser::ObjFileParser() ObjFileParser::ObjFileParser()
: m_DataIt() : m_DataIt()
, m_DataItEnd() , m_DataItEnd()
, m_pModel( NULL ) , m_pModel( nullptr )
, m_uiLine( 0 ) , m_uiLine( 0 )
, m_pIO( nullptr ) , m_pIO( nullptr )
, m_progress( nullptr ) , m_progress( nullptr )
@ -73,7 +73,7 @@ ObjFileParser::ObjFileParser( IOStreamBuffer<char> &streamBuffer, const std::str
const std::string &originalObjFileName) : const std::string &originalObjFileName) :
m_DataIt(), m_DataIt(),
m_DataItEnd(), m_DataItEnd(),
m_pModel(NULL), m_pModel(nullptr),
m_uiLine(0), m_uiLine(0),
m_pIO( io ), m_pIO( io ),
m_progress(progress), m_progress(progress),
@ -82,7 +82,7 @@ ObjFileParser::ObjFileParser( IOStreamBuffer<char> &streamBuffer, const std::str
std::fill_n(m_buffer,Buffersize,0); std::fill_n(m_buffer,Buffersize,0);
// Create the model instance to store all the data // Create the model instance to store all the data
m_pModel = new ObjFile::Model(); m_pModel.reset(new ObjFile::Model());
m_pModel->m_ModelName = modelName; m_pModel->m_ModelName = modelName;
// create default material and store it // create default material and store it
@ -96,8 +96,6 @@ ObjFileParser::ObjFileParser( IOStreamBuffer<char> &streamBuffer, const std::str
} }
ObjFileParser::~ObjFileParser() { ObjFileParser::~ObjFileParser() {
delete m_pModel;
m_pModel = NULL;
} }
void ObjFileParser::setBuffer( std::vector<char> &buffer ) { void ObjFileParser::setBuffer( std::vector<char> &buffer ) {
@ -106,7 +104,7 @@ void ObjFileParser::setBuffer( std::vector<char> &buffer ) {
} }
ObjFile::Model *ObjFileParser::GetModel() const { ObjFile::Model *ObjFileParser::GetModel() const {
return m_pModel; return m_pModel.get();
} }
void ObjFileParser::parseFile( IOStreamBuffer<char> &streamBuffer ) { void ObjFileParser::parseFile( IOStreamBuffer<char> &streamBuffer ) {
@ -479,8 +477,6 @@ void ObjFileParser::getFace( aiPrimitiveType type ) {
} else { } else {
//On error, std::atoi will return 0 which is not a valid value //On error, std::atoi will return 0 which is not a valid value
delete face; delete face;
delete m_pModel;
m_pModel = nullptr;
throw DeadlyImportError("OBJ: Invalid face indice"); throw DeadlyImportError("OBJ: Invalid face indice");
} }
@ -642,7 +638,7 @@ void ObjFileParser::getMaterialLib() {
m_pIO->Close( pFile ); m_pIO->Close( pFile );
// Importing the material library // Importing the material library
ObjFileMtlImporter mtlImporter( buffer, strMatName, m_pModel ); ObjFileMtlImporter mtlImporter( buffer, strMatName, m_pModel.get() );
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------

View File

@ -44,6 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <vector> #include <vector>
#include <string> #include <string>
#include <map> #include <map>
#include <memory>
#include <assimp/vector2.h> #include <assimp/vector2.h>
#include <assimp/vector3.h> #include <assimp/vector3.h>
#include <assimp/mesh.h> #include <assimp/mesh.h>
@ -145,7 +146,7 @@ private:
//! Iterator to end position of buffer //! Iterator to end position of buffer
DataArrayIt m_DataItEnd; DataArrayIt m_DataItEnd;
//! Pointer to model instance //! Pointer to model instance
ObjFile::Model *m_pModel; std::unique_ptr<ObjFile::Model> m_pModel;
//! Current line (for debugging) //! Current line (for debugging)
unsigned int m_uiLine; unsigned int m_uiLine;
//! Helper buffer //! Helper buffer