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#include <Poco/String.h>
10
11namespace Mantid::Geometry {
12//----------------------------------------------------------------------------------------------
18const std::string AbstractIDFObject::expectedExtension() { return ".xml"; }
19
20//----------------------------------------------------------------------------------------------
23IDFObject::IDFObject(const std::string &fileName)
24 : m_defFile(fileName), m_hasFileName(!fileName.empty()), m_cachePath(m_defFile.path()),
25 m_cacheParentDirectory(m_cachePath.parent()), m_cachePathStr(m_cachePath.toString())
26
27{}
28
33const Poco::Path IDFObject::getParentDirectory() const { return m_cacheParentDirectory; }
34
39const Poco::Path &IDFObject::getFileFullPath() const { return m_cachePath; }
40
41const std::string &IDFObject::getFileFullPathStr() const { return m_cachePathStr; }
42
47std::string IDFObject::getFileNameOnly() const { return m_cachePath.getFileName(); }
48
53std::string IDFObject::getExtension() const {
54 std::string ext = m_cachePath.getExtension();
55 if (ext.empty())
56 return ext;
57 else
58 return "." + ext;
59}
60
65std::string IDFObject::getMangledName() const {
66 std::string idfText = Kernel::ChecksumHelper::loadFile(getFileFullPathStr(), true);
67 std::string checksum = Kernel::ChecksumHelper::sha1FromString(Poco::trim(idfText));
68 return this->getFileNameOnly() + checksum;
69}
70
75bool IDFObject::exists() const { return m_hasFileName && m_defFile.exists(); }
76
77} // namespace Mantid::Geometry
static const std::string expectedExtension()
Returns the expected extension of an IDF file.
Definition: IDFObject.cpp:18
const Poco::File m_defFile
Definition: IDFObject.h:66
IDFObject(const std::string &fileName)
Constructor.
Definition: IDFObject.cpp:23
const Poco::Path & getFileFullPath() const override
Getter for the full file path.
Definition: IDFObject.cpp:39
const std::string & getFileFullPathStr() const override
Definition: IDFObject.cpp:41
std::string getMangledName() const override
Gets the idf file as a mangled name.
Definition: IDFObject.cpp:65
const std::string m_cachePathStr
Definition: IDFObject.h:70
const Poco::Path getParentDirectory() const override
Gets the parent directory of the file.
Definition: IDFObject.cpp:33
bool exists() const override
Check that the file exists.
Definition: IDFObject.cpp:75
const Poco::Path m_cacheParentDirectory
Definition: IDFObject.h:69
std::string getFileNameOnly() const override
Gets the filename for the FileObject.
Definition: IDFObject.cpp:47
const Poco::Path m_cachePath
Definition: IDFObject.h:68
std::string getExtension() const override
Gets the extension of this IDF file, including the leading period.
Definition: IDFObject.cpp:53
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.