Skip to content
Snippets Groups Projects
Commit 508eab36 authored by Alexis Girault's avatar Alexis Girault
Browse files

ENH: Implement fileExists in reader

Check if file exists in imstkMeshReader.
parent e8e8b047
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,8 @@
#include "imstkMeshReader.h"
#include <sys/stat.h>
#include "imstkVTKMeshReader.h"
#include "imstkVegaMeshReader.h"
......@@ -30,12 +32,13 @@ namespace imstk {
std::shared_ptr<Mesh>
MeshReader::read(const std::string& filePath)
{
FileType meshType = MeshReader::getFileType(filePath);
if (meshType == FileType::UNKNOWN)
if (!MeshReader::fileExists(filePath))
{
LOG(WARNING) << "MeshReader::read error: file not found: " << filePath;
return nullptr;
}
FileType meshType = MeshReader::getFileType(filePath);
switch (meshType)
{
case FileType::VTK :
......@@ -55,6 +58,13 @@ MeshReader::read(const std::string& filePath)
return nullptr;
}
bool
MeshReader::fileExists(const std::string& file)
{
struct stat buf;
return (stat(file.c_str(), &buf) == 0);
}
const MeshReader::FileType
MeshReader::getFileType(const std::string& filePath)
{
......
......@@ -55,10 +55,15 @@ public:
~MeshReader() = default;
///
/// \brief
/// \brief read
///
static std::shared_ptr<Mesh> read(const std::string& filePath);
///
/// \brief fileExists
///
static bool fileExists(const std::string& file);
protected:
static const FileType getFileType(const std::string& filePath);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment