#include "gromacs/options/options.h"
#include "gromacs/utility/arrayref.h"
#include "gromacs/utility/exceptions.h"
-#include "gromacs/utility/file.h"
+#include "gromacs/utility/fileredirector.h"
#include "gromacs/utility/path.h"
#include "gromacs/utility/stringutil.h"
* The first match is returned.
* Returns an empty string if no existing file is found.
*/
-std::string findExistingExtension(const std::string &prefix,
- const FileNameOptionInfo &option)
+std::string findExistingExtension(const std::string &prefix,
+ const FileNameOptionInfo &option,
+ const IFileInputRedirector *redirector)
{
ConstArrayRef<int> types = option.fileTypes();
ConstArrayRef<int>::const_iterator i;
for (i = types.begin(); i != types.end(); ++i)
{
std::string testFilename(prefix + ftp2ext_with_dot(*i));
- if (File::exists(testFilename))
+ if (redirector->fileExists(testFilename))
{
return testFilename;
}
class FileNameOptionManager::Impl
{
public:
- Impl() : bInputCheckingDisabled_(false) {}
+ Impl()
+ : redirector_(&defaultFileInputRedirector()),
+ bInputCheckingDisabled_(false)
+ {
+ }
+ //! Redirector for file existence checks.
+ const IFileInputRedirector *redirector_;
//! Global default file name, if set.
- std::string defaultFileName_;
+ std::string defaultFileName_;
//! Whether input option processing has been disabled.
- bool bInputCheckingDisabled_;
+ bool bInputCheckingDisabled_;
};
/********************************************************************
{
}
+void FileNameOptionManager::setInputRedirector(
+ const IFileInputRedirector *redirector)
+{
+ impl_->redirector_ = redirector;
+}
+
void FileNameOptionManager::disableInputOptionChecking(bool bDisable)
{
impl_->bInputCheckingDisabled_ = bDisable;
const int fileType = fn2ftp(value.c_str());
if (bInput && !impl_->bInputCheckingDisabled_)
{
- if (fileType == efNR && File::exists(value))
+ if (fileType == efNR && impl_->redirector_->fileExists(value))
{
ConstArrayRef<const char *> compressedExtensions(c_compressedExtensions);
ConstArrayRef<const char *>::const_iterator ext;
}
else if (fileType == efNR)
{
- std::string processedValue = findExistingExtension(value, option);
+ const std::string processedValue
+ = findExistingExtension(value, option, impl_->redirector_);
if (!processedValue.empty())
{
return processedValue;
{
// TODO: Treat also library files.
}
- else if (!bAllowMissing && !File::exists(value))
+ else if (!bAllowMissing && !impl_->redirector_->fileExists(value))
{
std::string message
= formatString("File '%s' does not exist or is not accessible.",
const bool bAllowMissing = option.allowMissing();
if (bInput)
{
- std::string completedName = findExistingExtension(realPrefix, option);
+ const std::string completedName
+ = findExistingExtension(realPrefix, option, impl_->redirector_);
if (!completedName.empty())
{
return completedName;