/* * Name: long ChToInt(const char *ch) * Func: if ch has int charactors, change to int and return * * Para: * const char *ch Point to the text * int n Lenth of the string * * ret : long * * 2011.4.12 by zy * */ long ChToInt(const char *ch, int n) { long i = 0; if(n > 1){ return ch[0] == '-' ? (ChToInt(ch, n - 1)*10 - (ch[n-1] - '0')) : (ChToInt(ch, n - 1)*10 + (ch[n-1] - '0')); } else { return ch[0] == '-' ? 0 : (ch[0] - '0'); } }
bool isToday( struct tm& nowT, std::string &res ) { if ( res.length() < 8 ){ return false; } if ( ((nowT.tm_year+1900)*10000 + (nowT.tm_mon+1)*100 + nowT.tm_mday) !=ChToInt(res.c_str(),8) ){ return false; } return true; }
double CAdjustStock::calcExpr( const Tree &tree ) { //int num = tree.childNum(); for (int i = 0; i < tree.childNum() ; i++) { const Tree& tmp_tree = tree.child(i) ; calcExpr(tmp_tree); } double calResult=0; //当前节点类型 //cout << "tree type =" << tree->getType(tree) << endl; switch (tree.type()) { case LT_: case GT: case OR: case AND: { double a1=numbers.top(); numbers.pop(); double a2=numbers.top(); numbers.pop(); calResult = OP(tree.type(),a1,a2); break; } case DOUBLE: { numbers.push( ChToInt(tree.text().c_str(), tree.text().length()) ); break; } case VAR: { //取到语法树的变量节点 a,b string strVar( tree.text() ); map<string, double>::iterator iter; iter = m_parseMap.find(strVar); if ( iter != m_parseMap.end() ) { //查找,转换成变量对应的数值 numbers.push( iter->second ); } } default: { break; } } return calResult; }