diff --git a/Core/InputOutput/OutputDataIOHelper.cpp b/Core/InputOutput/OutputDataIOHelper.cpp index 9103d28e7c1e3f5fbf04eba039c42d0802a3ee5a..b3651439b248253aa9a636580c9a6d178e9d4ebe 100644 --- a/Core/InputOutput/OutputDataIOHelper.cpp +++ b/Core/InputOutput/OutputDataIOHelper.cpp @@ -31,12 +31,12 @@ bool OutputDataIOHelper::isCompressed(const std::string& name) bool OutputDataIOHelper::isGZipped(const std::string& name) { - return Utils::FileSystem::GetFileExtension(name) == GzipExtention; + return FileSystem::GetFileExtension(name) == GzipExtention; } bool OutputDataIOHelper::isBZipped(const std::string& name) { - return Utils::FileSystem::GetFileExtension(name) == BzipExtention; + return FileSystem::GetFileExtension(name) == BzipExtention; } @@ -51,7 +51,7 @@ std::string OutputDataIOHelper::GetFileMainExtension(const std::string& name) else if(isBZipped(name)) { stripped_name = name.substr(0, name.size()-BzipExtention.size()); } - return Utils::FileSystem::GetFileExtension(stripped_name); + return FileSystem::GetFileExtension(stripped_name); } bool OutputDataIOHelper::isBinaryFile(const std::string& file_name) diff --git a/Core/Tools/FileSystem.cpp b/Core/Tools/FileSystem.cpp index 5c2cc7c8968fe843b004297f1be58e4e483bfc54..e6ec9abbbbd912a0da2371872d720b3a333a1274 100644 --- a/Core/Tools/FileSystem.cpp +++ b/Core/Tools/FileSystem.cpp @@ -21,34 +21,34 @@ //! Returns path to the current (working) directory. -std::string Utils::FileSystem::GetWorkingPath() +std::string FileSystem::GetWorkingPath() { return boost::filesystem::current_path().string(); } //! Returns path to BornAgain home directory. -std::string Utils::FileSystem::GetHomePath() +std::string FileSystem::GetHomePath() { throw Exceptions::NotImplementedException( - "Utils::FileSystem::GetHomePath()-> Not implemented anymore..."); + "FileSystem::GetHomePath()-> Not implemented anymore..."); } //! Returns file extension. -std::string Utils::FileSystem::GetFileExtension(const std::string& name) +std::string FileSystem::GetFileExtension(const std::string& name) { return boost::filesystem::extension(name.c_str()); } -bool Utils::FileSystem::CreateDirectory(const std::string &dir_name) +bool FileSystem::CreateDirectory(const std::string &dir_name) { assert(dir_name!=""); return boost::filesystem::create_directory(dir_name); } -std::string Utils::FileSystem::GetJoinPath(const std::string &spath1, const std::string &spath2) +std::string FileSystem::GetJoinPath(const std::string &spath1, const std::string &spath2) { assert(spath1!=""); assert(spath2!=""); @@ -60,7 +60,7 @@ std::string Utils::FileSystem::GetJoinPath(const std::string &spath1, const std: } //! Returns file names that agree with glob pattern. -std::vector<std::string> Utils::FileSystem::glob(const std::string& pattern) +std::vector<std::string> FileSystem::glob(const std::string& pattern) { glob_t glob_result; ::glob(pattern.c_str(), GLOB_TILDE, NULL, &glob_result); diff --git a/Core/Tools/FileSystem.h b/Core/Tools/FileSystem.h index f55693db97201743ad831d61d14cc1c981b1df08..7455f1882ce2d74fa04a95d91474c4656ad4e71e 100644 --- a/Core/Tools/FileSystem.h +++ b/Core/Tools/FileSystem.h @@ -22,34 +22,26 @@ //! Utilities to deal with file system. -namespace Utils { +namespace FileSystem { -//! @class FileSystem -//! @ingroup tools_internal -//! @brief Class collecting utilities to work with file system. - -class BA_CORE_API_ FileSystem -{ -public: //! Returns path to the current (working) directory - static std::string GetWorkingPath(); + std::string GetWorkingPath(); //! Returns path to BornAgain home directory - static std::string GetHomePath(); + std::string GetHomePath(); //! Returns file extension - static std::string GetFileExtension(const std::string& name); + std::string GetFileExtension(const std::string& name); //! creates directory in current directory - static bool CreateDirectory(const std::string& dir_name); + bool CreateDirectory(const std::string& dir_name); //! join paths together - static std::string GetJoinPath(const std::string& spath1, const std::string& spath2); + std::string GetJoinPath(const std::string& spath1, const std::string& spath2); //! Returns file names that agree with glob pattern. - static std::vector<std::string> glob(const std::string& pattern); -}; + std::vector<std::string> glob(const std::string& pattern); -} +} // namespace FileSystem #endif // FILESYSTEM_H diff --git a/Tests/Functional/Core/CoreTest.cpp b/Tests/Functional/Core/CoreTest.cpp index 84cd1327ae234568b85b2b3fa84b98ad46bd0623..00e988097d1738c4e5a1492ec1d00d0d2efbafac 100644 --- a/Tests/Functional/Core/CoreTest.cpp +++ b/Tests/Functional/Core/CoreTest.cpp @@ -36,7 +36,7 @@ CoreTest::~CoreTest() void CoreTest::runTest() { // Load reference if available - m_ref_filename = Utils::FileSystem::GetJoinPath(CORE_STD_REF_DIR, getName() + ".int.gz"); + m_ref_filename = FileSystem::GetJoinPath(CORE_STD_REF_DIR, getName() + ".int.gz"); try { m_reference = IntensityDataIOFactory::readOutputData( m_ref_filename ); } catch(const std::exception& ex) { @@ -56,8 +56,8 @@ void CoreTest::runTest() m_result = compareIntensityMaps(*result_data.get(), *m_reference); // Save simulation if different from reference. if (getTestResult() != SUCCESS) { - Utils::FileSystem::CreateDirectory(CORE_STD_OUT_DIR); - std::string out_fname = Utils::FileSystem::GetJoinPath( + FileSystem::CreateDirectory(CORE_STD_OUT_DIR); + std::string out_fname = FileSystem::GetJoinPath( CORE_STD_OUT_DIR, getName() + ".int"); IntensityDataIOFactory::writeOutputData(*result_data, out_fname); std::cout << "New simulation result stored in " << out_fname << ".\n" diff --git a/Tests/Functional/Core/PolDWBAMagCylinders2.cpp b/Tests/Functional/Core/PolDWBAMagCylinders2.cpp index 38df1f2afb0c63d101861a1e576867943e7c72d9..a98705846a821240c9e578408b8f1146e1f503dd 100644 --- a/Tests/Functional/Core/PolDWBAMagCylinders2.cpp +++ b/Tests/Functional/Core/PolDWBAMagCylinders2.cpp @@ -7,7 +7,7 @@ int main(int, char**) { - const std::string trunc = Utils::FileSystem::GetJoinPath(CORE_SPECIAL_REF_DIR, + const std::string trunc = FileSystem::GetJoinPath(CORE_SPECIAL_REF_DIR, "/polmagcylinders2_reference_"); const std::unique_ptr<OutputData<double> > P_reference00(IntensityDataIOFactory::readOutputData(trunc + "00.int.gz")); diff --git a/Tests/Functional/PyCore/export/PyExportTest.cpp b/Tests/Functional/PyCore/export/PyExportTest.cpp index bac71cac3cc0258657c44d5ded3d8bdfc361b4a7..cb6ad0959bb34ac21f0066d993c46d3cabaab1b6 100644 --- a/Tests/Functional/PyCore/export/PyExportTest.cpp +++ b/Tests/Functional/PyCore/export/PyExportTest.cpp @@ -45,7 +45,7 @@ PyExportTest::~PyExportTest() void PyExportTest::runTest() { // Generate Python script - std::string pyscript_filename = Utils::FileSystem::GetJoinPath(PYEXPORT_TMP_DIR, + std::string pyscript_filename = FileSystem::GetJoinPath(PYEXPORT_TMP_DIR, getName() + ".py"); std::ostringstream ostr; ostr << PythonFormatting::simulationToPython(m_reference_simulation); @@ -57,7 +57,7 @@ void PyExportTest::runTest() // the system calls 'remove' and 'system' may break the order of output lines. // Run Python script - std::string output_name = Utils::FileSystem::GetJoinPath(PYEXPORT_TMP_DIR, getName()); + std::string output_name = FileSystem::GetJoinPath(PYEXPORT_TMP_DIR, getName()); std::string output_path = output_name + ".ref.int"; std::remove( output_path.c_str() ); std::cout << "Removed old data set " << output_path << "." << std::endl/*sic*/; diff --git a/Tests/Functional/PyCore/persistence/PyPersistenceTest.cpp b/Tests/Functional/PyCore/persistence/PyPersistenceTest.cpp index c9567f6451ca3e50eb7262282a1bf314292313c5..b1099cf233dfa5cad01b2de71ec301e4be855030 100644 --- a/Tests/Functional/PyCore/persistence/PyPersistenceTest.cpp +++ b/Tests/Functional/PyCore/persistence/PyPersistenceTest.cpp @@ -37,14 +37,14 @@ PyPersistenceTest::PyPersistenceTest( void PyPersistenceTest::runTest() { // Set output data filename stem, and remove old output files - std::string dat_stem = Utils::FileSystem::GetJoinPath(PYPERSIST_OUT_DIR, getName()); - for (const std::string& fname: Utils::FileSystem::glob(dat_stem+".*.*")) { + std::string dat_stem = FileSystem::GetJoinPath(PYPERSIST_OUT_DIR, getName()); + for (const std::string& fname: FileSystem::glob(dat_stem+".*.*")) { std::remove( fname.c_str() ); std::cout << "Removed old output " << fname.c_str() << ".\n"; } // Run Python script - std::string py_filename = Utils::FileSystem::GetJoinPath(m_directory, getName() + ".py"); + std::string py_filename = FileSystem::GetJoinPath(m_directory, getName() + ".py"); std::string command = std::string("PYTHONPATH=") + BUILD_LIB_DIR + " " + BORNAGAIN_PYTHON_EXE + " " + py_filename + " " + dat_stem; @@ -59,7 +59,7 @@ void PyPersistenceTest::runTest() // Glob simulation results std::map<const std::string, const std::string> dat; std::string dat_pattern = dat_stem + ".*.*"; - for (const std::string& fname: Utils::FileSystem::glob(dat_pattern)) + for (const std::string& fname: FileSystem::glob(dat_pattern)) dat.insert(make_pair(Utils::String::split(fname,".")[1]+"."+ Utils::String::split(fname,".")[2], fname)); @@ -70,9 +70,9 @@ void PyPersistenceTest::runTest() } // Glob reference files - std::string ref_stem = Utils::FileSystem::GetJoinPath(PYPERSIST_REF_DIR, getName()); + std::string ref_stem = FileSystem::GetJoinPath(PYPERSIST_REF_DIR, getName()); std::map<const std::string, const std::string> ref; - for (const std::string& fname: Utils::FileSystem::glob(ref_stem+".*.*")) + for (const std::string& fname: FileSystem::glob(ref_stem+".*.*")) ref.insert(make_pair(Utils::String::split(fname,".")[1]+"."+ Utils::String::split(fname,".")[2], fname));