/*! \param Wtree \param RecBufSw */ xbShort xbExpn::ProcessExpression( xbExpNode * Wtree, xbShort RecBufSw ) { xbExpNode * WorkNode; xbShort rc; if( Wtree == 0 ) Wtree = Tree; memset(WorkBuf, 0x00, WorkBufMaxLen+1 ); /* initialize the stack - free any expnodes */ while( GetStackDepth() > 0 ) { WorkNode = (xbExpNode *) Pop(); if( !WorkNode->InTree ) delete WorkNode; } if(( WorkNode = GetFirstTreeNode( Wtree )) == NULL ) return XB_NO_DATA; while( WorkNode ) { Push(WorkNode); if( WorkNode->Type == 'D' && WorkNode->dbf ) { WorkNode->dbf->GetField( WorkNode->FieldNo, WorkNode->StringResult, RecBufSw ); if( WorkNode->dbf->GetFieldType( WorkNode->FieldNo ) == 'N' || WorkNode->dbf->GetFieldType( WorkNode->FieldNo ) == 'F' ) WorkNode->DoubResult = WorkNode->dbf->GetDoubleField( WorkNode->FieldNo, RecBufSw ); } else if( WorkNode->Type == 'O' ) { if(( rc = ProcessOperator( RecBufSw )) != XB_NO_ERROR ) return rc; } else if( WorkNode->Type == 'F' ) if(( rc = ProcessFunction( WorkNode->NodeText )) != XB_NO_ERROR ) return rc; WorkNode = GetNextTreeNode( WorkNode ); } if( GetStackDepth() != 1 ) /* should only have result left in stack */ return XB_PARSE_ERROR; return XB_NO_ERROR; }
/*! */ xbDouble xbExpn::GetDoubleResult() { xbDouble d; xbExpNode * e; if( GetStackDepth() < 1 ) return (xbDouble) 0; e = (xbExpNode *) Pop(); d = e->DoubResult; Push(e); return d; }
/*! */ xbLong xbExpn::GetIntResult() { xbLong l; xbExpNode * e; if( GetStackDepth() < 1 ) return 0L; e = (xbExpNode *) Pop(); l = e->IntResult; Push(e); return l; }
/*! */ xbString & xbExpn::GetStringResult() { xbString *s = 0; xbExpNode *e; if( GetStackDepth() < 1 ) return *s; e = (xbExpNode *) Pop(); s = &e->StringResult; Push(e); return *s; }
void CObjectOStreamXml::x_EndNamespace(const string& ns_name) { if (!m_UseSchemaRef || ns_name.empty()) { return; } string nsPrefix = m_NsNameToPrefix[ns_name]; // we should erase them according to Namespace Scoping rules // http://www.w3.org/TR/REC-xml-names/#scoping m_NsPrefixes.pop_back(); if (find(m_NsPrefixes.begin(), m_NsPrefixes.end(), nsPrefix) == m_NsPrefixes.end()) { m_NsNameToPrefix.erase(ns_name); m_NsPrefixToName.erase(nsPrefix); } m_CurrNsPrefix = m_NsPrefixes.empty() ? kEmptyStr : m_NsPrefixes.back(); if (!m_Attlist && GetStackDepth() <= 2) { m_NsNameToPrefix.clear(); m_NsPrefixToName.clear(); } }
char CObjectIStreamAsn::SkipWhiteSpace(void) { try { // catch CEofException for ( ;; ) { char c = m_Input.SkipSpaces(); switch ( c ) { case '\t': m_Input.SkipChar(); continue; case '\r': case '\n': m_Input.SkipChar(); SkipEndOfLine(c); continue; case '-': // check for comments if ( m_Input.PeekChar(1) != '-' ) { return '-'; } m_Input.SkipChars(2); // skip comments SkipComments(); continue; default: return c; } } } catch (CEofException& e) { if (GetStackDepth() <= 2) { throw; } else { // There should be no eof here, report as error ThrowError(fEOF, e.what()); } } return '\0'; }
void CObjectIStreamJson::EndChoice(void) { EndBlock((GetStackDepth() > 1 && FetchFrameFromTop(1).GetNotag()) ? 0 : '}'); }
// choice void CObjectIStreamJson::BeginChoice(const CChoiceTypeInfo* choiceType) { StartBlock((GetStackDepth() > 1 && FetchFrameFromTop(1).GetNotag()) ? 0 : '{'); }
// class void CObjectIStreamJson::BeginClass(const CClassTypeInfo* classInfo) { StartBlock((GetStackDepth() > 1 && FetchFrameFromTop(1).GetNotag()) ? 0 : '{'); }
/*! \param RecBufSw */ xbShort xbExpn::ProcessOperator( xbShort RecBufSw ) { xbExpNode * WorkNode; char Operator[6]; char t; if( GetStackDepth() < 3 ) return XB_PARSE_ERROR; WorkNode = (xbExpNode *) Pop(); if( WorkNode->Len > 5 ) return XB_PARSE_ERROR; memset( Operator, 0x00, 6 ); strncpy( Operator, WorkNode->NodeText, WorkNode->Len ); if( !WorkNode->InTree ) delete WorkNode; /* load up operand 1 */ WorkNode = (xbExpNode *) Pop(); if(( OpType1 = GetOperandType( WorkNode )) == 0 ) return XB_PARSE_ERROR; if( OpLen1 < WorkNode->DataLen+1 && WorkNode->Type != 'd' ) { if( OpLen1 > 0 ) free( Op1 ); if(( Op1 = (char *) malloc( WorkNode->DataLen+1 )) == NULL ) { return XB_NO_MEMORY; } OpLen1 = WorkNode->DataLen+1; } OpDataLen1 = WorkNode->DataLen; memset( Op1, 0x00, WorkNode->DataLen+1 ); if( WorkNode->Type == 'D' && WorkNode->dbf ) { /* database field */ WorkNode->dbf->GetField( WorkNode->FieldNo, Op1, RecBufSw ); t = WorkNode->dbf->GetFieldType( WorkNode->FieldNo ); if( t == 'N' || t == 'F' ) Opd1 = strtod( WorkNode->StringResult, 0 ); else if( t == 'D' ){ // date field xbDate d; Opd1 = d.JulianDays( WorkNode->StringResult ); } } else if( WorkNode->Type == 'C' ) /* constant */ memcpy( Op1, WorkNode->NodeText, WorkNode->DataLen ); else if( WorkNode->Type == 's' ) /* previous result */ memcpy( Op1, WorkNode->StringResult, WorkNode->DataLen+1 ); else if( WorkNode->Type == 'd' ) /* previous numeric result */ Opd1 = WorkNode->DoubResult; else if( WorkNode->Type == 'N' ) /* previous numeric result */ Opd1 = strtod( WorkNode->StringResult, 0 ); else if(WorkNode->Type == 'l') /* previous logical result 3/26/00 dtb */ Opd1 = WorkNode->IntResult; if( !WorkNode->InTree ) delete WorkNode; /* load up operand 2 */ WorkNode = (xbExpNode *) Pop(); if(( OpType2 = GetOperandType( WorkNode )) == 0 ) return XB_PARSE_ERROR; if( OpLen2 < WorkNode->DataLen+1 && WorkNode->Type != 'd' ) { if( OpLen2 > 0 ) free( Op2 ); if(( Op2 = (char *) malloc( WorkNode->DataLen+1 )) == NULL ) { return XB_NO_MEMORY; } OpLen2 = WorkNode->DataLen+1; } OpDataLen2 = WorkNode->DataLen; memset( Op2, 0x00, WorkNode->DataLen+1 ); if( WorkNode->Type == 'D' && WorkNode->dbf ) { /* database field */ WorkNode->dbf->GetField( WorkNode->FieldNo, Op2, RecBufSw ); t = WorkNode->dbf->GetFieldType( WorkNode->FieldNo ); if( t == 'N' || t == 'F' ) Opd2 = strtod( WorkNode->StringResult, 0 ); else if( t == 'D' ){ // date field xbDate d; Opd2 = d.JulianDays( WorkNode->StringResult ); } } else if( WorkNode->Type == 'C' ) /* constant */ memcpy( Op2, WorkNode->NodeText, WorkNode->DataLen ); else if( WorkNode->Type == 's' ) /* previous result */ memcpy( Op2, WorkNode->StringResult, WorkNode->DataLen+1 ); else if( WorkNode->Type == 'd' ) /* previous numeric result */ Opd2 = WorkNode->DoubResult; else if( WorkNode->Type == 'N' ) /* previous numeric result */ Opd2 = strtod( WorkNode->StringResult, 0 ); else if(WorkNode->Type == 'l') /* previous logical result 3/26/00 dtb*/ Opd2 = WorkNode->IntResult; if( !WorkNode->InTree ) delete WorkNode; if( !ValidOperation( Operator, OpType1, OpType2 )) return XB_PARSE_ERROR; if( OpType1 == 'N' || OpType1 == 'L' || OpType1 == 'D' ) /* numeric procesing */ return NumericOperation( Operator ); else /* must be character */ return AlphaOperation( Operator ); }
/*! \param Func */ xbShort xbExpn::ProcessFunction( char * Func ) { /* 1 - pop function from stack 2 - verify function name and get no of parms needed 3 - verify no of parms >= remainder of stack 4 - pop parms off stack 5 - execute function 6 - push result back on stack */ char *buf = 0; xbExpNode *p1, *p2, *p3, *WorkNode, *FuncNode; xbShort ParmsNeeded,len; char ptype = 0; /* process type s=string, l=logical, d=double */ xbDouble DoubResult = 0; xbLong IntResult = 0; FuncNode = (xbExpNode *) Pop(); ParmsNeeded = GetFuncInfo( Func, 1 ); if( ParmsNeeded == -1 ) { return XB_INVALID_FUNCTION; } else { ParmsNeeded = 0; if( FuncNode->Sibling1 ) ParmsNeeded++; if( FuncNode->Sibling2 ) ParmsNeeded++; if( FuncNode->Sibling3 ) ParmsNeeded++; } if( ParmsNeeded > GetStackDepth()) return XB_INSUFFICIENT_PARMS; p1 = p2 = p3 = NULL; if( ParmsNeeded > 2 ) p3 = (xbExpNode *) Pop(); if( ParmsNeeded > 1 ) p2 = (xbExpNode *) Pop(); if( ParmsNeeded > 0 ) p1 = (xbExpNode *) Pop(); memset( WorkBuf, 0x00, WorkBufMaxLen+1); if( strncmp( Func, "ABS", 3 ) == 0 ) { ptype = 'd'; DoubResult = ABS( GetDoub( p1 )); } else if( strncmp( Func, "ASC", 3 ) == 0 ) { ptype = 'd'; DoubResult = ASC( p1->StringResult ); } else if( strncmp( Func, "AT", 2 ) == 0 ) { ptype = 'd'; DoubResult = AT( p1->StringResult, p2->StringResult ); } else if( strncmp( Func, "CDOW", 4 ) == 0 ) { ptype = 's'; buf = CDOW( p1->StringResult ); } else if( strncmp( Func, "CHR", 3 ) == 0 ) { ptype = 's'; buf = CHR( GetInt( p1 )); } else if( strncmp( Func, "CMONTH", 6 ) == 0 ) { ptype = 's'; buf = CMONTH( p1->StringResult ); } else if( strncmp( Func, "CTOD", 4 ) == 0 ) { ptype = 's'; buf = CTOD( p1->StringResult ); } else if( strncmp( Func, "DATE", 4 ) == 0 ) { ptype = 's'; buf = DATE(); } else if( strncmp( Func, "DAY", 3 ) == 0 ) { ptype = 'd'; DoubResult = DAY( p1->StringResult ); } else if( strncmp( Func, "DESCEND", 7 ) == 0 && p1->ExpressionType == 'C' ) { ptype = 's'; buf = DESCEND( p1->StringResult.c_str() ); } else if( strncmp( Func, "DESCEND", 7 ) == 0 && p1->ExpressionType == 'N' ) { ptype = 'd'; DoubResult = DESCEND( GetDoub( p1 )); } else if( strncmp( Func, "DESCEND", 7 ) == 0 && p1->ExpressionType == 'D' ) { xbDate d( p1->StringResult ); ptype = 'd'; DoubResult = DESCEND( d ); } else if( strncmp( Func, "DOW", 3 ) == 0 ) { ptype = 'd'; DoubResult = DOW( p1->StringResult ); } else if( strncmp( Func, "DTOC", 4 ) == 0 ) { ptype = 's'; buf = DTOC( p1->StringResult ); } else if( strncmp( Func, "DTOS", 4 ) == 0 ) { ptype = 's'; buf = DTOS( p1->StringResult ); } else if( strncmp( Func, "EXP", 3 ) == 0 ) { ptype = 'd'; DoubResult = EXP( GetDoub( p1 )); } else if( strncmp( Func, "IIF", 3 ) == 0 ){ ptype = 's'; buf = IIF( p1->IntResult, p2->StringResult, p3->StringResult ); } else if( strncmp( Func, "INT", 3 ) == 0 ) { ptype = 'd'; DoubResult = INT( GetDoub( p1 )); } else if( strncmp( Func, "ISALPHA", 7 ) == 0 ) { ptype = 'l'; IntResult = ISALPHA( p1->StringResult ); } else if( strncmp( Func, "ISLOWER", 7 ) == 0 ) { ptype = 'l'; IntResult = ISLOWER( p1->StringResult ); } else if( strncmp( Func, "ISUPPER", 7 ) == 0 ) { ptype = 'l'; IntResult = ISUPPER( p1->StringResult ); } else if( strncmp( Func, "LEN", 3 ) == 0 ) { ptype = 'd'; DoubResult = LEN( p1->StringResult ); } else if( strncmp( Func, "LEFT", 4 ) == 0 ) { ptype = 's'; buf = LEFT( p1->StringResult, INT( p2->DoubResult )); } else if( strncmp( Func, "LTRIM", 5 ) == 0 ) { ptype = 's'; buf = LTRIM( p1->StringResult ); } else if( strncmp( Func, "LOG", 3 ) == 0 ) { ptype = 'd'; DoubResult = LOG( GetDoub( p1 )); } else if( strncmp( Func, "LOWER", 5 ) == 0 ) { ptype = 's'; buf = LOWER( p1->StringResult ); } else if( strncmp( Func, "MAX", 3 ) == 0 ) { ptype = 'd'; DoubResult = MAX( GetDoub( p1 ), GetDoub( p2 )); } else if( strncmp( Func, "MIN", 3 ) == 0 ) { ptype = 'd'; DoubResult = MIN( GetDoub( p1 ), GetDoub( p2 )); } else if( strncmp( Func, "MONTH", 5 ) == 0 ) { ptype = 'd'; DoubResult = MONTH( p1->StringResult ); } else if( strncmp( Func, "RECNO", 5 ) == 0 ) { ptype = 'd'; DoubResult = RECNO( FuncNode->dbf ); } else if( strncmp( Func, "REPLICATE", 9 ) == 0 ) { ptype = 's'; buf = REPLICATE( p1->StringResult, GetInt( p2 )); } else if( strncmp( Func, "RIGHT", 5 ) == 0 ) { ptype = 's'; buf = RIGHT( p1->StringResult, GetInt( p2 )); } else if( strncmp( Func, "RTRIM", 5 ) == 0 ) { ptype = 's'; buf = RTRIM( p1->StringResult ); } else if( strncmp( Func, "SPACE", 5 ) == 0 ) { ptype = 's'; buf = SPACE( INT( GetDoub( p1 ))); } else if( strncmp( Func, "SQRT", 4 ) == 0 ) { ptype = 'd'; DoubResult = SQRT( GetDoub( p1 )); } else if( strncmp( Func, "STRZERO", 7 ) == 0 && ParmsNeeded == 1 ) { ptype = 's'; buf = STRZERO( p1->StringResult ); } else if( strncmp( Func, "STRZERO", 7 ) == 0 && ParmsNeeded == 2 ) { ptype = 's'; buf = STRZERO( p1->StringResult, GetInt( p2 )); } else if( strncmp( Func, "STRZERO", 7 ) == 0 && ParmsNeeded == 3 ) { ptype = 's'; buf = STRZERO( p1->StringResult, GetInt( p2 ), GetInt( p3 )); } else if( strncmp( Func, "STR", 3 ) == 0 && p3 ) { ptype = 's'; if(p1->ExpressionType == 'N') buf = STR( p1->DoubResult, GetInt( p2 ), GetInt( p3 )); else buf = STR( p1->StringResult, GetInt( p2 ), GetInt( p3 )); } else if( strncmp( Func, "STR", 3 ) == 0 && p2 ) { ptype = 's'; buf = STR( p1->StringResult, GetInt( p2 )); } else if( strncmp( Func, "STR", 3 ) == 0 && p1 ) { ptype = 's'; buf = STR( p1->StringResult ); } else if( strncmp( Func, "SUBSTR", 6 ) == 0 ) { ptype = 's'; buf = SUBSTR( p1->StringResult, GetInt( p2 ), GetInt( p3 )); } else if( strncmp( Func, "TRIM", 4 ) == 0 ) { ptype = 's'; buf = TRIM( p1->StringResult ); } else if( strncmp( Func, "UPPER", 5 ) == 0 ) { ptype = 's'; buf = UPPER( p1->StringResult ); } else if( strncmp( Func, "VAL", 3 ) == 0 ) { ptype = 'd'; DoubResult = VAL( p1->StringResult ); } else if( strncmp( Func, "YEAR", 4 ) == 0 ) { ptype = 'd'; DoubResult = YEAR( p1->StringResult ); } if( p1 && !p1->InTree ) delete p1; if( p2 && !p2->InTree ) delete p2; if( p3 && !p3->InTree ) delete p3; if( !FuncNode->InTree ) delete FuncNode; if( buf ){ len = strlen( buf ); WorkNode = new xbExpNode; if( !WorkNode ) return XB_NO_MEMORY; WorkNode->ResultLen = len + 1; } else { len = 0; WorkNode = new xbExpNode; if( !WorkNode ) return XB_NO_MEMORY; WorkNode->ResultLen = 0; } switch( ptype ){ case 's': /* string or char result */ WorkNode->DataLen = len; WorkNode->ExpressionType = 'C'; WorkNode->Type = 's'; WorkNode->StringResult = buf; break; case 'd': /* numeric result */ WorkNode->DataLen = 0; WorkNode->ExpressionType = 'N'; WorkNode->Type = 'd'; WorkNode->DoubResult = DoubResult; break; case 'l': /* logical result */ WorkNode->DataLen = 0; WorkNode->ExpressionType = 'L'; WorkNode->Type = 'l'; WorkNode->IntResult = IntResult; break; default: std::cout << "\nInternal error. " << ptype; break; } Push(WorkNode); return XB_NO_ERROR; }