2015-02-26 15:02:31 +00:00
|
|
|
#include <iostream>
|
2017-10-10 15:30:28 +00:00
|
|
|
#include <sstream>
|
2015-02-26 15:02:31 +00:00
|
|
|
|
2015-06-01 15:28:29 +00:00
|
|
|
#include "trick/MonteVarCalculated.hh"
|
|
|
|
#include "trick/memorymanager_c_intf.h"
|
|
|
|
#include "trick/message_proto.h"
|
|
|
|
#include "trick/message_type.h"
|
2015-02-26 15:02:31 +00:00
|
|
|
|
|
|
|
Trick::MonteVarCalculated::MonteVarCalculated(std::string in_name, std::string in_unit) {
|
|
|
|
this->name = in_name;
|
|
|
|
this->unit = in_unit;
|
|
|
|
|
2021-05-27 03:12:02 +00:00
|
|
|
ref2 = ref_attributes(name.c_str());
|
2015-02-26 15:02:31 +00:00
|
|
|
if (ref2 == NULL) {
|
|
|
|
message_publish(MSG_ERROR, "Monte : MonteVarCalculated could not find parameter %s.\n", name.c_str()) ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-10 15:30:28 +00:00
|
|
|
// Composite the various properties of this MonteVarCalculated.
|
|
|
|
std::string Trick::MonteVarCalculated::describe_variable()
|
|
|
|
{
|
|
|
|
std::stringstream ss;
|
|
|
|
|
|
|
|
ss << "#NAME:\t" << this->name << "\n"
|
|
|
|
<< "#TYPE:\tCALCULATED\n"
|
|
|
|
<< "#UNIT:\t" << this->unit << "\n";
|
|
|
|
|
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
|
2015-02-26 15:02:31 +00:00
|
|
|
std::string Trick::MonteVarCalculated::get_next_value() {
|
|
|
|
char buffer[128];
|
|
|
|
if (ref2 != NULL) {
|
|
|
|
switch (ref2->attr->type) {
|
|
|
|
case TRICK_CHARACTER:
|
|
|
|
case TRICK_UNSIGNED_CHARACTER:
|
2022-11-15 21:00:05 +00:00
|
|
|
snprintf(buffer, sizeof(buffer), "%d", *(char *)ref2->address);
|
2015-02-26 15:02:31 +00:00
|
|
|
value = buffer;
|
|
|
|
break;
|
|
|
|
case TRICK_SHORT:
|
|
|
|
case TRICK_UNSIGNED_SHORT:
|
2022-11-15 21:00:05 +00:00
|
|
|
snprintf(buffer, sizeof(buffer), "%d", *(short *)ref2->address);
|
2015-02-26 15:02:31 +00:00
|
|
|
value = buffer;
|
|
|
|
break;
|
|
|
|
case TRICK_INTEGER:
|
|
|
|
case TRICK_UNSIGNED_INTEGER:
|
2023-08-11 15:29:51 +00:00
|
|
|
snprintf(buffer, sizeof(buffer), "%d", *(int *)ref2->address);
|
|
|
|
value = buffer;
|
|
|
|
break;
|
2015-02-26 15:02:31 +00:00
|
|
|
case TRICK_LONG:
|
|
|
|
case TRICK_UNSIGNED_LONG:
|
2022-11-15 21:00:05 +00:00
|
|
|
snprintf(buffer, sizeof(buffer), "%ld", *(long *)ref2->address);
|
2015-02-26 15:02:31 +00:00
|
|
|
value = buffer;
|
|
|
|
break;
|
|
|
|
case TRICK_LONG_LONG:
|
|
|
|
case TRICK_UNSIGNED_LONG_LONG:
|
2022-11-15 21:00:05 +00:00
|
|
|
snprintf(buffer, sizeof(buffer), "%lld", *(long long *)ref2->address);
|
2015-02-26 15:02:31 +00:00
|
|
|
value = buffer;
|
|
|
|
break;
|
|
|
|
case TRICK_FLOAT:
|
2022-11-15 21:00:05 +00:00
|
|
|
snprintf(buffer, sizeof(buffer), "%.15g", *(float *)ref2->address);
|
2015-02-26 15:02:31 +00:00
|
|
|
value = buffer;
|
|
|
|
break;
|
|
|
|
case TRICK_DOUBLE:
|
2022-11-15 21:00:05 +00:00
|
|
|
snprintf(buffer, sizeof(buffer), "%.15g", *(double *)ref2->address);
|
2015-02-26 15:02:31 +00:00
|
|
|
value = buffer;
|
|
|
|
break;
|
|
|
|
default:
|
2022-11-15 21:00:05 +00:00
|
|
|
snprintf(buffer, sizeof(buffer), "#Unsupported value type %d", ref2->attr->type) ;
|
2015-02-26 15:02:31 +00:00
|
|
|
break ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unit.empty()) {
|
2015-07-29 21:56:23 +00:00
|
|
|
return name + std::string(" = ") + value;
|
2015-02-26 15:02:31 +00:00
|
|
|
} else {
|
2015-07-29 21:56:23 +00:00
|
|
|
return name + std::string(" = trick.attach_units(\"") + unit + std::string("\", ") + value + std::string(")");
|
2015-02-26 15:02:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|