Implemented a fix for multiple concurrent file handles.

This commit is contained in:
Christopher LaChance 2017-10-27 14:13:28 -05:00
parent eba6118c92
commit 0a90c11541
2 changed files with 19 additions and 0 deletions

View File

@ -73,6 +73,10 @@ namespace Trick {
/** The input file stream. */
std::ifstream *input_file_stream; /**< \n trick_units(--) */
private:
// Used to store the current position of the stream for file opening and closing.
std::streampos stream_position;
public:
/**
* Constructs a MonteVarFile with the specified name, file name, column, and units.

View File

@ -34,6 +34,17 @@ std::string Trick::MonteVarFile::describe_variable() {
}
std::string Trick::MonteVarFile::get_next_value() {
// Reopen the file if not open.
if(!input_file_stream->is_open()) {
input_file_stream->open(this->file_name.c_str(), std::ifstream::in);
// If the stream position has been set, re-open file to this position.
if(this->stream_position != NULL) {
input_file_stream->seekg(this->stream_position);
}
}
if (input_file_stream->good()) {
std::string line;
// Skip the comments and empty lines in the data file.
@ -47,6 +58,10 @@ std::string Trick::MonteVarFile::get_next_value() {
}
while(line[0] == '#' || line[0] == '\0');
// Store the current stream position and close the file.
this->stream_position = input_file_stream->tellg();
input_file_stream->close();
// Count the number of columns in the input file.
char *token;
unsigned int ntokens = 0;