mirror of
https://github.com/nasa/trick.git
synced 2024-12-18 20:57:55 +00:00
Implemented a fix for multiple concurrent file handles.
This commit is contained in:
parent
eba6118c92
commit
0a90c11541
@ -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.
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user