Mantid
Loading...
Searching...
No Matches
FileDescriptor.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2013 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 "MantidKernel/DllConfig.h"
10
11#include <fstream>
12#include <stdio.h>
13#include <string>
14
15namespace Mantid {
16namespace Kernel {
17
26class MANTID_KERNEL_DLL FileDescriptor {
27public:
29 static bool isAscii(const std::string &filename, const size_t nbytes = 256);
31 static bool isAscii(std::istream &data, const size_t nbytes = 256);
33 static bool isAscii(FILE *file, const size_t nbytes = 256);
35 static bool isEmpty(const std::string &filename);
36
37public:
39 FileDescriptor(const std::string &filename);
42
44 FileDescriptor() = delete;
45
47 FileDescriptor(const FileDescriptor &) = delete;
48
51
56 inline const std::string &filename() const { return m_filename; }
62 inline const std::string &extension() const { return m_extension; }
66 inline bool isAscii() const { return m_ascii; }
70 bool isXML() const;
75 inline std::istream &data() { return m_file; }
77 void resetStreamToStart();
78
79private:
81 void initialize(const std::string &filename);
82
84 std::string m_filename;
86 std::string m_extension;
88 std::ifstream m_file;
90 bool m_ascii;
91};
92
93} // namespace Kernel
94} // namespace Mantid
Defines a wrapper around an open file.
std::string m_extension
Extension.
bool isAscii() const
Returns true if the descriptor is looking at an ascii file.
FileDescriptor(const FileDescriptor &)=delete
Disable copy operator.
FileDescriptor()=delete
Disable default constructor.
const std::string & filename() const
Access the filename.
std::istream & data()
Access the open file stream.
FileDescriptor & operator=(const FileDescriptor &)=delete
Disable assignment operator.
const std::string & extension() const
Access the file extension.
std::string m_filename
Full filename.
bool m_ascii
Flag indicating the file is pure ascii.
std::ifstream m_file
Open file stream.
Helper class which provides the Collimation Length for SANS instruments.