Newer
Older
#ifndef MANTID_KERNEL_FILEDESCRIPTOR_H_
#define MANTID_KERNEL_FILEDESCRIPTOR_H_
#include "MantidKernel/DllConfig.h"
#include <fstream>
#include <string>
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
namespace Mantid {
namespace Kernel {
/**
Defines a wrapper around an open file. Details of the file such as the filename
& extension can be queried.
The file is closed when the object is destroyed.
The object stores an opened fstream object that can be accessed using the data()
method.
Copyright © 2013 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_KERNEL_DLL FileDescriptor {
public:
/// Returns true if the file is considered ascii
static bool isAscii(const std::string &filename, const size_t nbytes = 256);
/// Returns true if the stream is considered ascii
static bool isAscii(std::istream &data, const size_t nbytes = 256);
/// Returns true if the file is considered ascii
static bool isAscii(FILE *file, const size_t nbytes = 256);
public:
/// Constructor accepting a filename
FileDescriptor(const std::string &filename);
/// Destructor
~FileDescriptor();
/// Disable default constructor
FileDescriptor() = delete;
/// Disable copy operator
FileDescriptor(const FileDescriptor &) = delete;
/// Disable assignment operator
FileDescriptor &operator=(const FileDescriptor &) = delete;
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* Access the filename
* @returns A reference to a const string containing the filename
*/
inline const std::string &filename() const { return m_filename; }
/**
* Access the file extension. Defined as the string after and including the
* last period character
* @returns A reference to a const string containing the file extension
*/
inline const std::string &extension() const { return m_extension; }
/**
* Returns true if the descriptor is looking at an ascii file
*/
inline bool isAscii() const { return m_ascii; }
/**
* Access the open file stream. DO NOT CLOSE IT
* @returns The current stream
*/
inline std::istream &data() { return m_file; }
/// Reset the file stream to the start of the file
void resetStreamToStart();
private:
/// Open the file and cache description elements
void initialize(const std::string &filename);
/// Full filename
std::string m_filename;
/// Extension
std::string m_extension;
/// Open file stream
std::ifstream m_file;
/// Flag indicating the file is pure ascii
bool m_ascii;
};
} // namespace Kernel
} // namespace Mantid
#endif /* MANTID_KERNEL_FILEDESCRIPTOR_H_ */