///PD_TRACE_DECLARE_FUNCTION ( SDB__MTHINCLUDEPARSER_PARSE, "_mthIncludeParser::parse" ) INT32 _mthIncludeParser::parse( const bson::BSONElement &e, _mthSAction &action ) const { INT32 rc = SDB_OK ; PD_TRACE_ENTRY( SDB__MTHINCLUDEPARSER_PARSE ) ; SDB_ASSERT( !e.eoo(), "can not be eoo" ) ; if ( !e.isNumber() ) { PD_LOG( PDERROR, "invalid element type[%d]", e.type() ) ; rc = SDB_INVALIDARG ; goto error ; } #if defined (_DEBUG) if ( 0 != _name.compare( e.fieldName() ) ) { PD_LOG( PDERROR, "field name[%s] is not valid", e.fieldName() ) ; rc = SDB_INVALIDARG ; goto error ; } #endif action.setName( _name.c_str() ) ; if ( 0 == e.numberLong() ) { action.setAttribute( MTH_S_ATTR_EXCLUDE ) ; } else { action.setAttribute( MTH_S_ATTR_INCLUDE ) ; action.setFunc( &mthIncludeBuild, &mthIncludeGet ) ; } done: PD_TRACE_EXITRC( SDB__MTHINCLUDEPARSER_PARSE, rc ) ; return rc ; error: goto done ; }
///PD_TRACE_DECLARE_FUNCTION ( SDB__MTHSUBSTRPARSER_PARSE, "_mthSubStrParser::parse" ) INT32 _mthSubStrParser::parse( const bson::BSONElement &e, _mthSAction &action ) const { INT32 rc = SDB_OK ; PD_TRACE_ENTRY( SDB__MTHSUBSTRPARSER_PARSE ) ; INT32 begin = 0 ; INT32 limit = -1 ; #if defined (_DEBUG) if ( 0 != _name.compare( e.fieldName() ) ) { PD_LOG( PDERROR, "field name[%s] is not valid", e.fieldName() ) ; rc = SDB_INVALIDARG ; goto error ; } #endif if ( e.isNumber() && 0 <= e.numberInt()) { limit = e.numberInt() ; } else if ( e.isNumber() ) { begin = e.numberInt() ; } else if ( Array == e.type() ) { BSONObjIterator i( e.embeddedObject() ) ; BSONElement ele ; if ( !i.more() ) { goto invalid_arg ; } ele = i.next() ; if ( !ele.isNumber() ) { goto invalid_arg ; } begin = ele.numberInt() ; if ( !i.more() ) { goto invalid_arg ; } ele = i.next() ; if ( !ele.isNumber() ) { goto invalid_arg ; } limit = ele.numberInt() ; } else { PD_LOG( PDERROR, "invalid element" ) ; rc = SDB_INVALIDARG ; goto error ; } action.setAttribute( MTH_S_ATTR_PROJECTION ) ; action.setFunc( &mthSubStrBuild, &mthSubStrGet ) ; action.setName( _name.c_str() ) ; action.setArg( BSON( "arg1" << begin << "arg2" << limit ) ) ; done: PD_TRACE_EXITRC( SDB__MTHSUBSTRPARSER_PARSE, rc ) ; return rc ; error: goto done ; invalid_arg: PD_LOG( PDERROR, "invalid substr argument:%s", e.toString( TRUE, TRUE ).c_str() ) ; rc = SDB_INVALIDARG ; goto error ; }