bool FaceIterator::operator ==(const FaceIterator &other) const
{
    if(isAtEnd() && other.isAtEnd())
        return true;

    if(isAtEnd() || other.isAtEnd())
        return false;

    return 
        (*static_cast<const Inherited *>(this) == other              ) &&
        _actPrimIndex                          == other._actPrimIndex;
}
Example #2
0
bool HtmlScraper::findNextElement( const String & elementName, const String & content )
{
	if(isAtEnd())
		return false;

	int currpos = _position;

	while(currpos >= 0)
	{
		// Find element
		int pos = _html.indexOf(currpos + 1, "<" + elementName);
		if(pos < 0)
			return false;

		currpos = pos;

		int endpos = _html.indexOf(pos, ">");
		if(endpos < 0)
			return false;

		// Check if content matches
		String element = _html.substring(pos + elementName.length() + 1, endpos);
		if(element.indexOf(content) >= 0)
			break;
	}

	_position = currpos;
	return true;
}
//----------------------------------------------------------------------------//
void Scrollbar::setConfig(const float* const document_size,
                          const float* const page_size,
                          const float* const step_size,
                          const float* const overlap_size,
                          const float* const position)
{
    const bool reset_max_position = d_endLockPosition && isAtEnd();
    bool config_changed = false;
    bool position_changed = false;

    if (document_size && (d_documentSize != *document_size))
    {
        d_documentSize = *document_size;
        config_changed = true;
    }

    if (page_size && (d_pageSize != *page_size))
    {
        d_pageSize = *page_size;
        config_changed = true;
    }

    if (step_size && (d_stepSize != *step_size))
    {
        d_stepSize = *step_size;
        config_changed = true;
    }

    if (overlap_size && (d_overlapSize != *overlap_size))
    {
        d_overlapSize = *overlap_size;
        config_changed = true;
    }

    if (position)
        position_changed = setScrollPosition_impl(*position);
    else if (reset_max_position)
        position_changed = setScrollPosition_impl(getMaxScrollPosition());

    // _always_ update the thumb to keep things in sync.  (though this
    // can cause a double-trigger of EventScrollPositionChanged, which
    // also happens with setScrollPosition anyway).
    updateThumb();

    //
    // Fire appropriate events based on actions we took.
    //
    if (config_changed)
    {
        WindowEventArgs args(this);
        onScrollConfigChanged(args);
    }

    if (position_changed)
    {
        WindowEventArgs args(this);
        onScrollPositionChanged(args);
    }
}
Example #4
0
bool Scanner::match(char expected)
{
	if (isAtEnd()) return false;
	if (source_[current_] != expected) return false;

	current_++;
	return true;
}
Example #5
0
bool Parser::parse(char &_c){
    if(!isAtEnd() && !isspace(*pb)){
        _c = *pb;
        ++pb;
        return true;
    }
    return false;
}
Example #6
0
void Scanner::string()
{
	while (peek() != '"' && !isAtEnd())
	{
		if (peek() == '\n') line_++;
		advance();
	}

	if (isAtEnd())
	{
		error(line_, "Unterminated string");
	}

	advance();

	auto value = source_.substr(start_ + 1, current_ + 1);
	addToken(STRING, value);
}
unsigned int DispenserControl::goToEnd ()
{
    unsigned int stepsTaken = 0;
    while ( !isAtEnd () )
    {
        stepsTaken += moveDispenserHead ( NUMBER_OF_STEPS_PER_REV, END );
    }
    return stepsTaken;
}
Example #8
0
	void visit(const SortTable* table) {
		Assert(isTheoryOpen());
		output() << "{ ";
		if (table->isRange()) {
			output() << print(table->first()) << ".." << print(table->last());
		} else {
			auto it = table->sortBegin();
			if (not it.isAtEnd()) {
				output() << print((*it));
				++it;
				for (; not it.isAtEnd(); ++it) {
					CHECKTERMINATION;
					output() << "; " << print((*it));
				}
			}
		}
		output() << " }";
	}
