Skip to content

Commit

Permalink
Switching from regular pointer to unique pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
rinkk authored and TomFischer committed Jul 11, 2019
1 parent e1462ac commit 0e3aaeb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
5 changes: 2 additions & 3 deletions Applications/DataExplorer/mainwindow.cpp
Expand Up @@ -616,12 +616,11 @@ void MainWindow::loadFile(ImportFileType::type t, const QString &fileName)
{
std::string file_name(fileName.toStdString());
FileIO::Gocad::GocadTSurfaceReader gcts;
std::vector<MeshLib::Mesh*> meshes;
std::vector<std::unique_ptr<MeshLib::Mesh>> meshes;
if (gcts.readFile(file_name, meshes))
{
for (MeshLib::Mesh* m : meshes)
for (auto& mesh : meshes)
{
std::unique_ptr<MeshLib::Mesh> mesh(m);
if (mesh != nullptr)
_meshModel->addMesh(std::move(mesh));
}
Expand Down
9 changes: 5 additions & 4 deletions Applications/FileIO/GocadIO/GocadTSurfaceReader.cpp
Expand Up @@ -32,7 +32,8 @@ GocadTSurfaceReader::GocadTSurfaceReader()
}

bool GocadTSurfaceReader::readFile(
std::string const& file_name, std::vector<MeshLib::Mesh*>& meshes)
std::string const& file_name,
std::vector<std::unique_ptr<MeshLib::Mesh>>& meshes)
{
std::ifstream in(file_name.c_str());
if (!in.is_open())
Expand All @@ -46,13 +47,13 @@ bool GocadTSurfaceReader::readFile(
{
std::string mesh_name = BaseLib::dropFileExtension(file_name) +
std::to_string(meshes.size() + 1);
MeshLib::Mesh* mesh = readMesh(in, mesh_name);
std::unique_ptr<MeshLib::Mesh> mesh(readMesh(in, mesh_name));
if (mesh == nullptr)
{
ERR("File parsing aborted...")
return false;
}
meshes.push_back(mesh);
meshes.push_back(std::move(mesh));
}
return true;
}
Expand Down Expand Up @@ -125,7 +126,7 @@ MeshLib::Mesh* GocadTSurfaceReader::readMesh(std::ifstream& in,
}
}
ERR("%s", eof_error.c_str());
return false;
return nullptr;
}

bool GocadTSurfaceReader::TSurfaceFound(std::ifstream& in) const
Expand Down
2 changes: 1 addition & 1 deletion Applications/FileIO/GocadIO/GocadTSurfaceReader.h
Expand Up @@ -41,7 +41,7 @@ class GocadTSurfaceReader final
GocadTSurfaceReader& operator=(GocadTSurfaceReader const& rhs) = delete;

/// Reads the specified file and writes data into internal mesh vector
bool readFile(std::string const& file_name, std::vector<MeshLib::Mesh*>& meshes);
bool readFile(std::string const& file_name, std::vector<std::unique_ptr<MeshLib::Mesh>>& meshes);

private:
/// Reads one mesh contained in the file (there may be more than one!)
Expand Down
7 changes: 4 additions & 3 deletions Applications/Utils/FileConverter/GocadTSurfaceReader.cpp
Expand Up @@ -55,20 +55,21 @@ int main(int argc, char* argv[])

std::string const file_name (input_arg.getValue());
FileIO::Gocad::GocadTSurfaceReader gcts;
std::vector<MeshLib::Mesh*> meshes;
std::vector<std::unique_ptr<MeshLib::Mesh>> meshes;
if (!gcts.readFile(file_name, meshes))
{
ERR("Error reading file.");
return 1;
}
std::string const dir = output_arg.getValue();
bool const write_binary = write_binary_arg.getValue();
std::string const delim = getDelim(dir);
for (MeshLib::Mesh* mesh : meshes)
for (auto& mesh : meshes)
{
INFO("Writing mesh \"%s\"", mesh->getName().c_str());
int data_mode = (write_binary) ? 2 : 0;
bool compressed = (write_binary) ? true : false;
MeshLib::IO::VtuInterface vtu(mesh, data_mode, compressed);
MeshLib::IO::VtuInterface vtu(mesh.get(), data_mode, compressed);
vtu.writeToFile(dir + delim + mesh->getName() + ".vtu");
}
return 0;
Expand Down

0 comments on commit 0e3aaeb

Please sign in to comment.