00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00035 #include "functcoverexpression.h"
00036
00037 FunctCoverExpression::FunctCoverExpression(AggregateFunctExpression * _aggfunct):
00038 RoundingExpression(et_cover, _aggfunct) {
00039 }
00040
00041 FunctCoverExpression::~FunctCoverExpression() {
00042 }
00043
00044 void FunctCoverExpression::eval(OutputStream & eos, Environment * env,
00045 unsigned modus) {
00046
00047 switch (modus) {
00048
00049 case EVAL_QUERY:
00050 {
00051 bool non_value = true;
00052 long double cover_val =
00053 calculateValue(eos, env, modus, non_value);
00054 if (!non_value) {
00055 const char *cover_str =
00056 MiscFunctions::getStringFromNumerical(cover_val);
00057 eos << cover_str;
00058 delete[]cover_str;
00059 } else {
00060 eos << OUTPUT_COVER_ON_NON_VALUE;
00061 }
00062 break;
00063 }
00064
00065 case EVAL_QUERY_SILENT:
00066 {
00067 bool non_value = true;
00068 long double cover_val =
00069 calculateValue(eos, env, modus, non_value);
00070 if (!non_value) {
00071 cur_val.setNumVal(cover_val);
00072 } else {
00073 const char *cover_non_val =
00074 new char[strlen(OUTPUT_COVER_ON_NON_VALUE) + 1];
00075 strcpy((char *) cover_non_val, OUTPUT_COVER_ON_NON_VALUE);
00076 cur_val.setStrVal(cover_non_val);
00077 }
00078 break;
00079 }
00080
00081 case EVAL_SIGNOFF:
00082 break;
00083
00084 default:
00085 throw
00086 RuntimeException
00087 ("FunctCoverExpression: Illegal Evaluation Mode",
00088 eid_runtime_illegalmode);
00089 break;
00090 }
00091 }
00092
00093 long double FunctCoverExpression::calculateValue(OutputStream & eos,
00094 Environment * env,
00095 unsigned modus,
00096 bool & non_value) {
00097
00098 long double cover_ret = 0;
00099
00100 aggfunct->prepareOperand(eos, env, modus);
00101 Value *agg_val = aggfunct->getNextValue();
00102
00103 if (agg_val->getType() == xsd_numeric) {
00104 non_value = false;
00105 long double aggfunct_result = agg_val->getNumVal();
00106
00107 cover_ret =
00108 aggfunct_result <
00109 0 ? floor(aggfunct_result) : ceil(aggfunct_result);
00110 }
00111 aggfunct->unprepareOperand();
00112
00113 return cover_ret;
00114 }