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