Skip to content

Commit 96170df

Browse files
Change boost::filesystem to std::filesystem
Refs #37868
1 parent d3762a4 commit 96170df

34 files changed

+164
-179
lines changed

Framework/API/test/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ if(CXXTEST_FOUND)
1919
Mantid::Nexus
2020
Mantid::NexusGeometry
2121
${BCRYPT}
22-
Boost::filesystem
2322
gmock
2423
Python::Python
2524
)

Framework/Algorithms/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ set_property(TARGET Algorithms PROPERTY FOLDER "MantidFramework")
10831083
target_link_libraries(
10841084
Algorithms
10851085
PUBLIC Mantid::API Mantid::HistogramData Mantid::Kernel Mantid::Geometry Mantid::Indexing
1086-
PRIVATE Mantid::DataObjects Mantid::Parallel Mantid::Types Boost::filesystem
1086+
PRIVATE Mantid::DataObjects Mantid::Parallel Mantid::Types
10871087
)
10881088

10891089
# Add the unit tests directory

Framework/Algorithms/src/CorelliCalibrationDatabase.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626

2727
#include <boost/algorithm/string/classification.hpp>
2828
#include <boost/algorithm/string/split.hpp>
29-
#include <boost/filesystem.hpp>
30-
#include <boost/filesystem/operations.hpp>
29+
#include <filesystem>
3130
#include <sstream>
3231
#include <string>
3332

