Code indexing in gitaly is broken and leads to code not being visible to the user. We work on the issue with highest priority.

Skip to content
Snippets Groups Projects
Commit 1cf0c9fc authored by kraus's avatar kraus
Browse files

check number of given arguments and throw exception if doesn't match

parent 39d1cebb
No related branches found
No related tags found
No related merge requests found
......@@ -29,6 +29,10 @@ struct FromFile {
static const std::string name;
Expressions::Result_t operator()(client::function::arguments_t args) {
if (args.size() != 1) {
throw OptPilotException("FromFile::operator()",
"fromFile expects 1 arguments, " + std::to_string(args.size()) + " given");
}
filename_ = boost::get<std::string>(args[0]);
......@@ -58,4 +62,4 @@ private:
};
#endif
#endif
\ No newline at end of file
......@@ -29,6 +29,10 @@ struct MaxNormRadialPeak {
static const std::string name;
Expressions::Result_t operator()(client::function::arguments_t args) {
if (args.size() != 4) {
throw OptPilotException("MaxNormRadialPeak::operator()",
"maxNormRadialPeak expects 4 arguments, " + std::to_string(args.size()) + " given");
}
meas_filename_ = boost::get<std::string>(args[0]);
sim_filename_ = boost::get<std::string>(args[1]);
......@@ -53,7 +57,7 @@ struct MaxNormRadialPeak {
}
double maximum = -1.0;
for (int turn = begin_; turn < end_ + 1; ++turn) {
double sim_value = 0.0, meas_value = 0.0;
try {
......@@ -97,4 +101,4 @@ private:
// mode:c
// c-basic-offset: 4
// indent-tabs-mode:nil
// End:
// End:
\ No newline at end of file
......@@ -23,6 +23,10 @@ struct NumberOfPeaks {
static const std::string name;
Expressions::Result_t operator()(client::function::arguments_t args) {
if (args.size() != 1) {
throw OptPilotException("NumberOfPeaks::operator()",
"numberOfPeaks expects 1 arguments, " + std::to_string(args.size()) + " given");
}
sim_filename_ = boost::get<std::string>(args[0]);
......@@ -30,7 +34,7 @@ struct NumberOfPeaks {
boost::scoped_ptr<PeakReader> sim_peaks(new PeakReader(sim_filename_));
std::size_t nPeaks = 0;
try {
sim_peaks->parseFile();
nPeaks = sim_peaks->getNumberOfPeaks();
......@@ -39,13 +43,13 @@ struct NumberOfPeaks {
is_valid = false;
}
return boost::make_tuple(nPeaks, is_valid);
}
private:
std::string sim_filename_;
// define a mapping to arguments in argument vector
boost::tuple<std::string> argument_types;
};
......@@ -56,4 +60,4 @@ private:
// mode:c
// c-basic-offset: 4
// indent-tabs-mode:nil
// End:
// End:
\ No newline at end of file
......@@ -12,26 +12,30 @@
#include "Expression/Parser/function.hpp"
struct ProbeVariable {
static const std::string name;
Expressions::Result_t operator()(client::function::arguments_t args) {
if (args.size() != 3) {
throw OptPilotException("ProbeVariable::operator()",
"probeVariable expects 3 arguments, " + std::to_string(args.size()) + " given");
}
var_name_ = boost::get<std::string>(args[0]);
id_ = boost::get<double>(args[1]); //FIXME Can't we use integer?
probe_filename_ = boost::get<std::string>(args[2]);
bool is_valid = true;
boost::scoped_ptr<ProbeReader> sim_probe(new ProbeReader(probe_filename_));
try {
sim_probe->parseFile();
} catch (OptPilotException &ex) {
std::cout << "Caught exception: " << ex.what() << std::endl;
is_valid = false;
}
double sim_value = 0.0;
try {
sim_probe->getVariableValue(id_, var_name_, sim_value);
......@@ -41,10 +45,10 @@ struct ProbeVariable {
<< std::endl;
is_valid = false;
}
return boost::make_tuple(sim_value, is_valid);
}
private:
std::string var_name_;
int id_;
......@@ -62,4 +66,4 @@ private:
#endif
};
#endif
#endif
\ No newline at end of file
......@@ -21,6 +21,10 @@ struct RadialPeak {
static const std::string name;
Expressions::Result_t operator()(client::function::arguments_t args) {
if (args.size() != 2) {
throw OptPilotException("RadialPeak::operator()",
"radialPeak expects 2 arguments, " + std::to_string(args.size()) + " given");
}
peak_filename_ = boost::get<std::string>(args[0]);
turn_number_ = boost::get<double>(args[1]);
......@@ -70,4 +74,4 @@ private:
// mode:c
// c-basic-offset: 4
// indent-tabs-mode:nil
// End:
// End:
\ No newline at end of file
......@@ -22,6 +22,11 @@ struct SDDSVariable {
Expressions::Result_t operator()(client::function::arguments_t args) {
if (args.size() != 3) {
throw OptPilotException("SDDSVariable::operator()",
"sddsVariableAt expects 3 arguments, " + std::to_string(args.size()) + " given");
}
var_name_ = boost::get<std::string>(args[0]);
spos_ = boost::get<double>(args[1]);
stat_filename_ = boost::get<std::string>(args[2]);
......@@ -79,6 +84,11 @@ struct sameSDDSVariable {
}
Expressions::Result_t operator()(client::function::arguments_t args) {
if (args.size() != 2) {
throw OptPilotException("sameSDDSVariable::operator()",
"statVariableAt expects 2 arguments, " + std::to_string(args.size()) + " given");
}
args.push_back(stat_filename_);
return var_(args);
}
......@@ -88,4 +98,4 @@ private:
SDDSVariable var_;
};
#endif
#endif
\ No newline at end of file
......@@ -38,6 +38,11 @@ struct SumErrSq {
Expressions::Result_t operator()(client::function::arguments_t args) {
if (args.size() != 3) {
throw OptPilotException("SumErrSq::operator()",
"sumErrSq expects 3 arguments, " + std::to_string(args.size()) + " given");
}
std::string measurement_filename = boost::get<std::string>(args[0]);
var_name_ = boost::get<std::string>(args[1]);
stat_filename_ = boost::get<std::string>(args[2]);
......@@ -87,4 +92,4 @@ private:
boost::tuple<std::string, std::string, std::string> argument_types;
};
#endif
#endif
\ No newline at end of file
......@@ -27,6 +27,10 @@ struct SumErrSqRadialPeak {
static const std::string name;
Expressions::Result_t operator()(client::function::arguments_t args) {
if (args.size() != 4) {
throw OptPilotException("SumErrSqRadialPeak::operator()",
"sumErrSqRadialPeak expects 4 arguments, " + std::to_string(args.size()) + " given");
}
meas_filename_ = boost::get<std::string>(args[0]);
sim_filename_ = boost::get<std::string>(args[1]);
......@@ -96,4 +100,4 @@ private:
// mode:c
// c-basic-offset: 4
// indent-tabs-mode:nil
// End:
// End:
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment