Removed redundant checks and this-> keywords.

This commit is contained in:
Christopher LaChance 2017-10-31 13:17:14 -05:00
parent 0dbdc2d7b9
commit cf75a15be8

View File

@ -9,9 +9,9 @@
#include "trick/exec_proto.h" #include "trick/exec_proto.h"
Trick::MonteVarFile::MonteVarFile(std::string in_name, std::string in_file_name, unsigned int in_column, std::string in_unit) : input_file_stream(NULL) { Trick::MonteVarFile::MonteVarFile(std::string in_name, std::string in_file_name, unsigned int in_column, std::string in_unit) : input_file_stream(NULL) {
this->name = in_name; name = in_name;
this->column = in_column; column = in_column;
this->unit = in_unit; unit = in_unit;
set_file_name(in_file_name); set_file_name(in_file_name);
} }
@ -24,26 +24,19 @@ Trick::MonteVarFile::~MonteVarFile() {
std::string Trick::MonteVarFile::describe_variable() { std::string Trick::MonteVarFile::describe_variable() {
std::stringstream ss; std::stringstream ss;
ss << "#NAME:\t\t" << this->name << "\n" ss << "#NAME:\t\t" << name << "\n"
<< "#TYPE:\t\tFILE\n" << "#TYPE:\t\tFILE\n"
<< "#UNIT:\t\t" << this->unit << "\n" << "#UNIT:\t\t" << unit << "\n"
<< "#FILE:\t\t" << this->file_name << "\n" << "#FILE:\t\t" << file_name << "\n"
<< "#COLUMN:\t" << this->column << "\n"; << "#COLUMN:\t" << column << "\n";
return ss.str(); return ss.str();
} }
std::string Trick::MonteVarFile::get_next_value() { std::string Trick::MonteVarFile::get_next_value() {
// Open the file and seek to the previous position.
// Reopen the file if not open. input_file_stream->open(file_name.c_str(), std::ifstream::in);
if(!input_file_stream->is_open()) { input_file_stream->seekg(stream_position);
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 != 0) {
input_file_stream->seekg(this->stream_position);
}
}
if (input_file_stream->good()) { if (input_file_stream->good()) {
std::string line; std::string line;
@ -59,7 +52,7 @@ std::string Trick::MonteVarFile::get_next_value() {
while(line[0] == '#' || line[0] == '\0'); while(line[0] == '#' || line[0] == '\0');
// Store the current stream position and close the file. // Store the current stream position and close the file.
this->stream_position = input_file_stream->tellg(); stream_position = input_file_stream->tellg();
input_file_stream->close(); input_file_stream->close();
// Count the number of columns in the input file. // Count the number of columns in the input file.
@ -90,13 +83,13 @@ std::string Trick::MonteVarFile::get_next_value() {
} }
// Return the value as a string. // Return the value as a string.
this->value = token; value = token;
std::stringstream ss; std::stringstream ss;
if(unit.empty()) if(unit.empty())
ss << this->name << " = " << token; ss << name << " = " << token;
else else
ss << this->name << " = " << "trick.attach_units(\"" << unit << "\", " << token << ")"; ss << name << " = " << "trick.attach_units(\"" << unit << "\", " << token << ")";
return ss.str(); return ss.str();
} }
@ -119,9 +112,9 @@ void Trick::MonteVarFile::set_file_name(std::string in_file_name) {
exec_terminate_with_return(-1, __FILE__, __LINE__, string_stream.str().c_str()); exec_terminate_with_return(-1, __FILE__, __LINE__, string_stream.str().c_str());
} }
this->file_name = in_file_name; file_name = in_file_name;
} }
void Trick::MonteVarFile::set_column(unsigned int in_column) { void Trick::MonteVarFile::set_column(unsigned int in_column) {
this->column = in_column; column = in_column;
} }