Example #9
0
std::vector<Definition*> SplitDefinitions::split(Structure* structure, UniqueNames<Rule*>& uniqueRuleNames){
	auto temptheo = splittheo->clone();
	auto models = ModelExpansion::doModelExpansion(temptheo, structure, NULL, NULL, { })._models;
	if (models.size() != 1) {
		throw IdpException("Invalid code path: no solution to definition splitting problem");
	}
	temptheo->recursiveDelete();

	auto splitmodel = models[0];
	splitmodel->makeTwoValued();

	auto sameDefInter = splitmodel->inter(sameDef);

	std::set<const DomainElement*> rulesDone;
	auto allrules = structure->inter(structure->vocabulary()->sort("rule"));

	std::vector<Definition*> result;
	for(auto ruleIt = allrules->begin(); not ruleIt.isAtEnd(); ++ruleIt){
		auto currentRuleName = (*ruleIt)[0];
		if(contains(rulesDone, currentRuleName)){
			continue;
		}
		Assert(currentRuleName->type() == DET_INT);

		auto currentDef = new Definition();
		result.push_back(currentDef);

		auto iterator = sameDefInter->ct()->begin();
		for (; not iterator.isAtEnd(); ++iterator) {
			auto currentTuple = *iterator;
			Assert(currentTuple.size() == 2);
			if (currentTuple[0] == currentRuleName) {
				Assert(currentTuple[1]->type() == DET_INT);
				auto otherRule = uniqueRuleNames.getOriginal(currentTuple[1]->value()._int);
				currentDef->add(otherRule);
				rulesDone.insert(currentTuple[1]);
			}
		}
	}

	delete(splitmodel);
	return result;
}
Example #10
0
bool HtmlScraper::gotoNextElement()
{
	if(isAtEnd())
		return false;
	int pos = _html.indexOfChar(_position + 1, '<');
	if(pos < 0)
		return false;
	_position = pos;
	return true;
}
Example #11
0
std::vector<Token> Scanner::scanTokens()
{
	while (!isAtEnd())
	{
		start_ = current_;
		scanToken();
	}
	tokens_.push_back(Token(EOF_T, "", "", line_));
	return tokens_;
}
Example #12
0
void VoiceboxDialog::checkFinalMessage() {
  if (isAtEnd()) {
    if (!edited_msgs.empty()) {
      enqueueBack("no_more_msg");
      state = PromptTurnover;
    } else {
      state = Bye;   
      enqueueBack("no_msg");
    }
  }
}
Example #13
0
void Scanner::scanToken()
{
	char c = advance();
	switch (c) {
	case '(': addToken(LEFT_PAREN); break;
	case ')': addToken(RIGHT_PAREN); break;
	case '{': addToken(LEFT_BRACE); break;
	case '}': addToken(RIGHT_BRACE); break;
	case ',': addToken(COMMA); break;
	case '.': addToken(DOT); break;
	case '-': addToken(MINUS); break;
	case '+': addToken(PLUS); break;
	case ';': addToken(SEMICOLON); break;
	case '*': addToken(STAR); break;
	case '!': addToken(match('=') ? BANG_EQUAL : BANG); break;
	case '=': addToken(match('=') ? EQUAL_EQUAL : EQUAL); break;
	case '<': addToken(match('=') ? LESS_EQUAL : LESS); break;
	case '>': addToken(match('=') ? GREATER_EQUAL : GREATER); break;
	case '/':
		if (match('/'))
		{
			while (peek() != '\n' && !isAtEnd()) advance();
		}
		else
		{
			addToken(SLASH);
		}
		break;
	case ' ':
	case '\r':
	case '\t':
		// Ignore whitespace.                      
		break;

	case '\n':
		line_++;
		break;
	case '"': string(); break;
	default:
		if (isDigit(c))
		{
			number();
		}
		else if (isAlpha(c))
		{
			identifier();
		}
		else
		{
			error(line_, "Unexpected character.");
		}
		break;
	}
}
Example #14
0
bool HtmlScraper::findNextElement( const String & elementName )
{
	if(isAtEnd())
		return false;

	int pos = _html.indexOf(_position + 1, "<" + elementName);
	if(pos < 0)
		return false;
	_position = pos;
	return true;
}
Example #15
0
static void test_peeking_front_buffered_stream(skiatest::Reporter* r,
                                               const SkStream& original,
                                               size_t bufferSize) {
    std::unique_ptr<SkStream> dupe(original.duplicate());
    REPORTER_ASSERT(r, dupe != nullptr);
    auto bufferedStream = SkFrontBufferedStream::Make(std::move(dupe), bufferSize);
    REPORTER_ASSERT(r, bufferedStream != nullptr);

    size_t peeked = 0;
    for (size_t i = 1; !bufferedStream->isAtEnd(); i++) {
        const size_t unpeekableBytes = compare_peek_to_read(r, bufferedStream.get(), i);
        if (unpeekableBytes > 0) {
            // This could not have returned a number greater than i.
            REPORTER_ASSERT(r, unpeekableBytes <= i);

            // We have reached the end of the buffer. Verify that it was at least
            // bufferSize.
            REPORTER_ASSERT(r, peeked + i - unpeekableBytes >= bufferSize);
            // No more peeking is supported.
            break;
        }
        peeked += i;
    }

    // Test that attempting to peek beyond the length of the buffer does not prevent rewinding.
    bufferedStream = SkFrontBufferedStream::Make(original.duplicate(), bufferSize);
    REPORTER_ASSERT(r, bufferedStream != nullptr);

    const size_t bytesToPeek = bufferSize + 1;
    SkAutoMalloc peekStorage(bytesToPeek);
    SkAutoMalloc readStorage(bytesToPeek);

    for (size_t start = 0; start <= bufferSize; start++) {
        // Skip to the starting point
        REPORTER_ASSERT(r, bufferedStream->skip(start) == start);

        const size_t bytesPeeked = bufferedStream->peek(peekStorage.get(), bytesToPeek);
        if (0 == bytesPeeked) {
            // Peeking should only fail completely if we have read/skipped beyond the buffer.
            REPORTER_ASSERT(r, start >= bufferSize);
            break;
        }

        // Only read the amount that was successfully peeked.
        const size_t bytesRead = bufferedStream->read(readStorage.get(), bytesPeeked);
        REPORTER_ASSERT(r, bytesRead == bytesPeeked);
        REPORTER_ASSERT(r, !memcmp(peekStorage.get(), readStorage.get(), bytesPeeked));

        // This should be safe to rewind.
        REPORTER_ASSERT(r, bufferedStream->rewind());
    }
}
Example #16
0
/*! Helper function to reset all state to the beginning of a new primitive.
    Also skips non-polygonal primitives(lines, points) and primtiives with less
    than 3 points.
*/
void EdgeIterator::startPrim(void)
{
    // already at end?
    if(isAtEnd())
        return;

    _edgePntIndex[0] = 0;
    _edgePntIndex[1] = 1;
    _actPrimIndex = 2;
    
    // loop until you find a useful primitive or run out
    while(! isAtEnd())
    {
        switch(getType())
        {           
        case GL_LINES:                              
        case GL_LINE_STRIP: 
        case GL_LINE_LOOP:      if(PrimitiveIterator::getLength() >= 2)
                                   return;
                                break; 
        case GL_POINTS:         // non-line types: (currently) ignored
        case GL_TRIANGLES: 
        case GL_TRIANGLE_STRIP:
        case GL_TRIANGLE_FAN:   
        case GL_POLYGON:        
        case GL_QUADS:
        case GL_QUAD_STRIP:
                                break;
        default:            SWARNING << "EdgeIterator::startPrim: encountered " 
                                     << "unknown primitive type " 
                                     << getType()
                                     << ", ignoring!" << std::endl;
                            break;
        }   
        
        ++(static_cast<PrimitiveIterator&>(*this));   
    }       
}
Example #17
0
const EdgeIterator &EdgeIterator::operator++()
{
    // already at end?
    if(isAtEnd())
        return *this;
    
    ++_edgeIndex;

    // at end of primitive?
    if(_actPrimIndex >= PrimitiveIterator::getLength() ||
	   getType() == GL_LINE_STRIP ||
	   getType() == GL_LINE_LOOP    )  // TODO: add GL_POLYLINE here ?!?!
    {
        ++(static_cast<PrimitiveIterator&>(*this));
        
        startPrim();
        
        return *this;
    }

    switch(getType())
    {
    case GL_LINES:          _edgePntIndex[0] = _actPrimIndex++;
                            _edgePntIndex[1] = _actPrimIndex++;
                            break;
#if 0 // probably to be implemented
                            
    case GL_POLYGON:        TODO
                            break;  
    case GL_TRIANGLES:      TODO
                            break;
    case GL_QUAD_STRIP:     TODO
                            break;
    case GL_TRIANGLE_STRIP: TODO
                            break;
    case GL_TRIANGLE_FAN:   TODO
                            break;
    case GL_QUADS:          TODO
                            break;
#endif // probably to be implemented
    default:                SWARNING << "EdgeIterator::++: encountered " 
                                      << "unknown primitive type " 
                                      << getType()
                                      << ", ignoring!" << std::endl;
                            startPrim();
                            break;
    }           

    return *this;
}
Example #18
0
bool checkEquality(Table one, Table two){
	if(one==two){
		return true;
	}
	if(one->size()!=two->size()){ // TODO infinity?
		return false;
	}
	for(auto i = one->begin(); not i.isAtEnd(); ++i){
		if(not two->contains(*i)){
			return false;
		}
	}
	return true;
}
//----------------------------------------------------------------------------//
void Scrollbar::setPageSize(float page_size)
{
    if (d_pageSize != page_size)
    {
        const bool reset_max_position = d_endLockPosition && isAtEnd();

        d_pageSize = page_size;

        if (reset_max_position)
            setScrollPosition(getMaxScrollPosition());
        else
            updateThumb();

        WindowEventArgs args(this);
        onScrollConfigChanged(args);
    }
}
unsigned int DispenserControl::moveDispenserHead ( unsigned int steps, Direction direction )
{
    int delta = 1;
    if ( direction == HOME )
    {
        delta = -delta; // reduce steps moving towards Home
    }

    dispenserDirPin = direction;

    bool stopMotorMovement = false;
    unsigned int stepsTaken = 0;

    inMotion = true;
    while ( ( !stopMotorMovement ) && ( stepsTaken < steps ) )
    {
        testLimitSwitches ();

        if ( isAtHome () && ( direction == HOME ) )
        {
            stopMotorMovement = true;
        }
        else if ( isAtEnd () && ( direction == END ) )
        {
            stopMotorMovement = true;
        }

        if ( !stopMotorMovement )
        {
            dispenserStepPin = ON;
            dispenserStepPin = OFF;
            stepsTaken++;
            dispenserCurrentPosition += delta;
            wait_us ( STEPPER_MOTOR_DELAY_MICRO_SECS ); // To prevent motor from stalling
        }
    }
    inMotion = false;

    return stepsTaken;
}
Example #21
0
void VoiceboxDialog::curMsgOP(const char* op) {
  if (!isAtEnd()) {
    string msgname = cur_msg->name;
    AmArg di_args,ret;
    di_args.push(domain.c_str());  // domain
    di_args.push(user.c_str());    // user
    di_args.push(msgname.c_str()); // msg name
    
    msg_storage->invoke(op,di_args,ret);  

    if ((ret.size() < 1)
	|| !isArgInt(ret.get(0))) {
      ERROR("%s returned wrong result type\n", op);
      return;
    }
    
    int errcode = ret.get(0).asInt();
    if (errcode != MSG_OK) {
      ERROR("%s error: %s\n", 
	    op, MsgStrError(errcode));
    }
  }  
}
Example #22
0
 InStream::operator bool() const
 {
     return !isAtEnd();
 }
