virtual void handle(int v)
	{
		if (v > 100)
			LOGT("T1 work");
		else
			handleNext(v);
	}
	virtual void handle(int v)
	{
		if (v < 50)
			LOGT("T2 work");
		else
			handleNext(v);
	}
Beispiel #3
0
int32_t SearchIterator::first(UErrorCode &status)
{
    if (U_FAILURE(status)) {
        return USEARCH_DONE;
    }
    setOffset(0, status);
    return handleNext(0, status);
}
Beispiel #4
0
int32_t SearchIterator::following(int32_t position, 
                                      UErrorCode &status)
{
    if (U_FAILURE(status)) {
        return USEARCH_DONE;
    }
    setOffset(position, status);
    return handleNext(position, status);
}
Beispiel #5
0
int32_t SearchIterator::next(UErrorCode &status)
{
    if (U_SUCCESS(status)) {
        int32_t offset = getOffset();
        int32_t matchindex  = m_search_->matchedIndex;
        int32_t     matchlength = m_search_->matchedLength;
        m_search_->reset = FALSE;
        if (m_search_->isForwardSearching == TRUE) {
            int32_t textlength = m_search_->textLength;
            if (offset == textlength || matchindex == textlength || 
                (matchindex != USEARCH_DONE && 
                matchindex + matchlength >= textlength)) {
                // not enough characters to match
                setMatchNotFound();
                return USEARCH_DONE; 
            }
        }
        else {
            // switching direction. 
            // if matchedIndex == USEARCH_DONE, it means that either a 
            // setOffset has been called or that previous ran off the text
            // string. the iterator would have been set to offset 0 if a 
            // match is not found.
            m_search_->isForwardSearching = TRUE;
            if (m_search_->matchedIndex != USEARCH_DONE) {
                // there's no need to set the collation element iterator
                // the next call to next will set the offset.
                return matchindex;
            }
        }

        if (matchlength > 0) {
            // if matchlength is 0 we are at the start of the iteration
            if (m_search_->isOverlap) {
                offset ++;
            }
            else {
                offset += matchlength;
            }
        }
        return handleNext(offset, status);
    }
    return USEARCH_DONE;
}
Beispiel #6
0
/**
 * Advances the iterator to the next boundary position.
 * @return The position of the first boundary after this one.
 */
int32_t BreakIterator::next(void) {
    // if we have cached break positions and we're still in the range
    // covered by them, just move one step forward in the cache
    if (fCachedBreakPositions != NULL) {
        if (fPositionInCache < fNumCachedBreakPositions - 1) {
            ++fPositionInCache;
            int32_t pos = fCachedBreakPositions[fPositionInCache];
            utext_setNativeIndex(fText, pos);
            return pos;
        }
        else {
            reset();
        }
    }

    int32_t startPos = current();
    int32_t result = handleNext(fForwardTable);
    if (fDictionaryCharCount > 0) {
        result = checkDictionary(startPos, result, FALSE);
    }
    return result;
}
Beispiel #7
0
/**
 * Sets the iterator to refer to the last boundary position before the
 * specified position.
 * @offset The position to begin searching for a break from.
 * @return The position of the last boundary before the starting position.
 */
