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 "aggregatefunctcountexpression.h"
00036
00037 AggregateFunctCountExpression::AggregateFunctCountExpression(VarExpression * _var):
00038 AggregateFunctExpression(et_aggregatefunctcount, _var) {
00039 }
00040
00041 AggregateFunctCountExpression::AggregateFunctCountExpression(VarStepExpression * _varstep):
00042 AggregateFunctExpression(et_aggregatefunctcount, _varstep) {
00043 }
00044
00045 AggregateFunctCountExpression::~AggregateFunctCountExpression() {
00046 }
00047
00048 void AggregateFunctCountExpression::eval(OutputStream & eos,
00049 Environment * env, unsigned modus) {
00050
00051 switch (modus) {
00052
00053 case EVAL_QUERY:
00054 {
00055 bool empty_sequence = true;
00056 long double count_val =
00057 calculateValue(eos, env, modus, empty_sequence);
00058 if (!empty_sequence) {
00059 const char *count_str =
00060 MiscFunctions::getStringFromNumerical(count_val);
00061 eos << count_str;
00062 delete[]count_str;
00063 } else {
00064 const char *count_str =
00065 MiscFunctions::
00066 getStringFromNumerical(OUTPUT_COUNT_ON_EMPTY_SEQUENCE);
00067 eos << count_str;
00068 delete[]count_str;
00069 }
00070 break;
00071 }
00072
00073 case EVAL_QUERY_SILENT:
00074 {
00075 bool empty_sequence = true;
00076 long double count_val =
00077 calculateValue(eos, env, modus, empty_sequence);
00078 if (!empty_sequence) {
00079 cur_val.setNumVal(count_val);
00080 } else {
00081 cur_val.setNumVal(OUTPUT_COUNT_ON_EMPTY_SEQUENCE);
00082 }
00083 break;
00084 }
00085
00086 case EVAL_SIGNOFF:
00087 forexp->eval(eos, env, EVAL_SIGNOFF);
00088 break;
00089
00090 default:
00091 throw
00092 RuntimeException
00093 ("AggregateFunctCountExpression: Illegal Evaluation Mode",
00094 eid_runtime_illegalmode);
00095 break;
00096 }
00097 }
00098
00099 long double AggregateFunctCountExpression::calculateValue(OutputStream & eos,
00100 Environment * env,
00101 unsigned modus,
00102 bool &
00103 empty_sequence) {
00104
00105 var ? bit->init(env->getNodeBinding(var->getId())) :
00106 bit->init(env->getNodeBinding(varstep->getId()));
00107
00108 long double count_ret = 0;
00109 long double result = 0;
00110
00111 while (BufferNode * cur =
00112 bit->getNext(READ_UP_TO_CLOSE_NONE, LOCK_CONTEXT_ALWAYS_CLEAR)) {
00113
00114 empty_sequence = false;
00115 result++;
00116
00117 forexp->evalSignOffForBinding(eos, env, cur);
00118 }
00119 bit->clear();
00120
00121 if (!empty_sequence) {
00122 count_ret = MiscFunctions::getRoundFrom(result);
00123 }
00124
00125 return count_ret;
00126 }