void operator()( const RangeType& range ) const {
     for( typename RangeType::iterator i = range.begin(); i!=range.end(); ++i ) {
         int k = i->first.value_of();
         ASSERT( 0<=k && size_t(k)<n, NULL );
         ++array[k];
     }
 }
示例#2
0
Location::Location( std::string const& locationString )
{
    bool lastCharWasNonRangeChar = true;
    vector<string> rawRangeList;
    vector<string>::iterator iterRawRange;

    for ( auto const& character : locationString ) {
        if ( charSet_.find(character) != charSet_.end() ) {
            if ( lastCharWasNonRangeChar ) {
                rawRangeList.push_back("");
                iterRawRange = rawRangeList.end()-1;
                lastCharWasNonRangeChar = false;
            }
            *iterRawRange += character;
        }
        else lastCharWasNonRangeChar = true;
    }

    typedef boost::tokenizer<boost::char_separator<char> > tokenizer;

    string firstString,secondString;
    for ( auto const& rawRange : rawRangeList )
    {
        RangeType range;
        boost::char_separator<char> sep(".");
        tokenizer token(rawRange,sep);
        tokenizer::const_iterator iterToken = token.begin();

        if ( iterToken == token.end() )
            throw GeneHunterException("Location: error reading " + locationString);

        firstString = *iterToken;
        ++iterToken;

        // Single base location
        if ( iterToken == token.end() )
            secondString = firstString;
        else {
            secondString = *iterToken;
            ++iterToken;
        }

        if ( iterToken != token.end() )
            throw GeneHunterException("Location: error reading " + locationString);

        if ( firstString[0] == '<' ) {
            range.setOpenLowerBoundary(true);
            firstString.erase(0,1);
        }
        range.setLowerBoundary(firstString);

        if ( secondString[0] == '>' ) {
            range.setOpenUpperBoundary(true);
            secondString.erase(0,1);
        }
        range.setUpperBoundary(secondString);

        rangeSet_.insert(range);
    }
}
 void operator()( const RangeType& range ) const {
     for( typename RangeType::iterator i = range.begin(); i!=range.end(); ++i ) {
         int k = Value<ContainerType>::key(*i);
         ASSERT( k == Value<ContainerType>::get(*i), NULL );
         ASSERT( 0<=k && k<n, NULL ); 
         array[k]++;
     }
 }
 void operator()( const RangeType& range ) const {
     for( typename RangeType::iterator i = range.begin(); i!=range.end(); ++i ) {
         int k = i->first;
         ASSERT( k == i->second, NULL );
         ASSERT( 0<=k && k<n, NULL ); 
         array[k]++;
     }
 }
