Example #1
0
File: Gro.cpp Project: fmenol/gro
Value * add_reaction ( std::list<Value *> * args, Scope * s ) {

    World * world = current_gro_program->get_world();

    // args are: reactants, products, rate
    std::list<Value *>::iterator i = args->begin();
    Value * R = *i; i++;
    Value * P = *i; i++;
    Value * k = *i;

    Reaction r (k->num_value());

    for ( i=R->list_value()->begin(); i != R->list_value()->end(); i++ ) {
        if ( (*i)->int_value() < 0 || (*i)->int_value() >= world->num_signals() )
            throw std::string ( "Reaction refers to a non-existant reactant." );
        r.add_reactant( (*i)->int_value() );
    }

    for ( i=P->list_value()->begin(); i != P->list_value()->end(); i++ ) {
        if ( (*i)->int_value() < 0 || (*i)->int_value() >= world->num_signals() )
            throw std::string ( "Reaction refers to a non-existant product." );
        r.add_product( (*i)->int_value() );
    }

    world->add_reaction(r);

    return new Value ( Value::UNIT );

}