/*! Helper function to reset all state to the beginning of a new primitive.
    Also skips non-polygonal primitives(lines, points) and primtiives with less
    than 3 points.
*/
void FaceIterator::startPrim(void)
{
    // already at end?
    if(isAtEnd())
        return;

    _facePntIndex[0] = 0;
    _facePntIndex[1] = 1;
    _facePntIndex[2] = 2;
    _facePntIndex[3] = -1;
    _actPrimIndex = 3;
    
    // loop until you find a useful primitive or run out
    while(! isAtEnd())
    {
        switch(getType())
        {
        case GL_POINTS:     // non-polygon types: ignored
        case GL_LINES:
        case GL_LINE_STRIP: 
        case GL_LINE_LOOP:  
                            break;
        case GL_TRIANGLES: 
        case GL_TRIANGLE_STRIP:
        case GL_TRIANGLE_FAN:   
                                if(PrimitiveIterator::getLength() >= 3)
                                    return;
                                break;
        case GL_POLYGON:        switch(PrimitiveIterator::getLength())
                                {
                                case 0: 
                                case 1: 
                                case 2: 
                                            break;
                                case 4:
                                            _facePntIndex[3] = _actPrimIndex++;     
                                            return;
                                default:
                                            return;
                                }
                                break;
        case GL_QUADS:          if(PrimitiveIterator::getLength() >= 4)
                                {
                                    _facePntIndex[3] = _actPrimIndex++;                         
                                    return;
                                }
                                break;
        case GL_QUAD_STRIP:         if(PrimitiveIterator::getLength() >= 4)
                                {
                                    _facePntIndex[3] = _facePntIndex[2];                        
                                    _facePntIndex[2] = _actPrimIndex++;                         
                                    return;
                                }
                                break;
        default:            SWARNING << "FaceIterator::startPrim: encountered " 
                                     << "unknown primitive type " 
                                     << getType()
                                     << ", ignoring!" << std::endl;
                            break;
        }   
        
        ++(static_cast<PrimitiveIterator&>(*this));   
    }       
}
/*! The increment operator steps the iterator to the next face. If it is
    already beyond the last face it does not change.
    
    \dev This is the central function of the whole iterator. It changes 
    _facePntIndex to contain the data for the next face, depending on the type
    of the currently active primitive and steps to the next primitive if the
    current one is exhausted. The only tricky part is the left/right swap for
    triangle strips, the rest is pretty simple. \enddev
*/
void FaceIterator::operator++()
{
    // already at end?
    if(isAtEnd())
        return;
    
    ++_faceIndex;

    // at end of primitive?
    if(_actPrimIndex >= PrimitiveIterator::getLength())
    {
        ++(static_cast<PrimitiveIterator&>(*this));
        
        startPrim();
        
        return;
    }

    switch(getType())
    {
    case GL_TRIANGLES:      _facePntIndex[0] = _actPrimIndex++;
                            _facePntIndex[1] = _actPrimIndex++;
                            _facePntIndex[2] = _actPrimIndex++;
                            _facePntIndex[3] = -1;
                            break;
    case GL_QUAD_STRIP:     _facePntIndex[0] = _facePntIndex[3];
                            _facePntIndex[1] = _facePntIndex[2];
                            _facePntIndex[3] = _actPrimIndex++;
                            _facePntIndex[2] = _actPrimIndex++;
                            break;
    case GL_TRIANGLE_STRIP: if(_actPrimIndex & 1)
                            {
                                _facePntIndex[0] = _facePntIndex[2];
                            }
                            else
                            {
                                _facePntIndex[1] = _facePntIndex[2];
                            }                           
                            _facePntIndex[2] = _actPrimIndex++;
                            
                            if(getPositionIndex(0) == getPositionIndex(1) ||
                               getPositionIndex(0) == getPositionIndex(2) ||
                               getPositionIndex(1) == getPositionIndex(2))
                            {
                                --_faceIndex;
                                ++(*this);
                            }
                               
                            break;
    case GL_POLYGON:
    case GL_TRIANGLE_FAN:   _facePntIndex[1] = _facePntIndex[2];
                            _facePntIndex[2] = _actPrimIndex++;
                            break;
    case GL_QUADS:          _facePntIndex[0] = _actPrimIndex++;
                            _facePntIndex[1] = _actPrimIndex++;
                            _facePntIndex[2] = _actPrimIndex++;
                            _facePntIndex[3] = _actPrimIndex++;
                            break;
    default:                SWARNING << "FaceIterator::++: encountered " 
                                      << "unknown primitive type " 
                                      << getType()
                                      << ", ignoring!" << std::endl;
                            startPrim();
                            break;
    }           
}
void ImportedModulesEnumerator::next()
{
    ASSERT(!isAtEnd());
    ++m_descriptor;
}
Example #26
0
DEF_TEST(FILEStreamWithOffset, r) {
    if (GetResourcePath().isEmpty()) {
        return;
    }

    SkString filename = GetResourcePath("images/baby_tux.png");
    SkFILEStream stream1(filename.c_str());
    if (!stream1.isValid()) {
        ERRORF(r, "Could not create SkFILEStream from %s", filename.c_str());
        return;
    }
    REPORTER_ASSERT(r, stream1.hasLength());
    REPORTER_ASSERT(r, stream1.hasPosition());

    // Seek halfway through the file. The second SkFILEStream will be created
    // with the same filename and offset and therefore will treat that offset as
    // the beginning.
    const size_t size = stream1.getLength();
    const size_t middle = size / 2;
    if (!stream1.seek(middle)) {
        ERRORF(r, "Could not seek SkFILEStream to %lu out of %lu", middle, size);
        return;
    }
    REPORTER_ASSERT(r, stream1.getPosition() == middle);

    FILE* file = sk_fopen(filename.c_str(), kRead_SkFILE_Flag);
    if (!file) {
        ERRORF(r, "Could not open %s as a FILE", filename.c_str());
        return;
    }

    if (fseek(file, (long) middle, SEEK_SET) != 0) {
        ERRORF(r, "Could not fseek FILE to %lu out of %lu", middle, size);
        return;
    }
    SkFILEStream stream2(file);

    const size_t remaining = size - middle;
    SkAutoTMalloc<uint8_t> expected(remaining);
    REPORTER_ASSERT(r, stream1.read(expected.get(), remaining) == remaining);

    auto test_full_read = [&r, &expected, remaining](SkStream* stream) {
        SkAutoTMalloc<uint8_t> actual(remaining);
        REPORTER_ASSERT(r, stream->read(actual.get(), remaining) == remaining);
        REPORTER_ASSERT(r, !memcmp(expected.get(), actual.get(), remaining));

        REPORTER_ASSERT(r, stream->getPosition() == stream->getLength());
        REPORTER_ASSERT(r, stream->isAtEnd());
    };

    auto test_rewind = [&r, &expected, remaining](SkStream* stream) {
        // Rewind goes back to original offset.
        REPORTER_ASSERT(r, stream->rewind());
        REPORTER_ASSERT(r, stream->getPosition() == 0);
        SkAutoTMalloc<uint8_t> actual(remaining);
        REPORTER_ASSERT(r, stream->read(actual.get(), remaining) == remaining);
        REPORTER_ASSERT(r, !memcmp(expected.get(), actual.get(), remaining));
    };

    auto test_move = [&r, &expected, size, remaining](SkStream* stream) {
        // Cannot move to before the original offset.
        REPORTER_ASSERT(r, stream->move(- (long) size));
        REPORTER_ASSERT(r, stream->getPosition() == 0);

        REPORTER_ASSERT(r, stream->move(std::numeric_limits<long>::min()));
        REPORTER_ASSERT(r, stream->getPosition() == 0);

        SkAutoTMalloc<uint8_t> actual(remaining);
        REPORTER_ASSERT(r, stream->read(actual.get(), remaining) == remaining);
        REPORTER_ASSERT(r, !memcmp(expected.get(), actual.get(), remaining));

        REPORTER_ASSERT(r, stream->isAtEnd());
        REPORTER_ASSERT(r, stream->getPosition() == remaining);

        // Cannot move beyond the end.
        REPORTER_ASSERT(r, stream->move(1));
        REPORTER_ASSERT(r, stream->isAtEnd());
        REPORTER_ASSERT(r, stream->getPosition() == remaining);
    };

    auto test_seek = [&r, &expected, middle, remaining](SkStream* stream) {
        // Seek to an arbitrary position.
        const size_t arbitrary = middle / 2;
        REPORTER_ASSERT(r, stream->seek(arbitrary));
        REPORTER_ASSERT(r, stream->getPosition() == arbitrary);
        const size_t miniRemaining = remaining - arbitrary;
        SkAutoTMalloc<uint8_t> actual(miniRemaining);
        REPORTER_ASSERT(r, stream->read(actual.get(), miniRemaining) == miniRemaining);
        REPORTER_ASSERT(r, !memcmp(expected.get() + arbitrary, actual.get(), miniRemaining));
    };

    auto test_seek_beginning = [&r, &expected, remaining](SkStream* stream) {
        // Seek to the beginning.
        REPORTER_ASSERT(r, stream->seek(0));
        REPORTER_ASSERT(r, stream->getPosition() == 0);
        SkAutoTMalloc<uint8_t> actual(remaining);
        REPORTER_ASSERT(r, stream->read(actual.get(), remaining) == remaining);
        REPORTER_ASSERT(r, !memcmp(expected.get(), actual.get(), remaining));
    };

    auto test_seek_end = [&r, remaining](SkStream* stream) {
        // Cannot seek past the end.
        REPORTER_ASSERT(r, stream->isAtEnd());

        REPORTER_ASSERT(r, stream->seek(remaining + 1));
        REPORTER_ASSERT(r, stream->isAtEnd());
        REPORTER_ASSERT(r, stream->getPosition() == remaining);

        const size_t middle = remaining / 2;
        REPORTER_ASSERT(r, stream->seek(middle));
        REPORTER_ASSERT(r, !stream->isAtEnd());
        REPORTER_ASSERT(r, stream->getPosition() == middle);

        REPORTER_ASSERT(r, stream->seek(remaining * 2));
        REPORTER_ASSERT(r, stream->isAtEnd());
        REPORTER_ASSERT(r, stream->getPosition() == remaining);

        REPORTER_ASSERT(r, stream->seek(std::numeric_limits<long>::max()));
        REPORTER_ASSERT(r, stream->isAtEnd());
        REPORTER_ASSERT(r, stream->getPosition() == remaining);
    };


    std::function<void (SkStream* stream, bool recurse)> test_all;
    test_all = [&](SkStream* stream, bool recurse) {
        REPORTER_ASSERT(r, stream->getLength() == remaining);
        REPORTER_ASSERT(r, stream->getPosition() == 0);

        test_full_read(stream);
        test_rewind(stream);
        test_move(stream);
        test_seek(stream);
        test_seek_beginning(stream);
        test_seek_end(stream);

        if (recurse) {
            // Duplicate shares the original offset.
            auto duplicate = stream->duplicate();
            if (!duplicate) {
                ERRORF(r, "Failed to duplicate the stream!");
            } else {
                test_all(duplicate.get(), false);
            }

            // Fork shares the original offset, too.
            auto fork = stream->fork();
            if (!fork) {
                ERRORF(r, "Failed to fork the stream!");
            } else {
                REPORTER_ASSERT(r, fork->isAtEnd());
                REPORTER_ASSERT(r, fork->getLength() == remaining);
                REPORTER_ASSERT(r, fork->rewind());

                test_all(fork.get(), false);
            }
        }
    };

    test_all(&stream2, true);
}
Example #27
0
char Scanner::peek() const
{
	if (isAtEnd()) return '\0';
	return source_[current_];
}
Example #28
0
void Parser::skipWhites(){
    while(!isAtEnd() && isspace(*pb)){
        ++pb;
    }
}
Example #29
0
void VoiceboxDialog::onDtmf(int event, int duration)
{
  DBG("VoiceboxDialog::onDtmf: event %d duration %d\n", 
      event, duration);
  
  if (EnteringPin == state) {
    play_list.flush();
    // check pin
    if (event<10) {
      entered_pin += int2str(event);
      DBG("added '%s': PIN is now '%s'.\n", 
	  int2str(event).c_str(), entered_pin.c_str());
    }
    if (event==10 || event==11) { // # and * keys
      if (entered_pin.compare(pin)) { // wrong pin
	entered_pin.clear();
	play_list.flush();
	prompts->addToPlaylist("pin_prompt", (long)this, play_list, true);
      }
    }
    if (!entered_pin.compare(pin)) {
      state = Prompting;
      doMailboxStart();
    }
  }

  if (MsgAction == state) {      
    if ((unsigned int)event == VoiceboxFactory::repeat_key) {
      play_list.flush();
      repeatCurMessage();
    } else if ((unsigned int)event == VoiceboxFactory::save_key) {
      state = Prompting;
      play_list.flush();
      enqueueBack("msg_saved");
      saveCurMessage();
      edited_msgs.push_back(*cur_msg);
      advanceMessage();
      checkFinalMessage();
      if (!isAtEnd()) {
	enqueueCurMessage();
      }
    } else if ((unsigned int)event == VoiceboxFactory::delete_key) { 
      state = Prompting;
      play_list.flush();
      enqueueBack("msg_deleted");
      deleteCurMessage(); 
      advanceMessage();
      checkFinalMessage();
      if (!isAtEnd()) {
	enqueueCurMessage();
      }
    } else if ((unsigned int)event == VoiceboxFactory::startover_key) { 
      if (isAtLastMsg()) {
	edited_msgs.push_back(*cur_msg);
	state = Prompting;
	mergeMsglists();
	gotoFirstSavedMessage();
	enqueueCurMessage();
      }
    }
  }

  if (PromptTurnover == state) {      
    if (((unsigned int)event == VoiceboxFactory::startover_key)
	&& (isAtEnd())) {
      state = Prompting;
      mergeMsglists();
      gotoFirstSavedMessage();
      enqueueCurMessage();
    }
  }
 
}
Example #30
0
bool Interval::decrementCounters() {

	decrement();
	return isAtEnd();
}