int32_t BreakIterator::preceding(int32_t offset) {
    // if we have cached break positions and offset is in the range
    // covered by them, use them
    if (fCachedBreakPositions != NULL) {
        // TODO: binary search?
        // TODO: What if offset is outside range, but break is not?
        if (offset > fCachedBreakPositions[0]
                && offset <= fCachedBreakPositions[fNumCachedBreakPositions - 1]) {
            fPositionInCache = 0;
            while (fPositionInCache < fNumCachedBreakPositions
                   && offset > fCachedBreakPositions[fPositionInCache])
                ++fPositionInCache;
            --fPositionInCache;
            // If we're at the beginning of the cache, need to reevaluate the
            // rule status
            if (fPositionInCache <= 0) {
                fLastStatusIndexValid = FALSE;
            }
            utext_setNativeIndex(fText, fCachedBreakPositions[fPositionInCache]);
            return fCachedBreakPositions[fPositionInCache];
        }
        else {
            reset();
        }
    }

    // if the offset passed in is already past the end of the text,
    // just return DONE; if it's before the beginning, return the
    // text's starting offset
    if (fText == NULL || offset > utext_nativeLength(fText)) {
        // return BreakIterator::DONE;
        return last();
    }
    else if (offset < 0) {
        return first();
    }

    // if we start by updating the current iteration position to the
    // position specified by the caller, we can just use previous()
    // to carry out this operation

    if (fSafeFwdTable != NULL) {
        // new rule syntax
        utext_setNativeIndex(fText, offset);
        int32_t newOffset = (int32_t)UTEXT_GETNATIVEINDEX(fText);
        if (newOffset != offset) {
            // Will come here if specified offset was not a code point boundary AND
            //   the underlying implmentation is using UText, which snaps any non-code-point-boundary
            //   indices to the containing code point.
            // For breakitereator::preceding only, these non-code-point indices need to be moved
            //   up to refer to the following codepoint.
            UTEXT_NEXT32(fText);
            offset = (int32_t)UTEXT_GETNATIVEINDEX(fText);
        }

        // TODO:  (synwee) would it be better to just check for being in the middle of a surrogate pair,
        //        rather than adjusting the position unconditionally?
        //        (Change would interact with safe rules.)
        // TODO:  change RBBI behavior for off-boundary indices to match that of UText?
        //        affects only preceding(), seems cleaner, but is slightly different.
        UTEXT_PREVIOUS32(fText);
        handleNext(fSafeFwdTable);
        int32_t result = (int32_t)UTEXT_GETNATIVEINDEX(fText);
        while (result >= offset) {
            result = previous();
        }
        return result;
    }
    if (fSafeRevTable != NULL) {
        // backup plan if forward safe table is not available
        //  TODO:  check whether this path can be discarded
        //         It's probably OK to say that rules must supply both safe tables
        //            if they use safe tables at all.  We have certainly never described
        //            to anyone how to work with just one safe table.
        utext_setNativeIndex(fText, offset);
        UTEXT_NEXT32(fText);
        
        // handle previous will give result <= offset
        handlePrevious(fSafeRevTable);

        // next will give result 0 or 1 boundary away from offset,
        // most of the time
        // we have to
        int32_t oldresult = next();
        while (oldresult < offset) {
            int32_t result = next();
            if (result >= offset) {
                return oldresult;
            }
            oldresult = result;
        }
        int32_t result = previous();
        if (result >= offset) {
            return previous();
        }
        return result;
    }

    // old rule syntax
    utext_setNativeIndex(fText, offset);
    return previous();
}
Beispiel #8
0
/**
 * Sets the iterator to refer to the first boundary position following
 * the specified position.
 * @offset The position from which to begin searching for a break position.
 * @return The position of the first break after the current position.
 */
