Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_FileInputStream.cpp
1// @HEADER
2// *****************************************************************************
3// Teuchos: Common Tools Package
4//
5// Copyright 2004 NTESS and the Teuchos contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
11#include "Teuchos_Assert.hpp"
12
13using namespace Teuchos;
14
16 : XMLInputStream(), file_(std::fopen(filename.c_str(), "rb"))
17{
19 std::runtime_error,
20 "FileInputStream ctor failed to open file: "
21 << filename);
22}
23
24unsigned int FileInputStream::readBytes(unsigned char* const toFill,
25 const unsigned int maxToRead)
26{
27 if (
28#if defined(ICL) || defined(__sgi)
29 feof(file_)
30#else
31 std::feof(file_)
32#endif
33 )
34 return (size_t)0;
35 int n = std::fread((void*) toFill, sizeof(char), maxToRead, file_);
36 if (n==0) return (size_t)0;
37
38 const bool
39 is_eof
40#if defined(ICL) || defined(__sgi)
41 = feof(file_)
42#else
43 = std::feof(file_)
44#endif
45 ;
46
48 n < 0 || (n<(int) maxToRead && !is_eof),
49 std::runtime_error,
50 "FileInputStream::readBytes error"
51 );
52
53 return (size_t) n;
54}
55
56// 2007/07/08: rabartl: Above, for some reason the header <cstdio> on the
57// Intel C++ compiler 8.0 for Windows XP just does not have the function
58// feof(...) in the correct std namespace. On this compiler, you just have to
59// access it from the global namespace.
Definition of XMLInputStream derived class for reading XML from a file.
virtual unsigned int readBytes(unsigned char *const toFill, const unsigned int maxToRead)
Read up to maxToRead bytes.
FileInputStream(const std::string &filename)
Construct with a filename.
Smart reference counting pointer class for automatic garbage collection.
XMLInputStream represents an XML input stream that can be used by a XMLInputSource.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...