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 "functfloorexpression.h"
00036
00037 FunctFloorExpression::FunctFloorExpression(AggregateFunctExpression * _aggfunct):
00038 RoundingExpression(et_floor, _aggfunct) {
00039 }
00040
00041 FunctFloorExpression::~FunctFloorExpression() {
00042 }
00043
00044 void FunctFloorExpression::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 floor_val =
00053 calculateValue(eos, env, modus, non_value);
00054 if (!non_value) {
00055 const char *floor_str =
00056 MiscFunctions::getStringFromNumerical(floor_val);
00057 eos << floor_str;
00058 delete[]floor_str;
00059 } else {
00060 eos << OUTPUT_FLOOR_ON_NON_VALUE;
00061 }
00062 break;
00063 }
00064
00065 case EVAL_QUERY_SILENT:
00066 {
00067 bool non_value = true;
00068 long double floor_val =
00069 calculateValue(eos, env, modus, non_value);
00070 if (!non_value) {
00071 cur_val.setNumVal(floor_val);
00072 } else {
00073 const char *floor_non_val =
00074 new char[strlen(OUTPUT_FLOOR_ON_NON_VALUE) + 1];
00075 strcpy((char *) floor_non_val, OUTPUT_FLOOR_ON_NON_VALUE);
00076 cur_val.setStrVal(floor_non_val);
00077 }
00078 break;
00079 }
00080
00081 case EVAL_SIGNOFF:
00082 break;
00083
00084 default:
00085 throw
00086 RuntimeException
00087 ("FunctFloorExpression: Illegal Evaluation Mode",
00088 eid_runtime_illegalmode);
00089 break;
00090 }
00091 }
00092
00093 long double FunctFloorExpression::calculateValue(OutputStream & eos,
00094 Environment * env,
00095 unsigned modus,
00096 bool & non_value) {
00097
00098 long double floor_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 floor_ret = floor(agg_val->getNumVal());
00106 }
00107 aggfunct->unprepareOperand();
00108
00109 return floor_ret;
00110 }