Ejemplo n.º 1
0
static void parseAVar(bool diamond){
    // it's a valid type
    char buf[256];
    bool autoRange=false;
    float mn=0,mx=0;
    int size;
    RawDataBuffer *b;
    tok.getnextident(buf); // get name
    
    // if diamond, get topic and datum index
    char tname[256];
    int idx;
#if DIAMOND
    if(diamond){
        tok.getnextcheck(T_TOPIC);
        tok.getnextident(tname);
        tok.getnextcheck(T_COMMA);
        idx = tok.getnextint();
        diamondMap[DiamondTopicKey(tname,idx)]=QString(buf);
        diamondapparatus::subscribe(tname);
        if(!diamondSet.contains(tname))
            diamondSet.insert(tname);
    }
#endif    
    size = tok.getnextint(); // and size
    // now get the range
    tok.getnextcheck(T_RANGE);
    switch(tok.getnext()){
    case T_INT:
    case T_FLOAT:
        mn = tok.getfloat();
        tok.getnextcheck(T_TO);
        mx = tok.getnextfloat();
        break;
    case T_AUTO:
        autoRange=true;
        break;
    default:
        throw UnexpException(&tok,"number or 'auto'");
        break;
    }
    b=createVar(T_NAMEFLOAT,buf,size,mn,mx);
    if(autoRange)
        ((DataBuffer<float>*)b)->setAutoRange();
}
Ejemplo n.º 2
0
DataBuffer<float> *ConfigManager::parseFloatSource(){
    
    DataBuffer<float> *b;
    char buf[256];
    
    switch(tok.getnext()){
    case T_VAR:
        tok.getnextident(buf);
        b = DataManager::findFloatBuffer(buf);
        if(!b)
            throw ParseException(&tok).set("undefined variable '%s'",buf);
        break;
    case T_EXPR:
        tok.getnextstring(buf);
        // OK, we're going to lose a reference to this, but such is life.
        // In this version we never delete expressions anyway.
        try {
            b = (new Expression(buf))->buffer;
        } catch(Exception& e){
            throw Exception(e,tok.getline());
        }
        // now parse the extra bits
        tok.getnextcheck(T_RANGE);
        float mn,mx;
        switch(tok.getnext()){
        case T_INT:
        case T_FLOAT:
            mn = tok.getfloat();
            tok.getnextcheck(T_TO);
            mx = tok.getnextfloat();
            b->setMinMax(mn,mx);
            break;
        case T_AUTO:
            b->setAutoRange();
            break;
        default:
            throw UnexpException(&tok,"expected number or 'auto'");
        }
        break;
    default:
        throw UnexpException(&tok,"'var' or 'expr'");
    }
    return b;
}