Skip to content

Commit

Permalink
AURORA: Replace PtrVector with std::vector<std::unique_ptr<>>
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Aug 24, 2020
1 parent 5066545 commit b6928b0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
20 changes: 10 additions & 10 deletions src/aurora/2dafile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#include <cassert>

#include <memory>
#include <utility>

#include "src/common/util.h"
#include "src/common/error.h"
Expand Down Expand Up @@ -252,7 +252,7 @@ void TwoDAFile::readRows2a(Common::SeekableReadStream &twoda,
if (count == 0)
continue;

_rows.push_back(row.release());
_rows.emplace_back(std::move(row));
}
}

Expand Down Expand Up @@ -281,7 +281,7 @@ void TwoDAFile::skipRowNames2b(Common::SeekableReadStream &twoda) {
*/

const uint32_t rowCount = twoda.readUint32LE();
_rows.resize(rowCount, 0);
_rows.resize(rowCount);

Common::StreamTokenizer tokenize(Common::StreamTokenizer::kRuleHeed);

Expand Down Expand Up @@ -318,7 +318,7 @@ void TwoDAFile::readRows2b(Common::SeekableReadStream &twoda) {
const size_t dataOffset = twoda.pos();

for (size_t i = 0; i < rowCount; i++) {
_rows[i] = new TwoDARow(*this);
_rows[i].reset(new TwoDARow(*this));

_rows[i]->_data.resize(columnCount);

Expand Down Expand Up @@ -352,11 +352,11 @@ void TwoDAFile::load(const GDAFile &gda) {
_headers[i] = headerString ? headerString : Common::UString::format("[%u]", headers[i].hash);
}

_rows.resize(gda.getRowCount(), 0);
_rows.resize(gda.getRowCount());
for (size_t i = 0; i < gda.getRowCount(); i++) {
const GFF4Struct *row = gda.getRow(i);

_rows[i] = new TwoDARow(*this);
_rows[i].reset(new TwoDARow(*this));
_rows[i]->_data.resize(gda.getColumnCount());

for (size_t j = 0; j < gda.getColumnCount(); j++) {
Expand Down Expand Up @@ -424,17 +424,17 @@ const TwoDARow &TwoDAFile::getRow(size_t row) const {
// No such row
return _emptyRow;

return *_rows[row];
return *_rows[row].get();
}

const TwoDARow &TwoDAFile::getRow(const Common::UString &header, const Common::UString &value) const {
size_t columnIndex = headerToColumn(header);
if (columnIndex == kFieldIDInvalid)
return _emptyRow;

for (std::vector<TwoDARow *>::const_iterator row = _rows.begin(); row != _rows.end(); ++row) {
if ((*row)->getString(columnIndex).equalsIgnoreCase(value))
return **row;
for (const auto &row : _rows) {
if (row->getString(columnIndex).equalsIgnoreCase(value))
return *row.get();
}

// No such row
Expand Down
8 changes: 2 additions & 6 deletions src/aurora/2dafile.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@
#ifndef AURORA_2DAFILE_H
#define AURORA_2DAFILE_H

#include <memory>
#include <vector>
#include <map>

#include <boost/noncopyable.hpp>

#include "src/common/types.h"
#include "src/common/deallocator.h"
#include "src/common/ptrvector.h"
#include "src/common/ustring.h"

#include "src/aurora/aurorafile.h"
Expand Down Expand Up @@ -93,9 +92,6 @@ class TwoDARow : boost::noncopyable {
const Common::UString &getCell(size_t n) const;

friend class TwoDAFile;

template<typename T>
friend void Common::DeallocatorDefault::destroy(T *);
};

/** Class to hold the two-dimensional array of a 2DA file.
Expand Down Expand Up @@ -175,7 +171,7 @@ class TwoDAFile : boost::noncopyable, public AuroraFile {
HeaderMap _headerMap;

TwoDARow _emptyRow;
Common::PtrVector<TwoDARow> _rows;
std::vector<std::unique_ptr<TwoDARow>> _rows;

// Loading helpers
void load(Common::SeekableReadStream &twoda);
Expand Down
4 changes: 2 additions & 2 deletions src/aurora/gdafile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ GDAFile::Type GDAFile::identifyType(const Columns &columns, const Row &rows, siz

void GDAFile::load(Common::SeekableReadStream *gda) {
try {
_gff4s.push_back(new GFF4File(gda, kG2DAID));
_gff4s.emplace_back(std::make_unique<GFF4File>(gda, kG2DAID));

const uint32_t version = _gff4s.back()->getTypeVersion();
if ((version != kVersion01) && (version != kVersion02))
Expand Down Expand Up @@ -306,7 +306,7 @@ void GDAFile::load(Common::SeekableReadStream *gda) {

void GDAFile::add(Common::SeekableReadStream *gda) {
try {
_gff4s.push_back(new GFF4File(gda, kG2DAID));
_gff4s.emplace_back(std::make_unique<GFF4File>(gda, kG2DAID));

const uint32_t version = _gff4s.back()->getTypeVersion();
if ((version != kVersion01) && (version != kVersion02))
Expand Down
4 changes: 2 additions & 2 deletions src/aurora/gdafile.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
#ifndef AURORA_GDAFILE_H
#define AURORA_GDAFILE_H

#include <memory>
#include <vector>
#include <map>

#include <boost/noncopyable.hpp>

#include "src/common/ustring.h"
#include "src/common/ptrvector.h"

#include "src/aurora/types.h"

Expand Down Expand Up @@ -133,7 +133,7 @@ class GDAFile : boost::noncopyable {


private:
typedef Common::PtrVector<GFF4File> GFF4s;
typedef std::vector<std::unique_ptr<GFF4File>> GFF4s;
typedef const GFF4List * Columns;
typedef const GFF4List * Row;
typedef std::vector<Row> Rows;
Expand Down

0 comments on commit b6928b0

Please sign in to comment.