Skip to content

Commit

Permalink
AURORA: Use ScopedPtr in the GFF classes
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Oct 26, 2016
1 parent a082419 commit d0ae588
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
7 changes: 3 additions & 4 deletions src/aurora/gff3file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ GFF3File::GFF3File(Common::SeekableReadStream *gff3, uint32 id, bool repairNWNPr
}

GFF3File::GFF3File(const Common::UString &gff3, FileType type, uint32 id, bool repairNWNPremium) :
_stream(0), _repairNWNPremium(repairNWNPremium), _offsetCorrection(0) {
_repairNWNPremium(repairNWNPremium), _offsetCorrection(0) {

_stream = ResMan.getResource(gff3, type);
_stream.reset(ResMan.getResource(gff3, type));
if (!_stream)
throw Common::Exception("No such GFF3 \"%s\"", TypeMan.setFileType(gff3, type).c_str());

Expand All @@ -84,8 +84,7 @@ GFF3File::~GFF3File() {
}

void GFF3File::clear() {
delete _stream;
_stream = 0;
_stream.reset();

for (StructArray::iterator strct = _structs.begin(); strct != _structs.end(); ++strct)
delete *strct;
Expand Down
3 changes: 2 additions & 1 deletion src/aurora/gff3file.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <boost/noncopyable.hpp>

#include "src/common/types.h"
#include "src/common/scopedptr.h"
#include "src/common/ustring.h"

#include "src/aurora/types.h"
Expand Down Expand Up @@ -114,7 +115,7 @@ class GFF3File : boost::noncopyable, public AuroraFile {
typedef std::vector<GFF3List> ListArray;


Common::SeekableReadStream *_stream;
Common::ScopedPtr<Common::SeekableReadStream> _stream;

Header _header; ///< The GFF3's header.

Expand Down
7 changes: 3 additions & 4 deletions src/aurora/gff4file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ GFF4File::GFF4File(Common::SeekableReadStream *gff4, uint32 type) :
}

GFF4File::GFF4File(const Common::UString &gff4, FileType fileType, uint32 type) :
_stream(0), _topLevelStruct(0) {
_topLevelStruct(0) {

_stream = ResMan.getResource(gff4, fileType);
_stream.reset(ResMan.getResource(gff4, fileType));
if (!_stream)
throw Common::Exception("No such GFF4 \"%s\"", TypeMan.setFileType(gff4, fileType).c_str());

Expand All @@ -84,8 +84,7 @@ GFF4File::~GFF4File() {
}

void GFF4File::clear() {
delete _stream;
_stream = 0;
_stream.reset();

for (StructMap::iterator s = _structs.begin(); s != _structs.end(); ++s)
delete s->second;
Expand Down
3 changes: 2 additions & 1 deletion src/aurora/gff4file.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <boost/noncopyable.hpp>

#include "src/common/types.h"
#include "src/common/scopedptr.h"
#include "src/common/ustring.h"
#include "src/common/encoding.h"

Expand Down Expand Up @@ -131,7 +132,7 @@ class GFF4File : boost::noncopyable, public AuroraFile {



Common::SeekableReadStream *_stream;
Common::ScopedPtr<Common::SeekableReadStream> _stream;

/** This GFF4's header. */
Header _header;
Expand Down
14 changes: 6 additions & 8 deletions src/aurora/ifofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,15 @@

namespace Aurora {

IFOFile::IFOFile() : _gff(0) {
IFOFile::IFOFile() {
clear();
}

IFOFile::~IFOFile() {
delete _gff;
}

void IFOFile::clear() {
delete _gff;
_gff = 0;
_gff.reset();

std::memset(_id, 0, sizeof(_id));

Expand Down Expand Up @@ -101,7 +99,7 @@ void IFOFile::unload() {
void IFOFile::load(bool repairNWNPremium) {
unload();

_gff = new GFF3File("module", kFileTypeIFO, MKTAG('I', 'F', 'O', ' '), repairNWNPremium);
_gff.reset(new GFF3File("module", kFileTypeIFO, MKTAG('I', 'F', 'O', ' '), repairNWNPremium));

const GFF3Struct &ifoTop = _gff->getTopLevel();

Expand All @@ -127,11 +125,11 @@ void IFOFile::load(bool repairNWNPremium) {
ifoTop.getLocString("Mod_Description", _description);

// ID
size_t idSize = _isSave ? 32 : 16;
Common::SeekableReadStream *id = ifoTop.getData("Mod_ID");
const size_t idSize = _isSave ? 32 : 16;
Common::ScopedPtr<Common::SeekableReadStream> id(ifoTop.getData("Mod_ID"));

if (id && (id->read(_id, idSize) != idSize))
throw Common::Exception("Can't read MOD ID");
delete id;

// TLK
_customTLK = ifoTop.getString("Mod_CustomTlk");
Expand Down
3 changes: 2 additions & 1 deletion src/aurora/ifofile.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <boost/noncopyable.hpp>

#include "src/common/types.h"
#include "src/common/scopedptr.h"
#include "src/common/ustring.h"

#include "src/aurora/locstring.h"
Expand Down Expand Up @@ -177,7 +178,7 @@ class IFOFile : boost::noncopyable {
// '---

private:
GFF3File *_gff; ///< The module.ifo GFF.
Common::ScopedPtr<GFF3File> _gff; ///< The module.ifo GFF.

byte _id[32]; ///< The module's unique ID.

Expand Down

0 comments on commit d0ae588

Please sign in to comment.