int32_t BreakIterator::following(int32_t offset) {
    // if we have cached break positions and offset is in the range
    // covered by them, use them
    // TODO: could use binary search
    // TODO: what if offset is outside range, but break is not?
    if (fCachedBreakPositions != NULL) {
        if (offset >= fCachedBreakPositions[0]
                && offset < fCachedBreakPositions[fNumCachedBreakPositions - 1]) {
            fPositionInCache = 0;
            // We are guaranteed not to leave the array due to range test above
            while (offset >= fCachedBreakPositions[fPositionInCache]) {
                ++fPositionInCache;
            }
            int32_t pos = fCachedBreakPositions[fPositionInCache];
            utext_setNativeIndex(fText, pos);
            return pos;
        }
        else {
            reset();
        }
    }

    // if the offset passed in is already past the end of the text,
    // just return DONE; if it's before the beginning, return the
    // text's starting offset
    fLastRuleStatusIndex  = 0;
    fLastStatusIndexValid = TRUE;
    if (fText == NULL || offset >= utext_nativeLength(fText)) {
        last();
        return next();
    }
    else if (offset < 0) {
        return first();
    }

    // otherwise, set our internal iteration position (temporarily)
    // to the position passed in.  If this is the _beginning_ position,
    // then we can just use next() to get our return value

    int32_t result = 0;

    if (fSafeRevTable != NULL) {
        // new rule syntax
        utext_setNativeIndex(fText, offset);
        // move forward one codepoint to prepare for moving back to a
        // safe point.
        // this handles offset being between a supplementary character
        UTEXT_NEXT32(fText);
        // handlePrevious will move most of the time to < 1 boundary away
        handlePrevious(fSafeRevTable);
        int32_t result = next();
        while (result <= offset) {
            result = next();
        }
        return result;
    }
    if (fSafeFwdTable != NULL) {
        // backup plan if forward safe table is not available
        utext_setNativeIndex(fText, offset);
        UTEXT_PREVIOUS32(fText);
        // handle next will give result >= offset
        handleNext(fSafeFwdTable);
        // previous will give result 0 or 1 boundary away from offset,
        // most of the time
        // we have to
        int32_t oldresult = previous();
        while (oldresult > offset) {
            int32_t result = previous();
            if (result <= offset) {
                return oldresult;
            }
            oldresult = result;
        }
        int32_t result = next();
        if (result <= offset) {
            return next();
        }
        return result;
    }
    // otherwise, we have to sync up first.  Use handlePrevious() to back
    // up to a known break position before the specified position (if
    // we can determine that the specified position is a break position,
    // we don't back up at all).  This may or may not be the last break
    // position at or before our starting position.  Advance forward
    // from here until we've passed the starting position.  The position
    // we stop on will be the first break position after the specified one.
    // old rule syntax

    utext_setNativeIndex(fText, offset);
    if (offset==0 || 
        offset==1  && utext_getNativeIndex(fText)==0) {
        return next();
    }
    result = previous();

    while (result != BreakIterator::DONE && result <= offset) {
        result = next();
    }

    return result;
}
Beispiel #9
0
void DebuggerIPCServer::parseRequest(PFPSimDebugger::DebugMsg *request) {
  switch (request->type()) {
    case PFPSimDebugger::DebugMsg_Type_Run:
    {
      if (!run_called) {
        run_called = true;
        PFPSimDebugger::RunMsg msg;
        msg.ParseFromString(request->message());
        if (msg.has_time_ns()) {
          handleRun(stod(msg.time_ns()));
        } else {
          handleRun();
        }
      } else {
      // TODO(eric): this is a temporary fix for the double run message problem
        SimulationEndMessage *msg = new SimulationEndMessage();
        send(msg);
        delete msg;
      }
      break;
    }
    case PFPSimDebugger::DebugMsg_Type_GetCounter:
    {
      PFPSimDebugger::GetCounterMsg msg;
      msg.ParseFromString(request->message());
      handleGetCounter(msg);
      break;
    }
    case PFPSimDebugger::DebugMsg_Type_GetAllCounters:
    {
      handleGetAllCounters();
      break;
    }
    case PFPSimDebugger::DebugMsg_Type_SetBreakpoint:
    {
      PFPSimDebugger::SetBreakpointMsg msg;
      msg.ParseFromString(request->message());
      handleSetBreakpoint(msg);
      break;
    }
    case PFPSimDebugger::DebugMsg_Type_Continue:
    {
      PFPSimDebugger::ContinueMsg msg;
      msg.ParseFromString(request->message());
      if (msg.has_time_ns()) {
        handleContinue(stod(msg.time_ns()));  // alternative to stod?
      } else {
        handleContinue();
      }
      break;
    }
    case PFPSimDebugger::DebugMsg_Type_GetAllBreakpoints:
    {
      handleGetAllBreakpoints();
      break;
    }
    case PFPSimDebugger::DebugMsg_Type_RemoveBreakpoint:
    {
      PFPSimDebugger::RemoveBreakpointMsg msg;
      msg.ParseFromString(request->message());
      handleRemoveBreakpoint(msg);
      break;
    }
    case PFPSimDebugger::DebugMsg_Type_WhoAmI:
    {
      handleWhoAmI();
      break;
    }
    case PFPSimDebugger::DebugMsg_Type_Next:
    {
      handleNext();
      break;
    }
    case PFPSimDebugger::DebugMsg_Type_GetPacketList:
    {
      PFPSimDebugger::GetPacketListMsg msg;
      msg.ParseFromString(request->message());
      handleGetPacketList(msg);
      break;
    }
    case PFPSimDebugger::DebugMsg_Type_SetWatchpoint:
    {
      PFPSimDebugger::SetWatchpointMsg msg;
      msg.ParseFromString(request->message());
      handleSetWatchpoint(msg);
      break;
    }
    case PFPSimDebugger::DebugMsg_Type_GetAllWatchpoints:
    {
      handleGetAllWatchpoints();
      break;
    }
    case PFPSimDebugger::DebugMsg_Type_RemoveWatchpoint:
    {
      PFPSimDebugger::RemoveWatchpointMsg msg;
      msg.ParseFromString(request->message());
      handleRemoveWatchpoint(msg);
      break;
    }
    case PFPSimDebugger::DebugMsg_Type_Backtrace:
    {
      PFPSimDebugger::BacktraceMsg msg;
      msg.ParseFromString(request->message());
      handleBacktrace(msg);
      break;
    }
    case PFPSimDebugger::DebugMsg_Type_EnableDisableBreakpoint:
    {
      PFPSimDebugger::EnableDisableBreakpointMsg msg;
      msg.ParseFromString(request->message());
      handleEnableDisableBreakpoint(msg);
      break;
    }
    case PFPSimDebugger::DebugMsg_Type_EnableDisableWatchpoint:
    {
      PFPSimDebugger::EnableDisableWatchpointMsg msg;
      msg.ParseFromString(request->message());
      handleEnableDisableWatchpoint(msg);
      break;
    }
    case PFPSimDebugger::DebugMsg_Type_IgnoreModule:
    {
      PFPSimDebugger::IgnoreModuleMsg msg;
      msg.ParseFromString(request->message());
      handleIgnoreModule(msg);
      break;
    }
    case PFPSimDebugger::DebugMsg_Type_GetAllIgnoreModules:
    {
      handleGetAllIgnoreModules();
      break;
    }
    case PFPSimDebugger::DebugMsg_Type_GetSimulationTime:
    {
      handleGetSimulationTime();
      break;
    }
    case PFPSimDebugger::DebugMsg_Type_BreakOnPacketDrop:
    {
      PFPSimDebugger::BreakOnPacketDropMsg msg;
      msg.ParseFromString(request->message());
      handleBreakOnPacketDrop(msg);
      break;
    }
    case PFPSimDebugger::DebugMsg_Type_GetDroppedPackets:
    {
      handleGetDroppedPackets();
      break;
    }
    case PFPSimDebugger::DebugMsg_Type_CPCommand:
    {
      PFPSimDebugger::CPCommandMsg msg;
      msg.ParseFromString(request->message());
      handleCPCommand(msg);
      break;
    }
    case PFPSimDebugger::DebugMsg_Type_GetTableEntries:
    {
      handleGetTableEntries();
      break;
    }
    case PFPSimDebugger::DebugMsg_Type_GetPacketField:
    {
      PFPSimDebugger::GetPacketFieldMsg msg;
      msg.ParseFromString(request->message());
      handleGetPacketField(msg.id(), msg.field_name());
      break;
    }
    case PFPSimDebugger::DebugMsg_Type_GetRawPacket:
    {
      PFPSimDebugger::GetRawPacketMsg msg;
      msg.ParseFromString(request->message());
      handleGetRawPacket(msg.id());
      break;
    }
    case PFPSimDebugger::DebugMsg_Type_GetParsedPacket:
    {
      PFPSimDebugger::GetParsedPacketMsg msg;
      msg.ParseFromString(request->message());
      handleGetParsedPacket(msg.id());
      break;
    }
    case PFPSimDebugger::DebugMsg_Type_StartTracing:
    {
      PFPSimDebugger::StartTracingMsg msg;
      msg.ParseFromString(request->message());
      handleStartTracing(msg);
    }
    default: {
      sendRequestFailed();
    }
  }
}
 void operator()(RequestStreamFrame& requestFrame) {
   handleNext(requestFrame);
 }
 void operator()(RequestFnfFrame& requestFrame) {
   handleNext(requestFrame);
 }
 void operator()(RequestResponseFrame& requestFrame) {
   handleNext(requestFrame);
 }