std::pair<int,int> CheckRecursiveRange(RangeType range) {
    std::pair<int,int> sum(0, 0); // count, sum
    for( Iterator i = range.begin(), e = range.end(); i != e; ++i ) {
        ++sum.first; sum.second += Value<ContainerType>::get(*i);
    }
    if( range.is_divisible() ) {
        RangeType range2( range, tbb::split() );
        std::pair<int,int> sum1 = CheckRecursiveRange<ContainerType,Iterator, RangeType>( range );
        std::pair<int,int> sum2 = CheckRecursiveRange<ContainerType,Iterator, RangeType>( range2 );
        sum1.first += sum2.first; sum1.second += sum2.second;
        ASSERT( sum == sum1, "Mismatched ranges after division");
    }
    return sum;
}
template<class DomainItemType, class RangeType> Domain* createItemDomain2(const QSqlRecord& rec, const Resource& resource){
    ItemDomain<DomainItemType> *itemdom = new ItemDomain<DomainItemType>(resource);
    const ConnectorFactory *factory = kernel()->factory<ConnectorFactory>("ilwis::ConnectorFactory");
    ConnectorInterface *connector = factory->createFromResource<>(resource, "internal");
    itemdom->setConnector(connector,IlwisObject::cmINPUT, IOOptions());
    itemdom->createTime(Time::now());
    itemdom->modifiedTime(Time::now());
    itemdom->fromInternal(rec);
    itemdom->name(resource.name());
    RangeType range ;
    InternalDatabaseConnection itemstable;
    QString query = "Select * from domainitems where code='" + resource.code() + "'";
    if (itemstable.exec(query) ) {
        while ( itemstable.next()){
            QSqlRecord rec = itemstable.record();
            range << rec.value("itemname").toString() + "|" + rec.value("itemcode").toString() + "|" + rec.value("itemdescription").toString();
        }
        itemdom->range(range.clone());
    }
    return itemdom;
}
void PlayDrillCommandClass::parse(StepContainer& stepContainer, const StringArray& steps, int& indexStepArray)
{
    StringArray params;
    String step, param, paramChoicePercentage;
    Step* newStep= NULL;
    
    int percentageSum= 0;
    
    while (indexStepArray < steps.getUsedElems())
    {
        step= steps[indexStepArray++].c_str();
		if (step.length() == 0) {
			return;
		}
        
        split(step, PARAM_SEP, params);

        volatile int     paramsIdx= 0; // one time idx was corrupted and led to wrong parsing. Let's try volatile.
    
        if (params.getUsedElems() == 0) {
            LOGF4(ERR_PREFIX, F("Unexpected param string:'"), step.c_str(), F("'"));
            return;
        }
    
        param= params[paramsIdx++].c_str();
        paramChoicePercentage= params[paramsIdx++].c_str();
        
        if (param.equals(F("wait"))) {
            WaitStep* waitStep= new WaitStep();
            param= params[paramsIdx++].c_str();
            waitStep->setWaitAfterMs(param.toInt());
            param= params[paramsIdx++].c_str();
            waitStep->setSynchronous(param.toInt() != 0);
            
            newStep= waitStep;
        }
		else if (param.equals(F("waitForHit"))) {
			WaitForHitStep* waitStep= new WaitForHitStep();
			param= params[paramsIdx++].c_str();
			waitStep->setTargetIndex(param.toInt());
			
			newStep= waitStep;
		}
        else if (param.equals(F("sound"))) {
            SoundStep* soundStep= new SoundStep();
            param= params[paramsIdx++].c_str();
            soundStep->setFrequency(param.toInt());
            param= params[paramsIdx++].c_str();
            soundStep->setDurationMs(param.toInt());
            
            newStep= soundStep;
        }
        else if (param.equals(F("speed"))) {
            RangeType range;
            SpeedStep* speedStep= new SpeedStep();
            param= params[paramsIdx++].c_str();
            range.initialize(param);
            speedStep->setSpeed(range);
            
            newStep= speedStep;
        }
        else if (param.equals(F("pos"))) {
            RangeType range;
            PositionStep* posStep= new PositionStep();
            param= params[paramsIdx++].c_str();
            range.initialize(param);
            posStep->setPosition(range);
            
            newStep= posStep;
        }
        else if (param.equals(F("angle"))) {
            RangeType range;
            AngleStep* posStep= new AngleStep();
            param= params[paramsIdx++].c_str();
            range.initialize(param);
            posStep->setAngle(range);
            
            newStep= posStep;
        }
        else if (param.equals(F("goto"))) {
            // goto/<targetIndex>/<maxLoopCount>
            GotoStep* gotoStep= new GotoStep();
            param= params[paramsIdx++].c_str();
            gotoStep->setTargetIndex(param.toInt());
            param= params[paramsIdx++].c_str();
            gotoStep->setMaxLoopCount(param.toInt());
            
            newStep= gotoStep;
        }
        else if (param.equals(F("choices"))) {
            ChoicesStep* choicesStep= new ChoicesStep();
            
            parse(*choicesStep, steps, indexStepArray);

            newStep= choicesStep;
        }
        else if (param.equals(F("choicesEOF"))) {
            return;
        }
        else if (param.equals(F("play"))) {
            RangeType range;
            // play/<speedRange>/<posRange>/<waitAfterMs>/<noOfBallsRange>
            
            PlayBallStep* playStep= new PlayBallStep();
            
            // speedRange
            {
                param= params[paramsIdx++].c_str();
                
                range.initialize(param);
                playStep->setSpeed(range);
            }
            
            // posRange
            {
                param= params[paramsIdx++].c_str();
                
                range.initialize(param);
                playStep->setPos(range);
            }

            // waitAfterMs
            {
                param= params[paramsIdx++].c_str();
                playStep->setWaitAfterMs(param.toInt());
            }
            
            // noOfBallsRange
            {
                param= params[paramsIdx++].c_str();
                
                range.initialize(param);
                playStep->setNoOfBalls(range);
            }

            // angle
            {
                param= params[paramsIdx++].c_str();
                
                range.initialize(param);
                playStep->setAngle(range);
            }
            newStep= playStep;
        }
        else if (param.length() > 0){
            LOGF4(ERR_PREFIX, F("Unexpected step: '"), param.c_str(), F("'"));
        }
        
        if (newStep != NULL) {
            percentageSum += paramChoicePercentage.toInt();
            newStep->setChoiceValue(percentageSum);
            
            stepContainer.add(newStep);
            newStep= NULL;
        }
    }
        
    LOGF("EOF Parsing");
}