31 std::ifstream
data(
filename.c_str(), std::ios::in | std::ios::binary);
33 throw std::invalid_argument(
"FileDescriptor::isAscii() - Unable to open file '" +
filename +
"'");
52 const std::streampos startPos =
data.tellg();
56 while (counter < nbytes) {
63 auto ch =
static_cast<unsigned long>(byte);
84 auto data =
new char[nbytes];
85 char *pend = &
data[fread(
data, 1, nbytes, file)];
86 int retval = fseek(file, 0, SEEK_SET);
88 throw std::runtime_error(
"FileDescriptor::isAscii - Cannot change position "
89 "to the beginning of the file with fseek");
94 for (
char *p =
data; p < pend; ++p) {
95 auto ch =
static_cast<unsigned long>(*p);
112 std::ifstream file(
filename.c_str());
115 throw std::invalid_argument(
"FileDescriptor::isEmpty() - Unable to open file '" +
filename +
"'");
118 return file.peek() == std::ifstream::traits_type::eof();
132 throw std::invalid_argument(
"FileDescriptor() - Empty filename '" +
filename +
"'");
135 throw std::invalid_argument(
"FileDescriptor() - File '" +
filename +
"' does not exist");
184 throw std::runtime_error(
"FileDescriptor::initialize - Cannot open file '" +
filename +
"' for reading");
std::string m_extension
Extension.
bool isAscii() const
Returns true if the descriptor is looking at an ascii file.
void resetStreamToStart()
Reset the file stream to the start of the file.
static bool isEmpty(const std::string &filename)
Returns true if the file is empty.
FileDescriptor()=delete
Disable default constructor.
const std::string & filename() const
Access the filename.
void initialize(const std::string &filename)
Open the file and cache description elements.
std::istream & data()
Access the open file stream.
bool isXML() const
Returns true if the descriptor is looking at an XML file.
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.
~FileDescriptor()
Destructor.
std::ifstream m_file
Open file stream.
bool exists(::NeXus::File &file, const std::string &name)
Based on the current group in the file, does the named sub-entry exist?
MANTID_KERNEL_DLL std::string toLower(const std::string &input)
Converts string to all lowercase.