trick/trick_source/sim_services/MonteCarlo/MonteVarFixed.cpp
Dan D. Jordan 9e0f0ba85a Added MonteVar setters where appropriate
Added set_unit mechanism to MonteVar baseclass. Added MonteVar's derived
classes setters where appropriate to facilitate changing inputs after
the instance of MonteVar has already been constructed. Fleshed out
MonteVarFile destructor to remove memory leaks.
2016-10-03 14:57:11 -05:00

29 lines
761 B
C++

#include <sstream>
#include <iomanip>
#include "trick/MonteVarFixed.hh"
Trick::MonteVarFixed::MonteVarFixed(std::string in_name, double in_value, std::string in_unit) {
this->name = in_name;
set_value(in_value);
this->unit = in_unit;
}
void Trick::MonteVarFixed::set_value(double in_value) {
std::ostringstream string_stream;
string_stream << std::setprecision(15) << in_value ;
this->value = string_stream.str();
}
std::string Trick::MonteVarFixed::get_next_value() {
std::ostringstream string_stream;
if (unit.empty()) {
string_stream << name << " = " << value;
}
else {
string_stream << name << " = trick.attach_units(\"" << unit << "\", " << value << ")";
}
return string_stream.str();
}