add custom constructor for TextFileReader that uses an already opened file descriptor
This commit is contained in:
@ -41,7 +41,7 @@ using namespace LAMMPS_NS;
|
||||
* \param filetype Description of file type for error messages */
|
||||
|
||||
TextFileReader::TextFileReader(const std::string &filename, const std::string &filetype)
|
||||
: filename(filename), filetype(filetype), ignore_comments(true)
|
||||
: filetype(filetype), ignore_comments(true)
|
||||
{
|
||||
fp = fopen(filename.c_str(), "r");
|
||||
|
||||
@ -51,6 +51,18 @@ TextFileReader::TextFileReader(const std::string &filename, const std::string &f
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \overload
|
||||
*
|
||||
* \param fp File descriptor of the already opened file
|
||||
* \param filetype Description of file type for error messages */
|
||||
|
||||
TextFileReader::TextFileReader(FILE *fp, const std::string &filetype)
|
||||
: filetype(filetype), fp(fp), ignore_comments(true)
|
||||
{
|
||||
if (fp == nullptr) throw FileReaderException("Invalid file descriptor");
|
||||
}
|
||||
|
||||
/** Closes the file */
|
||||
|
||||
TextFileReader::~TextFileReader() {
|
||||
|
||||
@ -25,7 +25,6 @@
|
||||
namespace LAMMPS_NS
|
||||
{
|
||||
class TextFileReader {
|
||||
std::string filename;
|
||||
std::string filetype;
|
||||
static constexpr int MAXLINE = 1024;
|
||||
char line[MAXLINE];
|
||||
@ -35,6 +34,8 @@ namespace LAMMPS_NS
|
||||
bool ignore_comments; //!< Controls whether comments are ignored
|
||||
|
||||
TextFileReader(const std::string &filename, const std::string &filetype);
|
||||
TextFileReader(FILE *fp, const std::string &filetype);
|
||||
|
||||
~TextFileReader();
|
||||
|
||||
void skip_line();
|
||||
|
||||
Reference in New Issue
Block a user