@@ -280,7 +279,7 @@ TableWorkspace_sptr CalibrationTableHandler::saveCompomentDatabase(const std::st
280279
// Load the database file for the specific component to a table workspace
281280
// if extant, otherwise instantiate an empty table
282281
TableWorkspace_sptr compcaltable = nullptr;
283-
if (boost::filesystem::exists(filename)) {
282+
if (std::filesystem::exists(filename)) {
284283
compcaltable = loadComponentCalibrationTable(filename, tablewsname);
285284
} else {
286285
compcaltable = createCalibrationTableWorkspace(tablewsname, true);
@@ -646,7 +645,7 @@ bool CorelliCalibrationDatabase::isFileExist(const std::string &filepath) {
646645

647646
// TODO - replace by std::filesystem::exists(filename) until C++17 is properly
648647
// supported
649-
return boost::filesystem::exists(filepath);
648+
return std::filesystem::exists(filepath);
650649
}
651650

652651
//-----------------------------------------------------------------------------
@@ -657,9 +656,9 @@ bool CorelliCalibrationDatabase::isFileExist(const std::string &filepath) {
657656
* @return
658657
*/
659658
std::string CorelliCalibrationDatabase::joinPath(const std::string &directory, const std::string &basename) {
660-
boost::filesystem::path dir(directory);
661-
boost::filesystem::path file(basename);
662-
boost::filesystem::path fullpath = dir / file;
659+
std::filesystem::path dir(directory);
660+
std::filesystem::path file(basename);
661+
std::filesystem::path fullpath = dir / file;
663662

664663
return fullpath.string();
665664
}

Framework/Algorithms/test/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ if(CXXTEST_FOUND)
4242
Mantid::DataObjects
4343
Mantid::Kernel
4444
Boost::boost
45-
Boost::filesystem
4645
${BCRYPT}
4746
gmock
4847
)

Framework/Algorithms/test/CorelliCalibrationDatabaseTest.h

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "MantidDataObjects/EventWorkspace.h"
1919
#include "MantidKernel/DateAndTime.h"
2020
#include "MantidKernel/TimeSeriesProperty.h"
21-
#include <boost/filesystem.hpp>
21+
#include <filesystem>
2222
#include <fstream>
2323

2424
using Mantid::Algorithms::CorelliCalibrationDatabase;
@@ -50,11 +50,11 @@ class CorelliCalibrationDatabaseTest : public CxxTest::TestSuite {
5050
void test_file_io() {
5151
// create directory
5252
std::string test_dir{"TestCorelliCalibrationX"};
53-
boost::filesystem::create_directory(test_dir);
54-
TS_ASSERT(boost::filesystem::is_directory(test_dir));
53+
std::filesystem::create_directory(test_dir);
54+
TS_ASSERT(std::filesystem::is_directory(test_dir));
5555

5656
// clean
57-
boost::filesystem::remove_all(test_dir);
57+
std::filesystem::remove_all(test_dir);
5858
}
5959

6060
//-----------------------------------------------------------------------------
@@ -125,20 +125,20 @@ class CorelliCalibrationDatabaseTest : public CxxTest::TestSuite {
125125
// component file: name, remove file if it does exist, save and check file
126126
// existence
127127
const std::string testcalibtablefilename{"/tmp/testsourcedb2.csv"};
128-
boost::filesystem::remove(testcalibtablefilename);
128+
std::filesystem::remove(testcalibtablefilename);
129129
calib_handler.saveCalibrationTable(testcalibtablefilename);
130-
TS_ASSERT(boost::filesystem::exists(testcalibtablefilename));
130+
TS_ASSERT(std::filesystem::exists(testcalibtablefilename));
131131
// load file and check
132132
TableWorkspace_sptr duptable = loadCSVtoTable(testcalibtablefilename, "DuplicatedSource");
133133
TS_ASSERT_EQUALS(duptable->rowCount(), 3);
134134
TS_ASSERT_DELTA(duptable->cell<double>(2, 6), 0.3424, 0.00001);
135135

136136
// Test: save single component file
137137
const std::string testsamplecalfilename{"/tmp/testsampledb2.csv"};
138-
boost::filesystem::remove(testsamplecalfilename);
138+
std::filesystem::remove(testsamplecalfilename);
139139
// save
140140
calib_handler.saveCompomentDatabase("20201117", "sample-position", testsamplecalfilename);
141-
TS_ASSERT(boost::filesystem::exists(testsamplecalfilename));
141+
TS_ASSERT(std::filesystem::exists(testsamplecalfilename));
142142

143143
// load
144144
TableWorkspace_sptr dupsampletable =
@@ -162,9 +162,9 @@ class CorelliCalibrationDatabaseTest : public CxxTest::TestSuite {
162162
// create directory database
163163
std::string calibdir{"/tmp/TestCorelliCalibration1117"};
164164
// clean previous
165-
boost::filesystem::remove_all(calibdir);
165+
std::filesystem::remove_all(calibdir);
166166
// create data base
167-
boost::filesystem::create_directory(calibdir);
167+
std::filesystem::create_directory(calibdir);
168168
// create a previously generated database file
169169
// will create the following files:
170170
// moderator.csv, sample-position.csv, bank2.csv, bank42.csv
@@ -206,11 +206,11 @@ class CorelliCalibrationDatabaseTest : public CxxTest::TestSuite {
206206
TS_ASSERT_EQUALS(combinedcalibws->cell<std::string>(4, 0), "bank42/sixteenpack");
207207

208208
// Output 2: search the saved output calibration file
209-
boost::filesystem::path pdir(calibdir);
210-
boost::filesystem::path pbase("corelli_instrument_20201117.csv");
211-
boost::filesystem::path ptodaycalfile = pdir / pbase;
209+
std::filesystem::path pdir(calibdir);
210+
std::filesystem::path pbase("corelli_instrument_20201117.csv");
211+
std::filesystem::path ptodaycalfile = pdir / pbase;
212212
std::string todaycalfile = ptodaycalfile.string();
213-
TS_ASSERT(boost::filesystem::exists(todaycalfile));
213+
TS_ASSERT(std::filesystem::exists(todaycalfile));
214214
// load and compare
215215
// ... ...
216216

@@ -341,13 +341,13 @@ class CorelliCalibrationDatabaseTest : public CxxTest::TestSuite {
341341
*/
342342
void create_existing_database_files(const std::string &calibdir, std::vector<std::string> &banks) {
343343

344-
boost::filesystem::path dir(calibdir);
344+
std::filesystem::path dir(calibdir);
345345

346346
for (auto bankname : banks) {
347347
// create full path database name
348348
std::string basename = bankname + ".csv";
349-
boost::filesystem::path basepath(basename);
350-
boost::filesystem::path fullpath = dir / basename;
349+
std::filesystem::path basepath(basename);
350+
std::filesystem::path fullpath = dir / basename;
351351
std::string filename = fullpath.string();
352352
// write file
353353
std::ofstream bankofs(filename, std::ofstream::out);
@@ -369,13 +369,13 @@ class CorelliCalibrationDatabaseTest : public CxxTest::TestSuite {
369369
void verify_component_files(const std::string &calfiledir, const std::string &component,
370370
size_t expectedrecordsnumber) {
371371
// Create full file path
372-
boost::filesystem::path pdir(calfiledir);
373-
boost::filesystem::path pbase(component + ".csv");
374-
boost::filesystem::path pcompcalfile = pdir / pbase;
372+
std::filesystem::path pdir(calfiledir);
373+
std::filesystem::path pbase(component + ".csv");
374+
std::filesystem::path pcompcalfile = pdir / pbase;
375375
std::string compcalfile = pcompcalfile.string();
376376

377377
// Assert file existence
378-
TS_ASSERT(boost::filesystem::exists(compcalfile));
378+
TS_ASSERT(std::filesystem::exists(compcalfile));
379379

380380
// Load table
381381
TableWorkspace_sptr tablews = loadCSVtoTable(compcalfile, "CorelliVerify_" + component);

Framework/Crystal/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ include_directories(inc)
261261
target_link_libraries(
262262
Crystal
263263
PUBLIC Mantid::API Mantid::Geometry Mantid::Kernel
264-
PRIVATE Mantid::DataObjects Mantid::Indexing Boost::filesystem
264+
PRIVATE Mantid::DataObjects Mantid::Indexing
265265
)
266266

267267
# Add the unit tests directory

Framework/Crystal/src/SCDCalibratePanels2.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
#include <boost/property_tree/ptree.hpp>
2929
#include <boost/property_tree/xml_parser.hpp>
3030

31-
#include <boost/filesystem.hpp>
3231
#include <boost/math/special_functions/round.hpp>
3332
#include <cmath>
33+
#include <filesystem>
3434
#include <fstream>
3535
#include <iostream>
3636
#include <sstream>
@@ -1435,7 +1435,7 @@ void SCDCalibratePanels2::profileL1(Mantid::API::IPeaksWorkspace_sptr &pws,
14351435
}
14361436
}
14371437

1438-
double xValues[7] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; // xValues is not used
1438+
const double xValues[7] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; // xValues is not used
14391439

14401440
// scan from -4cm to 4cm along dL1 where the minimum is supposed to be at 0 for null
14411441
// case with instrument at the engineering position
@@ -1464,8 +1464,7 @@ void SCDCalibratePanels2::profileL1(Mantid::API::IPeaksWorkspace_sptr &pws,
14641464
}
14651465

14661466
// output to file
1467-
auto filenamebase = boost::filesystem::temp_directory_path();
1468-
filenamebase /= boost::filesystem::unique_path("profileSCDCalibratePanels2_L1.csv");
1467+
auto filenamebase = std::filesystem::temp_directory_path() / "profileSCDCalibratePanels2_L1.csv";
14691468
std::ofstream profL1File;
14701469
profL1File.open(filenamebase.string());
14711470
profL1File << msgrst.str();
@@ -1538,8 +1537,8 @@ void SCDCalibratePanels2::profileBanks(Mantid::API::IPeaksWorkspace_sptr &pws,
15381537
target[i * 3 + j] = qv[j];
15391538
}
15401539
}
1541-
//
1542-
double xValues[7] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; // xValues is not used
1540+
1541+
const double xValues[7] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; // xValues is not used
15431542

15441543
// NOTE: very expensive scan of the parameter space
15451544
for (double dx = -1e-2; dx < 1e-2; dx += 2e-2 / 20.0) {
@@ -1585,9 +1584,8 @@ void SCDCalibratePanels2::profileBanks(Mantid::API::IPeaksWorkspace_sptr &pws,
15851584
}
15861585

15871586
// output to file
1588-
auto filenamebase = boost::filesystem::temp_directory_path();
1589-
std::string fnbase = "profileSCDCalibratePanels2_" + bankname + ".csv";
1590-
filenamebase /= boost::filesystem::unique_path(fnbase);
1587+
const std::string csvname = "profileSCDCalibratePanels2_" + bankname + ".csv";
1588+
auto filenamebase = std::filesystem::temp_directory_path() / csvname;
15911589
std::ofstream profBankFile;
15921590
profBankFile.open(filenamebase.string());
15931591
profBankFile << msgrst.str();
@@ -1644,7 +1642,7 @@ void SCDCalibratePanels2::profileT0(Mantid::API::IPeaksWorkspace_sptr &pws,
16441642
}
16451643
}
16461644

1647-
double xValues[7] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; // xValues is not used
1645+
const double xValues[7] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; // xValues is not used
16481646

16491647
// scan from -10 ~ 10 ms along dT0
16501648
double deltaT0 = -10;
@@ -1671,8 +1669,7 @@ void SCDCalibratePanels2::profileT0(Mantid::API::IPeaksWorkspace_sptr &pws,
16711669
}
16721670

16731671
// output to file
1674-
auto filenamebase = boost::filesystem::temp_directory_path();
1675-
filenamebase /= boost::filesystem::unique_path("profileSCDCalibratePanels2_T0.csv");
1672+
auto filenamebase = std::filesystem::temp_directory_path() / "profileSCDCalibratePanels2_T0.csv";
16761673
std::ofstream profL1File;
16771674
profL1File.open(filenamebase.string());
16781675
profL1File << msgrst.str();
@@ -1722,7 +1719,7 @@ void SCDCalibratePanels2::profileL1T0(Mantid::API::IPeaksWorkspace_sptr &pws,
17221719
}
17231720
}
17241721

1725-
double xValues[7] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; // xValues is not used
1722+
const double xValues[7] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; // xValues is not used
17261723

17271724
// profile begin
17281725
for (double deltaL1 = -4e-2; deltaL1 < 4e-2; deltaL1 += 1e-4) {
@@ -1748,8 +1745,7 @@ void SCDCalibratePanels2::profileL1T0(Mantid::API::IPeaksWorkspace_sptr &pws,
17481745
}
17491746

17501747
// output to file
1751-
auto filenamebase = boost::filesystem::temp_directory_path();
1752-
filenamebase /= boost::filesystem::unique_path("profileSCDCalibratePanels2_L1T0.csv");
1748+
auto filenamebase = std::filesystem::temp_directory_path() / "profileSCDCalibratePanels2_L1T0.csv";
17531749
std::ofstream profL1File;
17541750
profL1File.open(filenamebase.string());
17551751
profL1File << msgrst.str();

Framework/Crystal/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if(CXXTEST_FOUND)
99

1010
cxxtest_add_test(CrystalTest ${TEST_FILES})
1111
target_link_libraries(
12-
CrystalTest PRIVATE Mantid::Crystal Mantid::DataHandling Mantid::MDAlgorithms Mantid::Nexus Boost::filesystem gmock
12+
CrystalTest PRIVATE Mantid::Crystal Mantid::DataHandling Mantid::MDAlgorithms Mantid::Nexus gmock
1313
)
1414
add_framework_test_helpers(CrystalTest)
1515
add_dependencies(CrystalTest Algorithms CurveFitting)

Framework/Crystal/test/SCDCalibratePanels2ObjFuncTest.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include "MantidKernel/Logger.h"
3030
#include "MantidKernel/Unit.h"
3131

32-
#include <boost/filesystem.hpp>
3332
#include <boost/math/constants/constants.hpp>
3433
#include <boost/math/special_functions/round.hpp>
3534
#include <cxxtest/TestSuite.h>
@@ -83,9 +82,6 @@ class SCDCalibratePanels2ObjFuncTest : public CxxTest::TestSuite {
8382
void test_rot_shift() {
8483
g_log.notice() << "test_rot_shift() starts.\n";
8584

86-
// Generate unique temp files
87-
auto filenamebase = boost::filesystem::temp_directory_path();
88-
filenamebase /= boost::filesystem::unique_path("testBank_%%%%%%%%");
8985
// Make a clone of the standard peak workspace
9086
PeaksWorkspace_sptr pws = m_pws->clone();
9187
Mantid::API::IPeaksWorkspace_sptr ipws = std::dynamic_pointer_cast<Mantid::API::IPeaksWorkspace>(pws);
@@ -143,9 +139,6 @@ class SCDCalibratePanels2ObjFuncTest : public CxxTest::TestSuite {
143139
void test_detector_resize() {
144140
g_log.notice() << "test_Bank() starts.\n";
145141

146-
// Generate unique temp files
147-
auto filenamebase = boost::filesystem::temp_directory_path();
148-
filenamebase /= boost::filesystem::unique_path("testBank_%%%%%%%%");
149142
// Make a clone of the standard peak workspace
150143
PeaksWorkspace_sptr pws = m_pws->clone();
151144
Mantid::API::IPeaksWorkspace_sptr ipws = std::dynamic_pointer_cast<Mantid::API::IPeaksWorkspace>(pws);

0 commit comments

Comments
 (0)