Mantid
Loading...
Searching...
No Matches
IDFObject.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2012 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 +
7#pragma once
8
9#include "MantidGeometry/DllConfig.h"
10#ifndef Q_MOC_RUN
11#include <memory>
12#endif
13#include <filesystem>
14#include <stdexcept>
15
16namespace Mantid {
17namespace Geometry {
18
29class MANTID_GEOMETRY_DLL AbstractIDFObject {
30public:
31 AbstractIDFObject() = default;
32 static const std::string expectedExtension();
33 virtual std::filesystem::path getParentDirectory() const = 0;
34 virtual const std::filesystem::path &getFileFullPath() const = 0;
35 virtual const std::string &getFileFullPathStr() const = 0;
36 virtual std::string getFileNameOnly() const = 0;
37 virtual std::string getExtension() const = 0;
38 virtual std::string getMangledName() const = 0;
39 virtual bool exists() const = 0;
40 virtual ~AbstractIDFObject() = default;
41
42private:
45};
46
50class MANTID_GEOMETRY_DLL IDFObject : public AbstractIDFObject {
51public:
52 IDFObject(const std::string &fileName);
53 std::filesystem::path getParentDirectory() const override;
54 const std::filesystem::path &getFileFullPath() const override;
55 const std::string &getFileFullPathStr() const override;
56 std::string getFileNameOnly() const override;
57 std::string getExtension() const override;
58 std::string getMangledName() const override;
59 bool exists() const override;
60
61private:
64 const bool m_hasFileName;
65 const std::filesystem::path m_cachePath;
66 const std::filesystem::path m_cacheParentDirectory;
67 const std::string m_cachePathStr;
68};
69
70/*
71 * NULL IDFObject
72 */
73class MANTID_GEOMETRY_DLL NullIDFObject : public AbstractIDFObject {
74private:
75 std::string m_emptyResponse;
76 std::filesystem::path m_emptyPath;
77
78public:
79 NullIDFObject() : m_emptyResponse(""), m_emptyPath("") {}
80 std::filesystem::path getParentDirectory() const override {
81 throw std::runtime_error("Not implemented on NullIDFObject");
82 }
83 const std::filesystem::path &getFileFullPath() const override {
84 throw std::runtime_error("Not implemented on NullIDFObject");
85 }
86 const std::string &getFileFullPathStr() const override { return m_emptyResponse; }
87 std::string getFileNameOnly() const override { return m_emptyResponse; }
88 std::string getExtension() const override { return m_emptyResponse; }
89 std::string getMangledName() const override { throw std::runtime_error("Not implemented on NullIDFObject"); }
90 bool exists() const override { return false; }
91};
92
93using IDFObject_sptr = std::shared_ptr<AbstractIDFObject>;
94using IDFObject_const_sptr = std::shared_ptr<const AbstractIDFObject>;
95
96} // namespace Geometry
97} // namespace Mantid
IDFObject : File object wrapper over an IDF file.
Definition IDFObject.h:29
virtual std::filesystem::path getParentDirectory() const =0
virtual const std::filesystem::path & getFileFullPath() const =0
virtual std::string getFileNameOnly() const =0
AbstractIDFObject(const AbstractIDFObject &)
AbstractIDFObject & operator=(const AbstractIDFObject &)
virtual const std::string & getFileFullPathStr() const =0
virtual std::string getMangledName() const =0
virtual std::string getExtension() const =0
virtual bool exists() const =0
Concrete IDF Object.
Definition IDFObject.h:50
IDFObject & operator=(const IDFObject &)
const std::filesystem::path m_cacheParentDirectory
Definition IDFObject.h:66
const std::string m_cachePathStr
Definition IDFObject.h:67
IDFObject(const IDFObject &)
const std::filesystem::path m_cachePath
Definition IDFObject.h:65
bool exists() const override
Definition IDFObject.h:90
std::filesystem::path m_emptyPath
Definition IDFObject.h:76
std::filesystem::path getParentDirectory() const override
Definition IDFObject.h:80
const std::string & getFileFullPathStr() const override
Definition IDFObject.h:86
std::string getMangledName() const override
Definition IDFObject.h:89
std::string getExtension() const override
Definition IDFObject.h:88
const std::filesystem::path & getFileFullPath() const override
Definition IDFObject.h:83
std::string getFileNameOnly() const override
Definition IDFObject.h:87
bool exists(Nexus::File &file, const std::string &name)
std::shared_ptr< AbstractIDFObject > IDFObject_sptr
Definition IDFObject.h:93
std::shared_ptr< const AbstractIDFObject > IDFObject_const_sptr
Definition IDFObject.h:94
Helper class which provides the Collimation Length for SANS instruments.