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