-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use C++17 for file system operations in order to support Windows
1 parent
1b30da6
commit fa51fee
Showing
18 changed files
with
185 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
|
||
#include <sstream> | ||
|
||
#include <unistd.h> | ||
#include <memory> | ||
#include <limits> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#include <sstream> | ||
#include <unistd.h> | ||
#include <memory> | ||
#include <limits> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef AMREX_FILE_SYSTEM_H_ | ||
#define AMREX_FILE_SYSTEM_H_ | ||
|
||
#include <string> | ||
|
||
namespace amrex { | ||
namespace FileSystem { | ||
|
||
std::string | ||
CurrentPath (); | ||
|
||
bool | ||
Exists (std::string const& filename); | ||
|
||
bool | ||
Remove (std::string const& filename); | ||
|
||
}} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include <AMReX_FileSystem.H> | ||
#include <AMReX_Print.H> | ||
#include <AMReX.H> | ||
|
||
#if defined(_WIN32) || __cplusplus >= 201703L | ||
|
||
#include <filesystem> | ||
#include <system_error> | ||
|
||
namespace amrex { | ||
namespace FileSystem { | ||
|
||
bool | ||
Exists (std::string const& filename) | ||
{ | ||
std::error_code ec; | ||
return std::filesystem::exists(std::filesystem::path{filename}); | ||
} | ||
|
||
std::string | ||
CurrentPath () | ||
{ | ||
std::error_code ec; | ||
auto path = std::filesystem::current_path(ec); | ||
if (ec) { | ||
amrex::AllPrint() << "amrex::FileSystem::CurrentPath failed. " << ec.message() << std::endl; | ||
} | ||
return path.string(); | ||
} | ||
|
||
bool | ||
Remove (std::string const& filename) | ||
{ | ||
std::error_code ec; | ||
bool r = std::filesystem::remove(std::filesystem::path(filename),ec); | ||
return (!ec and r); | ||
} | ||
|
||
}} | ||
|
||
#else | ||
|
||
#include <cstddef> | ||
#include <unistd.h> | ||
#include <sys/stat.h> | ||
|
||
namespace amrex { | ||
namespace FileSystem { | ||
|
||
bool | ||
Exists (std::string const& filename) | ||
{ | ||
struct stat statbuff; | ||
return(lstat(filename.c_str(), &statbuff) != -1); | ||
} | ||
|
||
std::string | ||
CurrentPath () | ||
{ | ||
constexpr int bufSize = 1024; | ||
char temp[bufSize]; | ||
char *rCheck = getcwd(temp, bufSize); | ||
if(rCheck == 0) { | ||
amrex::Abort("**** Error: getcwd buffer too small."); | ||
} | ||
return std::string(rCheck); | ||
} | ||
|
||
bool | ||
Remove (std::string const& filename) | ||
{ | ||
return unlink(filename.c_str()); | ||
} | ||
|
||
}} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.