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 "functabsexpression.h"
00036
00037 FunctAbsExpression::FunctAbsExpression(AggregateFunctExpression * _aggfunct):
00038 RoundingExpression(et_abs, _aggfunct) {
00039 }
00040
00041 FunctAbsExpression::~FunctAbsExpression() {
00042 }
00043
00044 void FunctAbsExpression::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 abs_val = calculateValue(eos, env, modus, non_value);
00053
00054 if (!non_value) {
00055 const char *abs_str =
00056 MiscFunctions::getStringFromNumerical(abs_val);
00057 eos << abs_str;
00058 delete[]abs_str;
00059 } else {
00060 eos << OUTPUT_ABS_ON_NON_VALUE;
00061 }
00062 break;
00063 }
00064
00065 case EVAL_QUERY_SILENT:
00066 {
00067 bool non_value = true;
00068 long double abs_val = calculateValue(eos, env, modus, non_value);
00069
00070 if (!non_value) {
00071 cur_val.setNumVal(abs_val);
00072 } else {
00073 const char *abs_non_val =
00074 new char[strlen(OUTPUT_ABS_ON_NON_VALUE) + 1];
00075 strcpy((char *) abs_non_val, OUTPUT_ABS_ON_NON_VALUE);
00076 cur_val.setStrVal(abs_non_val);
00077 }
00078 break;
00079 }
00080
00081 case EVAL_SIGNOFF:
00082 break;
00083
00084 default:
00085 throw
00086 RuntimeException("FunctAbsExpression: Illegal Evaluation Mode",
00087 eid_runtime_illegalmode);
00088 break;
00089 }
00090 }
00091
00092 long double FunctAbsExpression::calculateValue(OutputStream & eos,
00093 Environment * env,
00094 unsigned modus,
00095 bool & non_value) {
00096
00097 long double abs_ret = 0;
00098
00099 aggfunct->prepareOperand(eos, env, modus);
00100 Value *agg_val = aggfunct->getNextValue();
00101
00102 if (agg_val->getType() == xsd_numeric) {
00103 non_value = false;
00104 abs_ret = fabs(agg_val->getNumVal());
00105 }
00106 aggfunct->unprepareOperand();
00107
00108 return abs_ret;
00109 }