Mantid
Loading...
Searching...
No Matches
IDFObject.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
9
10#include <Poco/String.h>
11#include <filesystem>
12
13namespace Mantid::Geometry {
14//----------------------------------------------------------------------------------------------
20const std::string AbstractIDFObject::expectedExtension() { return ".xml"; }
21
22//----------------------------------------------------------------------------------------------
25IDFObject::IDFObject(const std::string &fileName)
26 : m_hasFileName(!fileName.empty()), m_cachePath(fileName), m_cacheParentDirectory(m_cachePath.parent_path()),
27 m_cachePathStr(m_cachePath.string())
28
29{}
30
35std::filesystem::path IDFObject::getParentDirectory() const { return m_cacheParentDirectory; }
36
41const std::filesystem::path &IDFObject::getFileFullPath() const { return m_cachePath; }
42
43const std::string &IDFObject::getFileFullPathStr() const { return m_cachePathStr; }
44
49std::string IDFObject::getFileNameOnly() const { return m_cachePath.filename().string(); }
50
55std::string IDFObject::getExtension() const {
56 std::string ext = m_cachePath.extension().string();
57 return ext; // std::filesystem includes the leading dot
58}
59
64std::string IDFObject::getMangledName() const {
65 std::string idfText = Kernel::ChecksumHelper::loadFile(getFileFullPathStr(), true);
66 std::string checksum = Kernel::ChecksumHelper::sha1FromString(Poco::trim(idfText));
67 return this->getFileNameOnly() + checksum;
68}
69
74bool IDFObject::exists() const { return m_hasFileName && std::filesystem::exists(m_cachePath); }
75
76} // namespace Mantid::Geometry
static const std::string expectedExtension()
Returns the expected extension of an IDF file.
Definition IDFObject.cpp:20
std::filesystem::path getParentDirectory() const override
Gets the parent directory of the file.
Definition IDFObject.cpp:35
const std::filesystem::path m_cacheParentDirectory
Definition IDFObject.h:66
IDFObject(const std::string &fileName)
Constructor.
Definition IDFObject.cpp:25
const std::string & getFileFullPathStr() const override
Definition IDFObject.cpp:43
std::string getMangledName() const override
Gets the idf file as a mangled name.
Definition IDFObject.cpp:64
const std::filesystem::path & getFileFullPath() const override
Getter for the full file path.
Definition IDFObject.cpp:41
const std::string m_cachePathStr
Definition IDFObject.h:67
bool exists() const override
Check that the file exists.
Definition IDFObject.cpp:74
std::string getFileNameOnly() const override
Gets the filename for the FileObject.
Definition IDFObject.cpp:49
const std::filesystem::path m_cachePath
Definition IDFObject.h:65
std::string getExtension() const override
Gets the extension of this IDF file, including the leading period.
Definition IDFObject.cpp:55
MANTID_KERNEL_DLL std::string sha1FromString(const std::string &input)
create a SHA-1 checksum from a string
MANTID_KERNEL_DLL std::string loadFile(const std::string &filepath, const bool unixEOL)
Load contents of file into a string.